Search in sources :

Example 6 with Action

use of com.cinchapi.concourse.server.storage.Action in project concourse by cinchapi.

the class RecordTest method getAction.

/**
 * Get the appropriate action for {@code locator}, {@code key} and
 * {@code value} to maintain the offsetting constraint.
 *
 * @param locator
 * @param key
 * @param value
 * @return the appropriate action
 */
protected Action getAction(L locator, K key, V value) {
    Composite comp = Composite.create(locator, key, value);
    Action action = actions.get(comp);
    if (action == null || action == Action.REMOVE) {
        action = Action.ADD;
    } else {
        action = Action.REMOVE;
    }
    actions.put(comp, action);
    return action;
}
Also used : Action(com.cinchapi.concourse.server.storage.Action) Composite(com.cinchapi.concourse.server.io.Composite)

Example 7 with Action

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

Aggregations

Action (com.cinchapi.concourse.server.storage.Action)7 Value (com.cinchapi.concourse.server.model.Value)5 Text (com.cinchapi.concourse.server.model.Text)4 Identifier (com.cinchapi.concourse.server.model.Identifier)2 TObject (com.cinchapi.concourse.thrift.TObject)2 Composite (com.cinchapi.concourse.server.io.Composite)1 Revision (com.cinchapi.concourse.server.storage.db.Revision)1 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)1 Set (java.util.Set)1 Test (org.junit.Test)1