Search in sources :

Example 1 with Memory

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

the class Strategy method source.

/**
 * Return the {@link Source} that this {@link Strategy} recommends for
 * looking up the {@code key} in {@code record}.
 *
 * @param key
 * @param record
 * @return the {@link Source} to use for looking up {@code key} in
 *         {@code record}
 */
public Source source(String key, long record) {
    Memory memory = store.memory();
    // TODO: The notion of a "wide" operation should be extended to case
    // when the majority (or significant number) of, but not all keys are
    // involved with an operation.
    boolean isHistoricalOperation = command.operationTimestamp() != null;
    boolean isWideOperation = command.operationKeys().isEmpty() && !command.operation().startsWith("find");
    boolean isConditionKey = command.conditionKeys().contains(key);
    boolean isOrderKey = command.orderKeys().contains(key);
    boolean isKeyRequiringTimestampRetrieval = command.keysRequiringTimestampRetrieval().containsKey(key) || (isOrderKey && isHistoricalOperation);
    Source source;
    if ((isConditionKey || isOrderKey) && !isKeyRequiringTimestampRetrieval && command.operationRecords().size() != 1) {
        // The IndexRecord must be loaded to evaluate the condition, so
        // leverage it to gather the values for key/record
        source = Source.INDEX;
    } else if (isWideOperation) {
        // The entire record is involved in the operation, so force the full
        // TableRecord to be loaded.
        source = Source.RECORD;
    } else if (memory.contains(record)) {
        source = Source.RECORD;
    } else if (memory.contains(key, record)) {
        source = Source.FIELD;
    } else {
        source = command.operationKeys().size() > 1 ? Source.RECORD : Source.FIELD;
    }
    return source;
}
Also used : Memory(com.cinchapi.concourse.server.storage.Memory)

Aggregations

Memory (com.cinchapi.concourse.server.storage.Memory)1