public static ConsistencyLevel determineConsistency ( Map < Value , Set < ClusterNode > > versionNodeSetMap , int replicationFactor ) { boolean fullyConsistent = true ; Value latestVersion = null ; for ( Map . Entry < Value , Set < ClusterNode > > versionNodeSetEntry : versionNodeSetMap . entrySet ( ) ) { Value value = versionNodeSetEntry . getKey ( ) ; if ( latestVersion == null ) { latestVersion = value ; } else if ( value . isTimeStampLaterThan ( latestVersion ) ) { latestVersion = value ; } Set < ClusterNode > nodeSet = versionNodeSetEntry . getValue ( ) ; fullyConsistent = fullyConsistent && ( nodeSet . size ( ) == replicationFactor ) ; } if ( fullyConsistent ) { return ConsistencyLevel . FULL ; } else { // latest write consistent, effectively consistent if ( latestVersion != null && versionNodeSetMap . get ( latestVersion ) . size ( ) == replicationFactor ) { return ConsistencyLevel . LATEST_CONSISTENT ; } // all other states inconsistent return ConsistencyLevel . INCONSISTENT ; } }
Determine the consistency level of a key