| // 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 vsync |
| |
| import ( |
| "v.io/x/ref/services/syncbase/server/interfaces" |
| ) |
| |
| // SyncData represents the persistent state of the sync module. |
| type SyncData struct { |
| Id uint64 |
| } |
| |
| // DbSyncState represents the persistent sync state of a Database. |
| type DbSyncState struct { |
| GenVecs interfaces.Knowledge // knowledge capturing the locally-known generations of remote peers for data in Database. |
| SgGenVecs interfaces.Knowledge // knowledge capturing the locally-known generations of remote peers for syncgroups in Database. |
| IsPaused bool // tracks whether sync is paused by client. |
| } |
| |
| // LocalLogRec represents the persistent local state of a log record. Metadata |
| // is synced across peers, while pos is local-only. |
| type LocalLogRec struct { |
| Metadata interfaces.LogRecMetadata |
| Pos uint64 // position in the Database log. |
| } |
| |
| // SgLocalState holds the syncgroup local state, only relevant to this member |
| // (i.e. the local Syncbase). This is needed for crash recovery of the internal |
| // state transitions of the syncgroup. |
| type SgLocalState struct { |
| // The count of local joiners to the same syncgroup. |
| NumLocalJoiners uint32 |
| |
| // The syncgroup is watched when the sync Watcher starts processing the |
| // syncgroup data. When a syncgroup is created or joined, an entry is |
| // added to the Watcher queue (log) to inform it from which point to |
| // start accepting store mutations, an asynchronous notification similar |
| // to regular store mutations. When the Watcher processes that queue |
| // entry, it sets this bit to true. When Syncbase restarts, the value |
| // of this bit allows the new sync Watcher to recreate its in-memory |
| // state by resuming to watch only the prefixes of syncgroups that were |
| // previously being watched. |
| Watched bool |
| |
| // The syncgroup was published here by this remote peer (if non-empty |
| // string), typically the syncgroup creator. In this case the syncgroup |
| // cannot be GCed locally even if it has no local joiners. |
| RemotePublisher string |
| |
| // The syncgroup is in pending state on a device that learns the current |
| // state of the syncgroup from another device but has not yet received |
| // through peer-to-peer sync the history of the changes (DAG and logs). |
| // This happens in two cases: |
| // 1- A joiner was accepted into a syncgroup by a syncgroup admin and |
| // only given the current syncgroup info synchronously and will |
| // receive the full history later via p2p sync. |
| // 2- A remote server where the syncgroup is published was told by the |
| // syncgroup publisher the current syncgroup info synchronously and |
| // will receive the full history later via p2p sync. |
| // The pending state is over when the device reaches or exceeds the |
| // knowledge level indicated in the pending genvec. While SyncPending |
| // is true, no local syncgroup mutations are allowed (i.e. no join or |
| // set-spec requests). |
| SyncPending bool |
| PendingGenVec interfaces.GenVector |
| } |
| |
| // DagNode holds the information on an object mutation in the DAG. The node |
| // information is extracted from the log records exchanged between Syncbases. |
| // They are also stored in the DAG node to improve DAG traversal for conflict |
| // resolution and pruning without having to fetch the full log record. |
| type DagNode struct { |
| Level uint64 // node distance from root |
| Parents []string // references to parent versions |
| Logrec string // reference to log record |
| BatchId uint64 // ID of a write batch |
| Deleted bool // true if the change was a delete |
| PermId string // ID of the permissions controlling this version |
| PermVers string // current version of the permissions object |
| } |
| |
| // BatchInfo holds the information on a write batch: |
| // * The map of syncable (versioned) objects: {oid: version} |
| // * The map of linked objects {oid: version} that were not explicitly written |
| // as part of the batch but were reaffirmed during conflict resolution along |
| // with other objects written in this batch by the app by choosing |
| // "pickLocal" or "pickRemote". NOTE: this map is non empty only for batches |
| // created during conflict resolution. Unlike the Objects map, the collection |
| // of oid:version present in this map do not point back to this batch. They |
| // point to the batches that there were originally created in. |
| // * The total count of batch objects, including non-syncable ones. |
| // TODO(rdaoud): add support to track the read and scan sets. |
| type BatchInfo struct { |
| Objects map[string]string |
| LinkedObjects map[string]string |
| Count uint64 |
| } |