-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-12503. Compact snapshot DB before evicting a snapshot out of cache #8141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0294847
ec156b2
c4e1e76
711988e
1b47e0e
d9020de
6aad265
9fea1b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,22 @@ public void compactDB() throws IOException { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void compactTable(String tableName) throws IOException { | ||
| try (ManagedCompactRangeOptions options = new ManagedCompactRangeOptions()) { | ||
| compactTable(tableName, options); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void compactTable(String tableName, ManagedCompactRangeOptions options) throws IOException { | ||
| RocksDatabase.ColumnFamily columnFamily = db.getColumnFamily(tableName); | ||
| if (columnFamily == null) { | ||
| throw new IOException("Table not found: " + tableName); | ||
| } | ||
| db.compactRange(columnFamily, null, null, options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should set options.setMaxCompactionBytes() when we open the snapshot rocksdb this could be useful so that we ensure one sub compaction doesn't take up a lot of memory. Also look into making ManagedCompactRangeOptions.setMaxSubCompactions() configurable so that we don't use a lot of CPU for this operation. It is ok if the compactions take time.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created one to track: https://issues.apache.org/jira/browse/HDDS-13114 |
||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| if (metrics != null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,23 @@ public void compactDB() throws Exception { | |
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void compactTable() throws Exception { | ||
| assertNotNull(rdbStore, "DBStore cannot be null"); | ||
|
|
||
| for (int j = 0; j <= 20; j++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have an interesting observation here. When I play with the number of insertions. I noticed that It looks like once it is about to reach 6, it does some compaction before the new insertion. |
||
| insertRandomData(rdbStore, 0); | ||
| rdbStore.flushDB(); | ||
| } | ||
|
|
||
| int metaSizeBeforeCompact = rdbStore.getDb().getLiveFilesMetaDataSize(); | ||
| rdbStore.compactTable(StringUtils.bytes2String(RocksDB.DEFAULT_COLUMN_FAMILY)); | ||
| int metaSizeAfterCompact = rdbStore.getDb().getLiveFilesMetaDataSize(); | ||
|
|
||
| assertThat(metaSizeAfterCompact).isLessThan(metaSizeBeforeCompact); | ||
| assertThat(metaSizeAfterCompact).isEqualTo(1); | ||
| } | ||
|
|
||
| @Test | ||
| public void close() throws Exception { | ||
| assertNotNull(rdbStore, "DBStore cannot be null"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not synchronous. Even if we call this function from snapshot cache to compact db, it wouldn't be helpful since the compaction would be cancelled. We would have to wait for all the compactions to finish before we close it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider ManagedCompactRangeOptions.setExclusiveManualCompaction(true)
https://github.com/facebook/rocksdb/wiki/Manual-Compaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems default to true.
https://github.com/facebook/rocksdb/wiki/Manual-Compaction#compactrange