Skip to content

Instantly share code, notes, and snippets.

View Swarnim-singhal's full-sized avatar

Swarnim Singhal Swarnim-singhal

View GitHub Profile
@Swarnim-singhal
Swarnim-singhal / GossipDigestAck2.java
Created September 2, 2020 14:51
GossipDigestAck2
public class GossipDigestAck2 {
final Map<InetAddressAndPort, EndpointState> epStateMap;
GossipDigestAck2(Map<InetAddressAndPort, EndpointState> epStateMap){
this.epStateMap = epStateMap;
}
Map<InetAddressAndPort, EndpointState> getEndpointStateMap(){
return epStateMap;
}
}
public class GossipDigestAck {
final List<GossipDigest> gDigestList;
final Map<InetAddressAndPort, EndpointState> epStateMap;
GossipDigestAck(List<GossipDigest> gDigestList, Map<InetAddressAndPort, EndpointState> epStateMap{
this.gDigestList = gDigestList;
this.epStateMap = epStateMap;
}
public class GossipDigestSynVerbHandler extends GossipVerbHandler<GossipDigestSyn> {
public static final GossipDigestSynVerbHandler instance = new GossipDigestSynVerbHandler();
public void doVerb(Message<GossipDigestSyn> message) {
InetAddressAndPort from = message.from();
GossipDigestSyn gDigestMessage = message.payload;
List<GossipDigest> gDigestList = gDigestMessage.getGossipDigests();
public class GossipDigestSyn {
final String clusterId;
final String partioner;
final List<GossipDigest> gDigests;
public GossipDigestSyn(String clusterId, String partioner, List<GossipDigest> gDigests{
this.clusterId = clusterId;
this.partioner = partioner;
this.gDigests = gDigests;
public class GossipDigest implements Comparable<GossipDigest> {
final InetAddressAndPort endpoint;
final int generation; // generation stays the same when server is running and grows every time the node is started
final int maxVersion; // maximum version number is the biggest version number in EndPointState for this endpoint
GossipDigest(InetAddressAndPort ep, int gen, int version){
endpoint = ep;
generation = gen;
maxVersion = version;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
public final class InetAddressAndPort implements Serializable {
private static final long serialVersionUID = 0;
static volatile int defaultPort = 7000;
private final InetAddress address;
@Swarnim-singhal
Swarnim-singhal / ApplicationState.java
Created September 5, 2019 03:14
ApplicationState
public enum ApplicationState {
STATUS,
LOAD,
SCHEMA,
DC,
RACK,
RELEASE_VERSION,
REMOVAL_COORDINATOR,
SEVERITY,
NET_VERSION,
@Swarnim-singhal
Swarnim-singhal / EndpointState.java
Last active September 11, 2019 14:25
EndpointState
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
public class EndpointState {
private volatile HeartBeatState hbState;
private final AtomicReference<Map<ApplicationState, VersionedValue>> applicationState;
@Swarnim-singhal
Swarnim-singhal / AppState.java
Last active September 11, 2019 14:21
AppState
public enum AppState {
STATUS,
LOAD,
SCHEMA,
DC,
RACK,
RELEASE_VERSION,
REMOVAL_COORDINATOR,
SEVERITY,
NET_VERSION,
@Swarnim-singhal
Swarnim-singhal / HeartBeatState.java
Last active September 5, 2019 03:03
Data Structures used in Cassandra Gossip Porotocol
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;