From 72f2150b2845f69aae7b87d3121fd73cd2dc0cc6 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 1 May 2024 11:46:42 -0700 Subject: [PATCH 1/2] HDDS-10783. Close SstFileReaderIterator in RocksDBCheckpointDiffer --- .../rocksdiff/RocksDBCheckpointDiffer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 f3c322b5692..1a63cad7771 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 @@ -1579,14 +1579,15 @@ private CompactionFileInfo toFileInfo(String sstFile, fileReader.open(sstFile); String columnFamily = StringUtils.bytes2String( fileReader.getTableProperties().getColumnFamilyName()); - SstFileReaderIterator iterator = fileReader.newIterator(readOptions); - iterator.seekToFirst(); - String startKey = StringUtils.bytes2String(iterator.key()); - iterator.seekToLast(); - String endKey = StringUtils.bytes2String(iterator.key()); - fileInfoBuilder.setStartRange(startKey) - .setEndRange(endKey) - .setColumnFamily(columnFamily); + try (SstFileReaderIterator iterator = fileReader.newIterator(readOptions)) { + iterator.seekToFirst(); + String startKey = StringUtils.bytes2String(iterator.key()); + iterator.seekToLast(); + String endKey = StringUtils.bytes2String(iterator.key()); + fileInfoBuilder.setStartRange(startKey) + .setEndRange(endKey) + .setColumnFamily(columnFamily); + } } catch (RocksDBException rocksDBException) { // Ideally it should not happen. If it does just log the exception. // And let the compaction complete without the exception. From ba62ec9e794604bd6338034a0162403c414d1b78 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 1 May 2024 12:24:04 -0700 Subject: [PATCH 2/2] Use Managed objects for SstFileReader and SstFileReaderIterator in RocksDBCheckpointDiffer --- .../rocksdiff/RocksDBCheckpointDiffer.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 1a63cad7771..3fa1459488e 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 @@ -45,6 +45,8 @@ import org.apache.hadoop.hdds.utils.db.managed.ManagedReadOptions; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; +import org.apache.hadoop.hdds.utils.db.managed.ManagedSstFileReader; +import org.apache.hadoop.hdds.utils.db.managed.ManagedSstFileReaderIterator; import org.apache.ozone.compaction.log.CompactionFileInfo; import org.apache.ozone.compaction.log.CompactionLogEntry; import org.apache.ozone.rocksdb.util.RdbUtil; @@ -59,7 +61,6 @@ import org.rocksdb.RocksDB; import org.rocksdb.RocksDBException; import org.rocksdb.SstFileReader; -import org.rocksdb.SstFileReaderIterator; import org.rocksdb.TableProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -629,13 +630,12 @@ private long getSSTFileSummary(String filename) filename += SST_FILE_EXTENSION; } - try ( - ManagedOptions option = new ManagedOptions(); - SstFileReader reader = new SstFileReader(option)) { + try (ManagedOptions option = new ManagedOptions(); + ManagedSstFileReader reader = ManagedSstFileReader.managed(new SstFileReader(option))) { - reader.open(getAbsoluteSstFilePath(filename)); + reader.get().open(getAbsoluteSstFilePath(filename)); - TableProperties properties = reader.getTableProperties(); + TableProperties properties = reader.get().getTableProperties(); if (LOG.isDebugEnabled()) { LOG.debug("{} has {} keys", filename, properties.getNumEntries()); } @@ -1575,15 +1575,15 @@ private CompactionFileInfo toFileInfo(String sstFile, CompactionFileInfo.Builder fileInfoBuilder = new CompactionFileInfo.Builder(fileName); - try (SstFileReader fileReader = new SstFileReader(options)) { - fileReader.open(sstFile); - String columnFamily = StringUtils.bytes2String( - fileReader.getTableProperties().getColumnFamilyName()); - try (SstFileReaderIterator iterator = fileReader.newIterator(readOptions)) { - iterator.seekToFirst(); - String startKey = StringUtils.bytes2String(iterator.key()); - iterator.seekToLast(); - String endKey = StringUtils.bytes2String(iterator.key()); + try (ManagedSstFileReader fileReader = ManagedSstFileReader.managed(new SstFileReader(options))) { + fileReader.get().open(sstFile); + String columnFamily = StringUtils.bytes2String(fileReader.get().getTableProperties().getColumnFamilyName()); + try (ManagedSstFileReaderIterator iterator = + ManagedSstFileReaderIterator.managed(fileReader.get().newIterator(readOptions))) { + iterator.get().seekToFirst(); + String startKey = StringUtils.bytes2String(iterator.get().key()); + iterator.get().seekToLast(); + String endKey = StringUtils.bytes2String(iterator.get().key()); fileInfoBuilder.setStartRange(startKey) .setEndRange(endKey) .setColumnFamily(columnFamily);