use of com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range in project concourse by cinchapi.
the class Chunk method seek.
/**
* If it possible that they exist, look for any {@link Revision revisions}
* that match the {@code composite} and {@link Record#append(Revision)
* append} hem to the {@code record}.
*
* @param composite
* @param record
*/
public final void seek(Composite composite, Record<L, K, V> record) {
boolean mutable = isMutable();
Locks.lockIfCondition(segmentReadLock, mutable);
Locks.lockIfCondition(read, mutable);
try {
if (filter.mightContain(composite)) {
SortedSet<Revision<L, K, V>> revisions = $revisions != null ? $revisions.get() : null;
if (revisions != null) {
Iterator<Revision<L, K, V>> it = revisions.iterator();
// Since the revisions are
boolean processing = false;
// sorted, I can toggle this
// flag on once I reach a
// revision that I care about so
// that I can break out of the
// loop once I reach a revision
// I don't care about again.
boolean checkSecond = composite.parts().length > 1;
while (it.hasNext()) {
Revision<L, K, V> revision = it.next();
if (revision.getLocator().equals(composite.parts()[0]) && ((checkSecond && revision.getKey().equals(composite.parts()[1])) || !checkSecond)) {
processing = true;
record.append(revision);
} else if (processing) {
break;
}
}
} else {
Range range = manifest.lookup(composite);
long start = range.start();
long length = range.end() - (start - 1);
if (start != Manifest.NO_ENTRY && length > 0) {
Iterator<ByteBuffer> it = ByteableCollections.stream(channel(), position() + start, length, GlobalState.DISK_READ_BUFFER_SIZE);
while (it.hasNext()) {
Revision<L, K, V> revision = Byteables.read(it.next(), xRevisionClass());
Logger.debug("Attempting to append {} from {} to {}", revision, this, record);
record.append(revision);
}
}
}
}
} finally {
Locks.unlockIfCondition(read, mutable);
Locks.unlockIfCondition(segmentReadLock, mutable);
}
}
use of com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range in project concourse by cinchapi.
the class ManifestTest method testManifestLoadsLazily.
@Test
public void testManifestLoadsLazily() {
int count = TestData.getScaleCount() * 2;
Manifest manifest = Manifest.create(count);
Assert.assertTrue(manifest.isLoaded());
for (int i = 0; i < count; i++) {
Identifier key = Identifier.of(count);
manifest.putStart(count, key);
manifest.putEnd(count * 2, key);
}
ByteBuffer bytes = ByteBuffer.allocate((int) manifest.length());
manifest.flush(ByteSink.to(bytes));
bytes.flip();
FileSystem.writeBytes(bytes, file.toString());
manifest = Manifest.load(file, 0, bytes.capacity());
Assert.assertFalse(manifest.isLoaded());
manifest.lookup(Identifier.of(1));
Assert.assertTrue(manifest.isLoaded());
for (int i = 0; i < count; i++) {
Identifier key = Identifier.of(count);
Range range = manifest.lookup(key);
Assert.assertEquals(count, range.start());
Assert.assertEquals(count * 2, range.end());
}
}
use of com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range in project concourse by cinchapi.
the class ManifestTest method testManifestWorksAfterBeingFlushed.
@Test
public void testManifestWorksAfterBeingFlushed() {
int count = TestData.getScaleCount() * 2;
Manifest manifest = Manifest.create(count);
Identifier key = Identifier.of(count);
manifest.putStart(count, key);
manifest.putEnd(count * 2, key);
Range range = manifest.lookup(key);
Assert.assertEquals(count, range.start());
Assert.assertEquals(count * 2, range.end());
manifest.transfer(file);
range = manifest.lookup(key);
Assert.assertEquals(count, range.start());
Assert.assertEquals(count * 2, range.end());
}
use of com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range in project concourse by cinchapi.
the class ManifestTest method testManifestStreamedEntriesAccuracy.
@Test
public void testManifestStreamedEntriesAccuracy() {
int threshold = Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD;
Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD = (int) Math.pow(2, 16);
try {
Manifest manifest = Manifest.create(100000);
Text text = Text.wrap(Random.getString());
int count = 0;
int start = 0;
Map<Composite, Range> expected = Maps.newHashMap();
while (manifest.length() < Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD) {
Identifier record = Identifier.of(count);
int $start = start;
int end = start + TestData.getScaleCount();
Range range = new Manifest.Range() {
@Override
public long start() {
return $start;
}
@Override
public long end() {
return end;
}
};
Composite composite = Composite.create(text, record);
manifest.putStart(start, composite);
manifest.putEnd(end, composite);
expected.put(composite, range);
start = end + 1;
++count;
}
Path file = Paths.get(TestData.getTemporaryTestFile());
manifest.transfer(file);
Manifest $manifest = Manifest.load(file, 0, FileSystem.getFileSize(file.toString()));
expected.forEach((composite, range) -> {
Range actual = $manifest.lookup(composite);
Assert.assertEquals(range.start(), actual.start());
Assert.assertEquals(range.end(), actual.end());
});
} finally {
Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD = threshold;
}
}
Aggregations