use of com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum in project SilverKing by Morgan-Stanley.
the class TreeBuilder method build.
private NavigableMap<Long, RegionTreeBuilder> build(boolean allowRegionNotFound) {
while (keyIterator.hasNext()) {
KeyAndVersionChecksum kvc;
RegionTreeBuilder rtb;
kvc = keyIterator.next();
rtb = getBuilderForKey(kvc.getKey(), allowRegionNotFound);
if (rtb != null) {
rtb.addChecksum(kvc);
}
}
freezeBuilders();
return rtBuilders;
}
use of com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum in project SilverKing by Morgan-Stanley.
the class TreeTest method test.
public void test() {
ChecksumNode tree1;
ChecksumNode tree2;
ChecksumNode tree2b;
ChecksumNode tree3;
ChecksumNode tree4;
ChecksumNode tree5;
tree1 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, kvcList);
System.out.println(tree1);
tree2 = tree1.duplicate();
System.out.println("\n *** Should be equal ***");
System.out.println(TreeMatcher.match(tree2, tree1));
tree2b = RegionTreeBuilder.build(region, entriesPerNode, numKeys / 2, kvcList);
System.out.println(tree2b);
System.out.println("\n *** Should be equal (different key estimates) ***");
System.out.println(TreeMatcher.match(tree2b, tree1));
List<KeyAndVersionChecksum> _kvcList;
List<KeyAndVersionChecksum> _kvcList4;
KeyAndVersionChecksum kvc1;
KeyAndVersionChecksum kvc2;
long checksum2;
// remove one key so that we have destNotInSource and sourceNotInDest tests
_kvcList = new ArrayList<>(kvcList);
_kvcList.remove(0);
tree3 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, _kvcList);
// now create a mismatch
_kvcList4 = new ArrayList<>(kvcList);
kvc1 = _kvcList4.remove(0);
checksum2 = kvc1.getVersionChecksum() + 1;
kvc2 = new KeyAndVersionChecksum(kvc1.getKey(), checksum2);
_kvcList4.add(0, kvc2);
tree4 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, _kvcList4);
_kvcList4.remove(1);
tree5 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, _kvcList4);
System.out.println("\n *** Should have destNotInSource ***");
System.out.println(TreeMatcher.match(tree3, tree1));
System.out.println("\n *** Should have sourceNotInDest ***");
System.out.println(TreeMatcher.match(tree1, tree3));
System.out.println("\n *** Should have mismatch ***");
System.out.println(TreeMatcher.match(tree4, tree1));
System.out.println("\n *** Should be a mix ***");
System.out.println(TreeMatcher.match(tree5, tree3));
System.out.flush();
serializationTest(tree1);
}
use of com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum in project SilverKing by Morgan-Stanley.
the class ProtoChecksumTreeMessageGroup method deserialize.
public static ChecksumNode deserialize(ByteBuffer buffer) {
NodeType type;
RingRegion region;
int numChildren;
AbstractChecksumNode root;
type = NodeType.values()[buffer.get()];
if (type != NodeType.NULL) {
region = deserializeRegion(buffer);
numChildren = buffer.getInt();
} else {
region = null;
numChildren = 0;
}
switch(type) {
case NON_LEAF:
List<ChecksumNode> children;
children = new ArrayList<>(numChildren);
for (int i = 0; i < numChildren; i++) {
children.add(deserialize(buffer));
}
root = new NonLeafChecksumNode(region, children);
break;
case LEAF:
List<KeyAndVersionChecksum> keyAndVersionChecksums;
keyAndVersionChecksums = deserializeKeyAndVersionChecksums(buffer);
root = new LeafChecksumNode(region, keyAndVersionChecksums);
break;
case NULL:
root = null;
break;
default:
throw new RuntimeException("panic");
}
if (root != null) {
root.freezeIfNotFrozen();
}
return root;
}
use of com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum in project SilverKing by Morgan-Stanley.
the class TreeMatcher method match.
public static MatchResult match(ChecksumNode n0, ChecksumNode n1) {
MatchResult result;
Iterator<KeyAndVersionChecksum> i0;
Iterator<KeyAndVersionChecksum> i1;
KeyAndVersionChecksum kvc0;
KeyAndVersionChecksum kvc1;
boolean advance0;
boolean advance1;
RingRegion.ensureIdentical(n0.getRegion(), n1.getRegion());
result = new MatchResult();
i0 = n0.iterator();
i1 = n1.iterator();
kvc0 = null;
kvc1 = null;
advance0 = true;
advance1 = true;
while (i0.hasNext() && i1.hasNext()) {
if (advance0) {
kvc0 = i0.next();
}
if (advance1) {
kvc1 = i1.next();
}
if (kvc0.equals(kvc1)) {
// match
advance0 = true;
advance1 = true;
} else {
DHTKey k0;
DHTKey k1;
int comparisonResult;
k0 = kvc0.getKey();
k1 = kvc1.getKey();
comparisonResult = UnsignedKeyComparator.instance.compare(k0, k1);
if (comparisonResult == 0) {
// keys match, version checksums must not
result.addChecksumMismatch(kvc0);
advance0 = true;
advance1 = true;
} else {
// keys don't match; somebody has an entry not present in the other
if (comparisonResult < 0) {
// local key not present in other
result.addSourceNotInDest(kvc0);
advance0 = true;
advance1 = false;
} else {
// > 0
// other key not present locally
result.addDestNotInSource(kvc1);
advance0 = false;
advance1 = true;
}
}
}
}
// Check for the case where one index is not at the end.
if (i0.hasNext()) {
while (i0.hasNext()) {
result.addSourceNotInDest(i0.next());
}
} else {
while (i1.hasNext()) {
result.addDestNotInSource(i1.next());
}
}
return result;
}
use of com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum in project SilverKing by Morgan-Stanley.
the class LeafChecksumNode method computeChecksum.
private static ConvergenceChecksum computeChecksum(List<KeyAndVersionChecksum> keyAndVersionChecksums) {
ConvergenceChecksum checksum;
// checksum = new byte[keyValueChecksums.get(0).getValueChecksum().length];
checksum = null;
for (KeyAndVersionChecksum keyAndVersionChecksum : keyAndVersionChecksums) {
DHTKey key;
key = keyAndVersionChecksum.getKey();
if (checksum == null) {
checksum = new ConvergenceChecksum(keyAndVersionChecksum);
} else {
checksum = checksum.xor(new ConvergenceChecksum(keyAndVersionChecksum));
}
}
return checksum;
}
Aggregations