change

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package change provides the implementation of Change. Change is a set of operations that can be applied to a document.

Index

Constants

View Source
const (
	// InitialClientSeq is the initial sequence number of the client.
	InitialClientSeq = 0

	// InitialServerSeq is the initial sequence number of the server.
	InitialServerSeq = 0

	// MaxClientSeq is the maximum sequence number of the client.
	MaxClientSeq = math.MaxUint32

	// MaxServerSeq is the maximum sequence number of the server.
	MaxServerSeq = int64(math.MaxInt64)
)
View Source
const (
	// InitialLamport is the initial value of Lamport timestamp.
	InitialLamport = 0
)

Variables

InitialCheckpoint is the initial value of Checkpoint.

View Source
var (
	// InitialID represents the initial state ID. Usually this is used to
	// represent a state where nothing has been edited.
	InitialID = NewID(InitialClientSeq, InitialServerSeq, InitialLamport, time.InitialActorID, time.InitialVersionVector)
)

MaxCheckpoint is the maximum value of Checkpoint.

Functions

This section is empty.

Types

type Change

type Change struct {
	// contains filtered or unexported fields
}

Change represents a unit of modification in the document.

func New

func New(id ID, message string, operations []operations.Operation, p *innerpresence.PresenceChange) *Change

New creates a new instance of Change.

func (*Change) AfterOrEqual added in v0.5.3

func (c *Change) AfterOrEqual(other *Change) bool

AfterOrEqual returns whether this change is after or equal to the given change.

func (*Change) ClientSeq

func (c *Change) ClientSeq() uint32

ClientSeq returns the clientSeq of this change.

func (*Change) Execute

func (c *Change) Execute(root *crdt.Root, presences *innerpresence.Map) error

Execute applies this change to the given JSON root.

func (*Change) ID

func (c *Change) ID() ID

ID returns the ID of this change.

func (*Change) Message

func (c *Change) Message() string

Message returns the message of this change.

func (*Change) Operations

func (c *Change) Operations() []operations.Operation

Operations returns the operations of this change.

func (*Change) PresenceChange added in v0.4.5

func (c *Change) PresenceChange() *innerpresence.PresenceChange

PresenceChange returns the presence change of this change.

func (*Change) ServerSeq

func (c *Change) ServerSeq() int64

ServerSeq returns the serverSeq of this change.

func (*Change) SetActor

func (c *Change) SetActor(actor *time.ActorID)

SetActor sets the given actorID.

func (*Change) SetServerSeq

func (c *Change) SetServerSeq(serverSeq int64)

SetServerSeq sets the given serverSeq.

type Checkpoint added in v0.2.2

type Checkpoint struct {
	// serverSeq is the sequence of the change on the server. We can find the
	// change with serverSeq and documentID in the server. If the change is not
	// stored on the server, serverSeq is 0.
	ServerSeq int64

	// clientSeq is the sequence of the change within the client that made the
	// change.
	ClientSeq uint32
}

Checkpoint is used to determine the client received changes. It is not meant to be used to determine the logical order of changes.

func NewCheckpoint added in v0.2.2

func NewCheckpoint(serverSeq int64, clientSeq uint32) Checkpoint

NewCheckpoint creates a new instance of Checkpoint.

func (Checkpoint) Equals added in v0.2.2

func (cp Checkpoint) Equals(other Checkpoint) bool

Equals returns whether the given checkpoint is equal to this checkpoint or not.

func (Checkpoint) Forward added in v0.2.2

func (cp Checkpoint) Forward(other Checkpoint) Checkpoint

Forward updates the given checkpoint with those values when it is greater than the values of internal properties.

func (Checkpoint) IncreaseClientSeq added in v0.2.2

func (cp Checkpoint) IncreaseClientSeq(inc uint32) Checkpoint

IncreaseClientSeq creates a new instance with increased client sequence.

func (Checkpoint) NextClientSeq added in v0.2.2

func (cp Checkpoint) NextClientSeq() Checkpoint

NextClientSeq creates a new instance with next client sequence.

func (Checkpoint) NextServerSeq added in v0.2.2

func (cp Checkpoint) NextServerSeq(serverSeq int64) Checkpoint

NextServerSeq creates a new instance with next server sequence.

func (Checkpoint) String added in v0.2.2

func (cp Checkpoint) String() string

String returns the string of information about this checkpoint.

func (Checkpoint) SyncClientSeq added in v0.2.2

func (cp Checkpoint) SyncClientSeq(clientSeq uint32) Checkpoint

SyncClientSeq updates the given clientSeq if it is greater than the internal value.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context is used to record the context of modification when editing a document. Each time we add an operation, a new time ticket is issued. Finally, returns a Change after the modification has been completed.

func NewContext

func NewContext(id ID, message string, root *crdt.Root) *Context

NewContext creates a new instance of Context.

func (*Context) HasChange added in v0.4.5

func (c *Context) HasChange() bool

