change

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

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
)
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)
)

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) *Change

New creates a new instance of Change.

func (*Change) ClientSeq

func (c *Change) ClientSeq() uint32

ClientSeq returns the clientSeq of this change.

func (*Change) Execute

func (c *Change) Execute(root *json.Root) 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) ServerSeq

func (c *Change) ServerSeq() uint64

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 uint64)

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 uint64

	// 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 uint64, 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 uint64) 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 *json.Root) *Context

NewContext creates a new instance of Context.

func (*Context) HasOperations

func (c *Context) HasOperations() bool

HasOperations returns whether this change has operations or not.

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) Push

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

Push pushes a new operations into context queue.

func (*Context) RegisterElement

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

RegisterElement registers the given element to the root.

func (*Context) RegisterRemovedElementPair added in v0.1.1

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

RegisterRemovedElementPair registers the given element pair to hash table.

func (*Context) RegisterTextElementWithGarbage added in v0.1.11

func (c *Context) RegisterTextElementWithGarbage(textType json.TextElement)

RegisterTextElementWithGarbage register the given text element with garbage to hash table.

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 is for identifying the Change. It is immutable.

func NewID

func NewID(
	clientSeq uint32,
	serverSeq uint64,
	lamport uint64,
	actorID *time.ActorID,
) 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) ClientSeq

func (id ID) ClientSeq() uint32

ClientSeq returns the client sequence of this ID.

func (ID) Lamport

func (id ID) Lamport() uint64

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() uint64

ServerSeq returns the server sequence of this ID.

func (ID) SetActor

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

SetActor sets actorID.

func (ID) SetServerSeq added in v0.2.2

func (id ID) SetServerSeq(serverSeq uint64) ID

SetServerSeq sets server sequence of this ID.

func (ID) SyncLamport

func (id ID) SyncLamport(otherLamport uint64) ID

SyncLamport syncs lamport timestamp with the given 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

	// 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,
	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 the whether pack has changes 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