Search in sources :

Example 16 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method clearKeyRecord.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void clearKeyRecord(String key, long record, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        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 17 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method removeKeyValueRecords.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public Map<Long, Boolean> removeKeyValueRecords(String key, TObject value, List<Long> records, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    Map<Long, Boolean> result = Maps.newLinkedHashMap();
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        for (long record : records) {
            result.put(record, atomic.remove(key, value, record));
        }
    });
    return result;
}
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 18 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method consolidateRecords.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public boolean consolidateRecords(List<Long> records, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    Set<Long> $records = Sets.newLinkedHashSet(records);
    if ($records.size() >= 2) {
        AtomicSupport store = getStore(transaction, environment);
        AtomicOperation atomic = store.startAtomicOperation();
        try {
            Iterator<Long> it = $records.iterator();
            long destination = it.next();
            while (it.hasNext()) {
                // 1. Copy all data from the #source to the #destination
                long source = it.next();
                Map<String, Set<TObject>> data = store.select(source);
                for (Entry<String, Set<TObject>> entry : data.entrySet()) {
                    String key = entry.getKey();
                    for (TObject value : entry.getValue()) {
                        if (!atomic.verify(key, value, destination) && !atomic.add(key, value, destination)) {
                            return false;
                        }
                    }
                }
                // 2. Replace all incoming links to #source with links to
                // #destination
                Map<String, Set<Long>> incoming = Operations.traceRecordAtomic(source, Time.NONE, atomic);
                for (Entry<String, Set<Long>> entry : incoming.entrySet()) {
                    String key = entry.getKey();
                    for (long record : entry.getValue()) {
                        if (!atomic.remove(key, Convert.javaToThrift(Link.to(source)), record)) {
                            return false;
                        }
                        if (!atomic.add(key, Convert.javaToThrift(Link.to(destination)), record)) {
                            return false;
                        }
                    }
                }
                // 3. Clear the #source
                Operations.clearRecordAtomic(source, atomic);
            }
            return atomic.commit(CommitVersions.next());
        } catch (TransactionStateException e) {
            throw new TransactionException();
        } catch (AtomicStateException e) {
            return false;
        }
    } else {
        // don't return a truthy value.
        return false;
    }
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) SortableSet(com.cinchapi.concourse.data.sort.SortableSet) Set(java.util.Set) TransactionStateException(com.cinchapi.concourse.server.storage.TransactionStateException) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) AtomicStateException(com.cinchapi.concourse.server.storage.AtomicStateException) TransactionException(com.cinchapi.concourse.thrift.TransactionException) AtomicOperation(com.cinchapi.concourse.server.storage.AtomicOperation) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 19 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method clearRecord.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void clearRecord(long record, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        Operations.clearRecordAtomic(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 20 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method revertKeysRecordTime.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void revertKeysRecordTime(List<String> keys, long record, long timestamp, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        for (String key : keys) {
            Operations.revertAtomic(key, record, timestamp, 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)

Aggregations

TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)22 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)22 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)22 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)22 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)6 TObject (com.cinchapi.concourse.thrift.TObject)6 Multimap (com.google.common.collect.Multimap)3 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)2 AtomicOperation (com.cinchapi.concourse.server.storage.AtomicOperation)2 AtomicStateException (com.cinchapi.concourse.server.storage.AtomicStateException)2 TransactionStateException (com.cinchapi.concourse.server.storage.TransactionStateException)2 DuplicateEntryException (com.cinchapi.concourse.thrift.DuplicateEntryException)2 TransactionException (com.cinchapi.concourse.thrift.TransactionException)2 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)1 Set (java.util.Set)1