Search in sources :

Example 6 with Write

use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.

the class DatabaseTest method testRepairDuplicateDataWithAtomicCommit.

@Test
public void testRepairDuplicateDataWithAtomicCommit() {
    Database db = (Database) store;
    Set<Write> duplicates = Sets.newHashSet();
    for (int i = 0; i < 10; ++i) {
        duplicates.add(Write.add(TestData.getSimpleString(), TestData.getTObject(), TestData.getIdentifier().longValue()));
    }
    for (Write write : duplicates) {
        db.accept(write);
    }
    db.sync();
    Write duplicate = null;
    int count = 0;
    List<Write> toVerify = Lists.newArrayList();
    while (count < 5 || duplicate == null) {
        boolean addDuplicates = TestData.getScaleCount() % 3 == 0;
        for (int j = 0; j < TestData.getScaleCount(); ++j) {
            Write write = null;
            if (addDuplicates && TestData.getScaleCount() % 5 == 0) {
                write = Iterables.get(duplicates, Math.abs(TestData.getInt()) % duplicates.size());
                duplicate = MoreObjects.firstNonNull(duplicate, write);
            } else {
                while (write == null || duplicates.contains(write)) {
                    write = TestData.getWriteAdd();
                }
            }
            db.accept(write);
        }
        // Simulate Atomic Operation
        Write w1 = Write.add("foo", Convert.javaToThrift(Time.now()), Time.now());
        Write w2 = Write.add("foo", Convert.javaToThrift(Time.now()), Time.now());
        Write w3 = Write.add("foo", Convert.javaToThrift(Time.now()), Time.now());
        toVerify.add(w1);
        toVerify.add(w2);
        toVerify.add(w3);
        db.accept(w1);
        db.accept(w2.rewrite(w1.getVersion()));
        db.accept(w3.rewrite(w1.getVersion()));
        db.sync();
        ++count;
    }
    Write write = duplicate;
    try {
        db.verify(write.getKey().toString(), write.getValue().getTObject(), write.getRecord().longValue());
        Assert.fail("Expected an unoffset Write exception");
    } catch (Exception e) {
        Assert.assertTrue(true);
    }
    try {
        db.select(write.getRecord().longValue());
        Assert.fail("Expected an unoffset Write exception");
    } catch (Exception e) {
        Assert.assertTrue(true);
    }
    db.repair();
    db.verify(write.getKey().toString(), write.getValue().getTObject(), write.getRecord().longValue());
    db.select(write.getRecord().longValue());
    for (Write w : toVerify) {
        Assert.assertTrue(db.verify(w));
    }
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Example 7 with Write

use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.

the class DatabaseTest method testSearchIndexMultipleEnvironmentsConcurrently.

@Test
public void testSearchIndexMultipleEnvironmentsConcurrently() {
    List<Database> dbs = Lists.newArrayList();
    for (int i = 0; i < 10; ++i) {
        Database db = getStore();
        db.start();
        dbs.add(db);
    }
    String key = "test";
    String query = "son i";
    TObject value = Convert.javaToThrift("Jeff Nelson is the CEO");
    int count = 100;
    Set<Long> expected = Sets.newLinkedHashSet();
    Consumer<Database> func = db -> {
        for (int i = 0; i < count; ++i) {
            expected.add((long) i);
            Write write = Write.add("test", value, i);
            db.accept(write);
        }
    };
    for (Database db : dbs) {
        func.accept(db);
    }
    for (Database db : dbs) {
        Set<Long> actual = db.search(key, query);
        Assert.assertTrue(!actual.isEmpty());
        Assert.assertEquals(expected, actual);
    }
    for (Database db : dbs) {
        db.stop();
        if (!current.contentEquals(db.getBackingStore())) {
            FileSystem.deleteDirectory(db.getBackingStore());
        }
    }
}
Also used : Iterables(com.google.common.collect.Iterables) Store(com.cinchapi.concourse.server.storage.Store) TestData(com.cinchapi.concourse.util.TestData) Write(com.cinchapi.concourse.server.storage.temp.Write) Random(com.cinchapi.concourse.util.Random) Reflection(com.cinchapi.common.reflect.Reflection) Lists(com.google.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TObject(com.cinchapi.concourse.thrift.TObject) Convert(com.cinchapi.concourse.util.Convert) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Benchmark(com.cinchapi.common.profile.Benchmark) ExecutorService(java.util.concurrent.ExecutorService) Time(com.cinchapi.concourse.time.Time) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) FileSystem(com.cinchapi.concourse.server.io.FileSystem) Set(java.util.Set) MoreObjects(com.google.common.base.MoreObjects) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) File(java.io.File) Executors(java.util.concurrent.Executors) Sets(com.google.common.collect.Sets) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) Operator(com.cinchapi.concourse.thrift.Operator) Identifier(com.cinchapi.concourse.server.model.Identifier) Paths(java.nio.file.Paths) Assert(org.junit.Assert) Text(com.cinchapi.concourse.server.model.Text) Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Example 8 with Write

