private Map<String, GcTimes> getGcTimes() { Map<String, GcTimes> map = Maps.newHashMap(); List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcBean : gcBeans) { map.put(gcBean.getName(), new GcTimes(gcBean)); } return map; }
public Map<TableName, List<String>> getTableRegionMap() throws IOException { Map<TableName, List<String>> map = Maps.newTreeMap(); Map<TableName, Map<ServerName, List<String>>> tableServerRegionMap = getTableServerRegionMap(); for(TableName tableName : tableServerRegionMap.keySet()) { if(!map.containsKey(tableName)) { map.put(tableName, new LinkedList<>()); } for(List<String> subset: tableServerRegionMap.get(tableName).values()) { map.get(tableName).addAll(subset); } } return map; }
private static Map<String, String> createSaslPropertiesForEncryption(String encryptionAlgorithm) { Map<String, String> saslProps = Maps.newHashMapWithExpectedSize(3); saslProps.put(Sasl.QOP, QualityOfProtection.PRIVACY.getSaslQop()); saslProps.put(Sasl.SERVER_AUTH, "true"); saslProps.put("com.sun.security.sasl.digest.cipher", encryptionAlgorithm); return saslProps; }
Maps.newHashMap(); mapsByChunk.get(rec.alloc); if (mapForThisByteArray == null) { mapForThisByteArray = Maps.newTreeMap(); mapsByChunk.put(rec.alloc, mapForThisByteArray);
private <K,V> Entry<K,V> entry(K k, V v) { return Maps.immutableEntry(k, v); } }
/** Returns an empty mutable map whose keys will respect this {@link ElementOrder}. */ <K extends T, V> Map<K, V> createMap(int expectedSize) { switch (type) { case UNORDERED: return Maps.newHashMapWithExpectedSize(expectedSize); case INSERTION: return Maps.newLinkedHashMapWithExpectedSize(expectedSize); case SORTED: return Maps.newTreeMap(comparator()); default: throw new AssertionError(); } }
checkNotNull(left); checkNotNull(right); Comparator<? super K> comparator = orNaturalOrder(left.comparator()); SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator); SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator); SortedMap<K, V> onBoth = Maps.newTreeMap(comparator); SortedMap<K, MapDifference.ValueDifference<V>> differences = Maps.newTreeMap(comparator); doDifference(left, right, Equivalence.equals(), onlyOnLeft, onlyOnRight, onBoth, differences); return new SortedMapDifferenceImpl<K, V>(onlyOnLeft, onlyOnRight, onBoth, differences);
LOG.error("Diff: " + Maps.difference(expectedHashes, actualHashes));
Maps.newHashMap(); mapsByChunk.get(rec.alloc); if (mapForThisByteArray == null) { mapForThisByteArray = Maps.newTreeMap(); mapsByChunk.put(rec.alloc, mapForThisByteArray);
void reportArchivedFilesForQuota(List<? extends StoreFile> archivedFiles, List<Long> fileSizes) { // Sanity check from the caller if (archivedFiles.size() != fileSizes.size()) { throw new RuntimeException("Coding error: should never see lists of varying size"); } RegionServerServices rss = this.region.getRegionServerServices(); if (rss == null) { return; } List<Entry<String,Long>> filesWithSizes = new ArrayList<>(archivedFiles.size()); Iterator<Long> fileSizeIter = fileSizes.iterator(); for (StoreFile storeFile : archivedFiles) { final long fileSize = fileSizeIter.next(); if (storeFile.isHFile() && fileSize != 0) { filesWithSizes.add(Maps.immutableEntry(storeFile.getPath().getName(), fileSize)); } } if (LOG.isTraceEnabled()) { LOG.trace("Files archived: " + archivedFiles + ", reporting the following to the Master: " + filesWithSizes); } boolean success = rss.reportFileArchivalForQuotas(getTableName(), filesWithSizes); if (!success) { LOG.warn("Failed to report archival of files: " + filesWithSizes); } }
/** * Computes the difference between two maps. This difference is an immutable * snapshot of the state of the maps at the time this method is called. It * will never change, even if the maps change at a later time. * * <p>Since this method uses {@code HashMap} instances internally, the keys of * the supplied maps must be well-behaved with respect to * {@link Object#equals} and {@link Object#hashCode}. * * <p><b>Note:</b>If you only need to know whether two maps have the same * mappings, call {@code left.equals(right)} instead of this method. * * @param left the map to treat as the "left" map for purposes of comparison * @param right the map to treat as the "right" map for purposes of comparison * @return the difference between the two maps */ @SuppressWarnings("unchecked") public static <K, V> MapDifference<K, V> difference( Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) { if (left instanceof SortedMap) { SortedMap<K, ? extends V> sortedLeft = (SortedMap<K, ? extends V>) left; SortedMapDifference<K, V> result = difference(sortedLeft, right); return result; } return difference(left, right, Equivalence.equals()); }
private void updateFavoredNodesForRegion(RegionInfo regionInfo, List<ServerName> newFavoredNodes) throws IOException { Map<RegionInfo, List<ServerName>> regionFNMap = Maps.newHashMap(); regionFNMap.put(regionInfo, newFavoredNodes); fnm.updateFavoredNodes(regionFNMap); }
private void checkRegionsAndRegionLoads(Collection<RegionInfo> regions, Collection<RegionMetrics> regionLoads) { assertEquals("No of regions and regionloads doesn't match", regions.size(), regionLoads.size()); Map<byte[], RegionMetrics> regionLoadMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); for (RegionMetrics regionLoad : regionLoads) { regionLoadMap.put(regionLoad.getRegionName(), regionLoad); } for (RegionInfo info : regions) { assertTrue("Region not in regionLoadMap region:" + info.getRegionNameAsString() + " regionMap: " + regionLoadMap, regionLoadMap.containsKey(info.getRegionName())); } }
/** * Count the number of rows and the number of entries from a scanner * * @param scanner * The Scanner * @return An entry where the first item is rows observed and the second is entries observed. */ private Entry<Long,Long> sumTable(ResultScanner scanner) { long rowsObserved = 0L; long entriesObserved = 0L; // Read all the records in the table for (Result result : scanner) { rowsObserved++; while (result.advance()) { entriesObserved++; } } return Maps.immutableEntry(rowsObserved,entriesObserved); } }
/** * Retrieve the directories into which snapshots have been restored from * ({@link #RESTORE_DIRS_KEY}) * * @param conf Configuration to extract restore directories from * @return the directories into which snapshots have been restored from * @throws IOException */ public Map<String, Path> getSnapshotDirs(Configuration conf) throws IOException { List<Map.Entry<String, String>> kvps = ConfigurationUtil.getKeyValues(conf, RESTORE_DIRS_KEY); Map<String, Path> rtn = Maps.newHashMapWithExpectedSize(kvps.size()); for (Map.Entry<String, String> kvp : kvps) { rtn.put(kvp.getKey(), new Path(kvp.getValue())); } return rtn; }
LOG.error("Diff: " + Maps.difference(expectedHashes, actualHashes));
public void setSnapshotDirs(Configuration conf, Map<String, Path> snapshotDirs) { Map<String, String> toSet = Maps.newHashMap(); for (Map.Entry<String, Path> entry : snapshotDirs.entrySet()) { toSet.put(entry.getKey(), entry.getValue().toString()); } ConfigurationUtil.setKeyValues(conf, RESTORE_DIRS_KEY, toSet.entrySet()); }
private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName) throws IOException { Map<String, RegionState> rit = Maps.newTreeMap(); AssignmentManager am = master.getAssignmentManager(); for(TableName tableName : getRSGroupInfo(groupName).getTables()) { for(RegionInfo regionInfo: am.getRegionStates().getRegionsOfTable(tableName)) { RegionState state = am.getRegionStates().getRegionTransitionState(regionInfo); if(state != null) { rit.put(regionInfo.getEncodedName(), state); } } } return rit; }
public void processFileArchivals(FileArchiveNotificationRequest request, Connection conn, Configuration conf, FileSystem fs) throws IOException { final HashMultimap<TableName,Entry<String,Long>> archivedFilesByTable = HashMultimap.create(); // Group the archived files by table for (FileWithSize fileWithSize : request.getArchivedFilesList()) { TableName tn = ProtobufUtil.toTableName(fileWithSize.getTableName()); archivedFilesByTable.put( tn, Maps.immutableEntry(fileWithSize.getName(), fileWithSize.getSize())); } if (LOG.isTraceEnabled()) { LOG.trace("Grouped archived files by table: " + archivedFilesByTable); } // Report each set of files to the appropriate object for (TableName tn : archivedFilesByTable.keySet()) { final Set<Entry<String,Long>> filesWithSize = archivedFilesByTable.get(tn); final FileArchiverNotifier notifier = FileArchiverNotifierFactoryImpl.getInstance().get( conn, conf, fs, tn); notifier.addArchivedFiles(filesWithSize); } } }
@Override <K, V> Map<K, Collection<V>> createMap() { return Maps.newHashMapWithExpectedSize(expectedKeys); } };