Documentation ¶
Overview ¶
Package change provides the implementation of Change. Change is a set of operations that can be applied to a document.
Index ¶
- Constants
- Variables
- type Change
- func (c *Change) AfterOrEqual(other *Change) bool
- func (c *Change) ClientSeq() uint32
- func (c *Change) Execute(root *crdt.Root, presences *innerpresence.Map) error
- func (c *Change) ID() ID
- func (c *Change) Message() string
- func (c *Change) Operations() []operations.Operation
- func (c *Change) PresenceChange() *innerpresence.PresenceChange
- func (c *Change) ServerSeq() int64
- func (c *Change) SetActor(actor *time.ActorID)
- func (c *Change) SetServerSeq(serverSeq int64)
- type Checkpoint
- func (cp Checkpoint) Equals(other Checkpoint) bool
- func (cp Checkpoint) Forward(other Checkpoint) Checkpoint
- func (cp Checkpoint) IncreaseClientSeq(inc uint32) Checkpoint
- func (cp Checkpoint) NextClientSeq() Checkpoint
- func (cp Checkpoint) NextServerSeq(serverSeq int64) Checkpoint
- func (cp Checkpoint) String() string
- func (cp Checkpoint) SyncClientSeq(clientSeq uint32) Checkpoint
- type Context
- func (c *Context) HasChange() bool
- func (c *Context) ID() ID
- func (c *Context) IssueTimeTicket() *time.Ticket
- func (c *Context) LastTimeTicket() *time.Ticket
- func (c *Context) Push(op operations.Operation)
- func (c *Context) RegisterElement(elem crdt.Element)
- func (c *Context) RegisterGCPair(pair crdt.GCPair)
- func (c *Context) RegisterRemovedElementPair(parent crdt.Container, deleted crdt.Element)
- func (c *Context) SetPresenceChange(presenceChange innerpresence.PresenceChange)
- func (c *Context) ToChange() *Change
- type ID
- func (id ID) ActorID() *time.ActorID
- func (id ID) AfterOrEqual(other ID) bool
- func (id ID) ClientSeq() uint32
- func (id ID) Lamport() int64
- func (id ID) NewTimeTicket(delimiter uint32) *time.Ticket
- func (id ID) Next() ID
- func (id ID) ServerSeq() int64
- func (id ID) SetActor(actor *time.ActorID) ID
- func (id ID) SetClocks(otherLamport int64, vector time.VersionVector) ID
- func (id ID) SetServerSeq(serverSeq int64) ID
- func (id ID) SetVersionVector(vector time.VersionVector) ID
- func (id ID) SyncClocks(other ID) ID
- func (id ID) VersionVector() time.VersionVector
- type Pack
Constants ¶
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) )
const (
// InitialLamport is the initial value of Lamport timestamp.
InitialLamport = 0
)
Variables ¶
var InitialCheckpoint = NewCheckpoint(InitialServerSeq, InitialClientSeq)
InitialCheckpoint is the initial value of Checkpoint.
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) )
var MaxCheckpoint = NewCheckpoint(MaxServerSeq, MaxClientSeq)
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
AfterOrEqual returns whether this change is after or equal to the given 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) SetServerSeq ¶
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 ¶
NewContext creates a new instance of Context.
func (*Context) IssueTimeTicket ¶
IssueTimeTicket creates a time ticket to be used to create a new operation.
func (*Context) LastTimeTicket ¶ added in v0.4.0
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 ¶
RegisterElement registers the given element to the root.
func (*Context) RegisterGCPair ¶ added in v0.4.20
RegisterGCPair registers the given GC pair to the root.
func (*Context) RegisterRemovedElementPair ¶ added in v0.1.1
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.
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) AfterOrEqual ¶ added in v0.5.3
AfterOrEqual returns whether this ID is causally after or equal the given ID.
func (ID) NewTimeTicket ¶
NewTimeTicket creates a ticket of the given delimiter.
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
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
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
ChangesLen returns the size of the changes.
func (*Pack) HasChanges ¶
HasChanges returns whether pack has changes or not.
func (*Pack) IsAttached ¶ added in v0.4.25
IsAttached returns whether the document is attached or not.
func (*Pack) OperationsLen ¶ added in v0.1.10
OperationsLen returns the size of the operations.