blob: aa79fa518fdd417e8c7c33e34423526bcc262bf2 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package interfaces
import (
"time"
wire "v.io/v23/services/syncbase/nosql"
)
const (
NoGroupId = GroupId(0)
)
// TODO(hpucha): These are not final yet. This is an intermediate step.
const (
// NodeRec type log record adds a new node in the dag.
NodeRec = byte(0)
// LinkRec type log record adds a new link in the dag. Link records are
// added when a conflict is resolved by picking the local or the remote
// version as the resolution of a conflict, instead of creating a new
// version.
LinkRec = byte(1)
)
// PrefixGenVector is the generation vector for a data prefix, which maps each
// device id to its last locally known generation in the scope of that prefix.
// TODO(hpucha): Rename this type.
type PrefixGenVector map[uint64]uint64
// GenVector is the generation vector for a Database, and maps prefixes to their
// generation vectors. Note that the prefixes in a GenVector are relative to the
// the Application and Database name.
type GenVector map[string]PrefixGenVector
// LogRecMetadata represents the metadata of a single log record that is
// exchanged between two peers. Each log record represents a change made to an
// object in the store.
//
// TODO(hpucha): Add readset/scanset. Look into sending tx metadata only once
// per transaction.
type LogRecMetadata struct {
// Log related information.
Id uint64 // device id that created the log record.
Gen uint64 // generation number for the log record.
RecType byte // type of log record.
// Object related information.
// Id of the object that was updated. This id is relative to Application
// and Database names and is the store key for a particular row in a
// table.
ObjId string
CurVers string // current version number of the object.
Parents []string // 0, 1 or 2 parent versions that the current version is derived from.
UpdTime time.Time // timestamp when the update is generated.
PermId string // id of the permissions object controlling this version.
PermVers string // current version of the permissions object.
Shell bool // true when the mutation data is hidden due to permissions.
Delete bool // indicates whether the update resulted in object being deleted from the store.
BatchId uint64 // unique id of the Batch this update belongs to.
BatchCount uint64 // number of objects in the Batch.
}
// LogRec represents the on-wire representation of an entire log record: its
// metadata and data. Value is the actual value of a store object.
type LogRec struct {
Metadata LogRecMetadata
Value []byte
}
// GroupId is a globally unique syncgroup ID.
// TODO(hpucha): Make this a string since now the syncgroup id is an object id.
type GroupId uint64
// Possible states for a syncgroup.
type SyncgroupStatus enum {
// Indicates that a syncgroup is operational, but publishing to the
// remote server is pending.
PublishPending
// Indicates that the syncgroup is operational, but the publishing
// failed.
PublishRejected
// Indicates that the syncgroup is operational and published.
Running
}
// Syncgroup contains the state of a syncgroup.
type Syncgroup struct {
Id GroupId // globally unique identifier generated by Syncbase
Name string // globally unique Vanadium name chosen by app
SpecVersion string // version on syncgroup spec for concurrency control
Spec wire.SyncgroupSpec // app-given specification
Creator string // Creator's Vanadium name
AppName string // Globally unique App name
DbName string // Database name within the App
Status SyncgroupStatus // Status of the syncgroup
Joiners map[string]wire.SyncgroupMemberInfo // map of joiners to their metadata
}
// DeltaReq contains a request to sync either data or syncgroup metadata for a
// Database.
type DeltaReq union {
Sgs SgDeltaReq
Data DataDeltaReq
}
// DataDeltaReq contains the initiator's genvector and the set of syncgroups it
// is interested in within a Database (specified by the AppName/DbName) when
// requesting deltas for that Database.
type DataDeltaReq struct {
AppName string
DbName string
SgIds set[GroupId]
InitVec GenVector
}
// SgDeltaReq contains the initiator's genvector for the syncgroups it is
// interested in within a Database (specified by the AppName/DbName) when
// requesting deltas for those syncgroups.
type SgDeltaReq struct {
AppName string
DbName string
InitVec GenVector // Contains a genvector per syncgroup.
}
// DeltaResp contains the responder's genvector or the missing log records
// returned in response to an initiator's request for deltas for a Database.
type DeltaResp union {
Rec LogRec
RespVec GenVector
}
// ChunkHash contains the hash of a chunk that is part of a blob's recipe.
type ChunkHash struct {
Hash []byte
}
// ChunkData contains the data of a chunk.
type ChunkData struct {
Data []byte
}
// TimeReq contains the send timestamp from the requester.
type TimeReq struct {
SendTs time.Time
}
// TimeResp contains timestamps needed by the requester to correctly estimate
// the difference between the two clocks along with clock metadata required
// by the requester to decide which clock is more accurate.
type TimeResp struct {
// The send timestamp received in TimeReq from the originator.
OrigTs time.Time
// Time when the request was received.
RecvTs time.Time
// Time when the response was sent.
SendTs time.Time
// Timestamp received from NTP during last NTP sync. The last NTP sync could
// be done either by this device or some other device that this device
// synced its clock with.
LastNtpTs ?time.Time
// Number of reboots since last NTP sync.
NumReboots uint16
// Number of hops between this device and the device that did the last
// NTP sync.
NumHops uint16
}