Search in sources :

Example 11 with AutoCloseableLock

use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.

the class NoWriteLocalStore method close.

@Override
public void close() throws Exception {
    try (AutoCloseableLock lock = writeLock.open()) {
        store.clear();
        version = -1;
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock)

Example 12 with AutoCloseableLock

use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.

the class NoWriteLocalStore method delete.

@Override
public void delete(final String key) {
    try (AutoCloseableLock lock = writeLock.open()) {
        store.remove(key);
        version++;
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock)

Example 13 with AutoCloseableLock

use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.

the class NoWriteLocalStore method put.

@Override
public void put(final String key, final V value, final DataChangeVersion dataChangeVersion) {
    try (AutoCloseableLock lock = writeLock.open()) {
        if (dataChangeVersion != null && dataChangeVersion.getVersion() != version) {
            throw new VersionMismatchException("Version mismatch detected", dataChangeVersion.getVersion());
        }
        store.put(key, value);
        version++;
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Example 14 with AutoCloseableLock

use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.

the class InMemoryStore method close.

@Override
public void close() throws Exception {
    try (AutoCloseableLock lock = writeLock.open()) {
        store.clear();
        version = -1;
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock)

Example 15 with AutoCloseableLock

use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.

the class LocalPersistentStore method putIfAbsent.

@Override
public boolean putIfAbsent(String key, V value) {
    try (AutoCloseableLock lock = writeLock.open()) {
        try {
            Path p = makePath(key);
            if (fs.exists(p)) {
                return false;
            } else {
                try (OutputStream os = fs.create(makePath(key))) {
                    IOUtils.write(config.getSerializer().serialize(value), os);
                    version++;
                }
                return true;
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Aggregations

AutoCloseableLock (org.apache.drill.common.concurrent.AutoCloseableLock)17 IOException (java.io.IOException)5 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)3 OutputStream (java.io.OutputStream)2 Path (org.apache.hadoop.fs.Path)2 Function (com.google.common.base.Function)1 ByteBuf (io.netty.buffer.ByteBuf)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 ImmutableEntry (org.apache.drill.common.collections.ImmutableEntry)1 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)1 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)1 RawFragmentBatch (org.apache.drill.exec.record.RawFragmentBatch)1 Response (org.apache.drill.exec.rpc.Response)1 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)1 CustomResponse (org.apache.drill.exec.rpc.control.Controller.CustomResponse)1 FileStatus (org.apache.hadoop.fs.FileStatus)1