return watcher.run(Constants.BULK_ARBITRATOR_TYPE, tid, () -> { List<TKeyExtent> failures = new ArrayList<>();
@Override public boolean isActive(TInfo tinfo, long tid) { return transactionWatcher.isActive(tid); }
public <T> T run(String ztxBulk, long tid, Callable<T> callable) throws Exception { synchronized (counts) { if (!arbitrator.transactionAlive(ztxBulk, tid)) { throw new Exception("Transaction " + tid + " of type " + ztxBulk + " is no longer active"); } increment(tid); } try { return callable.call(); } finally { decrement(tid); } }
public TabletServer(ServerContext context) { this.context = context; this.masterLockCache = new ZooCache(context.getZooReaderWriter(), null); this.watcher = new TransactionWatcher(context); this.confFactory = context.getServerConfFactory(); this.fs = context.getVolumeManager();
@Override public void loadFiles(TInfo tinfo, TCredentials credentials, long tid, String dir, Map<TKeyExtent,Map<String,MapFileInfo>> tabletImports, boolean setTime) throws ThriftSecurityException { if (!security.canPerformSystemActions(credentials)) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); watcher.runQuietly(Constants.BULK_ARBITRATOR_TYPE, tid, () -> { tabletImports.forEach((tke, fileMap) -> { Map<FileRef,MapFileInfo> fileRefMap = new HashMap<>(); for (Entry<String,MapFileInfo> mapping : fileMap.entrySet()) { Path path = new Path(dir, mapping.getKey()); FileSystem ns = fs.getVolumeByPath(path).getFileSystem(); path = ns.makeQualified(path); fileRefMap.put(new FileRef(path.toString(), path), mapping.getValue()); } Tablet importTablet = onlineTablets.get(new KeyExtent(tke)); if (importTablet != null) { try { importTablet.importMapFiles(tid, fileRefMap, setTime); } catch (IOException ioe) { log.debug("files {} not imported to {}: {}", fileMap.keySet(), new KeyExtent(tke), ioe.getMessage()); } } }); }); }
new ServerConfigurationFactory(HdfsZooInstance.getInstance())); TransactionWatcher watcher = new TransactionWatcher(); final ThriftClientHandler tch = new ThriftClientHandler(context, watcher); Processor<Iface> processor = new Processor<Iface>(tch);
@Override public List<String> bulkImportFiles(TInfo tinfo, final TCredentials credentials, final long tid, final String tableId, final List<String> files, final String errorDir, final boolean setTime) throws ThriftSecurityException, ThriftTableOperationException, TException { try { if (!security.canPerformSystemActions(credentials)) throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); bulkImportStatus.updateBulkImportStatus(files, BulkImportState.INITIAL); log.debug("Got request to bulk import files to table(" + tableId + "): " + files); return transactionWatcher.run(Constants.BULK_ARBITRATOR_TYPE, tid, new Callable<List<String>>() { @Override public List<String> call() throws Exception { bulkImportStatus.updateBulkImportStatus(files, BulkImportState.PROCESSING); try { return BulkImporter.bulkLoad(context, tid, tableId, files, errorDir, setTime); } finally { bulkImportStatus.removeBulkImportStatus(files); } } }); } catch (AccumuloSecurityException e) { throw e.asThriftException(); } catch (Exception ex) { throw new TException(ex); } }
@Override public boolean isActive(TInfo tinfo, long tid) throws TException { return transactionWatcher.isActive(tid); }
AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(zki)); TransactionWatcher watcher = new TransactionWatcher(); ThriftClientHandler tch = new ThriftClientHandler( new AccumuloServerContext(new ServerConfigurationFactory(HdfsZooInstance.getInstance())),
/** * Run task only if transaction is still active in zookeeper. If the tx is no longer active then * that task is not run and a debug message is logged indicating the task was ignored. */ public void runQuietly(String ztxBulk, long tid, Runnable task) { synchronized (counts) { try { if (!arbitrator.transactionAlive(ztxBulk, tid)) { log.debug("Transaction " + tid + " of type " + ztxBulk + " is no longer active."); return; } } catch (Exception e) { log.warn("Unable to check if transaction " + tid + " of type " + ztxBulk + " is alive ", e); return; } increment(tid); } try { task.run(); } finally { decrement(tid); } }
@Override public List<String> bulkImportFiles(TInfo tinfo, final TCredentials tikw, final long tid, final String tableId, final List<String> files, final String errorDir, final boolean setTime) throws ThriftSecurityException, ThriftTableOperationException, TException { try { final TCredentials credentials = new TCredentials(tikw); if (!security.hasSystemPermission(credentials, credentials.getPrincipal(), SystemPermission.SYSTEM)) throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); return transactionWatcher.run(Constants.BULK_ARBITRATOR_TYPE, tid, new Callable<List<String>>() { @Override public List<String> call() throws Exception { return BulkImporter.bulkLoad(new ServerConfiguration(instance).getConfiguration(), instance, credentials, tid, tableId, files, errorDir, setTime); } }); } catch (AccumuloSecurityException e) { throw e.asThriftException(); } catch (Exception ex) { throw new TException(ex); } }
@Override public boolean isActive(TInfo tinfo, long tid) throws TException { return transactionWatcher.isActive(tid); }