db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientDeactivated = "deactivated"
	ClientActivated   = "activated"
)

Below are statuses of the client.

Variables

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

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

Functions

func EncodeOperations

func EncodeOperations(operations []operation.Operation) ([][]byte, error)

EncodeOperations encodes the given operations into bytes array.

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.

func (*ChangeInfo) ToChange

func (i *ChangeInfo) ToChange() (*change.Change, error)

ToChange creates Change model from this ChangeInfo.

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)

	// CreateChangeInfos stores the given changes.
	CreateChangeInfos(ctx context.Context, docID ID, changes []*change.Change) error

	// CreateSnapshotInfo stores the snapshot of the given document.
	CreateSnapshotInfo(ctx context.Context, docID ID, doc *document.InternalDocument) error

	// UpdateDocInfo updates the given document.
	UpdateDocInfo(ctx context.Context, docInfo *DocInfo) 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) GetKey

func (info *DocInfo) GetKey() (*key.Key, error)

GetKey creates Key instance of this DocInfo.

func (*DocInfo) IncreaseServerSeq

func (info *DocInfo) IncreaseServerSeq() uint64

IncreaseServerSeq increases server sequence of the document.

type ID

type ID string

ID represents ID of entity.

func (ID) String

func (id ID) String() string

String returns a string representation of this ID.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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