diff --git a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java index f34761576b8..a12f9a3bd8c 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java +++ b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java @@ -43,7 +43,7 @@ public class MutationsRejectedException extends AccumuloException { private static final long serialVersionUID = 1L; private final ArrayList cvsl = new ArrayList<>(); - private final HashMap> af = new HashMap<>(); + private final HashMap> af; private final HashSet es = new HashSet<>(); private final int unknownErrors; @@ -69,7 +69,7 @@ public MutationsRejectedException(Instance instance, List(hashMap); this.es.addAll(serverSideErrors); this.unknownErrors = unknownErrors; } @@ -95,7 +95,7 @@ public MutationsRejectedException(AccumuloClient client, List(hashMap); this.es.addAll(serverSideErrors); this.unknownErrors = unknownErrors; } diff --git a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java index ffa43e3bc47..a8e98481eed 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java +++ b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java @@ -123,7 +123,7 @@ private void _startNewLocalityGroup(String name, Set columnFamilie * @throws IllegalStateException When default locality group already started. */ public void startNewLocalityGroup(String name, List families) throws IOException { - HashSet fams = new HashSet<>(); + HashSet fams = new HashSet<>(families.size(), 1.0f); for (byte[] family : families) { fams.add(new ArrayByteSequence(family)); } @@ -147,7 +147,7 @@ public void startNewLocalityGroup(String name, byte[]... families) throws IOExce * @throws IllegalStateException When default locality group already started. */ public void startNewLocalityGroup(String name, Set families) throws IOException { - HashSet fams = new HashSet<>(); + HashSet fams = new HashSet<>(families.size(), 1.0f); for (String family : families) { fams.add(new ArrayByteSequence(family)); } @@ -162,7 +162,7 @@ public void startNewLocalityGroup(String name, Set families) throws IOEx * @throws IllegalStateException When default locality group already started. */ public void startNewLocalityGroup(String name, String... families) throws IOException { - HashSet fams = new HashSet<>(); + HashSet fams = new HashSet<>(families.length, 1.0f); for (String family : families) { fams.add(new ArrayByteSequence(family)); } diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java index c11b6f3c210..09d3fc69d86 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java @@ -31,6 +31,7 @@ import static org.apache.accumulo.core.util.threads.ThreadPoolNames.INSTANCE_OPS_COMPACTIONS_FINDER_POOL; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashSet; @@ -214,8 +215,11 @@ public List getManagerLocations() { @Override public Set getCompactors() { - Set compactors = new HashSet<>(); - ExternalCompactionUtil.getCompactorAddrs(context).values().forEach(addrs -> { + Collection> compactorGroups = + ExternalCompactionUtil.getCompactorAddrs(context).values(); + Set compactors = + new HashSet<>(compactorGroups.stream().mapToInt(List::size).sum(), 1.0f); + compactorGroups.forEach(addrs -> { addrs.forEach(hp -> compactors.add(hp.toString())); }); return compactors; diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java index 669a09570b5..94a58a8d8f8 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java @@ -1217,11 +1217,11 @@ public Map> getLocalityGroups(String tableName) AccumuloConfiguration conf = new ConfigurationCopy(this.getProperties(tableName)); Map> groups = LocalityGroupUtil.getLocalityGroups(conf); - Map> groups2 = new HashMap<>(); + Map> groups2 = new HashMap<>(groups.size(), 1.0f); for (Entry> entry : groups.entrySet()) { - HashSet colFams = new HashSet<>(); + HashSet colFams = new HashSet<>(entry.getValue().size(), 1.0f); for (ByteSequence bs : entry.getValue()) { colFams.add(new Text(bs.toArray())); @@ -1291,7 +1291,7 @@ public Set splitRangeByTablets(String tableName, Range range, int maxSpli mergedExtents.addAll(unmergedExtents); - Set ranges = new HashSet<>(); + Set ranges = new HashSet<>(mergedExtents.size(), 1.0f); for (KeyExtent k : mergedExtents) { ranges.add(k.toDataRange().clip(range)); } @@ -1671,7 +1671,7 @@ public void importTable(String tableName, Set importDirs, ImportConfigur boolean keepOffline = ic.isKeepOffline(); boolean keepMapping = ic.isKeepMappings(); - Set checkedImportDirs = new HashSet<>(); + Set checkedImportDirs = new HashSet<>(importDirs.size(), 1.0f); try { for (String s : importDirs) { checkedImportDirs.add(checkPath(s, "Table", "").toString()); diff --git a/core/src/main/java/org/apache/accumulo/core/data/Condition.java b/core/src/main/java/org/apache/accumulo/core/data/Condition.java index f1b6e13fb6c..59c5668fcf5 100644 --- a/core/src/main/java/org/apache/accumulo/core/data/Condition.java +++ b/core/src/main/java/org/apache/accumulo/core/data/Condition.java @@ -256,8 +256,8 @@ public Condition setIterators(IteratorSetting... iterators) { checkArgument(iterators != null, "iterators is null"); if (iterators.length > 1) { - HashSet names = new HashSet<>(); - HashSet prios = new HashSet<>(); + HashSet names = new HashSet<>(iterators.length, 1.0f); + HashSet prios = new HashSet<>(iterators.length, 1.0f); for (IteratorSetting iteratorSetting : iterators) { if (!names.add(iteratorSetting.getName())) { diff --git a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java index 53f834cedf9..275cdcde0d9 100644 --- a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java +++ b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java @@ -1454,7 +1454,7 @@ public void readFields(DataInput in) throws IOException { if ((first & 0x02) == 0x02) { int numMutations = WritableUtils.readVInt(in); - this.replicationSources = new HashSet<>(); + this.replicationSources = new HashSet<>(numMutations, 1.0f); for (int i = 0; i < numMutations; i++) { replicationSources.add(WritableUtils.readString(in)); } diff --git a/core/src/main/java/org/apache/accumulo/core/data/constraints/VisibilityConstraint.java b/core/src/main/java/org/apache/accumulo/core/data/constraints/VisibilityConstraint.java index c413600d5b8..e814782f2e0 100644 --- a/core/src/main/java/org/apache/accumulo/core/data/constraints/VisibilityConstraint.java +++ b/core/src/main/java/org/apache/accumulo/core/data/constraints/VisibilityConstraint.java @@ -64,7 +64,7 @@ public List check(Environment env, Mutation mutation) { HashSet ok = null; if (updates.size() > 1) { - ok = new HashSet<>(); + ok = new HashSet<>(updates.size()); } VisibilityEvaluator ve = null; diff --git a/core/src/main/java/org/apache/accumulo/core/file/rfile/RFile.java b/core/src/main/java/org/apache/accumulo/core/file/rfile/RFile.java index 9e2d4633c26..0e941129b8c 100644 --- a/core/src/main/java/org/apache/accumulo/core/file/rfile/RFile.java +++ b/core/src/main/java/org/apache/accumulo/core/file/rfile/RFile.java @@ -1449,7 +1449,7 @@ public void init(SortedKeyValueIterator source, Map op * @see LocalityGroupUtil#seek(FileSKVIterator, Range, String, Map) */ public Map> getLocalityGroupCF() { - Map> cf = new HashMap<>(); + Map> cf = new HashMap<>(localityGroups.size(), 1.0f); for (LocalityGroupMetadata lcg : localityGroups) { ArrayList setCF; diff --git a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnFamilySkippingIterator.java b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnFamilySkippingIterator.java index 3745bf0fc33..ae26b0dd81a 100644 --- a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnFamilySkippingIterator.java +++ b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnFamilySkippingIterator.java @@ -117,8 +117,7 @@ public void seek(Range range, Collection columnFamilies, boolean i if (columnFamilies instanceof Set) { colFamSet = (Set) columnFamilies; } else { - colFamSet = new HashSet<>(); - colFamSet.addAll(columnFamilies); + colFamSet = new HashSet<>(columnFamilies); } if (inclusive) { diff --git a/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java b/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java index c3c5f27485b..dd11a95df84 100644 --- a/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java +++ b/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java @@ -535,11 +535,12 @@ public static TabletMetadata create(String id, String prevEndRow, String endRow) * pulled from org.apache.accumulo.server.manager.LiveTServerSet */ public static synchronized Set getLiveTServers(ClientContext context) { - final Set liveServers = new HashSet<>(); final String path = context.getZooKeeperRoot() + Constants.ZTSERVERS; + final List children = context.getZooCache().getChildren(path); + final Set liveServers = new HashSet<>(children.size()); - for (String child : context.getZooCache().getChildren(path)) { + for (String child : children) { checkServer(context, path, child).ifPresent(liveServers::add); } log.trace("Found {} live tservers at ZK path: {}", liveServers.size(), path); diff --git a/core/src/main/java/org/apache/accumulo/core/util/LocalityGroupUtil.java b/core/src/main/java/org/apache/accumulo/core/util/LocalityGroupUtil.java index 4fdb0b60037..f6d2535ed3e 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/LocalityGroupUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/LocalityGroupUtil.java @@ -111,8 +111,8 @@ public static void checkLocalityGroups(Map config) public static Map> getLocalityGroups(AccumuloConfiguration acuconf) throws LocalityGroupConfigurationException { - Map> result = new HashMap<>(); String[] groups = acuconf.get(Property.TABLE_LOCALITY_GROUPS).split(","); + Map> result = new HashMap<>(groups.length); for (String group : groups) { if (!group.isEmpty()) { result.put(group, new HashSet<>()); diff --git a/core/src/main/java/org/apache/accumulo/core/util/compaction/ExternalCompactionUtil.java b/core/src/main/java/org/apache/accumulo/core/util/compaction/ExternalCompactionUtil.java index b3e4a99a7cc..27798d50803 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/compaction/ExternalCompactionUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/compaction/ExternalCompactionUtil.java @@ -116,10 +116,10 @@ public static Optional findCompactionCoordinator(ClientContext cont */ public static Map> getCompactorAddrs(ClientContext context) { try { - final Map> queuesAndAddresses = new HashMap<>(); final String compactorQueuesPath = context.getZooKeeperRoot() + Constants.ZCOMPACTORS; ZooReader zooReader = context.getZooReader(); List queues = zooReader.getChildren(compactorQueuesPath); + final Map> queuesAndAddresses = new HashMap<>(queues.size(), 1.0f); for (String queue : queues) { queuesAndAddresses.putIfAbsent(queue, new ArrayList<>()); try { @@ -254,16 +254,18 @@ public static List getCompactionsRunningOnCompactors(ClientCo getCompactionIdsRunningOnCompactors(ClientContext context) { final ExecutorService executor = ThreadPools.getServerThreadPools() .getPoolBuilder(COMPACTOR_RUNNING_COMPACTION_IDS_POOL).numCoreThreads(16).build(); - List> futures = new ArrayList<>(); - getCompactorAddrs(context).forEach((q, hp) -> { + var compactors = getCompactorAddrs(context); + List> futures = new ArrayList<>(compactors.size()); + + compactors.forEach((q, hp) -> { hp.forEach(hostAndPort -> { futures.add(executor.submit(() -> getRunningCompactionId(hostAndPort, context))); }); }); executor.shutdown(); - HashSet runningIds = new HashSet<>(); + HashSet runningIds = new HashSet<>(compactors.size() / 4); futures.forEach(future -> { try { diff --git a/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletStateChangeIterator.java b/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletStateChangeIterator.java index a14e78af05a..bf5af33b468 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletStateChangeIterator.java +++ b/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletStateChangeIterator.java @@ -129,7 +129,7 @@ static Set decodeMigrations(DataInputStream input, int count) throws if (input == null) { return Collections.emptySet(); } - Set result = new HashSet<>(); + Set result = new HashSet<>(count, 1.0f); for (int i = 0; i < count; i++) { // need a count and cannot use InputStream.available() because its behavior is not reliable // across InputStream impls @@ -142,8 +142,9 @@ private Set parseTableIDs(String tableIDs) { if (tableIDs == null) { return null; } - Set result = new HashSet<>(); - for (String tableID : tableIDs.split(",")) { + String[] ids = tableIDs.split(","); + Set result = new HashSet<>(ids.length, 1.0f); + for (String tableID : ids) { result.add(TableId.of(tableID)); } return result; @@ -154,9 +155,10 @@ private Set parseServers(String servers) { return null; } // parse "host:port[INSTANCE]" - Set result = new HashSet<>(); if (!servers.isEmpty()) { - for (String part : servers.split(",")) { + String[] s = servers.split(","); + Set result = new HashSet<>(s.length, 1.0f); + for (String part : s) { String[] parts = part.split("\\[", 2); String hostport = parts[0]; String instance = parts[1]; @@ -165,8 +167,9 @@ private Set parseServers(String servers) { } result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance)); } + return result; } - return result; + return null; } private Map parseMerges(String merges) { diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java b/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java index 9c8b1da8b5b..ad24713fca0 100644 --- a/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java +++ b/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java @@ -244,8 +244,9 @@ public Map getTableIDs() throws InterruptedException { while (retries <= 10) { try { zr.sync(tablesPath); - final Map tids = new HashMap<>(); - for (String table : zr.getChildren(tablesPath)) { + var tables = zr.getChildren(tablesPath); + final Map tids = new HashMap<>(tables.size(), 1.0f); + for (String table : tables) { TableId tableId = TableId.of(table); TableState tableState = null; String statePath = context.getZooKeeperRoot() + Constants.ZTABLES + "/" @@ -607,8 +608,9 @@ public Set getCandidateTableIDs() throws InterruptedException { } else if (level == DataLevel.METADATA) { return Set.of(MetadataTable.ID); } else if (level == DataLevel.USER) { - Set tableIds = new HashSet<>(); - getTableIDs().forEach((k, v) -> { + var tids = getTableIDs(); + Set tableIds = new HashSet<>(tids.size(), 1.0f); + tids.forEach((k, v) -> { if (v == TableState.ONLINE || v == TableState.OFFLINE) { // Don't return tables that are NEW, DELETING, or in an // UNKNOWN state. diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java index 50b4a9f1c3e..1d5863ca9e3 100644 --- a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java +++ b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java @@ -145,7 +145,7 @@ private void removeCandidatesInUse(GarbageCollectionEnvironment gce, List candidateEntriesToBeDeleted = new ArrayList<>(); Set tableIdsBefore = gce.getCandidateTableIDs(); - Set tableIdsSeen = new HashSet<>(); + Set tableIdsSeen = new HashSet<>(tableIdsBefore.size()); Iterator iter = gce.getReferences().iterator(); while (iter.hasNext()) { Reference ref = iter.next(); diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletClientHandler.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletClientHandler.java index 3644f6146c9..608291db7af 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletClientHandler.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletClientHandler.java @@ -177,7 +177,7 @@ public List bulkImport(TInfo tinfo, TCredentials credentials, final for (Entry> entry : files.entrySet()) { TKeyExtent tke = entry.getKey(); Map fileMap = entry.getValue(); - Map fileRefMap = new HashMap<>(); + Map fileRefMap = new HashMap<>(fileMap.size(), 1.0f); for (Entry mapping : fileMap.entrySet()) { Path path = new Path(mapping.getKey()); FileSystem ns = context.getVolumeManager().getFileSystemByPath(path); @@ -219,7 +219,7 @@ public void loadFiles(TInfo tinfo, TCredentials credentials, long tid, String di watcher.runQuietly(Constants.BULK_ARBITRATOR_TYPE, tid, () -> { tabletImports.forEach((tke, fileMap) -> { - Map newFileMap = new HashMap<>(); + Map newFileMap = new HashMap<>(fileMap.size(), 1.0f); for (Entry mapping : fileMap.entrySet()) { Path path = new Path(dir, mapping.getKey()); @@ -1209,7 +1209,9 @@ public void loadTablet(TInfo tinfo, TCredentials credentials, String lock, Set onlineOverlapping = KeyExtent.findOverlapping(extent, server.getOnlineTablets()); - Set all = new HashSet<>(); + Set all = new HashSet<>( + unopenedOverlapping.size() + openingOverlapping.size() + onlineOverlapping.size(), + 1.0f); all.addAll(unopenedOverlapping); all.addAll(openingOverlapping); all.addAll(onlineOverlapping); diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftScanClientHandler.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftScanClientHandler.java index e0a54c83745..1b3284036ba 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftScanClientHandler.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftScanClientHandler.java @@ -200,7 +200,7 @@ public InitialScan startScan(TInfo tinfo, TCredentials credentials, KeyExtent ex throw new NotServingTabletException(extent.toThrift()); } - HashSet columnSet = new HashSet<>(); + HashSet columnSet = new HashSet<>(columns.size(), 1.0f); for (TColumn tcolumn : columns) { columnSet.add(new Column(tcolumn)); } @@ -356,7 +356,7 @@ public InitialMultiScan startMultiScan(TInfo tinfo, TCredentials credentials, Map executionHints, long busyTimeout) throws ThriftSecurityException, TSampleNotPresentException, ScanServerBusyException { - final Map> batch = new HashMap<>(); + final Map> batch = new HashMap<>(tbatch.size(), 1.0f); tbatch.forEach((k, v) -> { batch.put(KeyExtent.fromThrift(k), v); }); diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java index 0726c1997cb..99a974f1c0b 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java @@ -406,7 +406,7 @@ public void run() { public Map> getActiveScansPerTable() { Map> counts = new HashMap<>(); - Set> copiedIdleSessions = new HashSet<>(); + Set> copiedIdleSessions = new HashSet<>(deferredCleanupQueue.size(), 1.0f); /** * Add sessions so that get the list returned in the active scans call @@ -446,7 +446,8 @@ public List getActiveScans() { final List activeScans = new ArrayList<>(); final long ct = System.currentTimeMillis(); - final Set> copiedIdleSessions = new HashSet<>(); + final Set> copiedIdleSessions = + new HashSet<>(deferredCleanupQueue.size(), 1.0f); /** * Add sessions that get the list returned in the active scans call diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CompactableUtils.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CompactableUtils.java index d332050aabc..0ef01a18838 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CompactableUtils.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CompactableUtils.java @@ -112,7 +112,7 @@ public class CompactableUtils { public static Map> getFirstAndLastKeys(Tablet tablet, Set allFiles) throws IOException { - final Map> result = new HashMap<>(); + final Map> result = new HashMap<>(allFiles.size(), 1.0f); final FileOperations fileFactory = FileOperations.getInstance(); final VolumeManager fs = tablet.getTabletServer().getVolumeManager(); final TableConfiguration tableConf = tablet.getTableConfiguration(); diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java index 8798abde4c4..994f119e5f4 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java @@ -341,7 +341,7 @@ public Tablet(final TabletServer tabletServer, final KeyExtent extent, final AtomicLong maxTime = new AtomicLong(Long.MIN_VALUE); final CommitSession commitSession = getTabletMemory().getCommitSession(); try { - Set absPaths = new HashSet<>(); + Set absPaths = new HashSet<>(datafiles.size()); for (TabletFile ref : datafiles.keySet()) { absPaths.add(ref.getPathStr()); } @@ -395,7 +395,7 @@ public Tablet(final TabletServer tabletServer, final KeyExtent extent, } } // make some closed references that represent the recovered logs - currentLogs = new HashSet<>(); + currentLogs = new HashSet<>(logEntries.size(), 1.0f); for (LogEntry logEntry : logEntries) { currentLogs.add(new DfsLogger(tabletServer.getContext(), tabletServer.getServerConfig(), logEntry.filename, logEntry.getColumnQualifier().toString()));