From 487e16f160db1126a9c0b2cea021547e0b902ee6 Mon Sep 17 00:00:00 2001 From: arbaazkhan1 Date: Tue, 10 Feb 2026 11:57:05 -0500 Subject: [PATCH 1/2] Refactored PreAllocatedArray.java into a static method --- .../accumulo/core/util/LocalityGroupUtil.java | 25 +++++--- .../accumulo/core/util/PreAllocatedArray.java | 62 ------------------- .../accumulo/core/util/PartitionerTest.java | 7 ++- ...rayTest.java => PreAllocatedListTest.java} | 46 +++++++------- .../apache/accumulo/tserver/InMemoryMap.java | 16 ++--- .../apache/accumulo/tserver/NativeMap.java | 14 ++--- 6 files changed, 58 insertions(+), 112 deletions(-) delete mode 100644 core/src/main/java/org/apache/accumulo/core/util/PreAllocatedArray.java rename core/src/test/java/org/apache/accumulo/core/util/{PreAllocatedArrayTest.java => PreAllocatedListTest.java} (71%) 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 ee27c220911..7ccd2bdafe0 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 @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -290,32 +291,31 @@ public boolean equals(Mutation m) { public static class Partitioner { private Map colfamToLgidMap; - private PreAllocatedArray> groups; + private List> groups; - public Partitioner(PreAllocatedArray> groups) { + public Partitioner(List> groups) { this.groups = groups; this.colfamToLgidMap = new HashMap<>(); - for (int i = 0; i < groups.length; i++) { + for (int i = 0; i < groups.size(); i++) { for (ByteSequence cf : groups.get(i).keySet()) { colfamToLgidMap.put(cf, i); } } } - public void partition(List mutations, - PreAllocatedArray> partitionedMutations) { + public void partition(List mutations, List> partitionedMutations) { final var mbs = new ArrayByteSequence(new byte[0], 0, 0); - PreAllocatedArray> parts = new PreAllocatedArray<>(groups.length + 1); + List> parts = newPreallocatedList(groups.size() + 1); for (Mutation mutation : mutations) { if (mutation.getUpdates().size() == 1) { int lgid = getLgid(mbs, mutation.getUpdates().get(0)); partitionedMutations.get(lgid).add(mutation); } else { - for (int i = 0; i < parts.length; i++) { + for (int i = 0; i < parts.size(); i++) { parts.set(i, null); } @@ -333,14 +333,14 @@ public void partition(List mutations, } if (lgcount == 1) { - for (int i = 0; i < parts.length; i++) { + for (int i = 0; i < parts.size(); i++) { if (parts.get(i) != null) { partitionedMutations.get(i).add(mutation); break; } } } else { - for (int i = 0; i < parts.length; i++) { + for (int i = 0; i < parts.size(); i++) { if (parts.get(i) != null) { partitionedMutations.get(i) .add(new PartitionedMutation(mutation.getRow(), parts.get(i))); @@ -355,7 +355,7 @@ private Integer getLgid(ArrayByteSequence mbs, ColumnUpdate cu) { mbs.reset(cu.getColumnFamily(), 0, cu.getColumnFamily().length); Integer lgid = colfamToLgidMap.get(mbs); if (lgid == null) { - lgid = groups.length; + lgid = groups.size(); } return lgid; } @@ -412,4 +412,9 @@ public static void ensureNonOverlappingGroups(Map> groups) { all.addAll(entry.getValue()); } } + + @SuppressWarnings("unchecked") + public static List newPreallocatedList(int size) { + return Arrays.asList((T[]) new Object[size]); + } } diff --git a/core/src/main/java/org/apache/accumulo/core/util/PreAllocatedArray.java b/core/src/main/java/org/apache/accumulo/core/util/PreAllocatedArray.java deleted file mode 100644 index 679b06f9ad6..00000000000 --- a/core/src/main/java/org/apache/accumulo/core/util/PreAllocatedArray.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.accumulo.core.util; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** - * A {@link List} implementation that represents a type-safe pre-allocated array. This should be - * used exactly like an array, but helps avoid type-safety issues when mixing arrays with generics. - * The iterator is unmodifiable. - */ -public final class PreAllocatedArray implements Iterable { - - private final List internal; - public final int length; - - /** - * Creates an instance of the given capacity, with all elements initialized to null - */ - @SuppressWarnings("unchecked") - public PreAllocatedArray(final int capacity) { - internal = Arrays.asList((T[]) new Object[capacity]); - length = capacity; - } - - /** - * Set the element at the specified index, and return the old value. - */ - public T set(final int index, final T element) { - return internal.set(index, element); - } - - /** - * Get the item stored at the specified index. - */ - public T get(final int index) { - return internal.get(index); - } - - @Override - public Iterator iterator() { - return internal.iterator(); - } -} diff --git a/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java b/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java index ab57aedd469..de97134b472 100644 --- a/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java @@ -18,6 +18,7 @@ */ package org.apache.accumulo.core.util; +import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; @@ -41,7 +42,7 @@ public class PartitionerTest { @Test public void test1() { - PreAllocatedArray> groups = new PreAllocatedArray<>(2); + List> groups = newPreallocatedList(2); groups.set(0, new HashMap<>()); groups.get(0).put(new ArrayByteSequence("cf1"), new MutableLong(1)); @@ -72,9 +73,9 @@ public void test1() { m5.put("cf5", "cq3", "v9"); List mutations = Arrays.asList(m1, m2, m3, m4, m5); - PreAllocatedArray> partitioned = new PreAllocatedArray<>(3); + List> partitioned = newPreallocatedList(3); - for (int i = 0; i < partitioned.length; i++) { + for (int i = 0; i < partitioned.size(); i++) { partitioned.set(i, new ArrayList<>()); } diff --git a/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedArrayTest.java b/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java similarity index 71% rename from core/src/test/java/org/apache/accumulo/core/util/PreAllocatedArrayTest.java rename to core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java index b25a43aea37..3c82016a5ab 100644 --- a/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedArrayTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java @@ -18,6 +18,7 @@ */ package org.apache.accumulo.core.util; +import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -25,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Iterator; +import java.util.List; import org.junit.jupiter.api.Test; @@ -32,49 +34,49 @@ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", justification = "lambda assertThrows testing exception thrown") -public class PreAllocatedArrayTest { +public class PreAllocatedListTest { /** - * Test method for {@link org.apache.accumulo.core.util.PreAllocatedArray#PreAllocatedArray(int)}. + * Test method for + * {@link org.apache.accumulo.core.util.LocalityGroupUtil#newPreallocatedList(int)} (int)}. */ @Test public void testPreAllocatedArray() { - PreAllocatedArray strings = new PreAllocatedArray<>(5); - assertEquals(5, strings.length); + List strings = newPreallocatedList(5); + assertEquals(5, strings.size()); - strings = new PreAllocatedArray<>(3); - assertEquals(3, strings.length); + strings = newPreallocatedList(3); + assertEquals(3, strings.size()); - strings = new PreAllocatedArray<>(0); - assertEquals(0, strings.length); + strings = newPreallocatedList(0); + assertEquals(0, strings.size()); } @Test public void testPreAllocatedArray_Fail() { - assertThrows(NegativeArraySizeException.class, () -> new PreAllocatedArray(-5)); + assertThrows(NegativeArraySizeException.class, () -> newPreallocatedList(-5)); } /** - * Test method for - * {@link org.apache.accumulo.core.util.PreAllocatedArray#set(int, java.lang.Object)}.
- * Test method for {@link org.apache.accumulo.core.util.PreAllocatedArray#get(int)}.
- * Test method for {@link org.apache.accumulo.core.util.PreAllocatedArray#iterator()}. + * Test method for {@link List#set(int, java.lang.Object)}.
+ * Test method for {@link List#get(int)}.
+ * Test method for {@link List#iterator()}. */ @Test public void testSet() { int capacity = 5; - PreAllocatedArray strings = new PreAllocatedArray<>(capacity); - assertEquals(capacity, strings.length); + List strings = newPreallocatedList(capacity); + assertEquals(capacity, strings.size()); // everything else should be null strings.set(1, "a"); strings.set(4, "b"); - assertEquals(capacity, strings.length); + assertEquals(capacity, strings.size()); // overwrite String b = strings.set(4, "c"); assertEquals("b", b); - assertEquals(capacity, strings.length); + assertEquals(capacity, strings.size()); Iterator iter = strings.iterator(); assertNull(iter.next()); // index 0 @@ -87,21 +89,21 @@ public void testSet() { @Test public void testSetIndexHigh() { - PreAllocatedArray strings = new PreAllocatedArray<>(3); + List strings = newPreallocatedList(3); strings.set(2, "in bounds"); assertThrows(IndexOutOfBoundsException.class, () -> strings.set(3, "out of bounds")); } @Test public void testSetIndexNegative() { - PreAllocatedArray strings = new PreAllocatedArray<>(3); + List strings = newPreallocatedList(3); strings.set(0, "in bounds"); assertThrows(IndexOutOfBoundsException.class, () -> strings.set(-3, "out of bounds")); } @Test public void testGetIndexHigh() { - PreAllocatedArray strings = new PreAllocatedArray<>(3); + List strings = newPreallocatedList(3); assertNull(strings.get(2)); // spotbugs error suppressed at class level for lambda assertThrows(IndexOutOfBoundsException.class, () -> strings.get(3)); @@ -109,7 +111,7 @@ public void testGetIndexHigh() { @Test public void testGetIndexNegative() { - PreAllocatedArray strings = new PreAllocatedArray<>(3); + List strings = newPreallocatedList(3); assertNull(strings.get(0)); // spotbugs error suppressed at class level for lambda assertThrows(IndexOutOfBoundsException.class, () -> strings.get(-3)); @@ -117,7 +119,7 @@ public void testGetIndexNegative() { @Test public void testIteratorRemove() { - PreAllocatedArray strings = new PreAllocatedArray<>(3); + List strings = newPreallocatedList(3); strings.set(1, "data"); var iter = strings.iterator(); for (int i = 0; i < 3; i++) { diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java index d943e3f6f85..387deb70fff 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java @@ -19,6 +19,7 @@ package org.apache.accumulo.tserver; import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; +import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; import java.io.IOException; import java.util.ArrayList; @@ -69,7 +70,6 @@ import org.apache.accumulo.core.util.LocalityGroupUtil; import org.apache.accumulo.core.util.LocalityGroupUtil.Partitioner; import org.apache.accumulo.core.util.Pair; -import org.apache.accumulo.core.util.PreAllocatedArray; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.conf.TableConfiguration; import org.apache.commons.lang3.mutable.MutableLong; @@ -280,17 +280,17 @@ public void mutate(List mutations, int kvCount) { private static class LocalityGroupMap implements SimpleMap { - private final PreAllocatedArray> groupFams; + private final List> groupFams; // the last map in the array is the default locality group private final SimpleMap[] maps; private final Partitioner partitioner; - private final PreAllocatedArray> partitioned; + private final List> partitioned; LocalityGroupMap(Map> groups, boolean useNativeMap) { - this.groupFams = new PreAllocatedArray<>(groups.size()); + this.groupFams = newPreallocatedList(groups.size()); this.maps = new SimpleMap[groups.size() + 1]; - this.partitioned = new PreAllocatedArray<>(groups.size() + 1); + this.partitioned = newPreallocatedList(groups.size() + 1); for (int i = 0; i < maps.length; i++) { maps[i] = newMap(useNativeMap); @@ -307,7 +307,7 @@ private static class LocalityGroupMap implements SimpleMap { partitioner = new LocalityGroupUtil.Partitioner(this.groupFams); - for (int i = 0; i < partitioned.length; i++) { + for (int i = 0; i < partitioned.size(); i++) { partitioned.set(i, new ArrayList<>()); } } @@ -329,7 +329,7 @@ public InterruptibleIterator skvIterator(SamplerConfigurationImpl samplerConfig) LocalityGroup[] groups = new LocalityGroup[maps.length]; for (int i = 0; i < groups.length; i++) { - if (i < groupFams.length) { + if (i < groupFams.size()) { groups[i] = new LocalityGroup(maps[i].skvIterator(null), groupFams.get(i), false); } else { groups[i] = new LocalityGroup(maps[i].skvIterator(null), null, true); @@ -364,7 +364,7 @@ public synchronized void mutate(List mutations, int kvCount) { try { partitioner.partition(mutations, partitioned); - for (int i = 0; i < partitioned.length; i++) { + for (int i = 0; i < partitioned.size(); i++) { if (!partitioned.get(i).isEmpty()) { maps[i].mutate(partitioned.get(i), kvCount); for (Mutation m : partitioned.get(i)) { diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java index 0b8a6816c29..7403a720889 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java @@ -18,6 +18,8 @@ */ package org.apache.accumulo.tserver; +import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; + import java.lang.ref.Cleaner.Cleanable; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Collection; @@ -45,7 +47,6 @@ import org.apache.accumulo.core.iterators.SortedKeyValueIterator; import org.apache.accumulo.core.iteratorsImpl.system.InterruptibleIterator; import org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException; -import org.apache.accumulo.core.util.PreAllocatedArray; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -181,7 +182,7 @@ private class ConcurrentIterator implements Iterator> { private NMIterator source; - private PreAllocatedArray> nextEntries; + private List> nextEntries; private int index; private int end; @@ -191,7 +192,7 @@ private class ConcurrentIterator implements Iterator> { ConcurrentIterator(Key key) { // start off with a small read ahead - nextEntries = new PreAllocatedArray<>(1); + nextEntries = newPreallocatedList(1); rlock.lock(); try { @@ -214,12 +215,11 @@ private void fill() { int amountRead = 0; // as we keep filling, increase the read ahead buffer - if (nextEntries.length < MAX_READ_AHEAD_ENTRIES) { - nextEntries = - new PreAllocatedArray<>(Math.min(nextEntries.length * 2, MAX_READ_AHEAD_ENTRIES)); + if (nextEntries.size() < MAX_READ_AHEAD_ENTRIES) { + nextEntries = newPreallocatedList(Math.min(nextEntries.size() * 2, MAX_READ_AHEAD_ENTRIES)); } - while (source.hasNext() && end < nextEntries.length) { + while (source.hasNext() && end < nextEntries.size()) { Entry ne = source.next(); nextEntries.set(end++, ne); amountRead += ne.getKey().getSize() + ne.getValue().getSize(); From 53c147f884e64b0e3ef1c33ea0aa9fc5a050f227 Mon Sep 17 00:00:00 2001 From: arbaazkhan1 Date: Thu, 19 Feb 2026 12:29:39 -0500 Subject: [PATCH 2/2] moved method into its own class --- .../accumulo/core/util/LocalityGroupUtil.java | 8 +---- .../accumulo/core/util/PreallocatedList.java | 29 +++++++++++++++++++ .../accumulo/core/util/PartitionerTest.java | 5 ++-- .../core/util/PreAllocatedListTest.java | 24 +++++++-------- .../apache/accumulo/tserver/InMemoryMap.java | 6 ++-- .../apache/accumulo/tserver/NativeMap.java | 8 ++--- 6 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 core/src/main/java/org/apache/accumulo/core/util/PreallocatedList.java 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 7ccd2bdafe0..c4ced7d223d 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 @@ -22,7 +22,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -308,7 +307,7 @@ public void partition(List mutations, List> partitioned final var mbs = new ArrayByteSequence(new byte[0], 0, 0); - List> parts = newPreallocatedList(groups.size() + 1); + List> parts = PreallocatedList.create(groups.size() + 1); for (Mutation mutation : mutations) { if (mutation.getUpdates().size() == 1) { @@ -412,9 +411,4 @@ public static void ensureNonOverlappingGroups(Map> groups) { all.addAll(entry.getValue()); } } - - @SuppressWarnings("unchecked") - public static List newPreallocatedList(int size) { - return Arrays.asList((T[]) new Object[size]); - } } diff --git a/core/src/main/java/org/apache/accumulo/core/util/PreallocatedList.java b/core/src/main/java/org/apache/accumulo/core/util/PreallocatedList.java new file mode 100644 index 00000000000..6fa1d3f62af --- /dev/null +++ b/core/src/main/java/org/apache/accumulo/core/util/PreallocatedList.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.accumulo.core.util; + +import java.util.Arrays; +import java.util.List; + +public class PreallocatedList { + @SuppressWarnings("unchecked") + public static List create(int size) { + return Arrays.asList((T[]) new Object[size]); + } +} diff --git a/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java b/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java index de97134b472..ba42f6d77d5 100644 --- a/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/PartitionerTest.java @@ -18,7 +18,6 @@ */ package org.apache.accumulo.core.util; -import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; @@ -42,7 +41,7 @@ public class PartitionerTest { @Test public void test1() { - List> groups = newPreallocatedList(2); + List> groups = PreallocatedList.create(2); groups.set(0, new HashMap<>()); groups.get(0).put(new ArrayByteSequence("cf1"), new MutableLong(1)); @@ -73,7 +72,7 @@ public void test1() { m5.put("cf5", "cq3", "v9"); List mutations = Arrays.asList(m1, m2, m3, m4, m5); - List> partitioned = newPreallocatedList(3); + List> partitioned = PreallocatedList.create(3); for (int i = 0; i < partitioned.size(); i++) { partitioned.set(i, new ArrayList<>()); diff --git a/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java b/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java index 3c82016a5ab..09060cc471b 100644 --- a/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/PreAllocatedListTest.java @@ -18,7 +18,6 @@ */ package org.apache.accumulo.core.util; -import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -37,24 +36,23 @@ public class PreAllocatedListTest { /** - * Test method for - * {@link org.apache.accumulo.core.util.LocalityGroupUtil#newPreallocatedList(int)} (int)}. + * Test method for {@link org.apache.accumulo.core.util.PreallocatedList#create(int)}. */ @Test public void testPreAllocatedArray() { - List strings = newPreallocatedList(5); + List strings = PreallocatedList.create(5); assertEquals(5, strings.size()); - strings = newPreallocatedList(3); + strings = PreallocatedList.create(3); assertEquals(3, strings.size()); - strings = newPreallocatedList(0); + strings = PreallocatedList.create(0); assertEquals(0, strings.size()); } @Test public void testPreAllocatedArray_Fail() { - assertThrows(NegativeArraySizeException.class, () -> newPreallocatedList(-5)); + assertThrows(NegativeArraySizeException.class, () -> PreallocatedList.create(-5)); } /** @@ -65,7 +63,7 @@ public void testPreAllocatedArray_Fail() { @Test public void testSet() { int capacity = 5; - List strings = newPreallocatedList(capacity); + List strings = PreallocatedList.create(capacity); assertEquals(capacity, strings.size()); // everything else should be null @@ -89,21 +87,21 @@ public void testSet() { @Test public void testSetIndexHigh() { - List strings = newPreallocatedList(3); + List strings = PreallocatedList.create(3); strings.set(2, "in bounds"); assertThrows(IndexOutOfBoundsException.class, () -> strings.set(3, "out of bounds")); } @Test public void testSetIndexNegative() { - List strings = newPreallocatedList(3); + List strings = PreallocatedList.create(3); strings.set(0, "in bounds"); assertThrows(IndexOutOfBoundsException.class, () -> strings.set(-3, "out of bounds")); } @Test public void testGetIndexHigh() { - List strings = newPreallocatedList(3); + List strings = PreallocatedList.create(3); assertNull(strings.get(2)); // spotbugs error suppressed at class level for lambda assertThrows(IndexOutOfBoundsException.class, () -> strings.get(3)); @@ -111,7 +109,7 @@ public void testGetIndexHigh() { @Test public void testGetIndexNegative() { - List strings = newPreallocatedList(3); + List strings = PreallocatedList.create(3); assertNull(strings.get(0)); // spotbugs error suppressed at class level for lambda assertThrows(IndexOutOfBoundsException.class, () -> strings.get(-3)); @@ -119,7 +117,7 @@ public void testGetIndexNegative() { @Test public void testIteratorRemove() { - List strings = newPreallocatedList(3); + List strings = PreallocatedList.create(3); strings.set(1, "data"); var iter = strings.iterator(); for (int i = 0; i < 3; i++) { diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java index 387deb70fff..d272c4c8141 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java @@ -19,7 +19,6 @@ package org.apache.accumulo.tserver; import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; -import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; import java.io.IOException; import java.util.ArrayList; @@ -70,6 +69,7 @@ import org.apache.accumulo.core.util.LocalityGroupUtil; import org.apache.accumulo.core.util.LocalityGroupUtil.Partitioner; import org.apache.accumulo.core.util.Pair; +import org.apache.accumulo.core.util.PreallocatedList; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.conf.TableConfiguration; import org.apache.commons.lang3.mutable.MutableLong; @@ -288,9 +288,9 @@ private static class LocalityGroupMap implements SimpleMap { private final List> partitioned; LocalityGroupMap(Map> groups, boolean useNativeMap) { - this.groupFams = newPreallocatedList(groups.size()); + this.groupFams = PreallocatedList.create(groups.size()); this.maps = new SimpleMap[groups.size() + 1]; - this.partitioned = newPreallocatedList(groups.size() + 1); + this.partitioned = PreallocatedList.create(groups.size() + 1); for (int i = 0; i < maps.length; i++) { maps[i] = newMap(useNativeMap); diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java index 7403a720889..38721ccb864 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java @@ -18,8 +18,6 @@ */ package org.apache.accumulo.tserver; -import static org.apache.accumulo.core.util.LocalityGroupUtil.newPreallocatedList; - import java.lang.ref.Cleaner.Cleanable; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Collection; @@ -47,6 +45,7 @@ import org.apache.accumulo.core.iterators.SortedKeyValueIterator; import org.apache.accumulo.core.iteratorsImpl.system.InterruptibleIterator; import org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException; +import org.apache.accumulo.core.util.PreallocatedList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -192,7 +191,7 @@ private class ConcurrentIterator implements Iterator> { ConcurrentIterator(Key key) { // start off with a small read ahead - nextEntries = newPreallocatedList(1); + nextEntries = PreallocatedList.create(1); rlock.lock(); try { @@ -216,7 +215,8 @@ private void fill() { // as we keep filling, increase the read ahead buffer if (nextEntries.size() < MAX_READ_AHEAD_ENTRIES) { - nextEntries = newPreallocatedList(Math.min(nextEntries.size() * 2, MAX_READ_AHEAD_ENTRIES)); + nextEntries = + PreallocatedList.create(Math.min(nextEntries.size() * 2, MAX_READ_AHEAD_ENTRIES)); } while (source.hasNext() && end < nextEntries.size()) {