use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.
the class SegmentTest method testConcurrency.
@Test
public void testConcurrency() throws InterruptedException {
AtomicBoolean succeeded = new AtomicBoolean(true);
AwaitableExecutorService executor = new AwaitableExecutorService(Executors.newCachedThreadPool());
try {
for (int i = 0; i < 1000; ++i) {
AtomicBoolean done = new AtomicBoolean(false);
long record = i;
String key = Long.toString(record);
TObject value = Convert.javaToThrift(Long.toString(record));
Write write = Write.add(key, value, record);
Identifier pk = Identifier.of(record);
Text text = Text.wrap(key);
Thread reader = new Thread(() -> {
while (!done.get()) {
TableRecord tr = TableRecord.create(pk);
IndexRecord ir = IndexRecord.create(text);
CorpusRecord cr = CorpusRecord.create(text);
segment.table().seek(Composite.create(pk), tr);
segment.index().seek(Composite.create(text), ir);
segment.corpus().seek(Composite.create(text), cr);
if (!done.get() && tr.isEmpty() != ir.isEmpty()) {
if (!tr.isEmpty() && ir.isEmpty()) {
// Later read is empty
succeeded.set(false);
System.out.println(AnyStrings.format("table empty = {} and index empty = {} for {}", tr.isEmpty(), ir.isEmpty(), record));
}
}
if (!done.get() && ir.isEmpty() != cr.isEmpty()) {
if (!ir.isEmpty() && cr.isEmpty()) {
// Later read is empty
succeeded.set(false);
System.out.println(AnyStrings.format("index empty = {} and corpus empty = {} for {}", tr.isEmpty(), cr.isEmpty(), record));
}
}
}
TableRecord tr = TableRecord.create(pk);
IndexRecord ir = IndexRecord.create(text);
CorpusRecord cr = CorpusRecord.create(text);
segment.table().seek(Composite.create(pk), tr);
segment.index().seek(Composite.create(text), ir);
segment.corpus().seek(Composite.create(text), cr);
if (tr.isEmpty()) {
succeeded.set(false);
System.out.println("After write finished, table still empty for " + record);
}
if (ir.isEmpty()) {
succeeded.set(false);
System.out.println("After write finished, index still empty for " + record);
}
if (cr.isEmpty()) {
succeeded.set(false);
System.out.println("After write finished, corpus still empty for " + record);
}
});
Thread writer = new Thread(() -> {
try {
segment.acquire(write, executor);
done.set(true);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
reader.start();
writer.start();
writer.join();
reader.join();
}
Assert.assertTrue(succeeded.get());
} finally {
executor.shutdown();
}
}
use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.
the class SegmentTest method testOffHeapSegmentEfficacy.
@Test
public void testOffHeapSegmentEfficacy() {
segment = Segment.createOffHeap(100);
Set<Write> writes = new LinkedHashSet<>();
for (int i = 0; i < 100; ++i) {
Write write = TestData.getWriteAdd();
writes.add(write);
segment.acquire(write);
}
Set<Write> actual = (Set<Write>) segment.writes().collect(Collectors.toCollection(LinkedHashSet::new));
Assert.assertEquals(writes, actual);
}
use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.
the class EngineTest method testReproGH_441.
@Test
public void testReproGH_441() throws Exception {
// Unexpected shutdown should not allow duplicate Write versions to by
// transferred
Engine engine = (Engine) store;
Buffer buffer = (Buffer) engine.limbo;
Database db = (Database) engine.durable;
Method method = buffer.getClass().getDeclaredMethod("canTransport");
method.setAccessible(true);
buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 1));
buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
buffer.insert(Write.remove("name", Convert.javaToThrift("jeff"), 2));
buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
buffer.insert(Write.remove("name", Convert.javaToThrift("jeff"), 2));
while (!(boolean) method.invoke(buffer)) {
// Fill the page so the
// buffer can transport
engine.add("count", Convert.javaToThrift(Time.now()), Time.now());
}
for (int i = 0; i < 6; ++i) {
buffer.transport(db);
}
db.sync();
engine.stop();
engine = new Engine(buffer.getBackingStore(), db.getBackingStore());
// Simulate unexpected shutdown by "restarting" the
engine.start();
// Engine
db = (Database) engine.durable;
while ((boolean) method.invoke(engine.limbo)) {
// wait until the first
// page in the buffer
// (which contains the
// same data that was
// previously
// transported) is done
// transporting again
Random.sleep();
}
Iterator<Write> it = db.iterator();
Set<Long> versions = new HashSet<>();
while (it.hasNext()) {
Assert.assertTrue(versions.add(it.next().getVersion()));
}
}
use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.
the class SimilarityCompactorTest method testSanityCheck.
@Test
public void testSanityCheck() {
SegmentStorageSystem storage = CompactorTests.getStorageSystem();
Segment a = Segment.create();
a.acquire(Write.add("name", Convert.javaToThrift("jeff"), 1));
a.acquire(Write.add("name", Convert.javaToThrift("ashleah"), 2));
a.acquire(Write.add("age", Convert.javaToThrift(33), 2));
a.acquire(Write.add("company", Convert.javaToThrift("Cinchapi"), 1));
a.transfer(Paths.get(TestData.getTemporaryTestFile()));
Segment b = Segment.create();
b.acquire(Write.add("name", Convert.javaToThrift("Jeff"), 1));
b.acquire(Write.remove("name", Convert.javaToThrift("jeff"), 1));
b.acquire(Write.remove("name", Convert.javaToThrift("ashleah"), 2));
b.acquire(Write.add("name", Convert.javaToThrift("Jeffery"), 1));
b.acquire(Write.add("company", Convert.javaToThrift("Know Full Well"), 2));
b.acquire(Write.add("age", Convert.javaToThrift(33), 1));
b.acquire(Write.add("age", Convert.javaToThrift(33.0), 1));
b.transfer(Paths.get(TestData.getTemporaryTestFile()));
storage.segments().add(a);
storage.segments().add(b);
// seg0
storage.segments().add(Segment.create());
SimilarityCompactor compactor = new SimilarityCompactor(storage);
compactor.minimumSimilarityThreshold(0);
List<Write> expected = storage.segments().stream().flatMap(segment -> segment.writes()).collect(Collectors.toList());
compactor.executeFullCompaction();
List<Write> actual = storage.segments().stream().flatMap(segment -> segment.writes()).collect(Collectors.toList());
Assert.assertEquals(2, storage.segments().size());
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && // assert that no data
actual.containsAll(expected));
// lost...
actual.forEach(System.out::println);
for (int i = 0; i < actual.size(); ++i) {
if (i > 0) {
Identifier previous = actual.get(i - 1).getRecord();
Identifier current = actual.get(i).getRecord();
// Assert that, from table view, all records are grouped
// together
Assert.assertTrue(current.longValue() == previous.longValue() || current.longValue() == previous.longValue() + 1);
}
}
Assert.assertEquals(ImmutableList.of(a, b), compactor.garbage());
}
use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.
the class EngineTest method testCommitVersionSplitBetweenBufferAndDatabase.
@Test
public void testCommitVersionSplitBetweenBufferAndDatabase() {
Engine engine = (Engine) store;
Buffer buffer = (Buffer) engine.limbo;
Database db = (Database) engine.durable;
engine.bufferTransportThreadSleepInMs = Integer.MAX_VALUE;
AtomicOperation atomic = engine.startAtomicOperation();
atomic.add("name", Convert.javaToThrift("jeff"), 1);
atomic.remove("name", Convert.javaToThrift("jeff"), 1);
long before = Time.now();
atomic.commit();
long after = Time.now();
while (!Reflection.<Boolean>call(buffer, "canTransport")) {
engine.add("foo", Convert.javaToThrift("bar"), Time.now());
}
buffer.transport(db);
db.sync();
Iterator<Write> it = db.iterator();
long version = 0;
while (it.hasNext()) {
Write write = it.next();
version = write.getVersion();
}
Assert.assertEquals(ImmutableSet.of(), store.find("name", Operator.EQUALS, Convert.javaToThrift("jeff")));
Assert.assertEquals(ImmutableSet.of(), store.find(before, "name", Operator.EQUALS, Convert.javaToThrift("jeff")));
Assert.assertEquals(ImmutableSet.of(), store.find(after, "name", Operator.EQUALS, Convert.javaToThrift("jeff")));
Assert.assertEquals(ImmutableSet.of(), store.find(version, "name", Operator.EQUALS, Convert.javaToThrift("jeff")));
engine.stop();
engine.bufferTransportThreadSleepInMs = Integer.MAX_VALUE;
engine.start();
it = db.iterator();
while (it.hasNext()) {
Write write = it.next();
System.out.println(write);
}
Assert.assertEquals(ImmutableSet.of(), store.find("name", Operator.EQUALS, Convert.javaToThrift("jeff")));
Assert.assertEquals(ImmutableSet.of(), store.find(before, "name", Operator.EQUALS, Convert.javaToThrift("jeff")));
Assert.assertEquals(ImmutableSet.of(), store.find(after, "name", Operator.EQUALS, Convert.javaToThrift("jeff")));
Assert.assertEquals(ImmutableSet.of(), store.find(version, "name", Operator.EQUALS, Convert.javaToThrift("jeff")));
}
Aggregations