Skip to content

Commit

Permalink
CDPD-69425. HDDS-10783. Close SstFileReaderIterator in RocksDBCheckpo…
Browse files Browse the repository at this point in the history
…intDiffer (apache#6616)

Change-Id: I6d81cbd3a872b1598aa211949bcb42a3c91b8fdf
  • Loading branch information
hemantk-12 authored and Hemant Kumar committed May 3, 2024
1 parent 01915ff commit 4ad9d5d
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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;
Expand All @@ -57,7 +59,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;
Expand Down Expand Up @@ -619,17 +620,17 @@ private long getSSTFileSummary(String filename)
if (!filename.endsWith(SST_FILE_EXTENSION)) {
filename += SST_FILE_EXTENSION;
}
try (ManagedOptions option = new ManagedOptions();
ManagedSstFileReader reader = ManagedSstFileReader.managed(new SstFileReader(option))) {

Options option = new Options();
SstFileReader reader = new SstFileReader(option);
reader.get().open(getAbsoluteSstFilePath(filename));

reader.open(getAbsoluteSstFilePath(filename));

TableProperties properties = reader.getTableProperties();
if (LOG.isDebugEnabled()) {
LOG.debug("{} has {} keys", filename, properties.getNumEntries());
TableProperties properties = reader.get().getTableProperties();
if (LOG.isDebugEnabled()) {
LOG.debug("{} has {} keys", filename, properties.getNumEntries());
}
return properties.getNumEntries();
}
return properties.getNumEntries();
}

private String getAbsoluteSstFilePath(String filename)
Expand Down Expand Up @@ -1524,19 +1525,20 @@ private List<CompactionFileInfo> toFileInfoList(
sstFile.length() - SST_FILE_EXTENSION_LENGTH);
CompactionFileInfo.Builder fileInfoBuilder =
new CompactionFileInfo.Builder(fileName);
SstFileReader fileReader = new SstFileReader(options);
try {
fileReader.open(sstFile);
try (ManagedSstFileReader fileReader = ManagedSstFileReader.managed(new SstFileReader(options))){
fileReader.get().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);
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);
}
} catch (RocksDBException rocksDBException) {
// Ideally it should not happen. If it does just log the exception.
// And let the compaction complete without the exception.
Expand Down

0 comments on commit 4ad9d5d

Please sign in to comment.