public void setIterator(String table, IteratorSetting setting) { try { // Remove any existing iterator settings of the same name, if applicable Map<String, EnumSet<IteratorScope>> iterators = connector.tableOperations().listIterators(table); if (iterators.containsKey(setting.getName())) { connector.tableOperations().removeIterator(table, setting.getName(), iterators.get(setting.getName())); } connector.tableOperations().attachIterator(table, setting); } catch (AccumuloSecurityException | AccumuloException e) { throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set iterator on table " + table, e); } catch (TableNotFoundException e) { throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set iterator, table does not exist", e); } }
boolean found = false; for (Iterator<IteratorSetting> iter = iterSettings.iterator(); iter.hasNext();) { if (iter.next().getName().equals(name)) { iter.remove(); found = true;
@Override public synchronized void addScanIterator(IteratorSetting si) { checkArgument(si != null, "si is null"); if (serverSideIteratorList.size() == 0) serverSideIteratorList = new ArrayList<>(); for (IterInfo ii : serverSideIteratorList) { if (ii.iterName.equals(si.getName())) throw new IllegalArgumentException("Iterator name is already in use " + si.getName()); if (ii.getPriority() == si.getPriority()) throw new IllegalArgumentException( "Iterator priority is already in use " + si.getPriority()); } serverSideIteratorList.add(new IterInfo(si.getPriority(), si.getIteratorClass(), si.getName())); if (serverSideIteratorOptions.size() == 0) serverSideIteratorOptions = new HashMap<>(); Map<String,String> opts = serverSideIteratorOptions.get(si.getName()); if (opts == null) { opts = new HashMap<>(); serverSideIteratorOptions.put(si.getName(), opts); } opts.putAll(si.getOptions()); }
public static <K extends WritableComparable<?>,V extends Writable> SortedKeyValueIterator<K,V> loadIterators( // @formatter:on IteratorScope scope, SortedKeyValueIterator<K,V> source, KeyExtent extent, AccumuloConfiguration conf, List<IteratorSetting> iterators, IteratorEnvironment env) throws IOException { List<IterInfo> ssiList = new ArrayList<>(); Map<String,Map<String,String>> ssio = new HashMap<>(); for (IteratorSetting is : iterators) { ssiList.add(new IterInfo(is.getPriority(), is.getIteratorClass(), is.getName())); ssio.put(is.getName(), is.getOptions()); } return loadIterators(scope, source, extent, conf, ssiList, ssio, env, true); }
@Override protected void setTableProperties(final CommandLine cl, final Shell shellState, final int priority, final Map<String,String> options, final String classname, final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException, TableNotFoundException { // instead of setting table properties, just put the options in a list to use at scan time String profile = cl.getOptionValue(profileOpt.getOpt()); // instead of setting table properties, just put the options in a list to use at scan time for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) { final Entry<String,String> entry = i.next(); if (entry.getValue() == null || entry.getValue().isEmpty()) { i.remove(); } } List<IteratorSetting> tableScanIterators = shellState.iteratorProfiles.get(profile); if (tableScanIterators == null) { tableScanIterators = new ArrayList<>(); shellState.iteratorProfiles.put(profile, tableScanIterators); } final IteratorSetting setting = new IteratorSetting(priority, name, classname); setting.addOptions(options); Iterator<IteratorSetting> iter = tableScanIterators.iterator(); while (iter.hasNext()) { if (iter.next().getName().equals(name)) { iter.remove(); } } tableScanIterators.add(setting); }
public void printVerboseInfo() throws IOException { StringBuilder sb = new StringBuilder("-\n"); sb.append("- Current user: ").append(accumuloClient.whoami()).append("\n"); if (execFile != null) sb.append("- Executing commands from: ").append(execFile).append("\n"); if (disableAuthTimeout) sb.append("- Authorization timeout: disabled\n"); else sb.append("- Authorization timeout: ") .append(String.format("%ds%n", TimeUnit.NANOSECONDS.toSeconds(authTimeout))); sb.append("- Debug: ").append(isDebuggingEnabled() ? "on" : "off").append("\n"); if (!scanIteratorOptions.isEmpty()) { for (Entry<String,List<IteratorSetting>> entry : scanIteratorOptions.entrySet()) { sb.append("- Session scan iterators for table ").append(entry.getKey()).append(":\n"); for (IteratorSetting setting : entry.getValue()) { sb.append("- Iterator ").append(setting.getName()).append(" options:\n"); sb.append("- ").append("iteratorPriority").append(" = ") .append(setting.getPriority()).append("\n"); sb.append("- ").append("iteratorClassName").append(" = ") .append(setting.getIteratorClass()).append("\n"); for (Entry<String,String> optEntry : setting.getOptions().entrySet()) { sb.append("- ").append(optEntry.getKey()).append(" = ") .append(optEntry.getValue()).append("\n"); } } } } sb.append("-\n"); reader.print(sb.toString()); }
sb.append("- Profile : " + entry.getKey() + "\n"); for (IteratorSetting setting : entry.getValue()) { if (name != null && !name.equals(setting.getName())) continue; sb.append("- Iterator ").append(setting.getName()).append(", ").append(" options:\n"); sb.append("- ").append("iteratorPriority").append(" = ") .append(setting.getPriority()).append("\n");
String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase()); String nameStr = String.format("%s.%s", scopeStr, setting.getName()); String optStr = String.format("%s.opt.", nameStr); Map<String,String> optionConflicts = new TreeMap<>(); if (property.getKey().equals(nameStr)) throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue())); if (property.getKey().startsWith(optStr)) optionConflicts.put(property.getKey(), property.getValue()); "iterator options conflict for " + setting.getName() + ": " + optionConflicts));
protected void addScanIterators(final Shell shellState, CommandLine cl, final Scanner scanner, final String tableName) throws Exception { List<IteratorSetting> tableScanIterators; if (cl.hasOption(profileOpt.getOpt())) { String profile = cl.getOptionValue(profileOpt.getOpt()); tableScanIterators = shellState.iteratorProfiles.get(profile); if (tableScanIterators == null) { throw new IllegalArgumentException("Profile " + profile + " does not exist"); } for (IteratorSetting iteratorSetting : tableScanIterators) { ensureTserversCanLoadIterator(shellState, tableName, iteratorSetting.getIteratorClass()); } } else { tableScanIterators = shellState.scanIteratorOptions.get(tableName); if (tableScanIterators == null) { Shell.log.debug("Found no scan iterators to set"); return; } } Shell.log.debug("Found " + tableScanIterators.size() + " scan iterators to set"); for (IteratorSetting setting : tableScanIterators) { Shell.log.debug("Setting scan iterator " + setting.getName() + " at priority " + setting.getPriority() + " using class name " + setting.getIteratorClass()); for (Entry<String,String> option : setting.getOptions().entrySet()) { Shell.log.debug("Setting option for " + setting.getName() + ": " + option.getKey() + "=" + option.getValue()); } scanner.addScanIterator(setting); } }
boolean found = false; for (Iterator<IteratorSetting> iter = tableScanIterators.iterator(); iter.hasNext();) { if (iter.next().getName().equals(name)) { iter.remove(); found = true;
String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase()); String nameStr = String.format("%s.%s", scopeStr, setting.getName()); String optStr = String.format("%s.opt.", nameStr); Map<String,String> optionConflicts = new TreeMap<>(); if (property.getKey().equals(nameStr)) throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue())); if (property.getKey().startsWith(optStr)) optionConflicts.put(property.getKey(), property.getValue()); "iterator options conflict for " + setting.getName() + ": " + optionConflicts));
@Override public void attachIterator(String tableName, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); checkArgument(setting != null, "setting is null"); checkArgument(scopes != null, "scopes is null"); checkIteratorConflicts(tableName, setting, scopes); for (IteratorScope scope : scopes) { String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), setting.getName()); for (Entry<String,String> prop : setting.getOptions().entrySet()) { this.setProperty(tableName, root + ".opt." + prop.getKey(), prop.getValue()); } this.setProperty(tableName, root, setting.getPriority() + "," + setting.getIteratorClass()); } }
@Override public void attachIterator(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException { checkIteratorConflicts(namespace, setting, scopes); for (IteratorScope scope : scopes) { String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), setting.getName()); for (Entry<String,String> prop : setting.getOptions().entrySet()) { this.setProperty(namespace, root + ".opt." + prop.getKey(), prop.getValue()); } this.setProperty(namespace, root, setting.getPriority() + "," + setting.getIteratorClass()); } }
scope.name().toLowerCase(), setting.getName()); for (Entry<String,String> prop : setting.getOptions().entrySet()) { iteratorProps.put(root + ".opt." + prop.getKey(), prop.getValue());
throw new IllegalArgumentException("No table or namespace specified"); sb.append("- Iterator ").append(setting.getName()).append(", ").append(scope) .append(" scope options:\n"); sb.append("- ").append("iteratorPriority").append(" = ")
public static TIteratorSetting toTIteratorSetting(IteratorSetting is) { return new TIteratorSetting(is.getPriority(), is.getName(), is.getIteratorClass(), is.getOptions()); }
public ByteBuffer compress(IteratorSetting[] iterators) { UnsynchronizedBuffer.Writer out = new UnsynchronizedBuffer.Writer(iterators.length * 8); out.writeVInt(iterators.length); for (IteratorSetting is : iterators) { out.writeVInt(getSymbolID(is.getName())); out.writeVInt(getSymbolID(is.getIteratorClass())); out.writeVInt(is.getPriority()); Map<String,String> opts = is.getOptions(); out.writeVInt(opts.size()); for (Entry<String,String> entry : opts.entrySet()) { out.writeVInt(getSymbolID(entry.getKey())); out.writeVInt(getSymbolID(entry.getValue())); } } return out.toByteBuffer(); }