schema

package
v0.0.0-...-cc9b1f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RWClient = "rw"
	ROClient = "ro"
	NoClient = "no"
)

XXClient is used to return the type of client

View Source
const (
	CollectionNameColNumGenerator = "-_-ColNumGenerator"
	CollectionNameClients         = "-_-Clients"
	CollectionNameCollections     = "-_-Collections"
	CollectionNameDatatypes       = "-_-Datatypes"
	CollectionNameOperations      = "-_-Operations"
	CollectionNameSnapshot        = "-_-Snapshots"
)

CollectionNameXXXX is the name of the collection for XXXX

View Source
const (
	// ID is an identifier of MongoDB
	ID = "_id"
)

Variables

View Source
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

View Source
var CollectionDocFields = struct {
	Name      string
	Num       string
	CreatedAt string
}{
	Name:      "_id",
	Num:       "num",
	CreatedAt: "createdAt",
}

CollectionDocFields defines the fields of CollectionDoc

View Source
var CounterDocFields = struct {
	ID  string
	Num string
}{
	ID:  "_id",
	Num: "num",
}

CounterDocFields defines the fields of CounterDoc

View Source
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

View Source
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

View Source
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

View Source
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

func ClientModelToBson(model *model.Client, collectionNum int32) *ClientDoc

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) GetModel

func (its *ClientDoc) GetModel() *model.Client

GetModel returns model.Client

func (*ClientDoc) GetType

func (its *ClientDoc) GetType() model.ClientType

GetType returns model.ClientType

func (*ClientDoc) String

func (its *ClientDoc) String() string

func (*ClientDoc) ToString

func (its *ClientDoc) ToString() string

ToString returns ClientDoc string

func (*ClientDoc) ToUpdateBSON

func (its *ClientDoc) ToUpdateBSON() bson.D

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

type CounterDoc struct {
	ID  string `bson:"_id"`
	Num int32  `bson:"num"`
}

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

type Filter bson.D

Filter is the type used to filter

func FilterByID

func FilterByID(id interface{}) Filter

FilterByID returns an instance of Filter of ID

func FilterByName

func FilterByName(name string) Filter

FilterByName returns an instance of Filter of Name

func GetFilter

func GetFilter() Filter

GetFilter returns an instance of Filter

func (Filter) AddExists

func (b Filter) AddExists(key string) Filter

AddExists adds the Filter which examines the existence of the key

func (Filter) AddFilterEQ

func (b Filter) AddFilterEQ(key string, value interface{}) Filter

AddFilterEQ is a function to add EQ to Filter

func (Filter) AddFilterGTE

func (b Filter) AddFilterGTE(key string, from interface{}) Filter

AddFilterGTE is a function to add GTE to Filter

func (Filter) AddFilterLTE

func (b Filter) AddFilterLTE(key string, to interface{}) Filter

AddFilterLTE is a function to add LTE to Filter

func (Filter) AddSnapshot

func (b Filter) AddSnapshot(data bson.M) Filter

AddSnapshot adds a snapshot value

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

func NewOperationDoc(op *model.Operation, duid string, sseq uint64, colNum int32) *OperationDoc

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL