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();
}
}
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());
}
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);
}
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);
}
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();
}
Aggregations