Documentation ¶
Index ¶
- Constants
- Variables
- func ToCheckPointBSON(checkPoint *model.CheckPoint) bson.M
- type ClientDoc
- type CollectionDoc
- type CounterDoc
- type DatatypeDoc
- func (its *DatatypeDoc) AddNewClient(cuid string, typ int8, ro bool) *SubscribedClientDoc
- func (its *DatatypeDoc) GetClientInDatatypeDoc(cuid string, ro bool) *SubscribedClientDoc
- func (its *DatatypeDoc) GetIndexModel() []mongo.IndexModel
- func (its *DatatypeDoc) GetType() model.TypeOfDatatype
- func (its *DatatypeDoc) HasClientInfo(cuid string) string
- func (its *DatatypeDoc) String() string
- func (its *DatatypeDoc) ToUpdateBSON() bson.D
- type Filter
- type MongoDBDoc
- type OpID
- type OperationDoc
- type SnapshotDoc
- type SseqSet
- type SubscribedClientDoc
- type UpdatedDatatypeDoc
Constants ¶
const ( RWClient = "rw" ROClient = "ro" NoClient = "no" )
XXClient is used to return the type of client
const ( CollectionNameColNumGenerator = "-_-ColNumGenerator" CollectionNameClients = "-_-Clients" CollectionNameCollections = "-_-Collections" CollectionNameDatatypes = "-_-Datatypes" CollectionNameOperations = "-_-Operations" CollectionNameSnapshot = "-_-Snapshots" )
CollectionNameXXXX is the name of the collection for XXXX
const (
// ID is an identifier of MongoDB
ID = "_id"
)
Variables ¶
var ClientDocFields = struct { CUID string Alias string CollectionNum string Type string SyncType string CreatedAt string UpdatedAt string }{ CUID: "_id", Alias: "alias", CollectionNum: "colNum", Type: "type", SyncType: "syncType", CreatedAt: "createdAt", UpdatedAt: "updatedAt", }
ClientDocFields defines the fields of ClientDoc
var CollectionDocFields = struct { Name string Num string CreatedAt string }{ Name: "_id", Num: "num", CreatedAt: "createdAt", }
CollectionDocFields defines the fields of CollectionDoc
var CounterDocFields = struct { ID string Num string }{ ID: "_id", Num: "num", }
CounterDocFields defines the fields of CounterDoc
var DatatypeDocFields = struct { DUID string Key string CollectionNum string Type string SseqBegin string SseqEnd string SseqSafe string Visible string CreatedAt string UpdatedAt string }{ DUID: "_id", Key: "key", CollectionNum: "colNum", Type: "type", SseqBegin: "sseqBegin", SseqEnd: "sseqEnd", SseqSafe: "sseqSafe", Visible: "visible", CreatedAt: "createdAt", UpdatedAt: "updatedAt", }
DatatypeDocFields defines the fields of DatatypeDoc
var OperationDocFields = struct { ID string DUID string CollectionNum string OpType string Sseq string Operation string CreatedAt string }{ ID: "_id", DUID: "duid", CollectionNum: "colNum", OpType: "type", Sseq: "sseq", Operation: "op", CreatedAt: "createdAt", }
OperationDocFields defines the fields of OperationDoc
var SnapshotDocFields = struct { ID string CollectionNum string DUID string Sseq string Meta string Snapshot string CreatedAt string }{ ID: "_id", CollectionNum: "colNum", DUID: "duid", Sseq: "sseq", Meta: "meta", Snapshot: "snapshot", CreatedAt: "createdAt", }
SnapshotDocFields defines the fields of SnapshotDoc
var (
UpsertOption = &options.UpdateOptions{
Upsert: &upsert,
}
)
options
Functions ¶
func ToCheckPointBSON ¶
func ToCheckPointBSON(checkPoint *model.CheckPoint) bson.M
ToCheckPointBSON is a function to change a checkpoint to BSON
Types ¶
type ClientDoc ¶
type ClientDoc struct { CUID string `bson:"_id"` Alias string `bson:"alias"` CollectionNum int32 `bson:"colNum"` Type int8 `bson:"type"` SyncType int8 `bson:"syncType"` CreatedAt time.Time `bson:"createdAt"` UpdatedAt time.Time `bson:"updatedAt"` }
ClientDoc defines the document for client, stored in MongoDB.
func ClientModelToBson ¶
ClientModelToBson returns a ClientDoc from a model.Client
func (*ClientDoc) GetIndexModel ¶
func (its *ClientDoc) GetIndexModel() []mongo.IndexModel
GetIndexModel returns the index models of ClientDoc
func (*ClientDoc) GetType ¶
func (its *ClientDoc) GetType() model.ClientType
GetType returns model.ClientType
func (*ClientDoc) ToUpdateBSON ¶
ToUpdateBSON returns a bson from a ClientDoc
type CollectionDoc ¶
type CollectionDoc struct { Name string `bson:"_id"` Num int32 `bson:"num"` CreatedAt time.Time `bson:"createdAt"` }
CollectionDoc defines the document of Collections collection, stored in MongoDB. More specifically, it stores a number associated to the collection.
func (*CollectionDoc) GetIndexModel ¶
func (its *CollectionDoc) GetIndexModel() []mongo.IndexModel
GetIndexModel returns the index models of CollectionDoc
func (*CollectionDoc) GetSummary ¶
func (its *CollectionDoc) GetSummary() string
GetSummary returns the summary of CollectionDoc
type CounterDoc ¶
CounterDoc defines a document for counter stored in MongoDB. Counter is used to assign number to a collection
type DatatypeDoc ¶
type DatatypeDoc struct { DUID string `json:"_id" bson:"_id"` UpdatedDatatypeDoc `json:",inline" bson:",inline"` }
DatatypeDoc defines a MongoDB document for datatype, stored in MongoDB
func NewDatatypeDoc ¶
func NewDatatypeDoc(duid, key string, colNum int32, typ string) *DatatypeDoc
NewDatatypeDoc returns a new DatatypeDoc
func (*DatatypeDoc) AddNewClient ¶
func (its *DatatypeDoc) AddNewClient(cuid string, typ int8, ro bool) *SubscribedClientDoc
AddNewClient adds a new RWClient
func (*DatatypeDoc) GetClientInDatatypeDoc ¶
func (its *DatatypeDoc) GetClientInDatatypeDoc(cuid string, ro bool) *SubscribedClientDoc
GetClientInDatatypeDoc returns SubscribedClientDoc
func (*DatatypeDoc) GetIndexModel ¶
func (its *DatatypeDoc) GetIndexModel() []mongo.IndexModel
GetIndexModel returns the index models of the collection of ClientDoc
func (*DatatypeDoc) GetType ¶
func (its *DatatypeDoc) GetType() model.TypeOfDatatype
GetType returns the type of datatype.
func (*DatatypeDoc) HasClientInfo ¶
func (its *DatatypeDoc) HasClientInfo(cuid string) string
HasClientInfo examines if the client info of cuid exists, and returns the client type
func (*DatatypeDoc) String ¶
func (its *DatatypeDoc) String() string
func (*DatatypeDoc) ToUpdateBSON ¶
func (its *DatatypeDoc) ToUpdateBSON() bson.D
ToUpdateBSON transforms DatatypeDoc to BSON type
type Filter ¶
Filter is the type used to filter
func FilterByID ¶
func FilterByID(id interface{}) Filter
FilterByID returns an instance of Filter of ID
func FilterByName ¶
FilterByName returns an instance of Filter of Name
func (Filter) AddFilterEQ ¶
AddFilterEQ is a function to add EQ to Filter
func (Filter) AddFilterGTE ¶
AddFilterGTE is a function to add GTE to Filter
func (Filter) AddFilterLTE ¶
AddFilterLTE is a function to add LTE to Filter
type MongoDBDoc ¶
type MongoDBDoc interface {
GetIndexModel() []mongo.IndexModel
}
MongoDBDoc is an interface for documents stored in MongoDB
type OpID ¶
type OpID struct { Era uint32 `bson:"era"` Lamport uint64 `bson:"lamport"` CUID string `bson:"cuid"` Seq uint64 `bson:"seq"` }
OpID is used to denote the operation ID in MongoDB
type OperationDoc ¶
type OperationDoc struct { ID string `bson:"_id"` DUID string `bson:"duid"` CollectionNum int32 `bson:"colNum"` OpType string `bson:"type"` OpID OpID `bson:"id"` Sseq uint64 `bson:"sseq"` Body []byte `bson:"body"` CreatedAt time.Time `bson:"createdAt"` }
OperationDoc defines a document for operation, stored in MongoDB
func NewOperationDoc ¶
NewOperationDoc creates a new OperationDoc with the given parameters
func (*OperationDoc) GetIndexModel ¶
func (its *OperationDoc) GetIndexModel() []mongo.IndexModel
GetIndexModel returns the index models of the collection of OperationDoc
func (*OperationDoc) GetOperation ¶
func (its *OperationDoc) GetOperation() *model.Operation
GetOperation returns a model.Operation by composing parameters of OperationDoc.
type SnapshotDoc ¶
type SnapshotDoc struct { ID string `bson:"_id"` CollectionNum int32 `bson:"colNum"` DUID string `bson:"duid"` Sseq uint64 `bson:"sseq"` Meta string `bson:"meta"` Snapshot []byte `bson:"snapshot"` CreatedAt time.Time `bson:"createdAt"` }
SnapshotDoc defines the document for snapshot, stored in MongoDB
func (*SnapshotDoc) GetIndexModel ¶
func (c *SnapshotDoc) GetIndexModel() []mongo.IndexModel
GetIndexModel returns the index models of the collection of SnapshotDoc
func (*SnapshotDoc) ToInsertBSON ¶
func (c *SnapshotDoc) ToInsertBSON() bson.M
ToInsertBSON transforms SnapshotDoc to BSON type
type SseqSet ¶
type SseqSet struct { Begin uint64 `json:"begin" bson:"begin"` End uint64 `json:"end" bson:"end"` Safe uint64 `json:"safe" bson:"safe"` }
SseqSet is a set of Sseq(Server Sequence)
type SubscribedClientDoc ¶
type SubscribedClientDoc struct { CP *model.CheckPoint `bson:"cp"` Type int8 `bson:"t"` At time.Time `bson:"at"` }
SubscribedClientDoc contains the information of a Client
func (*SubscribedClientDoc) GetCheckPoint ¶
func (its *SubscribedClientDoc) GetCheckPoint() *model.CheckPoint
GetCheckPoint returns *model.CheckPoint from SubscribedClientDoc
func (*SubscribedClientDoc) UpdateAt ¶
func (its *SubscribedClientDoc) UpdateAt()
UpdateAt updates at with current time
type UpdatedDatatypeDoc ¶
type UpdatedDatatypeDoc struct { Key string `json:"key" bson:"key"` CollectionNum int32 `json:"colNum" bson:"colNum"` Type string `json:"type" bson:"type"` Sseq SseqSet `json:"sseq" bson:"sseq"` // SseqBegin uint64 `json:"sseqBegin" bson:"sseqBegin"` // SseqEnd uint64 `json:"sseqEnd" bson:"sseqEnd"` // SseqSafe uint64 `json:"sseqSafe" bson:"sseqSafe"` Visible bool `json:"visible" bson:"visible"` CreatedAt time.Time `json:"createdAt" bson:"createdAt"` UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` RWClients map[string]*SubscribedClientDoc `json:"rwClients" bson:"rwClients"` ROClients map[string]*SubscribedClientDoc `json:"roClients" bson:"roClients"` }
UpdatedDatatypeDoc defines a MongoDB document for datatype, which are updated