Documentation ¶
Overview ¶
Package clock implements a logical clock, tracking changes at multiple peers.
Is is inspired by the paper "File Synchronization with Vector Time Pairs" and the Tra software. This structure avoids the need for tombstones.
http://publications.csail.mit.edu/tmp/MIT-CSAIL-TR-2005-014.pdf http://swtch.com/tra/
Index ¶
- Constants
- Variables
- type Action
- type Clock
- func (v *Clock) MarshalBinary() ([]byte, error)
- func (c *Clock) ResolveNew(other *Clock)
- func (c *Clock) ResolveOurs(other *Clock)
- func (c *Clock) ResolveTheirs(other *Clock)
- func (c *Clock) RewritePeers(m map[Peer]Peer) error
- func (c Clock) String() string
- func (c *Clock) Tombstone()
- func (v *Clock) UnmarshalBinary(p []byte) error
- func (c *Clock) Update(id Peer, now Epoch)
- func (c *Clock) UpdateFromChild(child *Clock) bool
- func (c *Clock) UpdateFromParent(parent *Clock)
- func (c *Clock) UpdateParent(id Peer, now Epoch)
- func (c *Clock) UpdateSync(id Peer, now Epoch)
- type Epoch
- type Peer
Constants ¶
const MaxPeer = ^Peer(0)
MaxPeer is the largest possible value a Peer can have.
Variables ¶
var (
ErrRewritePeerNotMapped = errors.New("cannot rewrite peer id for an unknown peer")
)
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action int
Action is a suggested action to take to combine two data items.
The zero value of Action is not valid.
const ( // Copy means that the incoming version is newer, and its data // should be used. Copy Action // Nothing means the local version is newer (or same), and data // should not change. Nothing // Conflict means the two versions have diverged. Conflict )
func SyncToMissing ¶
SyncToMissing returns what action receiving state from A to B should cause us to take. B does not exist currently.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a logical clock.
The zero value is a valid empty clock, but most callers should call Create to get the creation time set up.
func TombstoneFromParent ¶
TombstoneFromParent returns a new tombstone clock based on the parent.
func (*Clock) MarshalBinary ¶
MarshalBinary encodes Version into binary form.
func (*Clock) ResolveNew ¶
ResolveNew records a conflict resolution in favor of newly created content.
func (*Clock) ResolveOurs ¶
ResolveOurs records a conflict resolution in favor of us.
func (*Clock) ResolveTheirs ¶
ResolveTheirs records a conflict resolution in favor of other.
func (*Clock) RewritePeers ¶
RewritePeers updates the peer identifiers in the clock based on the given mapping. This is useful because the short identifiers are not globally allocated.
Returns ErrRewritePeerNotMapped if the clock contains a peer not present in the map. If an error occurs, the clock is in an undefined state and must not be used.
func (*Clock) UnmarshalBinary ¶
UnmarshalBinary decodes Version from binary form.
func (*Clock) Update ¶
Update adds or updates the version vector entry for id to point to time now.
As an optimization, it removes all the other modification time entries. This is only safe for files, not directories; see section 3.5.2 "Encoding Modification Times" of the Tra paper.
Caller guarantees that one of the following is true:
- now is greater than any old value seen for peer id
- now is equal to an earlier value for this peer id, and no other peer ids have been updated since that Update
func (*Clock) UpdateFromChild ¶
UpdateFromChild tracks child modification times in the parent.
Return value reports whether s changed.
func (*Clock) UpdateFromParent ¶
UpdateFromParent simplifies child sync times based on the parent.
func (*Clock) UpdateParent ¶
UpdateParent is like Update, but does not simplify the modification time version vector. It is safe to use for directories and other entities where updates are not necessarily sequenced.
Caller guarantees if an entry exists for id already, now is greater than or equal to the old value.
func (*Clock) UpdateSync ¶
UpdateSync updates the sync time only for id to point to time now.
Caller guarantees if an entry exists for id already, now is greater than or equal to the old value.
type Epoch ¶
type Epoch uint64
Epoch is a logical clock timestamp. Time 0 is never valid.