voldemort.versioning
Class VectorClock

java.lang.Object
  extended by voldemort.versioning.VectorClock
All Implemented Interfaces:
java.io.Serializable, Version

public class VectorClock
extends java.lang.Object
implements Version, java.io.Serializable

A vector of the number of writes mastered by each node. The vector is stored sparely, since, in general, writes will be mastered by only one node. This means implicitly all the versions are at zero, but we only actually store those greater than zero.

See Also:
Serialized Form

Constructor Summary
VectorClock()
          Construct an empty VectorClock
VectorClock(byte[] bytes)
          Takes the bytes of a VectorClock and creates a java object from them.
VectorClock(byte[] bytes, int offset)
          Read the vector clock from the given bytes starting from a particular offset
VectorClock(java.util.List<ClockEntry> versions, long timestamp)
          Deprecated. 
VectorClock(long timestamp)
           
 
Method Summary
 VectorClock clone()
           
 Occurred compare(Version v)
          Return whether or not the given version preceeded this one, succeeded it, or is concurrant with it
 void copyFromVectorClock(VectorClock vc)
          Function to copy values from another VectorClock.
 boolean equals(java.lang.Object object)
           
 java.util.List<ClockEntry> getEntries()
          Deprecated. 
 long getMaxVersion()
           
 long getTimestamp()
           
 java.util.TreeMap<java.lang.Short,java.lang.Long> getVersionMap()
           
 int hashCode()
           
 VectorClock incremented(int nodeId, long time)
          Get new vector clock based on this clock but incremented on index nodeId
 void incrementVersion(int node, long time)
          Increment the version info associated with the given node
 VectorClock merge(VectorClock clock)
           
 int sizeInBytes()
           
 byte[] toBytes()
           
 int toBytes(byte[] buf, int offset)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VectorClock

public VectorClock()
Construct an empty VectorClock


VectorClock

public VectorClock(long timestamp)

VectorClock

@Deprecated
public VectorClock(java.util.List<ClockEntry> versions,
                              long timestamp)
Deprecated. 

This function is not safe because it may break the pre-condition that clock entries should be sorted by nodeId


VectorClock

public VectorClock(byte[] bytes)
Takes the bytes of a VectorClock and creates a java object from them. For efficiency reasons the extra bytes can be attached to the end of the byte array that are not related to the VectorClock

Parameters:
bytes - The serialized bytes of the VectorClock

VectorClock

public VectorClock(byte[] bytes,
                   int offset)
Read the vector clock from the given bytes starting from a particular offset

Parameters:
bytes - The bytes to read from
offset - The offset to start reading from
Method Detail

getVersionMap

public java.util.TreeMap<java.lang.Short,java.lang.Long> getVersionMap()

toBytes

public byte[] toBytes()

toBytes

public int toBytes(byte[] buf,
                   int offset)

sizeInBytes

public int sizeInBytes()

incrementVersion

public void incrementVersion(int node,
                             long time)
Increment the version info associated with the given node

Parameters:
node - The node

incremented

public VectorClock incremented(int nodeId,
                               long time)
Get new vector clock based on this clock but incremented on index nodeId

Parameters:
nodeId - The id of the node to increment
Returns:
A vector clock equal on each element execept that indexed by nodeId

clone

public VectorClock clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getMaxVersion

public long getMaxVersion()

merge

public VectorClock merge(VectorClock clock)

compare

public Occurred compare(Version v)
Description copied from interface: Version
Return whether or not the given version preceeded this one, succeeded it, or is concurrant with it

Specified by:
compare in interface Version
Parameters:
v - The other version

getTimestamp

public long getTimestamp()

getEntries

@Deprecated
public java.util.List<ClockEntry> getEntries()
Deprecated. 


copyFromVectorClock

public void copyFromVectorClock(VectorClock vc)
Function to copy values from another VectorClock. This is used for in-place updates during a Voldemort put operation.

Parameters:
vc - The VectorClock object from which the inner values are to be copied.


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu