double calculateRate() { double totalRate = 0; for (Entry<String,Pair<Long,Long>> entry : prevSamples.entrySet()) { Pair<Long,Long> prevSample = entry.getValue(); Pair<Long,Long> sample = samples.get(entry.getKey()); totalRate += (sample.getSecond() - prevSample.getSecond()) / ((sample.getFirst() - prevSample.getFirst()) / (double) 1000); } return totalRate; }
@Override public Value getTopValue() { return hasTop() ? keys.get(keyPos).getSecond() : null; }
private Sampler getOrCreateSampler() { Pair<SamplerConfigurationImpl,Sampler> pair = samplerRef.get(); if (pair == null) { pair = getSampler(config); if (!samplerRef.compareAndSet(null, pair)) { pair = samplerRef.get(); } } return pair.getSecond(); }
public Entry<A,B> toMapEntry() { return new SimpleImmutableEntry<>(getFirst(), getSecond()); }
public Map<String,String> toTablePropertiesMap() { LinkedHashMap<String,String> propsMap = new LinkedHashMap<>(); for (Pair<String,String> pair : toTableProperties()) { propsMap.put(pair.getFirst(), pair.getSecond()); } return propsMap; }
public Map<Path,WalState> getAllState() throws WalMarkerException { Map<Path,WalState> result = new HashMap<>(); for (Entry<TServerInstance,List<UUID>> entry : getAllMarkers().entrySet()) { for (UUID id : entry.getValue()) { // This function is called by the Accumulo GC which deletes WAL markers. Therefore we do not // expect the following call to fail because the WAL info in ZK was deleted. Pair<WalState,Path> state = state(entry.getKey(), id); result.put(state.getSecond(), state.getFirst()); } } return result; }
public static String[] serializeColumns( Collection<Pair<Text,Text>> columnFamilyColumnQualifierPairs) { checkArgument(columnFamilyColumnQualifierPairs != null, "columnFamilyColumnQualifierPairs is null"); ArrayList<String> columnStrings = new ArrayList<>(columnFamilyColumnQualifierPairs.size()); for (Pair<Text,Text> column : columnFamilyColumnQualifierPairs) { if (column.getFirst() == null) throw new IllegalArgumentException("Column family can not be null"); String col = Base64.getEncoder().encodeToString(TextUtil.getBytes(column.getFirst())); if (column.getSecond() != null) col += ":" + Base64.getEncoder().encodeToString(TextUtil.getBytes(column.getSecond())); columnStrings.add(col); } return columnStrings.toArray(new String[0]); }
private long removeFiles(Collection<Pair<WalState,Path>> collection, final GCStatus status) { for (Pair<WalState,Path> stateFile : collection) { Path path = stateFile.getSecond(); log.debug("Removing {} WAL {}", stateFile.getFirst(), path); status.currentLog.deleted += removeFile(path); } return status.currentLog.deleted; }
public TTLSet(Map<String,String> objectStrings) { super(); for (Entry<String,String> entry : objectStrings.entrySet()) { String column = entry.getKey(); String ttl = entry.getValue().trim(); // skip the negate option, it will cause an exception to be thrown if (column.equals(NEGATE) && (ttl.isEmpty() || ttl.equalsIgnoreCase("true") || ttl.equalsIgnoreCase("false"))) { continue; } Long l = Long.parseLong(ttl); Pair<Text,Text> colPair = ColumnSet.decodeColumns(column); if (colPair.getSecond() == null) { addObject(colPair.getFirst(), l); } else { addObject(colPair.getFirst(), colPair.getSecond(), l); } } } }
public Pair<B,A> swap() { return new Pair<>(getSecond(), getFirst()); }
public static String qualified(String tableName, String defaultNamespace) { Pair<String,String> qualifiedTableName = qualify(tableName, defaultNamespace); if (Namespace.DEFAULT.equals(qualifiedTableName.getFirst())) return qualifiedTableName.getSecond(); else return qualifiedTableName.toString("", ".", ""); }
private void writeBuffer(String destPath, List<Pair<LogFileKey,LogFileValue>> buffer, int part) throws IOException { Path path = new Path(destPath, String.format("part-r-%05d", part)); FileSystem ns = fs.getVolumeByPath(path).getFileSystem(); try (MapFile.Writer output = new MapFile.Writer(ns.getConf(), ns.makeQualified(path), MapFile.Writer.keyClass(LogFileKey.class), MapFile.Writer.valueClass(LogFileValue.class))) { Collections.sort(buffer, Comparator.comparing(Pair::getFirst)); for (Pair<LogFileKey,LogFileValue> entry : buffer) { output.append(entry.getFirst(), entry.getSecond()); } } }
public ColumnToClassMapping(Map<String,String> objectStrings, Class<? extends K> c, String context) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException { this(); for (Entry<String,String> entry : objectStrings.entrySet()) { String column = entry.getKey(); String className = entry.getValue(); Pair<Text,Text> pcic = ColumnSet.decodeColumns(column); Class<?> clazz; if (context != null && !context.equals("")) clazz = AccumuloVFSClassLoader.getContextManager().getClassLoader(context) .loadClass(className); else clazz = AccumuloVFSClassLoader.loadClass(className, c); @SuppressWarnings("unchecked") K inst = (K) clazz.newInstance(); if (pcic.getSecond() == null) { addObject(pcic.getFirst(), inst); } else { addObject(pcic.getFirst(), pcic.getSecond(), inst); } } }
@Override public void setSamplerConfiguration(String tableName, SamplerConfiguration samplerConfiguration) throws AccumuloException, TableNotFoundException, AccumuloSecurityException { clearSamplerOptions(tableName); List<Pair<String,String>> props = new SamplerConfigurationImpl(samplerConfiguration) .toTableProperties(); for (Pair<String,String> pair : props) { setProperty(tableName, pair.getFirst(), pair.getSecond()); } }
public static <CT extends TServiceClient,RT> RT executeRaw(ClientContext context, TServiceClientFactory<CT> factory, ClientExecReturn<RT,CT> exec) throws Exception { while (true) { CT client = null; String server = null; try { Pair<String,CT> pair = ServerClient.getConnection(context, factory); server = pair.getFirst(); client = pair.getSecond(); return exec.execute(client); } catch (TApplicationException tae) { throw new AccumuloServerException(server, tae); } catch (TTransportException tte) { log.debug("ClientService request failed " + server + ", retrying ... ", tte); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } finally { if (client != null) ServerClient.close(client); } } }
public static void executeRawVoid(ClientContext context, ClientExec<ClientService.Client> exec) throws Exception { while (true) { ClientService.Client client = null; String server = null; try { Pair<String,Client> pair = ServerClient.getConnection(context); server = pair.getFirst(); client = pair.getSecond(); exec.execute(client); break; } catch (TApplicationException tae) { throw new AccumuloServerException(server, tae); } catch (TTransportException tte) { log.debug("ClientService request failed " + server + ", retrying ... ", tte); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } finally { if (client != null) ServerClient.close(client); } } }
private void populateMigrations(Set<TServerInstance> current, List<TabletMigration> migrationsOut, Moves moves) { if (moves.size() == 0) { return; } Function<KeyExtent,String> partitioner = getPartitioner(); for (Pair<KeyExtent,Location> entry : getLocationProvider()) { String group = partitioner.apply(entry.getFirst()); Location loc = entry.getSecond(); if (loc.equals(Location.NONE) || !current.contains(loc.getTserverInstance())) { migrationsOut.clear(); return; } TServerInstance dest = moves.removeMove(loc.getTserverInstance(), group); if (dest != null) { migrationsOut.add(new TabletMigration(entry.getFirst(), loc.getTserverInstance(), dest)); if (moves.size() == 0) { break; } } } } }
public static void prepareNewTableState(IZooReaderWriter zoo, String instanceId, Table.ID tableId, Namespace.ID namespaceId, String tableName, TableState state, NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException { // state gets created last log.debug("Creating ZooKeeper entries for new table {} (ID: {}) in namespace (ID: {})", tableName, tableId, namespaceId); Pair<String,String> qualifiedTableName = Tables.qualify(tableName); tableName = qualifiedTableName.getSecond(); String zTablePath = Constants.ZROOT + "/" + instanceId + Constants.ZTABLES + "/" + tableId; zoo.putPersistentData(zTablePath, new byte[0], existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_CONF, new byte[0], existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_NAMESPACE, namespaceId.getUtf8(), existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_NAME, tableName.getBytes(UTF_8), existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_FLUSH_ID, ZERO_BYTE, existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_COMPACT_ID, ZERO_BYTE, existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_COMPACT_CANCEL_ID, ZERO_BYTE, existsPolicy); zoo.putPersistentData(zTablePath + Constants.ZTABLE_STATE, state.name().getBytes(UTF_8), existsPolicy); }