public Gatherer(ClientContext context, TSummaryRequest request, AccumuloConfiguration tableConfig, CryptoService cryptoService) { this.ctx = context; this.tableId = Table.ID.of(request.tableId); this.startRow = ByteBufferUtil.toText(request.bounds.startRow); this.endRow = ByteBufferUtil.toText(request.bounds.endRow); this.clipRange = new Range(startRow, false, endRow, true); this.summaries = request.getSummarizers().stream().map(SummarizerConfigurationUtil::fromThrift) .collect(Collectors.toSet()); this.request = request; this.cryptoService = cryptoService; this.summarizerPattern = request.getSummarizerPattern(); if (summarizerPattern != null) { Pattern pattern = Pattern.compile(summarizerPattern); // The way conf is converted to string below is documented in the API, so consider this when // making changes! summarySelector = conf -> pattern .matcher(conf.getClassName() + " " + new TreeMap<>(conf.getOptions())).matches(); if (!summaries.isEmpty()) { summarySelector = summarySelector.or(conf -> summaries.contains(conf)); } } else if (!summaries.isEmpty()) { summarySelector = conf -> summaries.contains(conf); } else { summarySelector = conf -> true; } this.factory = new SummarizerFactory(tableConfig); }
@Override public void splitTablet(TInfo tinfo, TCredentials credentials, TKeyExtent tkeyExtent, ByteBuffer splitPoint) throws NotServingTabletException, ThriftSecurityException { Table.ID tableId = Table.ID.of(new String(ByteBufferUtil.toBytes(tkeyExtent.table))); Namespace.ID namespaceId = getNamespaceId(credentials, tableId); if (!security.canSplitTablet(credentials, tableId, namespaceId)) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); KeyExtent keyExtent = new KeyExtent(tkeyExtent); Tablet tablet = onlineTablets.get(keyExtent); if (tablet == null) { throw new NotServingTabletException(tkeyExtent); } if (keyExtent.getEndRow() == null || !keyExtent.getEndRow().equals(ByteBufferUtil.toText(splitPoint))) { try { if (TabletServer.this.splitTablet(tablet, ByteBufferUtil.toBytes(splitPoint)) == null) { throw new NotServingTabletException(tkeyExtent); } } catch (IOException e) { log.warn("Failed to split " + keyExtent, e); throw new RuntimeException(e); } } }
TableOperation tableOp = TableOperation.MERGE; String tableName = validateTableNameArgument(arguments.get(0), tableOp, null); Text startRow = ByteBufferUtil.toText(arguments.get(1)); Text endRow = ByteBufferUtil.toText(arguments.get(2)); TableOperation tableOp = TableOperation.DELETE_RANGE; String tableName = validateTableNameArgument(arguments.get(0), tableOp, NOT_METADATA); Text startRow = ByteBufferUtil.toText(arguments.get(1)); Text endRow = ByteBufferUtil.toText(arguments.get(2));
@Override public void mergeTablets(ByteBuffer login, String tableName, ByteBuffer startRow, ByteBuffer endRow) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException { try { getConnector(login).tableOperations().merge(tableName, ByteBufferUtil.toText(startRow), ByteBufferUtil.toText(endRow)); } catch (Exception e) { handleExceptionTNF(e); } }
@Override public void flushTable(ByteBuffer login, String tableName, ByteBuffer startRow, ByteBuffer endRow, boolean wait) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException { try { getConnector(login).tableOperations().flush(tableName, ByteBufferUtil.toText(startRow), ByteBufferUtil.toText(endRow), wait); } catch (Exception e) { handleExceptionTNF(e); } }
@Override public void deleteRows(ByteBuffer login, String tableName, ByteBuffer startRow, ByteBuffer endRow) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException { try { getConnector(login).tableOperations().deleteRows(tableName, ByteBufferUtil.toText(startRow), ByteBufferUtil.toText(endRow)); } catch (Exception e) { handleExceptionTNF(e); } }
@Override public org.apache.accumulo.proxy.thrift.Range getRowRange(ByteBuffer row) throws TException { return getRange(new Range(ByteBufferUtil.toText(row))); }
@Override public void addSplits(ByteBuffer login, String tableName, Set<ByteBuffer> splits) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException { try { SortedSet<Text> sorted = new TreeSet<>(); for (ByteBuffer split : splits) { sorted.add(ByteBufferUtil.toText(split)); } getConnector(login).tableOperations().addSplits(tableName, sorted); } catch (Exception e) { handleExceptionTNF(e); } }
@Override public void compact(TInfo tinfo, TCredentials credentials, String lock, String tableId, ByteBuffer startRow, ByteBuffer endRow) throws TException { try { checkPermission(credentials, lock, true, "compact"); } catch (ThriftSecurityException e) { log.error(e, e); throw new RuntimeException(e); } KeyExtent ke = new KeyExtent(new Text(tableId), ByteBufferUtil.toText(endRow), ByteBufferUtil.toText(startRow)); ArrayList<Tablet> tabletsToCompact = new ArrayList<Tablet>(); synchronized (onlineTablets) { for (Tablet tablet : onlineTablets.values()) if (ke.overlaps(tablet.getExtent())) tabletsToCompact.add(tablet); } Long compactionId = null; for (Tablet tablet : tabletsToCompact) { // all for the same table id, so only need to read // compaction id once if (compactionId == null) try { compactionId = tablet.getCompactionID().getFirst(); } catch (NoNodeException e) { log.info("Asked to compact table with no compaction id " + ke + " " + e.getMessage()); return; } tablet.compactAll(compactionId); } }
@Override public void splitTablet(TInfo tinfo, TCredentials credentials, TKeyExtent tkeyExtent, ByteBuffer splitPoint) throws NotServingTabletException, ThriftSecurityException { String tableId = new String(ByteBufferUtil.toBytes(tkeyExtent.table), UTF_8); if (!security.canSplitTablet(credentials, tableId)) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); KeyExtent keyExtent = new KeyExtent(tkeyExtent); Tablet tablet = onlineTablets.get(keyExtent); if (tablet == null) { throw new NotServingTabletException(tkeyExtent); } if (keyExtent.getEndRow() == null || !keyExtent.getEndRow().equals(ByteBufferUtil.toText(splitPoint))) { try { if (TabletServer.this.splitTablet(tablet, ByteBufferUtil.toBytes(splitPoint)) == null) { throw new NotServingTabletException(tkeyExtent); } } catch (IOException e) { log.warn("Failed to split " + keyExtent, e); throw new RuntimeException(e); } } }
@Override public ByteBuffer getMaxRow(ByteBuffer login, String tableName, Set<ByteBuffer> auths, ByteBuffer startRow, boolean startInclusive, ByteBuffer endRow, boolean endInclusive) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException { try { Connector connector = getConnector(login); Text startText = ByteBufferUtil.toText(startRow); Text endText = ByteBufferUtil.toText(endRow); Authorizations auth; if (auths != null) { auth = getAuthorizations(auths); } else { auth = connector.securityOperations().getUserAuthorizations(connector.whoami()); } Text max = connector.tableOperations().getMaxRow(tableName, auth, startText, startInclusive, endText, endInclusive); return TextUtil.getByteBuffer(max); } catch (Exception e) { handleExceptionTNF(e); return null; } }
|| !keyExtent.getEndRow().equals(ByteBufferUtil.toText(splitPoint))) { try { if (TabletServer.this.splitTablet(tablet, ByteBufferUtil.toBytes(splitPoint)) == null) {
@Override public void compactTable(ByteBuffer login, String tableName, ByteBuffer startRow, ByteBuffer endRow, List<org.apache.accumulo.proxy.thrift.IteratorSetting> iterators, boolean flush, boolean wait, CompactionStrategyConfig compactionStrategy) throws org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, org.apache.accumulo.proxy.thrift.AccumuloException, TException { try { CompactionConfig compactionConfig = new CompactionConfig() .setStartRow(ByteBufferUtil.toText(startRow)).setEndRow(ByteBufferUtil.toText(endRow)) .setIterators(getIteratorSettings(iterators)).setFlush(flush).setWait(wait); if (compactionStrategy != null) { // @formatter:off org.apache.accumulo.core.client.admin.CompactionStrategyConfig ccc = new org.apache.accumulo.core.client.admin.CompactionStrategyConfig( compactionStrategy.getClassName()); // @formatter:on if (compactionStrategy.options != null) ccc.setOptions(compactionStrategy.options); compactionConfig.setCompactionStrategy(ccc); } getConnector(login).tableOperations().compact(tableName, compactionConfig); } catch (Exception e) { handleExceptionTNF(e); } }