Search in sources :

Example 1 with AutoCloseableLock

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

the class CustomHandlerRegistry method registerCustomHandler.

public <REQUEST, RESPONSE> void registerCustomHandler(int messageTypeId, CustomMessageHandler<REQUEST, RESPONSE> handler, Controller.CustomSerDe<REQUEST> requestSerde, Controller.CustomSerDe<RESPONSE> responseSerde) {
    Preconditions.checkNotNull(handler);
    Preconditions.checkNotNull(requestSerde);
    Preconditions.checkNotNull(responseSerde);
    try (AutoCloseableLock lock = write.open()) {
        ParsingHandler<?, ?> parsingHandler = handlers.get(messageTypeId);
        if (parsingHandler != null) {
            throw new IllegalStateException(String.format("Only one handler can be registered for a given custom message type. You tried to register a handler for " + "the %d message type but one had already been registered.", messageTypeId));
        }
        parsingHandler = new ParsingHandler<REQUEST, RESPONSE>(handler, requestSerde, responseSerde);
        handlers.put(messageTypeId, parsingHandler);
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock)

Example 2 with AutoCloseableLock

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

the class LocalPersistentStore method contains.

@Override
public boolean contains(String key, DataChangeVersion dataChangeVersion) {
    try (AutoCloseableLock lock = readLock.open()) {
        try {
            Path path = makePath(key);
            boolean exists = fs.exists(path);
            if (exists && dataChangeVersion != null) {
                dataChangeVersion.setVersion(version);
            }
            return exists;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) IOException(java.io.IOException)

Example 3 with AutoCloseableLock

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

the class LocalPersistentStore method getRange.

@Override
public Iterator<Map.Entry<String, V>> getRange(int skip, int take) {
    try (AutoCloseableLock lock = readLock.open()) {
        try {
            List<FileStatus> f = fs.list(false, basePath);
            if (f == null || f.isEmpty()) {
                return Collections.emptyIterator();
            }
            List<String> files = Lists.newArrayList();
            for (FileStatus stat : f) {
                String s = stat.getPath().getName();
                if (s.endsWith(DRILL_SYS_FILE_SUFFIX)) {
                    files.add(s.substring(0, s.length() - DRILL_SYS_FILE_SUFFIX.length()));
                }
            }
            Collections.sort(files);
            return Iterables.transform(Iterables.limit(Iterables.skip(files, skip), take), new Function<String, Entry<String, V>>() {

                @Nullable
                @Override
                public Entry<String, V> apply(String key) {
                    return new ImmutableEntry<>(key, get(key));
                }
            }).iterator();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Function(com.google.common.base.Function) FileStatus(org.apache.hadoop.fs.FileStatus) ImmutableEntry(org.apache.drill.common.collections.ImmutableEntry) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) IOException(java.io.IOException)

Example 4 with AutoCloseableLock

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

the class InMemoryStore 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 5 with AutoCloseableLock

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

the class InMemoryStore 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);
        if (currentSize.incrementAndGet() > capacity) {
            //Pop Out Oldest
            store.pollLastEntry();
            currentSize.decrementAndGet();
        }
        version++;
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

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