Search in sources :

Example 11 with Write

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();
    }
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) Text(com.cinchapi.concourse.server.model.Text) IndexRecord(com.cinchapi.concourse.server.storage.db.IndexRecord) TableRecord(com.cinchapi.concourse.server.storage.db.TableRecord) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Identifier(com.cinchapi.concourse.server.model.Identifier) CorpusRecord(com.cinchapi.concourse.server.storage.db.CorpusRecord) AwaitableExecutorService(com.cinchapi.concourse.server.concurrent.AwaitableExecutorService) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 12 with Write

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);
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 13 with Write

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()));
    }
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Write(com.cinchapi.concourse.server.storage.temp.Write) Database(com.cinchapi.concourse.server.storage.db.Database) AtomicLong(java.util.concurrent.atomic.AtomicLong) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with Write

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());
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) CompactorTests(com.cinchapi.concourse.server.storage.db.compaction.CompactorTests) TestData(com.cinchapi.concourse.util.TestData) Test(org.junit.Test) SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) Write(com.cinchapi.concourse.server.storage.temp.Write) Collectors(java.util.stream.Collectors) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) List(java.util.List) Identifier(com.cinchapi.concourse.server.model.Identifier) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) Convert(com.cinchapi.concourse.util.Convert) Assert(org.junit.Assert) Identifier(com.cinchapi.concourse.server.model.Identifier) SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) Test(org.junit.Test)

Example 15 with Write

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")));
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Write(com.cinchapi.concourse.server.storage.temp.Write) Database(com.cinchapi.concourse.server.storage.db.Database) Test(org.junit.Test)

Aggregations

Write (com.cinchapi.concourse.server.storage.temp.Write)16 Test (org.junit.Test)13 Identifier (com.cinchapi.concourse.server.model.Identifier)5 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)5 Text (com.cinchapi.concourse.server.model.Text)4 StoreTest (com.cinchapi.concourse.server.storage.StoreTest)4 Database (com.cinchapi.concourse.server.storage.db.Database)4 TObject (com.cinchapi.concourse.thrift.TObject)4 Buffer (com.cinchapi.concourse.server.storage.temp.Buffer)3 Value (com.cinchapi.concourse.server.model.Value)2 Segment (com.cinchapi.concourse.server.storage.db.kernel.Segment)2 Convert (com.cinchapi.concourse.util.Convert)2 TestData (com.cinchapi.concourse.util.TestData)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2