use of com.cinchapi.concourse.server.storage.db.Revision 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.Revision in project concourse by cinchapi.
the class ChunkTest method testShiftExisting.
@SuppressWarnings("unchecked")
@Test
public void testShiftExisting() {
int count = TestData.getScaleCount();
for (int i = 0; i < count; ++i) {
chunk.insert(getLocator(), getKey(), getValue(), Time.now(), Action.ADD);
}
Iterator<Revision<L, K, V>> expected = ((Iterable<Revision<L, K, V>>) Reflection.get("revisions", chunk)).iterator();
OffHeapMemory memory = OffHeapMemory.allocateDirect(count * 3 * Write.MINIMUM_SIZE);
chunk.shift(memory);
Iterator<Revision<L, K, V>> actual = chunk.iterator();
while (expected.hasNext()) {
Revision<L, K, V> a = expected.next();
Revision<L, K, V> b = actual.next();
Assert.assertEquals(a, b);
}
}
use of com.cinchapi.concourse.server.storage.db.Revision in project concourse by cinchapi.
the class ChunkTest method testIterator.
@Test
public void testIterator() {
int count = TestData.getScaleCount();
Set<Revision<L, K, V>> revisions = Sets.newHashSetWithExpectedSize(count);
for (int i = 0; i < count; ++i) {
Revision<L, K, V> revision = null;
while (revision == null || revisions.contains(revision)) {
L locator = getLocator();
K key = getKey();
V value = getValue();
long version = Time.now();
Action type = Action.ADD;
revision = chunk.makeRevision(locator, key, value, version, type);
}
chunk.insert(revision.getLocator(), revision.getKey(), revision.getValue(), revision.getVersion(), revision.getType());
revisions.add(revision);
}
chunk.transfer(file);
chunk = load(file, filter, chunk.manifest());
Iterator<Revision<L, K, V>> it = chunk.iterator();
Set<Revision<L, K, V>> stored = Sets.newHashSetWithExpectedSize(count);
while (it.hasNext()) {
stored.add(it.next());
}
Assert.assertEquals(revisions, stored);
}
use of com.cinchapi.concourse.server.storage.db.Revision in project concourse by cinchapi.
the class SegmentTest method testDataDeduplication.
@Test
public void testDataDeduplication() {
String key = "name";
TObject value = Convert.javaToThrift("Fonamey");
long record = 1;
// Simulate adding and removing while server is running, but creating
// new intermediate TObjects
Write w1 = Write.add(key, Convert.javaToThrift("Fonamey"), record);
Write w2 = Write.remove(key, Convert.javaToThrift("Fonamey"), record);
Assert.assertNotSame(w1.getValue(), w2.getValue());
segment.acquire(w1);
segment.acquire(w2);
// Simulate loading data from disk and creating new intermediate because
// values are not cached when read
w1 = Write.fromByteBuffer(w1.getBytes());
w2 = Write.fromByteBuffer(w2.getBytes());
Assert.assertNotSame(w1.getValue(), w2.getValue());
segment.acquire(w1);
segment.acquire(w2);
int count = TestData.getScaleCount();
for (int i = 0; i < count; ++i) {
Write write = Numbers.isEven(i) ? Write.remove(key, value, record) : Write.add(key, value, record);
write = Write.fromByteBuffer(write.getBytes());
segment.acquire(write);
}
Text name = null;
Value fonamey = null;
Identifier one = null;
Position position = null;
Iterator<Revision<Identifier, Text, Value>> tit = segment.table().iterator();
while (tit.hasNext()) {
Revision<Identifier, Text, Value> revision = tit.next();
if (one == null) {
one = revision.getLocator();
}
if (name == null) {
name = revision.getKey();
}
if (fonamey == null) {
fonamey = revision.getValue();
}
Assert.assertSame(one, revision.getLocator());
Assert.assertSame(name, revision.getKey());
Assert.assertSame(fonamey, revision.getValue());
}
Iterator<Revision<Text, Value, Identifier>> iit = segment.index().iterator();
while (iit.hasNext()) {
Revision<Text, Value, Identifier> revision = iit.next();
if (one == null) {
one = revision.getValue();
}
if (name == null) {
name = revision.getLocator();
}
if (fonamey == null) {
fonamey = revision.getKey();
}
Assert.assertSame(one, revision.getValue());
Assert.assertSame(name, revision.getLocator());
Assert.assertSame(fonamey, revision.getKey());
}
Iterator<Revision<Text, Text, Position>> cit = segment.corpus().iterator();
while (cit.hasNext()) {
Revision<Text, Text, Position> revision = cit.next();
if (position == null) {
position = revision.getValue();
}
if (name == null) {
name = revision.getLocator();
}
Assert.assertSame(position, revision.getValue());
Assert.assertSame(name, revision.getLocator());
if (revision.getKey().toString().equals("name")) {
Assert.assertSame(name, revision.getKey());
}
}
}
use of com.cinchapi.concourse.server.storage.db.Revision in project concourse by cinchapi.
the class CorpusChunkTest method testDataDeduplication.
@Test
public void testDataDeduplication() {
Text locator1 = Text.wrap("name");
Text locator2 = Text.wrap("name");
Value key1 = Value.wrap(Convert.javaToThrift("Fonamey"));
Value key2 = Value.wrap(Convert.javaToThrift("Fonamey"));
Identifier value1 = Identifier.of(1);
Identifier value2 = Identifier.of(1);
CorpusChunk corpus = (CorpusChunk) chunk;
corpus.insert(locator2, key2, value2, Time.now(), Action.ADD);
corpus.insert(locator1, key1, value1, Time.now(), Action.ADD);
Position position = null;
Iterator<Revision<Text, Text, Position>> it = corpus.iterator();
while (it.hasNext()) {
Revision<Text, Text, Position> revision = it.next();
if (position == null) {
position = revision.getValue();
}
Assert.assertSame(locator2, revision.getLocator());
if (revision.getKey().toString().equals("name")) {
Assert.assertSame(locator2, revision.getKey());
}
Assert.assertSame(position, revision.getValue());
}
}
Aggregations