Search in sources :

Example 6 with Composite

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 = "&nbsp;</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);
    }
}
Also used : Composite(com.cinchapi.concourse.server.io.Composite) ByteableTest(com.cinchapi.concourse.server.io.ByteableTest) Test(org.junit.Test)

Example 7 with Composite

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();
    }
}
Also used : Composite(com.cinchapi.concourse.server.io.Composite) AnyStrings(com.cinchapi.common.base.AnyStrings) ListIterator(java.util.ListIterator) Logger(com.cinchapi.concourse.util.Logger) Receipt(com.cinchapi.concourse.server.storage.db.kernel.Segment.Receipt) Compactor(com.cinchapi.concourse.server.storage.db.compaction.Compactor) HashMultimap(com.google.common.collect.HashMultimap) Restricted(com.cinchapi.concourse.annotate.Restricted) TObjectSorter(com.cinchapi.concourse.server.model.TObjectSorter) TreeMultimap(com.google.common.collect.TreeMultimap) Transformers(com.cinchapi.concourse.util.Transformers) Map(java.util.Map) DurableStore(com.cinchapi.concourse.server.storage.DurableStore) Comparators(com.cinchapi.concourse.util.Comparators) ThreadFactory(java.util.concurrent.ThreadFactory) Path(java.nio.file.Path) AwaitableExecutorService(com.cinchapi.concourse.server.concurrent.AwaitableExecutorService) ThreadFactories(com.cinchapi.common.collect.concurrent.ThreadFactories) Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) ImmutableMap(com.google.common.collect.ImmutableMap) FileSystem(com.cinchapi.concourse.server.io.FileSystem) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ManagedOperation(com.cinchapi.concourse.server.jmx.ManagedOperation) UUID(java.util.UUID) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) CorpusArtifact(com.cinchapi.concourse.server.storage.db.kernel.CorpusArtifact) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) CheckedExceptions(com.cinchapi.common.base.CheckedExceptions) CacheBuilder(com.google.common.cache.CacheBuilder) Text(com.cinchapi.concourse.server.model.Text) CacheStats(com.google.common.cache.CacheStats) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ArrayBuilder(com.cinchapi.common.base.ArrayBuilder) Verify(com.cinchapi.common.base.Verify) Callable(java.util.concurrent.Callable) NoOpScheduledExecutorService(com.cinchapi.concourse.server.concurrent.NoOpScheduledExecutorService) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Write(com.cinchapi.concourse.server.storage.temp.Write) Multimap(com.google.common.collect.Multimap) NoOpCompactor(com.cinchapi.concourse.server.storage.db.compaction.NoOpCompactor) NoOpCache(com.cinchapi.concourse.server.storage.cache.NoOpCache) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Aliases(com.cinchapi.concourse.thrift.TObject.Aliases) TStrings(com.cinchapi.concourse.util.TStrings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) TObject(com.cinchapi.concourse.thrift.TObject) GlobalState(com.cinchapi.concourse.server.GlobalState) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SegmentLoadingException(com.cinchapi.concourse.server.storage.db.kernel.SegmentLoadingException) NoSuchElementException(java.util.NoSuchElementException) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Value(com.cinchapi.concourse.server.model.Value) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) Functions(com.google.common.base.Functions) Iterator(java.util.Iterator) HashCode(com.google.common.hash.HashCode) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) File(java.io.File) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Lock(java.util.concurrent.locks.Lock) Identifier(com.cinchapi.concourse.server.model.Identifier) Memory(com.cinchapi.concourse.server.storage.Memory) Paths(java.nio.file.Paths) Position(com.cinchapi.concourse.server.model.Position) Preconditions(com.google.common.base.Preconditions) WriteStreamProfiler(com.cinchapi.concourse.server.storage.WriteStreamProfiler) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) SimilarityCompactor(com.cinchapi.concourse.server.storage.db.compaction.similarity.SimilarityCompactor) Composite(com.cinchapi.concourse.server.io.Composite) ExecutionException(java.util.concurrent.ExecutionException) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 8 with Composite

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);
}
Also used : Composite(com.cinchapi.concourse.server.io.Composite)

Example 9 with Composite

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());
}
Also used : Path(java.nio.file.Path) Composite(com.cinchapi.concourse.server.io.Composite) Map(java.util.Map) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

Example 10 with Composite

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;
    }
}
Also used : Path(java.nio.file.Path) Identifier(com.cinchapi.concourse.server.model.Identifier) Composite(com.cinchapi.concourse.server.io.Composite) Text(com.cinchapi.concourse.server.model.Text) Range(com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

Aggregations

Composite (com.cinchapi.concourse.server.io.Composite)10 Path (java.nio.file.Path)4 Test (org.junit.Test)4 Identifier (com.cinchapi.concourse.server.model.Identifier)3 Text (com.cinchapi.concourse.server.model.Text)3 Segment (com.cinchapi.concourse.server.storage.db.kernel.Segment)3 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)3 Map (java.util.Map)3 Value (com.cinchapi.concourse.server.model.Value)2 CorpusArtifact (com.cinchapi.concourse.server.storage.db.kernel.CorpusArtifact)2 Receipt (com.cinchapi.concourse.server.storage.db.kernel.Segment.Receipt)2 AnyStrings (com.cinchapi.common.base.AnyStrings)1 ArrayBuilder (com.cinchapi.common.base.ArrayBuilder)1 CheckedExceptions (com.cinchapi.common.base.CheckedExceptions)1 Verify (com.cinchapi.common.base.Verify)1 ThreadFactories (com.cinchapi.common.collect.concurrent.ThreadFactories)1 Restricted (com.cinchapi.concourse.annotate.Restricted)1 GlobalState (com.cinchapi.concourse.server.GlobalState)1 AwaitableExecutorService (com.cinchapi.concourse.server.concurrent.AwaitableExecutorService)1 NoOpScheduledExecutorService (com.cinchapi.concourse.server.concurrent.NoOpScheduledExecutorService)1