Search in sources :

Example 1 with SegmentStorageSystem

use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.

the class CompactorLogicTest method testRunMergeShift.

@Test
public void testRunMergeShift() {
    SegmentStorageSystem storage = CompactorTests.getStorageSystem();
    for (int i = 0; i < 10; ++i) {
        storage.segments().add(createTestSegment());
    }
    Compactor compactor = new MergeCompactor(storage);
    compactor.runShift(0, 1);
    Assert.assertEquals(1, compactor.getShiftIndex());
    Assert.assertEquals(1, compactor.getShiftCount());
    compactor.runShift(0, 3);
    Assert.assertEquals(2, compactor.getShiftIndex());
    Assert.assertEquals(3, compactor.getShiftCount());
    compactor.runShift(9, 1);
    Assert.assertEquals(0, compactor.getShiftIndex());
    Assert.assertEquals(2, compactor.getShiftCount());
    // start over
    compactor.runShift(0, 10);
    Assert.assertEquals(0, compactor.getShiftIndex());
    Assert.assertEquals(1, compactor.getShiftCount());
    compactor.runShift(4, 5);
    Assert.assertEquals(0, compactor.getShiftIndex());
    Assert.assertEquals(6, compactor.getShiftCount());
}
Also used : SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) Test(org.junit.Test)

Example 2 with SegmentStorageSystem

use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.

the class CompactorLogicTest method testRunFailShift.

@Test
public void testRunFailShift() {
    SegmentStorageSystem storage = CompactorTests.getStorageSystem();
    for (int i = 0; i < 10; ++i) {
        storage.segments().add(createTestSegment());
    }
    Compactor compactor = new FailCompactor(storage);
    compactor.runShift(0, 6);
    Assert.assertEquals(1, compactor.getShiftIndex());
    Assert.assertEquals(6, compactor.getShiftCount());
    compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
    Assert.assertEquals(2, compactor.getShiftIndex());
    Assert.assertEquals(6, compactor.getShiftCount());
    compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
    Assert.assertEquals(3, compactor.getShiftIndex());
    Assert.assertEquals(6, compactor.getShiftCount());
    compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
    Assert.assertEquals(4, compactor.getShiftIndex());
    Assert.assertEquals(6, compactor.getShiftCount());
    compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
    Assert.assertEquals(5, compactor.getShiftIndex());
    Assert.assertEquals(6, compactor.getShiftCount());
    compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
    Assert.assertEquals(0, compactor.getShiftIndex());
    Assert.assertEquals(7, compactor.getShiftCount());
}
Also used : SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) Test(org.junit.Test)

Example 3 with SegmentStorageSystem

use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.

the class CompactorTests method getStorageSystem.

/**
 * Return a {@link SegmentStorageSystem} to use in a test.
 *
 * @return the {@link SegmentStorageSystem}
 */
public static SegmentStorageSystem getStorageSystem() {
    return new SegmentStorageSystem() {

        File fs = new File(FileSystem.tempFile());

        List<Segment> segments = new ArrayList<>();

        Lock lock = new ReentrantLock();

        @Override
        public long availableDiskSpace() {
            return fs.getUsableSpace();
        }

        @Override
        public Lock lock() {
            return lock;
        }

        @Override
        public Path save(Segment segment) {
            Path file = Paths.get(FileSystem.tempFile());
            segment.transfer(file);
            return file;
        }

        @Override
        public List<Segment> segments() {
            return segments;
        }

        @Override
        public long totalDiskSpace() {
            return fs.getTotalSpace();
        }
    };
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Path(java.nio.file.Path) SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) Lock(java.util.concurrent.locks.Lock) ReentrantLock(java.util.concurrent.locks.ReentrantLock)

Example 4 with SegmentStorageSystem

use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem 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)

Aggregations

SegmentStorageSystem (com.cinchapi.concourse.server.storage.db.SegmentStorageSystem)4 Test (org.junit.Test)3 Segment (com.cinchapi.concourse.server.storage.db.kernel.Segment)2 List (java.util.List)2 Identifier (com.cinchapi.concourse.server.model.Identifier)1 CompactorTests (com.cinchapi.concourse.server.storage.db.compaction.CompactorTests)1 Write (com.cinchapi.concourse.server.storage.temp.Write)1 Convert (com.cinchapi.concourse.util.Convert)1 TestData (com.cinchapi.concourse.util.TestData)1 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1 Assert (org.junit.Assert)1