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);
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations