Search in sources :

Example 1 with Write

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

the class Transaction method deserialize.

/**
 * Deserialize the content of this Transaction from {@code bytes}.
 *
 * @param bytes
 */
private void deserialize(ByteBuffer bytes) {
    locks = Maps.newHashMap();
    Iterator<ByteBuffer> it = ByteableCollections.iterator(ByteBuffers.slice(bytes, bytes.getInt()));
    while (it.hasNext()) {
        LockDescription lock = LockDescription.fromByteBuffer(it.next(), lockService, rangeLockService);
        locks.put(lock.getToken(), lock);
    }
    it = ByteableCollections.iterator(bytes);
    while (it.hasNext()) {
        Write write = Write.fromByteBuffer(it.next());
        limbo.insert(write);
    }
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Write

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

the class WriteStreamProfiler method deduplicate.

/**
 * Search through all of the {@link #streams} for any {@link Write Writes}
 * that are duplicated across the entire collection. Each {@link Stream}
 * that contains at least one duplicate {@link Write} is returned in a
 * {@link Map} from the offending stream to another one, generated by
 * {@code factory} that is clear of all duplicates.
 * <p>
 * The collection of {@link #streams} is <strong>NOT</strong> modified and
 * the "cleaned" streams that are {@link Map#values() values} in the
 * returned {@link Map} are only guaranteed to have had non-duplicate from
 * the original stream {@link WriteStream#append(Write) appended} (e.g. no
 * sync or save). If desired, the caller must manually update external
 * collections with cleaned streams.
 * </p>
 *
 * @param factory used to create a new {@link WriteStream} where
 *            non-duplicate data is staged.
 * @return a {@link Map} from each stream with duplicate data to a replicate
 *         stream where duplicates have been removed
 */
public Map<T, T> deduplicate(Supplier<T> factory) {
    duplicates = LinkedHashMultimap.create();
    Map<T, T> deduped = new HashMap<>();
    streams.forEach(stream -> {
        AtomicReference<T> staging = new AtomicReference<>(null);
        List<Write> unique = new ArrayList<>();
        stream.writes().forEach(write -> {
            HashCode hash = write.hash();
            if (hashes.add(hash)) {
                if (staging.get() != null) {
                    staging.get().append(write);
                } else {
                    unique.add(write);
                }
            } else {
                Logger.warn("Found duplicate Write {} in {}", write, stream);
                if (staging.get() == null) {
                    staging.set(factory.get());
                    for (Write seen : unique) {
                        staging.get().append(seen);
                    }
                    unique.clear();
                }
                duplicates.put(write, stream);
            }
        });
        if (staging.get() != null) {
            deduped.put(stream, staging.get());
        } else {
            Logger.info("No duplicate Writes found in {}", stream);
        }
    });
    return deduped;
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) HashCode(com.google.common.hash.HashCode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 3 with Write

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

the class SegmentTest method testRevisionTimestampTrackingPersistence.

@Test
public void testRevisionTimestampTrackingPersistence() throws SegmentLoadingException {
    Write w0 = TestData.getWriteRemove();
    Write w1 = TestData.getWriteAdd();
    segment.acquire(w1);
    Assert.assertEquals(w1.getVersion(), segment.minTs);
    Assert.assertEquals(w1.getVersion(), segment.maxTs);
    Write w2 = TestData.getWriteAdd();
    segment.acquire(w2);
    Assert.assertEquals(w1.getVersion(), segment.minTs);
    Assert.assertEquals(w2.getVersion(), segment.maxTs);
    Write w4 = TestData.getWriteAdd();
    Write w3 = TestData.getWriteAdd();
    segment.acquire(w3);
    Assert.assertEquals(w3.getVersion(), segment.maxTs);
    segment.acquire(w4);
    Assert.assertEquals(w3.getVersion(), segment.maxTs);
    segment.acquire(w0);
    Assert.assertEquals(w0.getVersion(), segment.minTs);
    Path file = Paths.get(TestData.getTemporaryTestFile());
    segment.transfer(file);
    segment = Segment.load(file);
    Assert.assertEquals(w0.getVersion(), segment.minTs);
    Assert.assertEquals(w3.getVersion(), segment.maxTs);
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) Path(java.nio.file.Path) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 4 with Write

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

the class SegmentTest method testRevisionTimestampTracking.

@Test
public void testRevisionTimestampTracking() {
    Write w0 = TestData.getWriteRemove();
    Write w1 = TestData.getWriteAdd();
    segment.acquire(w1);
    Assert.assertEquals(w1.getVersion(), segment.minTs);
    Assert.assertEquals(w1.getVersion(), segment.maxTs);
    Write w2 = TestData.getWriteAdd();
    segment.acquire(w2);
    Assert.assertEquals(w1.getVersion(), segment.minTs);
    Assert.assertEquals(w2.getVersion(), segment.maxTs);
    Write w4 = TestData.getWriteAdd();
    Write w3 = TestData.getWriteAdd();
    segment.acquire(w3);
    Assert.assertEquals(w3.getVersion(), segment.maxTs);
    segment.acquire(w4);
    Assert.assertEquals(w3.getVersion(), segment.maxTs);
    segment.acquire(w0);
    Assert.assertEquals(w0.getVersion(), segment.minTs);
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 5 with Write

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

the class DatabaseTest method testBackgroundManifestLoadConcurrency.

@Test
public void testBackgroundManifestLoadConcurrency() throws InterruptedException {
    Database db = (Database) store;
    List<Write> writes = Lists.newArrayList();
    for (int i = 0; i < TestData.getScaleCount() * 3; ++i) {
        String key = TestData.getSimpleString();
        TObject value = TestData.getTObject();
        long record = (Math.abs(TestData.getInt()) % 10) + 1;
        add(key, value, record);
        if (Math.abs(TestData.getInt()) % 3 == 0) {
            writes.add(Write.add(key, value, record));
        }
        if (Math.abs(TestData.getInt()) % 3 == 0) {
            db.sync();
        }
    }
    db.stop();
    db.start();
    ExecutorService executor = Executors.newFixedThreadPool(5);
    Iterator<Write> it = writes.iterator();
    while (it.hasNext()) {
        Write write = it.next();
        executor.execute(() -> {
            Assert.assertTrue(db.verify(write.getKey().toString(), write.getValue().getTObject(), write.getRecord().longValue()));
        });
    }
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) ExecutorService(java.util.concurrent.ExecutorService) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) 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