packs

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package packs implements PushPullPack which is used to sync the document between the client and the server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidServerSeq is returned when the given server seq greater than
	// the initial server seq.
	ErrInvalidServerSeq = errors.New("invalid server seq")
)

Functions

func BuildDocumentForServerSeq

func BuildDocumentForServerSeq(
	ctx context.Context,
	be *backend.Backend,
	docInfo *database.DocInfo,
	serverSeq int64,
) (*document.InternalDocument, error)

BuildDocumentForServerSeq returns a new document for the given serverSeq.

func FindChanges added in v0.2.11

func FindChanges(
	ctx context.Context,
	be *backend.Backend,
	docInfo *database.DocInfo,
	from int64,
	to int64,
) ([]*change.Change, error)

FindChanges fetches changes of the given document.

func PushPullKey

func PushPullKey(projectID types.ID, docKey key.Key) sync.Key

PushPullKey creates a new sync.Key of PushPull for the given document.

func SnapshotKey

func SnapshotKey(projectID types.ID, docKey key.Key) sync.Key

SnapshotKey creates a new sync.Key of Snapshot for the given document.

Types

type ServerPack

type ServerPack struct {
	// DocumentKey is key of the document.
	DocumentKey key.Key

	// Checkpoint is used to determine the client received changes.
	Checkpoint change.Checkpoint

	// ChangeInfos represents a unit of modification in the document.
	ChangeInfos []*database.ChangeInfo

	// Snapshot is a byte array that encode the document.
	Snapshot []byte

	// MinSyncedTicket is the minimum logical time taken by clients who attach the document.
	// It used to collect garbage on the replica on the client.
	MinSyncedTicket *time.Ticket

	// IsRemoved is a flag that indicates whether the document is removed.
	IsRemoved bool
}

ServerPack is similar to change.Pack, but has ChangeInfos instead of Changes to reduce type conversion in Server.

func NewServerPack

func NewServerPack(
	key key.Key,
	cp change.Checkpoint,
	changeInfos []*database.ChangeInfo,
	snapshot []byte,
) *ServerPack

NewServerPack creates a new instance of ServerPack.

func PushPull

func PushPull(
	ctx context.Context,
	be *backend.Backend,
	project *types.Project,
	clientInfo *database.ClientInfo,
	docInfo *database.DocInfo,
	reqPack *change.Pack,
	mode types.SyncMode,
) (*ServerPack, error)

PushPull stores the given changes and returns accumulated changes of the given document.

CAUTION(hackerwins, krapie): docInfo's state is constantly mutating as they are constantly used as parameters in subsequent subroutines.

func (*ServerPack) ApplyDocInfo added in v0.3.3

func (p *ServerPack) ApplyDocInfo(info *database.DocInfo)

ApplyDocInfo applies the given DocInfo to the ServerPack.

func (*ServerPack) ChangesLen

func (p *ServerPack) ChangesLen() int

ChangesLen returns the size of the changes.

func (*ServerPack) OperationsLen

func (p *ServerPack) OperationsLen() int

OperationsLen returns the size of the operations.

func (*ServerPack) SnapshotLen

func (p *ServerPack) SnapshotLen() int

SnapshotLen returns the size of the snapshot.

func (*ServerPack) ToPBChangePack

func (p *ServerPack) ToPBChangePack() (*api.ChangePack, error)

ToPBChangePack converts the given model format to Protobuf format.

Jump to

Keyboard shortcuts

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