Search in sources :

Example 6 with Value

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

the class Database method gather.

@Override
public Set<TObject> gather(String key, long record, long timestamp) {
    Text L = Text.wrapCached(key);
    Identifier V = Identifier.of(record);
    IndexRecord index = getIndexRecord(L);
    Set<Value> Ks = index.gather(V, timestamp);
    return Transformers.transformSet(Ks, Value::getTObject);
}
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 Value

use of com.cinchapi.concourse.server.model.Value 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 8 with Value

use of com.cinchapi.concourse.server.model.Value 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 9 with Value

use of com.cinchapi.concourse.server.model.Value 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 10 with Value

use of com.cinchapi.concourse.server.model.Value 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)

Aggregations

Value (com.cinchapi.concourse.server.model.Value)73 Text (com.cinchapi.concourse.server.model.Text)60 Test (org.junit.Test)43 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)34 Identifier (com.cinchapi.concourse.server.model.Identifier)25 CountDownLatch (java.util.concurrent.CountDownLatch)22 Set (java.util.Set)14 Operator (com.cinchapi.concourse.thrift.Operator)10 Action (com.cinchapi.concourse.server.storage.Action)6 Range (com.google.common.collect.Range)6 LinkedHashSet (java.util.LinkedHashSet)6 TObject (com.cinchapi.concourse.thrift.TObject)5 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 RangeToken (com.cinchapi.concourse.server.concurrent.RangeToken)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ByteBuffer (java.nio.ByteBuffer)3 Path (java.nio.file.Path)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Position (com.cinchapi.concourse.server.model.Position)2