Last active
September 5, 2019 03:03
-
-
Save Swarnim-singhal/f851dee32333000ab725adb14da9a5a1 to your computer and use it in GitHub Desktop.
Data Structures used in Cassandra Gossip Porotocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VersionGenerator { | |
private static final AtomicInteger version = new AtomicInteger(0); | |
public static int getNextVersion() { | |
return version.incrementAndGet(); | |
} | |
} | |
public class HeartBeatState implements Serializable { | |
private volatile int generation; | |
private volatile int version; | |
HeartBeatState(int gen) { | |
this(gen, 0); | |
} | |
public HeartBeatState(int gen, int ver) { | |
generation = gen; | |
version = ver; | |
} | |
int getGeneration() { return generation;} | |
void updateHeartBeat() { version = VersionGenerator.getNextVersion(); } | |
int getHeartBeatVersion() { return version; } | |
void forceNewerGenerationUnsafe() { generation += 1; } | |
void forceHighestPossibleVersionUnsafe() { version = Integer.MAX_VALUE; } | |
public String toString() { return | |
String.format("HeartBeat: generation = %d, version = %d", generation, version); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment