| // 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/syncbase/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. |
| 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. |
| 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. |
| 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 object. |
| 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 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 DeltaReq struct { |
| AppName string |
| DbName string |
| SgIds set[GroupId] |
| InitVec GenVector |
| } |
| |
| // 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 { |
| Start bool |
| Finish bool |
| 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 |
| } |