Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public RowBufferingIterator(Scanner scanner, ScannerOptions opts, Range range, l
this.batchSize = batchSize;
this.readaheadThreshold = readaheadThreshold;

buffer = bufferFactory.newBuffer();
buffer = bufferFactory.newBuffer(this.batchSize);

this.source = newIterator(range);

Expand Down Expand Up @@ -173,7 +173,7 @@ public void remove() {
}

public interface RowBufferFactory {
RowBuffer newBuffer();
RowBuffer newBuffer(int initialSize);
}

public interface RowBuffer extends Iterable<Entry<Key,Value>> {
Expand All @@ -188,14 +188,18 @@ public interface RowBuffer extends Iterable<Entry<Key,Value>> {
public static class MemoryRowBufferFactory implements RowBufferFactory {

@Override
public RowBuffer newBuffer() {
return new MemoryRowBuffer();
public RowBuffer newBuffer(int initialSize) {
return new MemoryRowBuffer(initialSize);
}
}

public static class MemoryRowBuffer implements RowBuffer {

private final ArrayList<Entry<Key,Value>> buffer = new ArrayList<>();
private final ArrayList<Entry<Key,Value>> buffer;

private MemoryRowBuffer(int initialSize) {
buffer = new ArrayList<>(initialSize);
}

@Override
public void add(Entry<Key,Value> entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ public Set<String> getScanServers() {
@Override
public List<String> getTabletServers() {
ZooCache cache = context.getZooCache();
String path = context.getZooKeeperRoot() + Constants.ZTSERVERS;
List<String> results = new ArrayList<>();
for (String candidate : cache.getChildren(path)) {
final String path = context.getZooKeeperRoot() + Constants.ZTSERVERS;
final List<String> candidates = cache.getChildren(path);
final List<String> results = new ArrayList<>(candidates.size());
for (String candidate : candidates) {
var children = cache.getChildren(path + "/" + candidate);
if (children != null && !children.isEmpty()) {
var copy = new ArrayList<>(children);
Expand All @@ -253,8 +254,9 @@ public List<ActiveScan> getActiveScans(String tserver)
try {
client = getClient(ThriftClientTypes.TABLET_SCAN, parsedTserver, context);

List<ActiveScan> as = new ArrayList<>();
for (var activeScan : client.getActiveScans(TraceUtil.traceInfo(), context.rpcCreds())) {
final var scans = client.getActiveScans(TraceUtil.traceInfo(), context.rpcCreds());
List<ActiveScan> as = new ArrayList<>(scans.size());
for (var activeScan : scans) {
try {
as.add(new ActiveScanImpl(context, activeScan));
} catch (TableNotFoundException e) {
Expand Down Expand Up @@ -326,7 +328,7 @@ public List<ActiveCompaction> getActiveCompactions()
var executorService = context.threadPools().getPoolBuilder(INSTANCE_OPS_COMPACTIONS_FINDER_POOL)
.numCoreThreads(numThreads).build();
try {
List<Future<List<ActiveCompaction>>> futures = new ArrayList<>();
List<Future<List<ActiveCompaction>>> futures = new ArrayList<>(tservers.size());

for (String tserver : tservers) {
futures.add(executorService.submit(() -> getActiveCompactions(tserver)));
Expand All @@ -344,7 +346,7 @@ public List<ActiveCompaction> getActiveCompactions()
}
});

List<ActiveCompaction> ret = new ArrayList<>();
List<ActiveCompaction> ret = new ArrayList<>(futures.size());
for (Future<List<ActiveCompaction>> future : futures) {
try {
ret.addAll(future.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private void binRanges(TabletLocator tabletLocator, List<Range> ranges,
binnedRanges2.put(entry.getKey(), tabletMap);
for (Entry<KeyExtent,List<Range>> tabletRanges : entry.getValue().entrySet()) {
Range tabletRange = tabletRanges.getKey().toDataRange();
List<Range> clippedRanges = new ArrayList<>();
List<Range> clippedRanges = new ArrayList<>(tabletRanges.getValue().size());
tabletMap.put(tabletRanges.getKey(), clippedRanges);
for (Range range : tabletRanges.getValue()) {
clippedRanges.add(tabletRange.clip(range));
Expand Down Expand Up @@ -339,7 +339,7 @@ private void processFailures(Map<KeyExtent,List<Range>> failures, ResultReceiver
failSleepTime = Math.min(5000, failSleepTime * 2);

Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>();
List<Range> allRanges = new ArrayList<>();
List<Range> allRanges = new ArrayList<>(failures.values().stream().mapToInt(List::size).sum());

for (List<Range> ranges : failures.values()) {
allRanges.addAll(ranges);
Expand Down Expand Up @@ -562,7 +562,7 @@ private void doLookups(Map<String,Map<KeyExtent,List<Range>>> binnedRanges,
List<String> locations = new ArrayList<>(binnedRanges.keySet());
Collections.shuffle(locations);

List<QueryTask> queryTasks = new ArrayList<>();
List<QueryTask> queryTasks = new ArrayList<>(locations.size());

for (final String tsLocation : locations) {

Expand Down Expand Up @@ -828,7 +828,7 @@ static void doLookup(ClientContext context, String server, Map<KeyExtent,List<Ra

// copy requested to unscanned map. we will remove ranges as they are scanned in trackScanning()
for (Entry<KeyExtent,List<Range>> entry : requested.entrySet()) {
ArrayList<Range> ranges = new ArrayList<>();
ArrayList<Range> ranges = new ArrayList<>(entry.getValue().size());
for (Range range : entry.getValue()) {
ranges.add(new Range(range));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,8 @@ public void readFields(DataInput in) throws IOException {

boolean valuesPresent = (first & 0x01) == 0x01;
if (valuesPresent) {
values = new ArrayList<>();
int numValues = WritableUtils.readVInt(in);
values = new ArrayList<>(numValues);
for (int i = 0; i < numValues; i++) {
len = WritableUtils.readVInt(in);
byte[] val = new byte[len];
Expand Down Expand Up @@ -1480,8 +1480,8 @@ private void oldReadFields(byte first, DataInput in) throws IOException {
List<byte[]> localValues;
boolean valuesPresent = in.readBoolean();
if (valuesPresent) {
localValues = new ArrayList<>();
int numValues = in.readInt();
localValues = new ArrayList<>(numValues);
for (int i = 0; i < numValues; i++) {
len = in.readInt();
byte[] val = new byte[len];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void readFields(DataInput in, int version) throws IOException {

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
ArrayList<Integer> oal = new ArrayList<>();
ArrayList<Integer> oal = new ArrayList<>(size);

for (int i = 0; i < size; i++) {
IndexEntry ie = new IndexEntry(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public static SortedKeyValueIterator<Key,Value> convertItersAndLoad(IteratorScop
List<IteratorSetting> iterators, IteratorEnvironment env)
throws IOException, ReflectiveOperationException {

List<IterInfo> ssiList = new ArrayList<>();
Map<String,Map<String,String>> ssio = new HashMap<>();
List<IterInfo> ssiList = new ArrayList<>(iterators.size());
Map<String,Map<String,String>> ssio = new HashMap<>(iterators.size());

for (IteratorSetting is : iterators) {
ssiList.add(new IterInfo(is.getPriority(), is.getIteratorClass(), is.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static IteratorSetting toIteratorSetting(TIteratorSetting tis) {
}

public static IteratorConfig toIteratorConfig(List<IteratorSetting> iterators) {
ArrayList<TIteratorSetting> tisList = new ArrayList<>();
ArrayList<TIteratorSetting> tisList = new ArrayList<>(iterators.size());

for (IteratorSetting iteratorSetting : iterators) {
tisList.add(toTIteratorSetting(iteratorSetting));
Expand All @@ -63,7 +63,7 @@ public static IteratorConfig toIteratorConfig(List<IteratorSetting> iterators) {
}

public static List<IteratorSetting> toIteratorSettings(IteratorConfig ic) {
List<IteratorSetting> ret = new ArrayList<>();
List<IteratorSetting> ret = new ArrayList<>(ic.getIterators().size());
for (TIteratorSetting tIteratorSetting : ic.getIterators()) {
ret.add(toIteratorSetting(tIteratorSetting));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ default Pair<String,C> getTabletServerConnection(Logger LOG, ThriftClientTypes<C

final long rpcTimeout = context.getClientTimeoutInMillis();
final ZooCache zc = context.getZooCache();
final List<String> tservers = new ArrayList<>();

tservers.addAll(zc.getChildren(context.getZooKeeperRoot() + Constants.ZTSERVERS));
final List<String> tservers =
new ArrayList<>(zc.getChildren(context.getZooKeeperRoot() + Constants.ZTSERVERS));

if (tservers.isEmpty()) {
if (warned.compareAndSet(false, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public void getAssignments(AssignmentParameters params) {

Function<TabletId,String> partitioner = getLoggingPartitioner();

List<ComparablePair<String,TabletId>> tabletsByGroup = new ArrayList<>();
List<ComparablePair<String,TabletId>> tabletsByGroup =
new ArrayList<>(params.unassignedTablets().size());
for (Entry<TabletId,TabletServerId> entry : params.unassignedTablets().entrySet()) {
TabletServerId last = entry.getValue();
if (last != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public boolean getMigrations(Map<TabletServerId,TServerStatus> current,

// Sort by total number of online tablets, per server
int total = 0;
ArrayList<ServerCounts> totals = new ArrayList<>();
ArrayList<ServerCounts> totals = new ArrayList<>(current.size());
for (Entry<TabletServerId,TServerStatus> entry : current.entrySet()) {
int serverTotal = 0;
if (entry.getValue() != null && entry.getValue().getTableMap() != null) {
Expand Down Expand Up @@ -241,11 +241,11 @@ public boolean getMigrations(Map<TabletServerId,TServerStatus> current,
List<TabletMigration> move(ServerCounts tooMuch, ServerCounts tooLittle, int count,
Map<TableId,Map<TabletId,TabletStatistics>> donerTabletStats) {

if (count == 0) {
if (count <= 0) {
return Collections.emptyList();
}

List<TabletMigration> result = new ArrayList<>();
List<TabletMigration> result = new ArrayList<>(count);
// Copy counts so we can update them as we propose migrations
Map<TableId,Integer> tooMuchMap = tabletCountsPerTable(tooMuch.status);
Map<TableId,Integer> tooLittleMap = tabletCountsPerTable(tooLittle.status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void init(InitParameters params) {
ExecutorConfig[] execConfigs =
new Gson().fromJson(params.getOptions().get("executors"), ExecutorConfig[].class);

List<Executor> tmpExec = new ArrayList<>();
List<Executor> tmpExec = new ArrayList<>(execConfigs.length);

for (ExecutorConfig executorConfig : execConfigs) {
Long maxSize = executorConfig.maxSize == null ? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private class PartitionFuture implements Future<SummaryCollection> {
Map<String,Map<TabletFile,List<TRowRange>>> filesGBL;
filesGBL = getFilesGroupedByLocation(fileSelector);

List<CompletableFuture<ProcessedFiles>> futures = new ArrayList<>();
List<CompletableFuture<ProcessedFiles>> futures = new ArrayList<>(filesGBL.size() + 1);
if (previousWork != null) {
futures.add(CompletableFuture
.completedFuture(new ProcessedFiles(previousWork.summaries, factory)));
Expand Down Expand Up @@ -433,7 +433,7 @@ public interface FileSystemResolver {
public Future<SummaryCollection> processFiles(FileSystemResolver volMgr,
Map<String,List<TRowRange>> files, BlockCache summaryCache, BlockCache indexCache,
Cache<String,Long> fileLenCache, ExecutorService srp) {
List<CompletableFuture<SummaryCollection>> futures = new ArrayList<>();
List<CompletableFuture<SummaryCollection>> futures = new ArrayList<>(files.size());
for (Entry<String,List<TRowRange>> entry : files.entrySet()) {
futures.add(CompletableFuture.supplyAsync(() -> {
List<RowRange> rrl =
Expand Down Expand Up @@ -504,7 +504,7 @@ public Future<SummaryCollection> gather(ExecutorService es) {
// have each tablet server process ~100K files
int numRequest = Math.max(numFiles / 100_000, 1);

List<CompletableFuture<SummaryCollection>> futures = new ArrayList<>();
List<CompletableFuture<SummaryCollection>> futures = new ArrayList<>(numRequest);

AtomicBoolean cancelFlag = new AtomicBoolean(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ByteArraySet(Collection<? extends byte[]> c) {
}

public static ByteArraySet fromStrings(Collection<String> c) {
List<byte[]> lst = new ArrayList<>();
List<byte[]> lst = new ArrayList<>(c.size());
for (String s : c) {
lst.add(s.getBytes(UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static List<ByteBuffer> toByteBuffers(Collection<byte[]> bytesList) {
if (bytesList == null) {
return null;
}
ArrayList<ByteBuffer> result = new ArrayList<>();
ArrayList<ByteBuffer> result = new ArrayList<>(bytesList.size());
for (byte[] bytes : bytesList) {
result.add(ByteBuffer.wrap(bytes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static void updateTotalEntries() {
Collections.synchronizedSet(new HashSet<>());

public static List<CompactionInfo> getRunningCompactions() {
ArrayList<CompactionInfo> compactions = new ArrayList<>();
ArrayList<CompactionInfo> compactions = new ArrayList<>(runningCompactions.size());

runningCompactions.forEach(compactor -> compactions.add(new CompactionInfo(compactor)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ private static int countReaders(Map<String,List<OpenReader>> files) {

private List<FileSKVIterator> takeLRUOpenFiles(int numToTake) {

ArrayList<OpenReader> openReaders = new ArrayList<>();
ArrayList<OpenReader> openReaders = new ArrayList<>(openFiles.size());

for (Entry<String,List<OpenReader>> entry : openFiles.entrySet()) {
openReaders.addAll(entry.getValue());
}

Collections.sort(openReaders);

ArrayList<FileSKVIterator> ret = new ArrayList<>();
ArrayList<FileSKVIterator> ret = new ArrayList<>(openReaders.size());

for (int i = 0; i < numToTake && i < openReaders.size(); i++) {
OpenReader or = openReaders.get(i);
Expand Down Expand Up @@ -517,7 +517,7 @@ public synchronized List<InterruptibleIterator> openFiles(Map<TabletFile,DataFil
Map<FileSKVIterator,String> newlyReservedReaders = openFiles(
files.keySet().stream().map(TabletFile::getPathStr).collect(Collectors.toList()));

ArrayList<InterruptibleIterator> iters = new ArrayList<>();
ArrayList<InterruptibleIterator> iters = new ArrayList<>(newlyReservedReaders.size());

boolean sawTimeSet = files.values().stream().anyMatch(DataFileValue::isTimeSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public boolean rename(Path path, Path newPath) throws IOException {
@Override
public void bulkRename(Map<Path,Path> oldToNewPathMap, int poolSize, String poolName,
String transactionId) throws IOException {
List<Future<Void>> results = new ArrayList<>();
List<Future<Void>> results = new ArrayList<>(oldToNewPathMap.size());
ExecutorService workerPool = ThreadPools.getServerThreadPools().getPoolBuilder(poolName)
.numCoreThreads(poolSize).build();
oldToNewPathMap.forEach((oldPath, newPath) -> results.add(workerPool.submit(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ public static void deleteTable(TableId tableId, boolean insertDeletes, ServerCon

public static Pair<List<LogEntry>,SortedMap<StoredTabletFile,DataFileValue>>
getFileAndLogEntries(ServerContext context, KeyExtent extent) throws IOException {
ArrayList<LogEntry> result = new ArrayList<>();
TreeMap<StoredTabletFile,DataFileValue> sizes = new TreeMap<>();

TabletMetadata tablet = context.getAmple().readTablet(extent, FILES, LOGS, PREV_ROW, DIR);
Expand All @@ -384,7 +383,7 @@ public static void deleteTable(TableId tableId, boolean insertDeletes, ServerCon
throw new RuntimeException("Tablet " + extent + " not found in metadata");
}

result.addAll(tablet.getLogs());
ArrayList<LogEntry> result = new ArrayList<>(tablet.getLogs());

tablet.getFilesMap().forEach(sizes::put);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ private void processPending() {

while (!Thread.interrupted()) {
try {
ArrayList<ExternalCompactionFinalState> batch = new ArrayList<>();
ArrayList<ExternalCompactionFinalState> batch =
new ArrayList<>(pendingNotifications.size());
batch.add(pendingNotifications.take());
pendingNotifications.drainTo(batch);

LOG.trace("Processing pending of batch size {}", batch.size());

List<Future<?>> futures = new ArrayList<>();
List<Future<?>> futures = new ArrayList<>(batch.size());

List<ExternalCompactionId> statusesToDelete = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void write(Mutation m) {
private void processMutations() {
Timer timer = Timer.startNew();
while (true) {
ArrayList<Work> batch = new ArrayList<>();
ArrayList<Work> batch = new ArrayList<>(mutations.size());
try {
batch.add(mutations.take());
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public List<String> getActiveTservers(TInfo tinfo, TCredentials credentials)
}

Set<TServerInstance> tserverInstances = manager.onlineTabletServers();
List<String> servers = new ArrayList<>();
List<String> servers = new ArrayList<>(tserverInstances.size());
for (TServerInstance tserverInstance : tserverInstances) {
servers.add(tserverInstance.getHostPort());
}
Expand Down
Loading