Search in sources :

Example 46 with Value

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

the class IndexRecord method coalesce.

/**
 * Return all the key/value mappings of keys that matched {@code key} at
 * {@code timestamp} in a case insensitive manner.
 *
 * @param key
 * @param timestamp
 * @return the matching entries
 */
private Map<Value, Set<Identifier>> coalesce(Value key, long timestamp) {
    read.lock();
    try {
        Map<Value, Set<Identifier>> data = Maps.newLinkedHashMap();
        Map<Value, List<CompactRevision<Identifier>>> coalesced = ((CoalescableTreeMap<Value, List<CompactRevision<Identifier>>>) history).coalesce(key, CASE_INSENSITIVE_COALESCER);
        for (Entry<Value, List<CompactRevision<Identifier>>> entry : coalesced.entrySet()) {
            Value stored = entry.getKey();
            List<CompactRevision<Identifier>> revisions = entry.getValue();
            Set<Identifier> values = Sets.newLinkedHashSet();
            Iterator<CompactRevision<Identifier>> it = revisions.iterator();
            while (it.hasNext()) {
                CompactRevision<Identifier> revision = it.next();
                if (revision.getVersion() <= timestamp) {
                    if (revision.getType() == Action.ADD) {
                        values.add(revision.getValue());
                    } else {
                        values.remove(revision.getValue());
                    }
                } else {
                    break;
                }
            }
            data.put(stored, values);
        }
        return data;
    } finally {
        read.unlock();
    }
}
Also used : CoalescableTreeMap(com.cinchapi.common.collect.CoalescableTreeMap) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) List(java.util.List)

Example 47 with Value

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

the class Limbo method search.

@Override
public Set<Long> search(String key, String query) {
    Map<Long, Set<Value>> matches = Maps.newHashMap();
    String[] needle = TStrings.stripStopWordsAndTokenize(query.toLowerCase());
    if (needle.length > 0) {
        for (Iterator<Write> it = getSearchIterator(key); it.hasNext(); ) {
            Write write = it.next();
            Value value = write.getValue();
            long record = write.getRecord().longValue();
            if (isPossibleSearchMatch(key, write, value)) {
                /*
                     * NOTE: It is not enough to merely check if the stored text
                     * contains the query because the Database does infix
                     * indexing/searching, which has some subtleties:
                     * 1. Stop words are removed from the both stored indices
                     * and the search query
                     * 2. A query and document are considered to match if the
                     * document contains a sequence of terms where each term or
                     * a substring of the term matches the term in the same
                     * relative position of the query.
                     */
                // CON-10: compare lowercase for case insensitive search
                String stored = (String) (value.getObject());
                String[] haystack = TStrings.stripStopWordsAndTokenize(stored.toLowerCase());
                if (haystack.length > 0 && TStrings.isInfixSearchMatch(needle, haystack)) {
                    Set<Value> values = matches.computeIfAbsent(record, $ -> new HashSet<>());
                    if (write.getType() == Action.REMOVE) {
                        values.remove(value);
                    } else {
                        values.add(value);
                    }
                }
            }
        }
    }
    // SearchRecord#search())
    return Sets.newLinkedHashSet(Maps.filterValues(matches, emptySetFilter).keySet());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Value(com.cinchapi.concourse.server.model.Value)

Example 48 with Value

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

the class Limbo method chronologize.

/**
 * Return a time series that contains the values stored for {@code key} in
 * {@code record} at each modification timestamp between {@code start}
 * (inclusive) and {@code end} (exclusive).
 *
 * @param key the field name
 * @param record the record id
 * @param start the start timestamp (inclusive)
 * @param end the end timestamp (exclusive)
 * @param context the prior context
 * @return a {@link Map mapping} from modification timestamp to a non-empty
 *         {@link Set} of values that were contained at that timestamp
 */
public Map<Long, Set<TObject>> chronologize(String key, long record, long start, long end, Map<Long, Set<TObject>> context) {
    Set<TObject> snapshot = Iterables.getLast(context.values(), Sets.<TObject>newLinkedHashSet());
    if (snapshot.isEmpty() && !context.isEmpty()) {
        // CON-474: Empty set is placed in the context if it was the last
        // snapshot known to the database
        context.remove(Time.NONE);
    }
    for (Iterator<Write> it = iterator(); it.hasNext(); ) {
        Write write = it.next();
        long timestamp = write.getVersion();
        if (timestamp >= end) {
            break;
        } else {
            Text $key = write.getKey();
            long $record = write.getRecord().longValue();
            Action action = write.getType();
            if ($key.toString().equals(key) && $record == record) {
                snapshot = Sets.newLinkedHashSet(snapshot);
                Value value = write.getValue();
                if (action == Action.ADD) {
                    snapshot.add(value.getTObject());
                } else if (action == Action.REMOVE) {
                    snapshot.remove(value.getTObject());
                }
                if (timestamp >= start) {
                    context.put(timestamp, snapshot);
                }
            }
        }
    }
    return Maps.filterValues(context, emptySetFilter);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Action(com.cinchapi.concourse.server.storage.Action) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 49 with Value

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

the class Database method select.

@Override
public Set<TObject> select(String key, long record) {
    Identifier L = Identifier.of(record);
    Text K = Text.wrapCached(key);
    TableRecord table = getTableRecord(L, K);
    Set<Value> data = table.get(K);
    return Transformers.transformSet(data, 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 50 with Value

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

the class RangeLockServiceTest method testWriteGtHigherValueIsNotRangeBlockedIfReadingBw.

@Test
public void testWriteGtHigherValueIsNotRangeBlockedIfReadingBw() throws InterruptedException {
    final Text key = Variables.register("key", TestData.getText());
    final Value value1 = Variables.register("value1", TestData.getValue());
    final Value value2 = Variables.register("value2", increase(value1));
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch finishLatch = new CountDownLatch(1);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            rangeLockService.getReadLock(key, Operator.BETWEEN, value1, value2).lock();
            startLatch.countDown();
            try {
                finishLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            rangeLockService.getReadLock(key, Operator.BETWEEN, value1, value2).unlock();
        }
    });
    t.start();
    startLatch.await();
    Value value3 = Variables.register("value3", increase(value2));
    Assert.assertFalse(rangeLockService.isRangeBlocked(LockType.WRITE, RangeToken.forWriting(key, value3)));
    finishLatch.countDown();
}
Also used : Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

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