use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.
the class TextTest method testCompositeConsistency.
@Test
public void testCompositeConsistency() {
String key = "description";
String term = " </p><p><s";
Composite c1 = Composite.create(Text.wrap(key), Text.wrap(term));
int count = TestData.getScaleCount();
for (int i = 0; i < count; ++i) {
Composite c2 = Composite.create(Text.wrap(key), Text.wrap(term.toCharArray(), 0, term.length()));
Assert.assertEquals(c1, c2);
}
}
use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.
the class Database method getCorpusRecord.
/**
* Return the CorpusRecord identified by {@code key}.
*
* @param key
* @param query
* @param toks {@code query} split by whitespace
* @return the CorpusRecord
*/
private CorpusRecord getCorpusRecord(Text key, Text infix) {
masterLock.readLock().lock();
try {
Composite composite = Composite.create(key, infix);
Cache<Composite, CorpusRecord> cache = ENABLE_SEARCH_CACHE ? corpusCaches.computeIfAbsent(key, $ -> buildCache()) : DISABLED_CORPUS_CACHE;
return cache.get(composite, () -> {
CorpusRecord $ = CorpusRecord.createPartial(key, infix);
for (Segment segment : segments) {
segment.corpus().seek(composite, $);
}
return $;
});
} catch (ExecutionException e) {
throw CheckedExceptions.wrapAsRuntimeException(e);
} finally {
masterLock.readLock().unlock();
}
}
use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.
the class Chunk method insertUnsafe.
/**
* {@link #insert(Byteable, Byteable, Byteable, long, Action)}
* without locking. Only call this method directly if the {@link Chunk} is
* {@link #concurrent}.
*
* @param locator
* @param key
* @param value
* @param version
* @param type
* @return the inserted {@link Revision}
* @throws IllegalStateException
*/
protected final Artifact<L, K, V> insertUnsafe(L locator, K key, V value, long version, Action type) throws IllegalStateException {
Preconditions.checkState(isMutable(), "Cannot modify an immutable chunk");
// @formatter:off
locator = deduplicate(locator);
key = deduplicate(key);
value = deduplicate(value);
// @formatter:on
Revision<L, K, V> revision = makeRevision(locator, key, value, version, type);
revisions.add(revision);
revisionCount.incrementAndGet();
// @formatter:off
Composite[] composites = Array.containing(Composite.create(revision.getLocator()), Composite.create(revision.getLocator(), revision.getKey()), Composite.create(revision.getLocator(), revision.getKey(), // NOTE: The entire revision is added
revision.getValue()));
// @formatter:on
for (Composite composite : composites) {
filter.put(composite);
}
incrementLengthBy(revision.size() + 4);
manifest = null;
bytes = null;
return makeArtifact(revision, composites);
}
use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.
the class ManifestTest method testBackgroundLoadEntriesWorksHit.
@SuppressWarnings("rawtypes")
@Test
public void testBackgroundLoadEntriesWorksHit() {
Set<Composite> composites = Sets.newLinkedHashSet();
Manifest manifest = Manifest.create(100000);
for (int i = 0; i < TestData.getScaleCount(); ++i) {
Composite composite = Composite.create(TestData.getText());
if (composites.add(composite)) {
manifest.putStart(i, composite);
manifest.putEnd(i + 1, composite);
}
}
Path file = Paths.get(TestData.getTemporaryTestFile());
manifest.transfer(file);
manifest = Manifest.load(file, 0, FileSystem.getFileSize(file.toString()));
Composite composite = composites.iterator().next();
Map map = Reflection.call(manifest, "entries", composite);
Assert.assertTrue(map.containsKey(composite));
Assert.assertEquals(1, map.size());
while (Reflection.get("$entries", manifest) == null || Reflection.call(Reflection.get("$entries", manifest), "get") == null) {
/* spin */
}
map = Reflection.call(manifest, "entries", composite);
Assert.assertTrue(map.containsKey(composite));
Assert.assertEquals(composites.size(), map.size());
map = Reflection.call(manifest, "entries");
Assert.assertTrue(map.containsKey(composite));
Assert.assertEquals(composites.size(), map.size());
}
use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.
the class ManifestTest method testManifestStreamedEntriesAccuracy.
@Test
public void testManifestStreamedEntriesAccuracy() {
int threshold = Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD;
Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD = (int) Math.pow(2, 16);
try {
Manifest manifest = Manifest.create(100000);
Text text = Text.wrap(Random.getString());
int count = 0;
int start = 0;
Map<Composite, Range> expected = Maps.newHashMap();
while (manifest.length() < Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD) {
Identifier record = Identifier.of(count);
int $start = start;
int end = start + TestData.getScaleCount();
Range range = new Manifest.Range() {
@Override
public long start() {
return $start;
}
@Override
public long end() {
return end;
}
};
Composite composite = Composite.create(text, record);
manifest.putStart(start, composite);
manifest.putEnd(end, composite);
expected.put(composite, range);
start = end + 1;
++count;
}
Path file = Paths.get(TestData.getTemporaryTestFile());
manifest.transfer(file);
Manifest $manifest = Manifest.load(file, 0, FileSystem.getFileSize(file.toString()));
expected.forEach((composite, range) -> {
Range actual = $manifest.lookup(composite);
Assert.assertEquals(range.start(), actual.start());
Assert.assertEquals(range.end(), actual.end());
});
} finally {
Manifest.MANIFEST_LENGTH_ENTRY_STREAMING_THRESHOLD = threshold;
}
}
Aggregations