Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeOperations(operations []operation.Operation) ([][]byte, error)
- type ChangeInfo
- type ClientDocInfo
- type ClientInfo
- func (i *ClientInfo) AttachDocument(docID ID) error
- func (i *ClientInfo) Checkpoint(docID ID) *checkpoint.Checkpoint
- func (i *ClientInfo) DetachDocument(docID ID) error
- func (i *ClientInfo) EnsureDocumentAttached(docID ID) error
- func (i *ClientInfo) IsAttached(docID ID) (bool, error)
- func (i *ClientInfo) UpdateCheckpoint(docID ID, cp *checkpoint.Checkpoint) error
- type DB
- type DocInfo
- type ID
- type SnapshotInfo
- type SyncedSeqInfo
Constants ¶
const ( ClientDeactivated = "deactivated" ClientActivated = "activated" )
Below are statuses of the client.
Variables ¶
var ( ErrClientNotActivated = errors.New("client not activated") ErrDocumentNotAttached = errors.New("document not attached") ErrDocumentNeverAttached = errors.New("client has never attached the document") ErrDocumentAlreadyAttached = errors.New("document already attached") )
Below are the errors may occur depending on the document and client status.
var ( // ErrInvalidID is returned when the given ID is not ObjectID. ErrInvalidID = errors.New("invalid ID") // ErrClientNotFound is returned when the client could not be found. ErrClientNotFound = errors.New("client not found") // ErrDocumentNotFound is returned when the document could not be found. ErrDocumentNotFound = errors.New("document not found") // ErrConflictOnUpdate is returned when a conflict occurs during update. ErrConflictOnUpdate = errors.New("conflict on update") )
Functions ¶
Types ¶
type ChangeInfo ¶
type ChangeInfo struct { DocID ID `bson:"doc_id_fake"` ServerSeq uint64 `bson:"server_seq"` ClientSeq uint32 `bson:"client_seq"` Lamport uint64 `bson:"lamport"` Actor ID `bson:"actor_fake"` Message string `bson:"message"` Operations [][]byte `bson:"operations"` }
ChangeInfo is a structure representing information of a change.
type ClientDocInfo ¶
type ClientDocInfo struct { Status string `bson:"status"` ServerSeq uint64 `bson:"server_seq"` ClientSeq uint32 `bson:"client_seq"` }
ClientDocInfo is a structure representing information of the document attached to the client.
type ClientInfo ¶
type ClientInfo struct { ID ID `bson:"_id_fake"` Key string `bson:"key"` Status string `bson:"status"` Documents map[ID]*ClientDocInfo `bson:"documents"` CreatedAt time.Time `bson:"created_at"` UpdatedAt time.Time `bson:"updated_at"` }
ClientInfo is a structure representing information of a client.
func (*ClientInfo) AttachDocument ¶
func (i *ClientInfo) AttachDocument(docID ID) error
AttachDocument attaches the given document to this client.
func (*ClientInfo) Checkpoint ¶
func (i *ClientInfo) Checkpoint(docID ID) *checkpoint.Checkpoint
Checkpoint returns the checkpoint of the given document.
func (*ClientInfo) DetachDocument ¶
func (i *ClientInfo) DetachDocument(docID ID) error
DetachDocument detaches the given document from this client.
func (*ClientInfo) EnsureDocumentAttached ¶
func (i *ClientInfo) EnsureDocumentAttached(docID ID) error
EnsureDocumentAttached ensures the given document is attached.
func (*ClientInfo) IsAttached ¶
func (i *ClientInfo) IsAttached(docID ID) (bool, error)
IsAttached returns whether the given document is attached to this client.
func (*ClientInfo) UpdateCheckpoint ¶
func (i *ClientInfo) UpdateCheckpoint( docID ID, cp *checkpoint.Checkpoint, ) error
UpdateCheckpoint updates the checkpoint of the given document.
type DB ¶
type DB interface { // Close all resources of this database. Close() error // ActivateClient activates the client of the given key. ActivateClient(ctx context.Context, key string) (*ClientInfo, error) // DeactivateClient deactivates the client of the given ID. DeactivateClient(ctx context.Context, clientID ID) (*ClientInfo, error) // FindClientInfoByID finds the client of the given ID. FindClientInfoByID(ctx context.Context, clientID ID) (*ClientInfo, error) // UpdateClientInfoAfterPushPull updates the client from the given clientInfo // after handling PushPull. UpdateClientInfoAfterPushPull(ctx context.Context, clientInfo *ClientInfo, docInfo *DocInfo) error // FindDocInfoByKey finds the document of the given key. If the // createDocIfNotExist condition is true, create the document if it does not // exist. FindDocInfoByKey( ctx context.Context, clientInfo *ClientInfo, bsonDocKey string, createDocIfNotExist bool, ) (*DocInfo, error) // StoreChangeInfos stores the given changes then updates the given docInfo. StoreChangeInfos( ctx context.Context, docInfo *DocInfo, initialServerSeq uint64, changes []*change.Change, ) error // CreateSnapshotInfo stores the snapshot of the given document. CreateSnapshotInfo(ctx context.Context, docID ID, doc *document.InternalDocument) error // FindChangeInfosBetweenServerSeqs returns the changes between two server sequences. FindChangeInfosBetweenServerSeqs( ctx context.Context, docID ID, from uint64, to uint64, ) ([]*change.Change, error) // UpdateAndFindMinSyncedTicket updates the given serverSeq of the given client // and returns the min synced ticket. UpdateAndFindMinSyncedTicket( ctx context.Context, clientInfo *ClientInfo, docID ID, serverSeq uint64, ) (*time.Ticket, error) // FindLastSnapshotInfo finds the last snapshot of the given document. FindLastSnapshotInfo(ctx context.Context, docID ID) (*SnapshotInfo, error) }
DB represents database which reads or saves Yorkie data.
type DocInfo ¶
type DocInfo struct { ID ID `bson:"_id_fake"` Key string `bson:"key"` ServerSeq uint64 `bson:"server_seq"` Owner ID `bson:"owner_fake"` CreatedAt time.Time `bson:"created_at"` AccessedAt time.Time `bson:"accessed_at"` UpdatedAt time.Time `bson:"updated_at"` }
DocInfo is a structure representing information of the document.
func (*DocInfo) IncreaseServerSeq ¶
IncreaseServerSeq increases server sequence of the document.
type ID ¶
type ID string
ID represents ID of entity.
func IDFromBytes ¶ added in v0.1.2
IDFromBytes returns ID represented by the encoded hexadecimal string from bytes.
type SnapshotInfo ¶
type SnapshotInfo struct { ID ID `bson:"_id_fake"` DocID ID `bson:"doc_id_fake"` ServerSeq uint64 `bson:"server_seq"` Snapshot []byte `bson:"snapshot"` CreatedAt time.Time `bson:"created_at"` }
SnapshotInfo is a structure representing information of the snapshot.
type SyncedSeqInfo ¶
type SyncedSeqInfo struct { DocID ID `bson:"doc_id_fake"` ClientID ID `bson:"client_id_fake"` ServerSeq uint64 `bson:"server_seq"` }
SyncedSeqInfo is a structure representing information about the synchronized sequence for each client.