Skip to content

Commit 2da0696

Browse files
authored
HDDS-14021. Read-only RDBStore should not flush on close (#9384)
1 parent 25a1f80 commit 2da0696

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

  • hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class RDBStore implements DBStore {
7676
private final long maxDbUpdatesSizeThreshold;
7777
private final ManagedDBOptions dbOptions;
7878
private final ManagedStatistics statistics;
79+
private final boolean readOnly;
7980

8081
@SuppressWarnings("parameternumber")
8182
RDBStore(File dbFile, ManagedDBOptions dbOptions, ManagedStatistics statistics,
@@ -113,6 +114,7 @@ public class RDBStore implements DBStore {
113114

114115
db = RocksDatabase.open(dbFile, dbOptions, writeOptions,
115116
families, readOnly);
117+
this.readOnly = readOnly;
116118

117119
// dbOptions.statistics() only contribute to part of RocksDB metrics in
118120
// Ozone. Enable RocksDB metrics even dbOptions.statistics() is off.
@@ -251,13 +253,15 @@ public void close() {
251253
if (statistics != null) {
252254
IOUtils.close(LOG, statistics);
253255
}
254-
try {
255-
// Flush to ensure all data is persisted to disk before closing.
256-
flushDB();
257-
LOG.debug("Successfully flushed DB before close");
258-
} catch (Exception e) {
259-
LOG.warn("Failed to flush DB before close", e);
260-
// Continue with close even if flush fails
256+
if (!readOnly) {
257+
try {
258+
// Flush to ensure all data is persisted to disk before closing.
259+
flushDB();
260+
LOG.debug("Successfully flushed DB before close");
261+
} catch (Exception e) {
262+
LOG.warn("Failed to flush DB before close", e);
263+
// Continue with close even if flush fails
264+
}
261265
}
262266
IOUtils.close(LOG, db);
263267
}
@@ -365,7 +369,7 @@ public void dropTable(String tableName) throws RocksDatabaseException {
365369
db.getManagedRocksDb().get().dropColumnFamily(columnFamily.getHandle());
366370
} catch (RocksDBException e) {
367371
throw new RocksDatabaseException("Failed to drop " + tableName, e);
368-
}
372+
}
369373
}
370374
}
371375

0 commit comments

Comments
 (0)