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