use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.

the class EngineTest method testSameWriteVersionDatabaseIntersectionDetection.

@Test
public void testSameWriteVersionDatabaseIntersectionDetection() {
    Engine engine = (Engine) store;
    Buffer buffer = (Buffer) engine.limbo;
    Database db = (Database) engine.durable;
    int count = TestData.getScaleCount();
    AtomicLong commits = new AtomicLong();
    AtomicLong expected = new AtomicLong();
    for (int i = 0; i < count; ++i) {
        AtomicOperation atomic = engine.startAtomicOperation();
        int writes = TestData.getScaleCount();
        for (int j = 0; j < writes; ++j) {
            atomic.add("name", Convert.javaToThrift("jeff" + i), Math.abs(TestData.getInt()) % 2 == 0 ? Time.now() : j);
            expected.incrementAndGet();
        }
        atomic.commit();
        commits.incrementAndGet();
    }
    while (Reflection.<Boolean>call(buffer, "canTransport")) {
        buffer.transport(db);
    }
    Set<Long> versions = new HashSet<>();
    AtomicLong actual = new AtomicLong();
    Iterator<Write> it = db.iterator();
    while (it.hasNext()) {
        versions.add(it.next().getVersion());
        actual.incrementAndGet();
    }
    it = buffer.iterator();
    while (it.hasNext()) {
        versions.add(it.next().getVersion());
        actual.incrementAndGet();
    }
    Assert.assertEquals(commits.get(), versions.size());
    Assert.assertEquals(expected.get(), actual.get());
    engine.stop();
    engine.start();
    buffer = (Buffer) engine.limbo;
    db = (Database) engine.durable;
    versions.clear();
    actual = new AtomicLong(0);
    it = db.iterator();
    while (it.hasNext()) {
        Write write = it.next();
        versions.add(write.getVersion());
        actual.incrementAndGet();
    }
    it = buffer.iterator();
    while (it.hasNext()) {
        Write write = it.next();
        versions.add(write.getVersion());
        actual.incrementAndGet();
    }
    Assert.assertEquals(commits.get(), versions.size());
    Assert.assertEquals(expected.get(), actual.get());
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Write(com.cinchapi.concourse.server.storage.temp.Write) AtomicLong(java.util.concurrent.atomic.AtomicLong) Database(com.cinchapi.concourse.server.storage.db.Database) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Write

use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.

the class Upgrade0_11_0_1 method doTask.

@Override
protected void doTask() {
    Environments.iterator(GlobalState.BUFFER_DIRECTORY, GlobalState.DATABASE_DIRECTORY).forEachRemaining(environment -> {
        logInfoMessage("Upgrading Storage Format v2 data files to Storage Format v3 in environment {}", environment);
        Path directory = Paths.get(GlobalState.DATABASE_DIRECTORY).resolve(environment);
        Database db = new Database(directory);
        db.start();
        try {
            Path cpb = directory.resolve("cpb");
            Iterable<Block<Identifier, Text, Value>> blocks = StorageFormatV2.load(cpb, TableRevision.class);
            for (Block<Identifier, Text, Value> block : blocks) {
                for (Revision<Identifier, Text, Value> revision : block) {
                    Write write = Reflection.newInstance(Write.class, revision.getType(), revision.getKey(), revision.getValue(), revision.getLocator(), // (authorized)
                    revision.getVersion());
                    db.accept(write);
                }
                db.sync();
                logInfoMessage("Finished transferring v2 data Block {} to v3 Segment format", block.getId());
            }
        } finally {
            db.stop();
        }
    });
}
Also used : Path(java.nio.file.Path) Write(com.cinchapi.concourse.server.storage.temp.Write) Identifier(com.cinchapi.concourse.server.model.Identifier) Database(com.cinchapi.concourse.server.storage.db.Database) Value(com.cinchapi.concourse.server.model.Value) Block(com.cinchapi.concourse.server.storage.format.StorageFormatV2.Block) Text(com.cinchapi.concourse.server.model.Text)

Example 10 with Write

use of com.cinchapi.concourse.server.storage.temp.Write 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());
        }
    }
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) Position(com.cinchapi.concourse.server.model.Position) Text(com.cinchapi.concourse.server.model.Text) Identifier(com.cinchapi.concourse.server.model.Identifier) Revision(com.cinchapi.concourse.server.storage.db.Revision) Value(com.cinchapi.concourse.server.model.Value) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) 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