public static <K2,V2,K1 extends K2,V1 extends V2> Pair<K2,V2> fromEntry(Entry<K1,V1> entry) { return new Pair<>(entry.getKey(), entry.getValue()); }
public static Pair<String,String> qualify(String tableName, String defaultNamespace) { if (!tableName.matches(VALID_NAME_REGEX)) throw new IllegalArgumentException("Invalid table name '" + tableName + "'"); if (MetadataTable.OLD_NAME.equals(tableName)) tableName = MetadataTable.NAME; if (tableName.contains(".")) { String[] s = tableName.split("\\.", 2); return new Pair<>(s[0], s[1]); } return new Pair<>(defaultNamespace, tableName); }
public List<Pair<String,String>> toTableProperties() { ArrayList<Pair<String,String>> props = new ArrayList<>(); for (Entry<String,String> entry : options.entrySet()) { props .add(new Pair<>(Property.TABLE_SAMPLER_OPTS.getKey() + entry.getKey(), entry.getValue())); } // intentionally added last, so its set last props.add(new Pair<>(Property.TABLE_SAMPLER.getKey(), className)); return props; }
private static Pair<SamplerConfigurationImpl,Sampler> getSampler(AccumuloConfiguration config) { try { SamplerConfigurationImpl sampleConfig = SamplerConfigurationImpl.newSamplerConfig(config); if (sampleConfig == null) { return new Pair<>(null, null); } return new Pair<>(sampleConfig, SamplerFactory.newSampler(sampleConfig, config)); } catch (IOException e) { throw new RuntimeException(e); } }
void updateTabletServer(String name, long sampleTime, long numEvents) { Pair<Long,Long> newSample = new Pair<>(sampleTime, numEvents); Pair<Long,Long> lastSample = samples.get(name); if (lastSample == null || !lastSample.equals(newSample)) { samples.put(name, newSample); if (lastSample != null) { prevSamples.put(name, lastSample); } } serversUpdated.add(name); }
public static Set<Pair<Text,Text>> deserializeFetchedColumns(Collection<String> serialized) { Set<Pair<Text,Text>> columns = new HashSet<>(); if (serialized == null) { return columns; } for (String col : serialized) { int idx = col.indexOf(":"); Text cf = new Text(idx < 0 ? Base64.getDecoder().decode(col) : Base64.getDecoder().decode(col.substring(0, idx))); Text cq = idx < 0 ? null : new Text(Base64.getDecoder().decode(col.substring(idx + 1))); columns.add(new Pair<>(cf, cq)); } return columns; }
private static Pair<WalState,Path> parse(byte data[]) { String parts[] = new String(data, UTF_8).split(","); return new Pair<>(WalState.valueOf(parts[0]), new Path(parts[1])); }
private LoggerOperation logKeyData(LogFileKey key, Durability d) throws IOException { return logFileData(singletonList(new Pair<>(key, EMPTY)), d); }
/** * Generates a list with the scan entries over time * * @return Scan entries over time */ @GET @Path("time/scanEntries") public List<Pair<String,List<Pair<Long,Integer>>>> getScanEntries() { List<Pair<String,List<Pair<Long,Integer>>>> scanEntries = new ArrayList<>(); Pair<String,List<Pair<Long,Integer>>> read = new Pair<>("Read", Monitor.getScanRateOverTime()); Pair<String,List<Pair<Long,Integer>>> returned = new Pair<>("Returned", Monitor.getQueryRateOverTime()); scanEntries.add(read); scanEntries.add(returned); return scanEntries; }
private static void calcCacheHitRate(List<Pair<Long,Double>> hitRate, long currentTime, EventCounter cacheHits, EventCounter cacheReq) { long req = cacheReq.calculateCount(); if (req > 0) hitRate.add( new Pair<>(currentTime, cacheHits.calculateCount() / (double) cacheReq.calculateCount())); else hitRate.add(new Pair<>(currentTime, null)); }
Pair<Long,Map<FileRef,DataFileValue>> reserveFilesForScan() { synchronized (tablet) { while (reservationsBlocked) { try { tablet.wait(50); } catch (InterruptedException e) { log.warn("{}", e.getMessage(), e); } } Set<FileRef> absFilePaths = new HashSet<>(datafileSizes.keySet()); long rid = nextScanReservationId++; scanFileReservations.put(rid, absFilePaths); Map<FileRef,DataFileValue> ret = new HashMap<>(); for (FileRef path : absFilePaths) { fileScanReferenceCounts.increment(path, 1); ret.put(path, datafileSizes.get(path)); } return new Pair<>(rid, ret); } }
public static Pair<Integer,Integer> parse(String portRange) { int idx = portRange.indexOf('-'); if (idx != -1) { int low = Integer.parseInt(portRange.substring(0, idx)); int high = Integer.parseInt(portRange.substring(idx + 1)); if (!VALID_RANGE.containsInteger(low) || !VALID_RANGE.containsInteger(high) || !(low <= high)) { throw new IllegalArgumentException( "Invalid port range specified, only 1024 to 65535 supported."); } return new Pair<>(low, high); } throw new IllegalArgumentException( "Invalid port range specification, must use M-N notation."); }
public static Pair<Text,Text> decodeColumns(String columns) { if (!isValidEncoding(columns)) throw new IllegalArgumentException("Invalid encoding " + columns); String[] cols = columns.split(":"); if (cols.length == 1) { return new Pair<>(decode(cols[0]), null); } else if (cols.length == 2) { return new Pair<>(decode(cols[0]), decode(cols[1])); } else { throw new IllegalArgumentException(columns); } }
public Pair<B,A> swap() { return new Pair<>(getSecond(), getFirst()); }
public LoggerOperation log(CommitSession cs, Mutation m, Durability d) throws IOException { LogFileKey key = new LogFileKey(); key.event = MUTATION; key.seq = cs.getWALogSeq(); key.tabletId = cs.getLogId(); LogFileValue value = new LogFileValue(); value.mutations = singletonList(m); return logFileData(singletonList(new Pair<>(key, value)), d); }
public LoggerOperation logManyTablets(Collection<TabletMutations> mutations) throws IOException { Durability durability = Durability.NONE; List<Pair<LogFileKey,LogFileValue>> data = new ArrayList<>(); for (TabletMutations tabletMutations : mutations) { LogFileKey key = new LogFileKey(); key.event = MANY_MUTATIONS; key.seq = tabletMutations.getSeq(); key.tabletId = tabletMutations.getTid(); LogFileValue value = new LogFileValue(); value.mutations = tabletMutations.getMutations(); data.add(new Pair<>(key, value)); durability = maxDurability(tabletMutations.getDurability(), durability); } return logFileData(data, durability); }
private Map<FileRef,Pair<Key,Key>> getFirstAndLastKeys(SortedMap<FileRef,DataFileValue> allFiles) throws IOException { Map<FileRef,Pair<Key,Key>> result = new HashMap<>(); FileOperations fileFactory = FileOperations.getInstance(); VolumeManager fs = getTabletServer().getFileSystem(); for (Entry<FileRef,DataFileValue> entry : allFiles.entrySet()) { FileRef file = entry.getKey(); FileSystem ns = fs.getVolumeByPath(file.path()).getFileSystem(); try (FileSKVIterator openReader = fileFactory.newReaderBuilder() .forFile(file.path().toString(), ns, ns.getConf(), context.getCryptoService()) .withTableConfiguration(this.getTableConfiguration()).seekToBeginning().build()) { Key first = openReader.getFirstKey(); Key last = openReader.getLastKey(); result.put(file, new Pair<>(first, last)); } } return result; }
protected Iterable<Pair<KeyExtent,Location>> getLocationProvider() { return () -> { try { return TabletsMetadata.builder().forTable(tableId).fetchLocation().fetchPrev() .build(context).stream().map(tm -> { Location loc = Location.NONE; if (tm.hasCurrent()) { loc = new Location(new TServerInstance(tm.getLocation())); } return new Pair<>(tm.getExtent(), loc); }).iterator(); } catch (Exception e) { throw new RuntimeException(e); } }; }
private static Pair<Text,KeyExtent> verifyRootTablet(ServerContext context, TServerInstance instance) throws AccumuloException { ZooTabletStateStore store = new ZooTabletStateStore(context); if (!store.iterator().hasNext()) { throw new AccumuloException("Illegal state: location is not set in zookeeper"); } TabletLocationState next = store.iterator().next(); if (!instance.equals(next.future)) { throw new AccumuloException("Future location is not to this server for the root tablet"); } if (next.current != null) { throw new AccumuloException("Root tablet already has a location set"); } try { return new Pair<>(new Text(MetadataTableUtil.getRootTabletDir(context)), null); } catch (IOException e) { throw new AccumuloException(e); } }
@Override public void append(Key key, Value val) { // ensure the key provided by the user has the correct prefix if (!key.equals(prefixKey, getKeyPrefix())) throw new IllegalArgumentException("Key prefixes are not equal " + key + " " + prefixKey); // Transformation could have produced a key that falls outside // of the seek range, or one that the user cannot see. Check // these before adding it to the output list. if (includeTransformedKey(key)) { // try to defend against a scan or compaction using all memory in a tablet server if (appened > maxBufferSize) throw new BufferOverflowException( "Exceeded buffer size of " + maxBufferSize + ", prefixKey: " + prefixKey); if (getSource().hasTop() && key == getSource().getTopKey()) key = new Key(key); keys.add(new Pair<>(key, new Value(val))); appened += (key.getSize() + val.getSize() + 128); } } });