HasChange returns whether this context has changes.

func (*Context) ID

func (c *Context) ID() ID

ID returns ID for new change.

func (*Context) IssueTimeTicket

func (c *Context) IssueTimeTicket() *time.Ticket

IssueTimeTicket creates a time ticket to be used to create a new operation.

func (*Context) LastTimeTicket added in v0.4.0

func (c *Context) LastTimeTicket() *time.Ticket

LastTimeTicket returns the last time ticket issued by this context.

func (*Context) Push

func (c *Context) Push(op operations.Operation)

Push pushes a new operations into context queue.

func (*Context) RegisterElement

func (c *Context) RegisterElement(elem crdt.Element)

RegisterElement registers the given element to the root.

func (*Context) RegisterGCPair added in v0.4.20

func (c *Context) RegisterGCPair(pair crdt.GCPair)

RegisterGCPair registers the given GC pair to the root.

func (*Context) RegisterRemovedElementPair added in v0.1.1

func (c *Context) RegisterRemovedElementPair(parent crdt.Container, deleted crdt.Element)

RegisterRemovedElementPair registers the given element pair to hash table.

func (*Context) SetPresenceChange added in v0.4.5

func (c *Context) SetPresenceChange(presenceChange innerpresence.PresenceChange)

SetPresenceChange sets the presence change of the user who made the change.

func (*Context) ToChange

func (c *Context) ToChange() *Change

ToChange creates a new change of this context.

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID represents the identifier of the change. It is used to identify the change and to order the changes. It is also used to detect the relationship between changes whether they are causally related or concurrent.

func NewID

func NewID(
	clientSeq uint32,
	serverSeq int64,
	lamport int64,
	actorID *time.ActorID,
	versionVector time.VersionVector,
) ID

NewID creates a new instance of ID.

func (ID) ActorID added in v0.2.2

func (id ID) ActorID() *time.ActorID

ActorID returns the actorID of this ID.

func (ID) AfterOrEqual added in v0.5.3

func (id ID) AfterOrEqual(other ID) bool

AfterOrEqual returns whether this ID is causally after or equal the given ID.

func (ID) ClientSeq

func (id ID) ClientSeq() uint32

ClientSeq returns the client sequence of this ID.

func (ID) Lamport

func (id ID) Lamport() int64

Lamport returns the lamport clock of this ID.

func (ID) NewTimeTicket

func (id ID) NewTimeTicket(delimiter uint32) *time.Ticket

NewTimeTicket creates a ticket of the given delimiter.

func (ID) Next

func (id ID) Next() ID

Next creates a next ID of this ID.

func (ID) ServerSeq added in v0.2.2

func (id ID) ServerSeq() int64

ServerSeq returns the server sequence of this ID.

func (ID) SetActor

func (id ID) SetActor(actor *time.ActorID) ID

SetActor sets actorID.

func (ID) SetClocks added in v0.5.3

func (id ID) SetClocks(otherLamport int64, vector time.VersionVector) ID

SetClocks sets the given clocks to this ID. This is used when the snapshot is given from the server.

func (ID) SetServerSeq added in v0.2.2

func (id ID) SetServerSeq(serverSeq int64) ID

SetServerSeq sets server sequence of this ID.

func (ID) SetVersionVector added in v0.5.3

func (id ID) SetVersionVector(vector time.VersionVector) ID

SetVersionVector sets version vector

func (ID) SyncClocks added in v0.5.3

func (id ID) SyncClocks(other ID) ID

SyncClocks syncs logical clocks with the given ID.

func (ID) VersionVector added in v0.5.3

func (id ID) VersionVector() time.VersionVector

VersionVector returns the version vector of this ID.

type Pack

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

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

	// Change represents a unit of modification in the document.
	Changes []*Change

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

	// VersionVector represents two vectors of the document.
	// 1. In request, it is the version vector of the document on the client.
	// 2. In response(Snapshot), it is the version vector of the snapshot of the document.
	VersionVector time.VersionVector

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

	// TODO(hackerwins): This field is deprecated.
	// 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
}

Pack is a unit for delivering changes in a document to the remote.

func NewPack

func NewPack(
	key key.Key,
	cp Checkpoint,
	changes []*Change,
	versionVector time.VersionVector,
	snapshot []byte,
) *Pack

NewPack creates a new instance of Pack.

func (*Pack) ChangesLen added in v0.1.10

func (p *Pack) ChangesLen() int

ChangesLen returns the size of the changes.

func (*Pack) HasChanges

func (p *Pack) HasChanges() bool

HasChanges returns whether pack has changes or not.

func (*Pack) IsAttached added in v0.4.25

func (p *Pack) IsAttached() bool

IsAttached returns whether the document is attached or not.

func (*Pack) OperationsLen added in v0.1.10

func (p *Pack) OperationsLen() int

OperationsLen returns the size of the operations.

Jump to

Keyboard shortcuts

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