use of com.ms.silverking.cloud.dht.common.SimpleKey in project SilverKing by Morgan-Stanley.
the class DataSegmentWalker method next.
/**
* Position at next entry. Initial call
* @return if there is an additional entry
*/
@Override
public DataSegmentWalkEntry next() {
long msl;
long lsl;
int storedLength;
int uncompressedLength;
int compressedLength;
long nextMSL;
long nextLSL;
if (!hasNext) {
return null;
} else {
DHTKey curKey;
int curOffset;
long version;
long creationTime;
// double keyEntropy;
byte storageState;
ValueCreator creator;
ByteBuffer entry;
int nextEntryPostKeyPosition;
if (debug) {
System.out.println("position: " + position);
}
msl = dataSegment.getLong(position);
lsl = dataSegment.getLong(position + NumConversion.BYTES_PER_LONG);
curOffset = position;
position += DHTKey.BYTES_PER_KEY;
curKey = new SimpleKey(msl, lsl);
// FUTURE - probably delete the below code, but could consider some
// additional sanity checking
/*
keyEntropy = KeyUtil.keyEntropy(curKey);
if (keyEntropy < minValidKeyEntropy) {
boolean sane;
Log.warning("Invalid key: ", curKey +" "+ position);
sane = false;
// FUTURE - need more sophisticated validation of entry
// FUTURE - we need to decode the entry
while (!sane) {
if (position > dataSegment.limit() - DHTKey.BYTES_PER_KEY) { // FUTURE - crude limit; refine
Log.warning("Ran off the end of the segment searching for a valid key");
return null;
}
position++;
msl = dataSegment.getLong(position);
lsl = dataSegment.getLong(position + NumConversion.BYTES_PER_LONG);
curKey = new SimpleKey(msl, lsl);
keyEntropy = KeyUtil.keyEntropy(curKey);
if (keyEntropy >= minValidKeyEntropy) {
try {
storedLength = MetaDataUtil.getStoredLength(dataSegment, position);
if (storedLength > 0) {
uncompressedLength = MetaDataUtil.getUncompressedLength(dataSegment, position);
if (uncompressedLength >= 0) {
compressedLength = MetaDataUtil.getCompressedLength(dataSegment, position);
if (compressedLength >= 0) {
if (position + storedLength < dataSegment.limit()
&& uncompressedLength < compressedLength) {
sane = true;
}
}
}
}
} catch (Exception e) {
// couldn't decode entry, move to next
}
}
}
}
if (debug) {
System.out.printf("%x:%x %3.2f\n", msl, lsl, keyEntropy);
}
*/
storedLength = MetaDataUtil.getStoredLength(dataSegment, position);
uncompressedLength = MetaDataUtil.getUncompressedLength(dataSegment, position);
compressedLength = MetaDataUtil.getCompressedLength(dataSegment, position);
version = MetaDataUtil.getVersion(dataSegment, position);
creationTime = MetaDataUtil.getCreationTime(dataSegment, position);
storageState = MetaDataUtil.getStorageState(dataSegment, position);
creator = MetaDataUtil.getCreator(dataSegment, position);
if (debug) {
System.out.println(storedLength);
}
nextEntryPostKeyPosition = position + storedLength + DHTKey.BYTES_PER_KEY;
// Check to see if it's possible that there is another entry
if (nextEntryPostKeyPosition + MetaDataUtil.getMinimumEntrySize() < dataSegment.limit()) {
int nextEntryStoredLength;
// Check to see if the potential next entry actually fits in this segment
nextEntryStoredLength = MetaDataUtil.getStoredLength(dataSegment, nextEntryPostKeyPosition);
if (debug) {
System.out.printf("nextEntryPostKeyPosition %d nextEntryStoredLength %d dataSegment.limit() %d\n", nextEntryPostKeyPosition, nextEntryStoredLength, dataSegment.limit());
}
if (nextEntryPostKeyPosition + nextEntryStoredLength < dataSegment.limit()) {
nextMSL = dataSegment.getLong(nextEntryPostKeyPosition);
nextLSL = dataSegment.getLong(nextEntryPostKeyPosition + NumConversion.BYTES_PER_LONG);
hasNext = !(nextMSL == 0 && nextLSL == 0);
if (debug) {
System.out.printf("a: hastNext %s\n", hasNext);
}
} else {
hasNext = false;
if (debug) {
System.out.printf("b: hastNext %s\n", hasNext);
}
}
} else {
// No room for valid next entry
hasNext = false;
if (debug) {
System.out.printf("c: hastNext %s\n", hasNext);
}
}
entry = (ByteBuffer) ((ByteBuffer) dataSegment.duplicate().position(position)).slice().limit(storedLength);
position += storedLength;
return new DataSegmentWalkEntry(curKey, version, curOffset, storedLength, uncompressedLength, compressedLength, DHTKey.BYTES_PER_KEY, entry, creationTime, creator, storageState);
}
}
use of com.ms.silverking.cloud.dht.common.SimpleKey in project SilverKing by Morgan-Stanley.
the class MD5KeyDigest method computeKey.
@Override
public DHTKey computeKey(byte[] bytes) {
MessageDigest md;
md = MD5Digest.getLocalMessageDigest();
md.update(bytes, 0, bytes.length);
return new SimpleKey(md.digest());
}
use of com.ms.silverking.cloud.dht.common.SimpleKey in project SilverKing by Morgan-Stanley.
the class IntRehashTest method rehashTest.
public static void rehashTest(int size) {
IntArrayCuckoo map;
map = new IntArrayCuckoo(new WritableCuckooConfig(totalEntries, numSubTables, entriesPerBucket, cuckooLimit));
for (int i = 0; i < size; i++) {
try {
map.put(new SimpleKey(0, i), i);
} catch (TableFullException tfe) {
System.out.println("rehashing");
map = IntArrayCuckoo.rehashAndAdd(map, new SimpleKey(0, i), i);
}
}
}
Aggregations