Search in sources :

Example 1 with Value

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

the class Buffer method chronologize.

@Override
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);
    }
    Iterator<Write> it = iterator(key, record, end - 1);
    try {
        while (it.hasNext()) {
            Write write = it.next();
            long timestamp = write.getVersion();
            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);
    } finally {
        Iterators.close(it);
    }
}
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 2 with Value

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

the class Database method explore.

@Override
public Map<Long, Set<TObject>> explore(String key, Aliases aliases, long timestamp) {
    Text L = Text.wrapCached(key);
    IndexRecord index = getIndexRecord(L);
    Value[] Ks = Transformers.transformArray(aliases.values(), Value::wrap, Value.class);
    Map<Identifier, Set<Value>> map = index.findAndGet(timestamp, aliases.operator(), Ks);
    return Transformers.transformTreeMapSet(map, Identifier::longValue, Value::getTObject, Long::compare);
}
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 3 with Value

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

the class IndexRecord method findAndGet.

/**
 * Explore this record and return a mapping from PrimaryKey to the Values
 * that cause the corresponding records to satisfy {@code operator} in
 * relation to the specified {@code values} (and at the specified
 * {@code timestamp} if {@code historical} is {@code true}).
 *
 * @param historical - if {@code true} query the history, otherwise query
 *            the current state
 * @param timestamp - this value is ignored if {@code historical} is
 *            {@code false}, otherwise this value is the historical
 *            timestamp at which to query the field
 * @param operator
 * @param values
 * @return the relevant data that causes the matching records to satisfy the
 *         criteria
 */
private Map<Identifier, Set<Value>> findAndGet(boolean historical, long timestamp, Operator operator, Value... values) {
    /* Authorized */
    // CON-667: Value ordering for Strings is such that uppercase characters
    // are "smaller" than lowercase ones. Concourse uses case insensitive
    // matching, so we sometimes must modify the input #values in order to
    // ensure that all equal forms of a value are captured or excluded as
    // necessary.
    read.lock();
    try {
        Map<Identifier, Set<Value>> data = Maps.newHashMap();
        Value value = values[0];
        if (operator == Operator.EQUALS) {
            for (Entry<Value, Set<Identifier>> entry : (historical ? coalesce(value, timestamp) : coalesce(value)).entrySet()) {
                Value stored = entry.getKey();
                for (Identifier record : entry.getValue()) {
                    MultimapViews.put(data, record, stored);
                }
            }
        } else if (operator == Operator.NOT_EQUALS) {
            for (Value stored : historical ? history.keySet() : present.keySet()) {
                if (!value.equalsIgnoreCase(stored)) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.GREATER_THAN) {
            // CON-667
            value = value.toLowerCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).tailSet(value, false)) {
                if (!historical || stored.compareToIgnoreCase(value) > 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.GREATER_THAN_OR_EQUALS) {
            // CON-667
            value = value.toUpperCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).tailSet(value, true)) {
                if (!historical || stored.compareToIgnoreCase(value) >= 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.LESS_THAN) {
            // CON-667
            value = value.toUpperCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).headSet(value, false)) {
                if (!historical || stored.compareToIgnoreCase(value) < 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.LESS_THAN_OR_EQUALS) {
            // CON-667
            value = value.toLowerCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).headSet(value, true)) {
                if (!historical || stored.compareToIgnoreCase(value) <= 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.BETWEEN) {
            Preconditions.checkArgument(values.length > 1);
            Value value2 = values[1];
            // CON-667
            value = value.toUpperCase();
            // CON-667
            value2 = value2.toUpperCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).subSet(value, true, value2, false)) {
                if (!historical || (stored.compareTo(value) >= 0 && stored.compareTo(value2) < 0)) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.REGEX) {
            Pattern p = Pattern.compile(value.getObject().toString());
            for (Value stored : historical ? history.keySet() : present.keySet()) {
                Matcher m = p.matcher(stored.getObject().toString());
                if (m.matches()) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.NOT_REGEX) {
            Pattern p = Pattern.compile(value.getObject().toString());
            for (Value stored : historical ? history.keySet() : present.keySet()) {
                Matcher m = p.matcher(stored.getObject().toString());
                if (!m.matches()) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else {
            throw new UnsupportedOperationException();
        }
        return data;
    } finally {
        read.unlock();
    }
}
Also used : Pattern(java.util.regex.Pattern) NavigableSet(java.util.NavigableSet) Identifier(com.cinchapi.concourse.server.model.Identifier) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Matcher(java.util.regex.Matcher) Value(com.cinchapi.concourse.server.model.Value)

Example 4 with Value

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

the class TableRecord method chronologize.

/**
 * Return a time series of values that holds the data stored for {@code key}
 * after each modification.
 *
 * @param key the field name
 * @param start the start timestamp (inclusive)
 * @param end the end timestamp (exclusive)
 * @return the time series of values held in the {@code key} field between
 *         {@code start} and {@code end}
 */
public Map<Long, Set<Value>> chronologize(Text key, long start, long end) {
    read.lock();
    try {
        Map<Long, Set<Value>> context = Maps.newLinkedHashMap();
        List<CompactRevision<Value>> revisions = history.get(key);
        Set<Value> snapshot = Sets.newLinkedHashSet();
        if (revisions != null) {
            Iterator<CompactRevision<Value>> it = revisions.iterator();
            while (it.hasNext()) {
                CompactRevision<Value> revision = it.next();
                long timestamp = revision.getVersion();
                if (timestamp >= end) {
                    break;
                } else {
                    Action action = revision.getType();
                    snapshot = Sets.newLinkedHashSet(snapshot);
                    Value value = revision.getValue();
                    if (action == Action.ADD) {
                        snapshot.add(value);
                    } else if (action == Action.REMOVE) {
                        snapshot.remove(value);
                    }
                    if (timestamp >= start) {
                        context.put(timestamp, snapshot);
                    }
                }
            }
        }
        if (snapshot.isEmpty()) {
            // CON-474: If the last snapshot is empty, add it here so that
            // the Buffer has the proper context
            context.put(Time.NONE, snapshot);
        }
        return context;
    } finally {
        read.unlock();
    }
}
Also used : Action(com.cinchapi.concourse.server.storage.Action) Set(java.util.Set) Value(com.cinchapi.concourse.server.model.Value)

Example 5 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, long timestamp) {
    Identifier L = write.getRecord();
    Text K = write.getKey();
    Value V = write.getValue();
    TableRecord table = getTableRecord(L, K);
    return table.contains(K, V, timestamp);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) 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