This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 92b5eea47d6 HDDS-16615. Replace Pair with domain objects in RocksDB
modules and test-utils (#11978)
92b5eea47d6 is described below
commit 92b5eea47d64e45641a0a8b522a20d4b6e70b0be
Author: Navink <[email protected]>
AuthorDate: Sat Nov 7 19:56:35 2026 +0530
HDDS-16615. Replace Pair with domain objects in RocksDB modules and
test-utils (#11978)
---
hadoop-hdds/rocks-native/pom.xml | 9 +++--
.../hadoop/hdds/utils/NativeLibraryLoader.java | 22 ++++++-----
.../utils/db/TestManagedRawSSTFileIterator.java | 45 ++++++++++++++--------
.../ozone/rocksdiff/RocksDBCheckpointDiffer.java | 38 +++++++++++-------
.../hadoop/hdds/utils/db/TestSstFileSetReader.java | 25 ++++++------
.../rocksdiff/TestRocksDBCheckpointDiffer.java | 33 +++++++++-------
hadoop-hdds/test-utils/pom.xml | 4 --
.../org/apache/ozone/test/GenericTestUtils.java | 6 +--
8 files changed, 107 insertions(+), 75 deletions(-)
diff --git a/hadoop-hdds/rocks-native/pom.xml b/hadoop-hdds/rocks-native/pom.xml
index bb4494da0e3..a83d7cd173d 100644
--- a/hadoop-hdds/rocks-native/pom.xml
+++ b/hadoop-hdds/rocks-native/pom.xml
@@ -31,10 +31,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.ozone</groupId>
<artifactId>hdds-common</artifactId>
@@ -54,6 +50,11 @@
</dependency>
<!-- Test dependencies -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.ozone</groupId>
<artifactId>hdds-test-utils</artifactId>
diff --git
a/hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryLoader.java
b/hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryLoader.java
index 7eb10a8b18f..388e524fec1 100644
---
a/hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryLoader.java
+++
b/hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryLoader.java
@@ -32,7 +32,6 @@
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.ozone.util.ShutdownHookManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -127,9 +126,9 @@ public synchronized boolean loadLibrary(final String
libraryName, final List<Str
}
if (!loaded) {
- Pair<Optional<File>, List<File>> files =
copyResourceFromJarToTemp(libraryName, dependentFiles);
- if (files.getKey().isPresent()) {
- System.load(files.getKey().get().getAbsolutePath());
+ LoadedLibrary files = copyResourceFromJarToTemp(libraryName,
dependentFiles);
+ if (files.libraryFile().isPresent()) {
+ System.load(files.libraryFile().get().getAbsolutePath());
loaded = true;
}
}
@@ -153,15 +152,14 @@ static InputStream getResourceStream(String
libraryFileName) throws IOException
.getResourceAsStream(libraryFileName);
}
- private Pair<Optional<File>, List<File>> copyResourceFromJarToTemp(final
String libraryName,
- final
List<String> dependentFileNames)
+ private LoadedLibrary copyResourceFromJarToTemp(final String libraryName,
final List<String> dependentFileNames)
throws IOException {
final String libraryFileName = getJniLibraryFileName(libraryName);
InputStream is = null;
try {
is = getResourceStream(libraryFileName);
if (is == null) {
- return Pair.of(Optional.empty(), null);
+ return new LoadedLibrary(Optional.empty(), null);
}
final String nativeLibDir = getSystemProperty(NATIVE_LIB_TMP_DIR);
@@ -183,7 +181,7 @@ private Pair<Optional<File>, List<File>>
copyResourceFromJarToTemp(final String
}
final File tempDir = tempPath.toFile();
if (!tempDir.exists()) {
- return Pair.of(Optional.empty(), null);
+ return new LoadedLibrary(Optional.empty(), null);
}
Path libPath = tempPath.resolve(libraryFileName);
@@ -210,11 +208,17 @@ private Pair<Optional<File>, List<File>>
copyResourceFromJarToTemp(final String
ShutdownHookManager.get().addShutdownHook(
() -> FileUtils.deleteQuietly(tempDir),
LIBRARY_SHUTDOWN_HOOK_PRIORITY);
- return Pair.of(Optional.of(libFile), dependentFiles);
+ return new LoadedLibrary(Optional.of(libFile), dependentFiles);
} finally {
if (is != null) {
is.close();
}
}
}
+
+ /**
+ * A native library file extracted to a temp directory, paired with its
dependent files,
+ * used to load the library with System.load.
+ */
+ private record LoadedLibrary(Optional<File> libraryFile, List<File>
dependentFiles) { }
}
diff --git
a/hadoop-hdds/rocks-native/src/test/java/org/apache/hadoop/hdds/utils/db/TestManagedRawSSTFileIterator.java
b/hadoop-hdds/rocks-native/src/test/java/org/apache/hadoop/hdds/utils/db/TestManagedRawSSTFileIterator.java
index f7a700b172f..e4e4cd4e07e 100644
---
a/hadoop-hdds/rocks-native/src/test/java/org/apache/hadoop/hdds/utils/db/TestManagedRawSSTFileIterator.java
+++
b/hadoop-hdds/rocks-native/src/test/java/org/apache/hadoop/hdds/utils/db/TestManagedRawSSTFileIterator.java
@@ -36,7 +36,6 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
import org.apache.hadoop.hdds.utils.NativeLibraryNotLoadedException;
import org.apache.hadoop.hdds.utils.RocksTestUtils;
@@ -61,18 +60,17 @@ class TestManagedRawSSTFileIterator {
@TempDir
private Path tempDir;
- private File createSSTFileWithKeys(
- TreeMap<Pair<String, Integer>, String> keys) throws Exception {
+ private File createSSTFileWithKeys(TreeMap<KeyType, String> keys) throws
Exception {
File file = Files.createFile(tempDir.resolve("tmp_sst_file.sst")).toFile();
try (ManagedEnvOptions envOptions = new ManagedEnvOptions();
ManagedOptions managedOptions = new ManagedOptions();
ManagedSstFileWriter sstFileWriter = new
ManagedSstFileWriter(envOptions, managedOptions)) {
sstFileWriter.open(file.getAbsolutePath());
- for (Map.Entry<Pair<String, Integer>, String> entry : keys.entrySet()) {
- if (entry.getKey().getValue() == 0) {
-
sstFileWriter.delete(entry.getKey().getKey().getBytes(StandardCharsets.UTF_8));
+ for (Map.Entry<KeyType, String> entry : keys.entrySet()) {
+ if (entry.getKey().type() == 0) {
+
sstFileWriter.delete(entry.getKey().key().getBytes(StandardCharsets.UTF_8));
} else {
-
sstFileWriter.put(entry.getKey().getKey().getBytes(StandardCharsets.UTF_8),
+
sstFileWriter.put(entry.getKey().key().getBytes(StandardCharsets.UTF_8),
entry.getValue().getBytes(StandardCharsets.UTF_8));
}
}
@@ -113,8 +111,8 @@ public static void init() throws
NativeLibraryNotLoadedException {
@MethodSource("keyValueFormatArgs")
public void testSSTDumpIteratorWithKeyFormat(String keyFormat, String
valueFormat, IteratorType type)
throws Exception {
- TreeMap<Pair<String, Integer>, String> keys = IntStream.range(0,
100).boxed().collect(Collectors.toMap(
- i -> Pair.of(String.format(keyFormat, i), i % 2),
+ TreeMap<KeyType, String> keys = IntStream.range(0,
100).boxed().collect(Collectors.toMap(
+ i -> new KeyType(String.format(keyFormat, i), i % 2),
i -> i % 2 == 0 ? "" : String.format(valueFormat, i),
(v1, v2) -> v2, TreeMap::new));
File file = createSSTFileWithKeys(keys);
@@ -122,25 +120,25 @@ public void testSSTDumpIteratorWithKeyFormat(String
keyFormat, String valueForma
ManagedRawSSTFileReader reader = new ManagedRawSSTFileReader(
options, file.getAbsolutePath(), 2 * 1024 * 1024)) {
List<Optional<String>> testBounds =
RocksTestUtils.getTestingBounds(keys.keySet().stream()
- .collect(Collectors.toMap(Pair::getKey, Pair::getValue, (v1, v2) ->
v1, TreeMap::new)));
+ .collect(Collectors.toMap(KeyType::key, KeyType::type, (v1, v2) ->
v1, TreeMap::new)));
for (Optional<String> keyStart : testBounds) {
for (Optional<String> keyEnd : testBounds) {
- Map<Pair<String, Integer>, String> expectedKeys =
keys.entrySet().stream()
- .filter(e -> keyStart.map(s -> e.getKey().getKey().compareTo(s)
>= 0).orElse(true))
- .filter(e -> keyEnd.map(s -> e.getKey().getKey().compareTo(s) <
0).orElse(true))
+ Map<KeyType, String> expectedKeys = keys.entrySet().stream()
+ .filter(e -> keyStart.map(s -> e.getKey().key().compareTo(s) >=
0).orElse(true))
+ .filter(e -> keyEnd.map(s -> e.getKey().key().compareTo(s) <
0).orElse(true))
.collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue, (v1, v2) -> v1, TreeMap::new));
Optional<ManagedSlice> lowerBound = keyStart.map(s -> new
ManagedSlice(StringUtils.string2Bytes(s)));
Optional<ManagedSlice> upperBound = keyEnd.map(s -> new
ManagedSlice(StringUtils.string2Bytes(s)));
try (ManagedRawSSTFileIterator<ManagedRawSSTFileIterator.KeyValue>
iterator =
reader.newIterator(Function.identity(),
lowerBound.orElse(null), upperBound.orElse(null), type)) {
- Iterator<Map.Entry<Pair<String, Integer>, String>> expectedKeyItr
= expectedKeys.entrySet().iterator();
+ Iterator<Map.Entry<KeyType, String>> expectedKeyItr =
expectedKeys.entrySet().iterator();
while (iterator.hasNext()) {
ManagedRawSSTFileIterator.KeyValue r = iterator.next();
assertTrue(expectedKeyItr.hasNext());
- Map.Entry<Pair<String, Integer>, String> expectedKey =
expectedKeyItr.next();
+ Map.Entry<KeyType, String> expectedKey = expectedKeyItr.next();
String key = r.getKey() == null ? null :
StringCodec.get().fromCodecBuffer(r.getKey());
- assertEquals(type.readKey() ? expectedKey.getKey().getKey() :
null, key);
+ assertEquals(type.readKey() ? expectedKey.getKey().key() : null,
key);
assertEquals(type.readValue() ? expectedKey.getValue() : null,
type.readValue() ?
StringCodec.get().fromCodecBuffer(r.getValue()) : r.getValue());
expectedKeyItr.remove();
@@ -154,4 +152,19 @@ public void testSSTDumpIteratorWithKeyFormat(String
keyFormat, String valueForma
}
}
}
+
+ /**
+ * SST key paired with its entry type (0 = delete, otherwise put),
+ * ordered by key then type so entries are written to the SST file in sorted
order.
+ */
+ private record KeyType(String key, int type) implements Comparable<KeyType> {
+ @Override
+ public int compareTo(KeyType o) {
+ int cmp = key.compareTo(o.key);
+ if (cmp != 0) {
+ return cmp;
+ }
+ return Integer.compare(type, o.type);
+ }
+ }
}
diff --git
a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
index 0566ee10ffd..333031ce14c 100644
---
a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
+++
b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
@@ -67,7 +67,6 @@
import java.util.stream.Stream;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import
org.apache.hadoop.hdds.protocol.proto.HddsProtos.CompactionLogEntryProto;
@@ -1099,10 +1098,9 @@ public void pruneOlderSnapshotsWithCompactionHistory() {
if (!shouldRun()) {
return;
}
- Pair<Set<String>, List<byte[]>> fileNodeToKeyPair =
- getOlderFileNodes();
- Set<String> lastCompactionSstFiles = fileNodeToKeyPair.getLeft();
- List<byte[]> keysToRemove = fileNodeToKeyPair.getRight();
+ CompactionKeys compactionKeys = getOlderFileNodes();
+ Set<String> lastCompactionSstFiles = compactionKeys.compactionNodes();
+ List<byte[]> keysToRemove = compactionKeys.keysToRemove();
Set<String> sstFileNodesRemoved =
pruneSstFileNodesFromDag(lastCompactionSstFiles);
@@ -1124,9 +1122,9 @@ public void pruneOlderSnapshotsWithCompactionHistory() {
* Returns the list of input files from the compaction entries which are
* older than the maximum allowed in the compaction DAG.
*/
- private synchronized Pair<Set<String>, List<byte[]>> getOlderFileNodes() {
+ private synchronized CompactionKeys getOlderFileNodes() {
if (closed) {
- return Pair.of(Collections.emptySet(), Collections.emptyList());
+ return new CompactionKeys(Collections.emptySet(),
Collections.emptyList());
}
long compactionLogPruneStartTime = System.currentTimeMillis();
Set<String> compactionNodes = new HashSet<>();
@@ -1156,7 +1154,7 @@ private synchronized Pair<Set<String>, List<byte[]>>
getOlderFileNodes() {
// TODO: Handle this properly before merging the PR.
throw new RuntimeException(exception);
}
- return Pair.of(compactionNodes, keysToRemove);
+ return new CompactionKeys(compactionNodes, keysToRemove);
}
private synchronized void removeKeyFromCompactionLogTable(
@@ -1420,16 +1418,16 @@ public void pruneSstFileValues() {
private void removeValueFromSSTFile(ManagedOptions options, String
sstFilePath, File prunedFile) throws IOException {
try (ManagedRawSSTFileReader sstFileReader = new
ManagedRawSSTFileReader(options, sstFilePath, SST_READ_AHEAD_SIZE);
- ManagedRawSSTFileIterator<Pair<CodecBuffer, Integer>> itr =
sstFileReader.newIterator(
- keyValue -> Pair.of(keyValue.getKey(), keyValue.getType()), null,
null, KEY_ONLY);
+ ManagedRawSSTFileIterator<CodecBufferAndType> itr =
sstFileReader.newIterator(
+ keyValue -> new CodecBufferAndType(keyValue.getKey(),
keyValue.getType()), null, null, KEY_ONLY);
RDBSstFileWriter sstFileWriter = new RDBSstFileWriter(prunedFile);
CodecBuffer emptyCodecBuffer = CodecBuffer.getEmptyBuffer()) {
while (itr.hasNext()) {
- Pair<CodecBuffer, Integer> keyValue = itr.next();
- if (keyValue.getValue() == 0) {
- sstFileWriter.delete(keyValue.getKey());
+ CodecBufferAndType keyValue = itr.next();
+ if (keyValue.type() == 0) {
+ sstFileWriter.delete(keyValue.buffer());
} else {
- sstFileWriter.put(keyValue.getKey(), emptyCodecBuffer);
+ sstFileWriter.put(keyValue.buffer(), emptyCodecBuffer);
}
}
}
@@ -1519,4 +1517,16 @@ ConcurrentMap<String, CompactionFileInfo>
getInflightCompactions() {
public SSTFilePruningMetrics getPruningMetrics() {
return sstFilePruningMetrics;
}
+
+ /**
+ * The old compaction SST file nodes paired with the compaction log keys to
remove,
+ * used to prune older snapshots from the compaction DAG.
+ */
+ private record CompactionKeys(Set<String> compactionNodes, List<byte[]>
keysToRemove) { }
+
+ /**
+ * An SST key buffer paired with its entry type (0 = delete, otherwise put),
+ * used to rewrite SST files without values when pruning.
+ */
+ record CodecBufferAndType(CodecBuffer buffer, int type) { }
}
diff --git
a/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/hadoop/hdds/utils/db/TestSstFileSetReader.java
b/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/hadoop/hdds/utils/db/TestSstFileSetReader.java
index b27b5591ff7..7a277368b9f 100644
---
a/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/hadoop/hdds/utils/db/TestSstFileSetReader.java
+++
b/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/hadoop/hdds/utils/db/TestSstFileSetReader.java
@@ -36,7 +36,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
import org.apache.hadoop.hdds.utils.RocksTestUtils;
import org.apache.hadoop.hdds.utils.db.managed.ManagedEnvOptions;
@@ -118,10 +117,10 @@ private Map<String, Integer> createKeys(int startRange,
int endRange) {
* contains a subset of the total key space for testing overlapping
scenarios.
*
* @param numberOfFiles Number of SST files to create
- * @return Pair containing the complete sorted key map and list of SST file
paths
+ * @return DummyData containing the complete sorted key map and list of SST
file paths
* @throws RocksDBException if there's an error during SST file creation
*/
- private Pair<SortedMap<String, Integer>, List<Path>> createDummyData(int
numberOfFiles) throws RocksDBException {
+ private DummyData createDummyData(int numberOfFiles) throws RocksDBException
{
List<Path> files = new ArrayList<>();
int numberOfKeysPerFile = 10;
TreeMap<String, Integer> keys =
@@ -139,7 +138,7 @@ private Pair<SortedMap<String, Integer>, List<Path>>
createDummyData(int numberO
Path tmpSSTFile = createRandomSSTFile(fileKeys);
files.add(tmpSSTFile);
}
- return Pair.of(keys, files);
+ return new DummyData(keys, files);
}
/**
@@ -153,9 +152,9 @@ private Pair<SortedMap<String, Integer>, List<Path>>
createDummyData(int numberO
@ValueSource(ints = {0, 1, 2, 3, 7, 10})
public void testGetKeyStream(int numberOfFiles)
throws RocksDBException, CodecException {
- Pair<SortedMap<String, Integer>, List<Path>> data =
createDummyData(numberOfFiles);
- List<Path> files = data.getRight();
- SortedMap<String, Integer> keys = data.getLeft();
+ DummyData data = createDummyData(numberOfFiles);
+ List<Path> files = data.files();
+ SortedMap<String, Integer> keys = data.keys();
// Getting every possible combination of 2 elements from the sampled keys.
// Reading the sst file lying within the given bounds and
// validating the keys read from the sst file.
@@ -195,10 +194,9 @@ public void testGetKeyStream(int numberOfFiles)
public void testGetKeyStreamWithTombstone(int numberOfFiles)
throws RocksDBException, CodecException {
assumeTrue(ManagedRawSSTFileReader.tryLoadLibrary());
- Pair<SortedMap<String, Integer>, List<Path>> data =
- createDummyData(numberOfFiles);
- List<Path> files = data.getRight();
- SortedMap<String, Integer> keys = data.getLeft();
+ DummyData data = createDummyData(numberOfFiles);
+ List<Path> files = data.files();
+ SortedMap<String, Integer> keys = data.keys();
// Getting every possible combination of 2 elements from the sampled keys.
// Reading the sst file lying within the given bounds and
// validating the keys read from the sst file.
@@ -360,4 +358,9 @@ public void
testDuplicateKeyHandlingWithLatestFilePrecedence(int numberOfFiles)
"Should have correct total number of distinct keys");
}
+ /**
+ * The complete sorted key map paired with the SST files holding those keys,
+ * used to verify reads across multiple SST files.
+ */
+ private record DummyData(SortedMap<String, Integer> keys, List<Path> files)
{ }
}
diff --git
a/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/ozone/rocksdiff/TestRocksDBCheckpointDiffer.java
b/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/ozone/rocksdiff/TestRocksDBCheckpointDiffer.java
index d646fbec7bf..c79f83d2e54 100644
---
a/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/ozone/rocksdiff/TestRocksDBCheckpointDiffer.java
+++
b/hadoop-hdds/rocksdb-checkpoint-differ/src/test/java/org/apache/ozone/rocksdiff/TestRocksDBCheckpointDiffer.java
@@ -93,7 +93,6 @@
import java.util.stream.Stream;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.utils.IOUtils;
@@ -1740,10 +1739,10 @@ public void testPruneSSTFileValues() throws Exception {
assertEquals(0L, sstFilePruningMetrics.getCompactionsProcessed());
assertEquals(0L, sstFilePruningMetrics.getFilesRemovedTotal());
- List<Pair<String, Integer>> keys = new ArrayList<Pair<String, Integer>>();
- keys.add(Pair.of("key1", Integer.valueOf(1)));
- keys.add(Pair.of("key2", Integer.valueOf(0)));
- keys.add(Pair.of("key3", Integer.valueOf(1)));
+ List<KeyType> keys = new ArrayList<KeyType>();
+ keys.add(new KeyType("key1", Integer.valueOf(1)));
+ keys.add(new KeyType("key2", Integer.valueOf(0)));
+ keys.add(new KeyType("key3", Integer.valueOf(1)));
String inputFile78 = "000078";
String inputFile73 = "000073";
@@ -1777,10 +1776,10 @@ public void testPruneSSTFileValues() throws Exception {
MockedConstruction<ManagedRawSSTFileReader> mockedRawSSTReader =
Mockito.mockConstruction(
ManagedRawSSTFileReader.class, (mock, context) -> {
ManagedRawSSTFileIterator mockedRawSSTFileItr =
mock(ManagedRawSSTFileIterator.class);
- Iterator<Pair<CodecBuffer, Integer>> keyItr =
keys.stream().map(i -> {
+ Iterator<RocksDBCheckpointDiffer.CodecBufferAndType> keyItr =
keys.stream().map(i -> {
keyCodecBuffer.clear();
-
keyCodecBuffer.put(ByteBuffer.wrap(i.getKey().getBytes(UTF_8)));
- return Pair.of(keyCodecBuffer, i.getValue());
+ keyCodecBuffer.put(ByteBuffer.wrap(i.key().getBytes(UTF_8)));
+ return new
RocksDBCheckpointDiffer.CodecBufferAndType(keyCodecBuffer, i.type());
}).iterator();
doAnswer(i ->
keyItr.hasNext()).when(mockedRawSSTFileItr).hasNext();
doAnswer(i -> keyItr.next()).when(mockedRawSSTFileItr).next();
@@ -1831,16 +1830,16 @@ public void testPruneSSTFileValues() throws Exception {
assertEquals(1L, sstFilePruningMetrics.getFilesRemovedTotal());
}
- private void createSSTFileWithKeys(File file, List<Pair<String, Integer>>
keys) throws RocksDatabaseException {
+ private void createSSTFileWithKeys(File file, List<KeyType> keys) throws
RocksDatabaseException {
byte[] value = "dummyValue".getBytes(UTF_8);
try (RDBSstFileWriter sstFileWriter = new RDBSstFileWriter(file)) {
- Iterator<Pair<String, Integer>> itr = keys.iterator();
+ Iterator<KeyType> itr = keys.iterator();
while (itr.hasNext()) {
- Pair<String, Integer> entry = itr.next();
- if (entry.getValue() == 0) {
- sstFileWriter.delete(entry.getKey().getBytes(UTF_8));
+ KeyType entry = itr.next();
+ if (entry.type() == 0) {
+ sstFileWriter.delete(entry.key().getBytes(UTF_8));
} else {
- sstFileWriter.put(entry.getKey().getBytes(UTF_8), value);
+ sstFileWriter.put(entry.key().getBytes(UTF_8), value);
}
}
}
@@ -2075,4 +2074,10 @@ public void testShouldSkipFile(String description,
assertEquals(expectedResult, rocksDBCheckpointDiffer
.shouldSkipCompaction(columnFamilyBytes, inputFiles, outputFiles));
}
+
+ /**
+ * An SST key paired with its entry type (0 = delete, otherwise put),
+ * used to build SST files containing both puts and deletes.
+ */
+ private record KeyType(String key, int type) { }
}
diff --git a/hadoop-hdds/test-utils/pom.xml b/hadoop-hdds/test-utils/pom.xml
index 4042647ea10..af1ee78ea4b 100644
--- a/hadoop-hdds/test-utils/pom.xml
+++ b/hadoop-hdds/test-utils/pom.xml
@@ -46,10 +46,6 @@
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
diff --git
a/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java
b/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java
index 2e6bc601ded..a65175287ff 100644
---
a/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java
+++
b/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java
@@ -31,6 +31,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.time.Instant;
+import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -43,7 +44,6 @@
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CharSequenceInputStream;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
@@ -221,8 +221,8 @@ public static <T> T getFieldReflection(Object object,
String fieldName)
public static <K, V> Map<V, K> getReverseMap(Map<K, List<V>> map) {
return map.entrySet().stream().flatMap(entry -> entry.getValue().stream()
- .map(v -> Pair.of(v, entry.getKey())))
- .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
+ .map(v -> new AbstractMap.SimpleEntry<>(v, entry.getKey())))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]