Search in sources :

Example 71 with AtomicSupport

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

the class ConcourseServer method findOrInsertCriteriaJson.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public long findOrInsertCriteriaJson(TCriteria criteria, String json, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    List<Multimap<String, Object>> objects = Lists.newArrayList(Convert.jsonToJava(json));
    AbstractSyntaxTree ast = compiler.parse(criteria);
    AtomicSupport store = getStore(transaction, environment);
    Set<Long> records = Sets.newLinkedHashSet();
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        records.clear();
        Operations.findOrInsertAtomic(records, objects, ast, atomic);
    });
    if (records.size() == 1) {
        return Iterables.getOnlyElement(records);
    } else {
        throw new DuplicateEntryException(AnyStrings.joinWithSpace("Found", records.size(), "records that match", Language.translateFromThriftCriteria(criteria).ccl()));
    }
}
Also used : Multimap(com.google.common.collect.Multimap) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) DuplicateEntryException(com.cinchapi.concourse.thrift.DuplicateEntryException) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 72 with AtomicSupport

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

the class ConcourseServer method countKeyCcl.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public long countKeyCcl(String key, String ccl, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AbstractSyntaxTree ast = compiler.parse(ccl);
    AtomicSupport store = getStore(transaction, environment);
    return AtomicOperations.supplyWithRetry(store, (atomic) -> {
        Set<Long> records = ast.accept(Finder.instance(), atomic);
        return Operations.countKeyRecordsAtomic(key, records, Time.NONE, atomic);
    });
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 73 with AtomicSupport

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

the class ConcourseServer method clearKeyRecords.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void clearKeyRecords(String key, List<Long> records, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        for (long record : records) {
            Operations.clearKeyRecordAtomic(key, record, atomic);
        }
    });
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 74 with AtomicSupport

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

the class ConcourseServer method selectCriteriaTimeOrderPage.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, Set<TObject>>> selectCriteriaTimeOrderPage(TCriteria criteria, long timestamp, TOrder order, TPage page, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AbstractSyntaxTree ast = compiler.parse(criteria);
    AtomicSupport store = getStore(transaction, environment);
    Supplier<SortableTable<Set<TObject>>> supplier = () -> emptySortableResultDataset();
    return AtomicOperations.supplyWithRetry(store, atomic -> Operations.selectAstOptionalAtomic(atomic, ast, timestamp, Orders.from(order), Pages.from(page), supplier));
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) SortableTable(com.cinchapi.concourse.data.sort.SortableTable) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 75 with AtomicSupport

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

the class ConcourseServer method insertJson.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public Set<Long> insertJson(String json, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    List<Multimap<String, Object>> objects = Convert.anyJsonToJava(json);
    AtomicSupport store = getStore(transaction, environment);
    Set<Long> records = Sets.newLinkedHashSet();
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        records.clear();
        List<DeferredWrite> deferred = Lists.newArrayList();
        for (Multimap<String, Object> object : objects) {
            long record;
            if (object.containsKey(Constants.JSON_RESERVED_IDENTIFIER_NAME)) {
                // If the $id$ is specified in the JSON blob, insert the
                // data into that record since no record(s) are provided
                // as method parameters.
                // WARNING: This means that doing the equivalent of
                // `insert(jsonify(records))` will cause an infinite
                // loop because this method will attempt to insert the
                // data into the same records from which it was
                // exported. Therefore, advise users to not export data
                // with the $id and import that same data in the same
                // environment.
                record = ((Number) Iterables.getOnlyElement(object.get(Constants.JSON_RESERVED_IDENTIFIER_NAME))).longValue();
            } else {
                record = Time.now();
            }
            atomic.touch(record);
            if (Operations.insertAtomic(object, record, atomic, deferred)) {
                records.add(record);
            } else {
                throw AtomicStateException.RETRY;
            }
        }
        Operations.insertDeferredAtomic(deferred, atomic);
    });
    return records;
}
Also used : Multimap(com.google.common.collect.Multimap) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Aggregations

AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)192 TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)179 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)179 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)157 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)120 TObject (com.cinchapi.concourse.thrift.TObject)101 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)96 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)87 Set (java.util.Set)78 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)76 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)73 SortableColumn (com.cinchapi.concourse.data.sort.SortableColumn)72 Map (java.util.Map)62 AtomicOperation (com.cinchapi.concourse.server.storage.AtomicOperation)60 AtomicReference (java.util.concurrent.atomic.AtomicReference)59 NonBlockingHashMap (org.cliffc.high_scale_lib.NonBlockingHashMap)58 AtomicStateException (com.cinchapi.concourse.server.storage.AtomicStateException)57 TransactionStateException (com.cinchapi.concourse.server.storage.TransactionStateException)57 Diff (com.cinchapi.concourse.thrift.Diff)57 TransactionException (com.cinchapi.concourse.thrift.TransactionException)57