@Override public synchronized void close() { List<AutoCloseable> closeables = new ArrayList<>(); closeables.add(() -> super.close()); List<AutoCloseable> backList = new ArrayList<>(); backList.addAll(closeable.getCloseables()); Collections.reverse(backList); closeables.addAll(backList); AutoCloseables.closeNoChecked(AutoCloseables.all(closeables)); } }
private void exclusively(ExclusiveOperation operation) throws IOException { // Attempt to acquire all exclusive locks to limit concurrent writes occurring. ArrayList<AutoCloseableLock> acquiredLocks = new ArrayList<>(exclusiveLocks.length); for (int i = 0; i < exclusiveLocks.length; i++) { try { // We cannot ensure that all write locks can be acquired, so a best attempt must be made. // If lock is still held after waiting 3 seconds, continue with the lock acquisition and close. // Note: The data from the concurrent write cannot be guaranteed to be persisted on restart. if (exclusiveLocks[i].tryOpen(3L, TimeUnit.SECONDS) != null) { acquiredLocks.add(exclusiveLocks[i]); } } catch (InterruptedException e) { // Do nothing. } } try(DeferredException deferred = new DeferredException()) { try { operation.execute(deferred); } catch(RocksDBException e) { deferred.addException(e); } deferred.suppressingClose(AutoCloseables.all(acquiredLocks)); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } }
private Pipeline get(PhysicalOperator operator) throws Exception { try(RollbackCloseable closeable = AutoCloseables.rollbackable(AutoCloseables.all(operators))) { final CreatorVisitor visitor = new CreatorVisitor(); OpPipe opPipe = operator.accept(visitor, null); Preconditions.checkNotNull(opPipe.getPipe()); Pipeline driver = new Pipeline(opPipe.getPipe(), visitor.terminal, operators, sharedResourcesContext); closeable.commit(); return driver; } }