Search in sources :

Example 6 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method verify.

@Override
public boolean verify(Write write) {
    Identifier L = write.getRecord();
    Text K = write.getKey();
    Value V = write.getValue();
    Record<Identifier, Text, Value> table = ENABLE_VERIFY_BY_LOOKUP ? getLookupRecord(L, K, V) : getTableRecord(L, K);
    return table.contains(K, V);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 7 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method getLookupRecord.

/**
 * Return a {@link Record} that is guaranteed to have the present state for
 * whether {@code value} is contained for {@code key} in {@code record}. The
 * truth of this query can be obtained using the
 * {@link Record#contains(com.cinchapi.concourse.server.io.Byteable, com.cinchapi.concourse.server.io.Byteable)}
 * method on the returned {@link Record}.
 * <p>
 * The query answered by this {@link Record} can also be answered by that
 * returned from {@link #getTableRecord(Identifier)}
 * and {@link #getTableRecord(Identifier, Text)}, but this method will
 * attempt to short circuit by not loading {@link Revisions} that don't
 * involve {@code record}, {@code key} and {@code value}. As a result, the
 * returned {@link Record} is not cached and cannot be reliably used for
 * other queries.
 * </p>
 *
 * @param record
 * @param key
 * @param value
 * @return the {@link Record}
 */
private Record<Identifier, Text, Value> getLookupRecord(Identifier record, Text key, Value value) {
    masterLock.readLock().lock();
    try {
        // First, see if there is a cached full or partial Record that can
        // allow a lookup to be performed.
        Composite c1 = Composite.create(record);
        Composite c2 = null;
        Composite c3 = null;
        Record<Identifier, Text, Value> lookup = tableCache.getIfPresent(c1);
        if (lookup == null) {
            c2 = Composite.create(record, key);
            lookup = tablePartialCache.getIfPresent(c2);
        }
        if (lookup == null) {
            // Create a LookupRecord to handle this, but DO NOT cache it
            // since it has no other utility.
            c3 = Composite.create(record, key, value);
            lookup = new LookupRecord(record, key, value);
            for (Segment segment : segments) {
                if (segment.table().mightContain(c3)) {
                    // Whenever it is possible that the LKV exists, we must
                    // gather Revisions for LK within a Record so the
                    // current state of LKV can be determined.
                    segment.table().seek(c2, lookup);
                }
            }
        }
        return lookup;
    } finally {
        masterLock.readLock().unlock();
    }
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Composite(com.cinchapi.concourse.server.io.Composite) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 8 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Segment method acquire.

/**
 * Append the {@code write} to this {@link Segment} using the
 * {@code executor} to asynchronously write to all the contained
 * {@link Block blocks}.
 *
 * @param write
 * @param executor
 * @return a {@link Receipt} that contains the {@link Revision Revisions}
 *         that were created as a consequence of the transfer
 * @throws InterruptedException
 */
public Receipt acquire(Write write, AwaitableExecutorService executor) throws InterruptedException {
    Preconditions.checkState(isMutable(), "Cannot transfer Writes to an immutable Segment");
    writeLock.lock();
    try {
        // @formatter:off
        Identifier record = write.getRecord();
        Text key = write.getKey();
        Value value = write.getValue();
        long version = write.getVersion();
        Action type = write.getType();
        Receipt.Builder receipt = Receipt.builder();
        Runnable[] tasks = Array.containing(() -> {
            TableArtifact artifact = table.insert(record, key, value, version, type);
            receipt.itemize(artifact);
        }, () -> {
            IndexArtifact artifact = index.insert(key, value, record, version, type);
            receipt.itemize(artifact);
        }, () -> {
            Collection<CorpusArtifact> artifacts = corpus.insert(key, value, record, version, type);
            receipt.itemize(artifacts);
        });
        // @formatter:on
        executor.await((task, error) -> Logger.error("Unexpected error when trying to transfer the following Write to the Database: {}", write, error), tasks);
        // CON-587: Set the min/max version of this Segment because it
        // cannot be assumed that revisions are inserted in monotonically
        // increasing order of version.
        maxTs = Math.max(write.getVersion(), maxTs);
        minTs = Math.min(write.getVersion(), minTs);
        return receipt.build();
    } finally {
        writeLock.unlock();
    }
}
Also used : Action(com.cinchapi.concourse.server.storage.Action) Text(com.cinchapi.concourse.server.model.Text) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value)

Example 9 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method select.

@Override
public Map<String, Set<TObject>> select(long record, long timestamp) {
    Identifier L = Identifier.of(record);
    TableRecord table = getTableRecord(L);
    Map<Text, Set<Value>> data = table.getAll(timestamp);
    return Transformers.transformTreeMapSet(data, Text::toString, Value::getTObject, Comparators.CASE_INSENSITIVE_STRING_COMPARATOR);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 10 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method chronologize.

@Override
public Map<Long, Set<TObject>> chronologize(String key, long record, long start, long end) {
    Identifier L = Identifier.of(record);
    Text K = Text.wrapCached(key);
    TableRecord table = getTableRecord(L);
    Map<Long, Set<Value>> data = table.chronologize(K, start, end);
    return Transformers.transformMapSet(data, Functions.identity(), Value::getTObject);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Aggregations

Identifier (com.cinchapi.concourse.server.model.Identifier)40 Text (com.cinchapi.concourse.server.model.Text)28 Value (com.cinchapi.concourse.server.model.Value)25 Test (org.junit.Test)18 Set (java.util.Set)13 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)9 LinkedHashSet (java.util.LinkedHashSet)7 ByteBuffer (java.nio.ByteBuffer)6 Path (java.nio.file.Path)6 Write (com.cinchapi.concourse.server.storage.temp.Write)4 List (java.util.List)4 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 Position (com.cinchapi.concourse.server.model.Position)3 Action (com.cinchapi.concourse.server.storage.Action)3 Range (com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Composite (com.cinchapi.concourse.server.io.Composite)2 CorpusRecord (com.cinchapi.concourse.server.storage.db.CorpusRecord)2