forked from apache/ozone
-
Notifications
You must be signed in to change notification settings - Fork 0
HDDS-12960. SST Statistics-Based RocksDB Compaction Scheduling #2
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
Closed
peterxcli
wants to merge
32
commits into
master
from
hdds12960-implement-finer-compaction-and-provide-benchmark-data
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
518cf04
Support cacheIterator method with startKey for full table cache
peterxcli 3c987ed
Support CF key range compaction and SST properties retrieval for rocksDB
peterxcli 565b258
Add range compaction service skelton
peterxcli ef1b22d
Refactor compaction logic to utilize StringUtils for key conversion a…
peterxcli dd3aa20
Enhance FullTableCache iterator to handle null startKey and add getKe…
peterxcli 8ee058f
comment out FSO table compactor
peterxcli dbe59d3
Add CompoundKeyRangeStats class for managing key range statistics and…
peterxcli 2902190
Refactor range compaction configuration by renaming maxEntriesSum to …
peterxcli dcb840f
Enhance StringUtils with new methods for key prefix upper bound, max,…
peterxcli 63d65cb
fix pmd
peterxcli 9ac937b
Rename "deletedDirTable" to "deletedDirectoryTable" in RangeCompactio…
peterxcli 0de2e26
Refactor ManagedRange to implement AutoCloseable, ensuring proper res…
peterxcli c6dc493
Update Javadoc in DBStore to clarify parameter naming from 'columnFam…
peterxcli 8ece808
Add range compaction service configuration to ozone-default.xml
peterxcli 86a9a69
Minor adjustment and fixes
peterxcli 2ef8b45
Refactor key range handling by removing ManagedRange and replacing it…
peterxcli 27b3900
Update rocksJava JNI patch to fix GetPropertiesOfTableInRange
peterxcli 191c19b
try to fix ci
peterxcli 3898760
Add disk space cleanup script for ci
peterxcli 835a39c
fix checkstyle and pmd
peterxcli d39fd56
Update pom.xml for rocksdb version and add GitHub repository configur…
peterxcli aa83ae1
Remove disk space cleanup script and related workflow steps from CI c…
peterxcli 122e321
Enhance getCompoundKeyRangeStatsFromRange method in OBSTableCompactor…
peterxcli 122c21d
Fix some logic in OBS table compactor
peterxcli b45fe1a
add log
peterxcli 7d18be3
Update Grafana dashboard JSON files to replace Prometheus datasource …
peterxcli ca48dd7
Remove uid: "--Grafana--"
peterxcli 91770bd
Disable the range compaction service by default and add a new benchma…
peterxcli e10d58a
Add max live keys limit to OmKeyBenchGenerator and optimize key retri…
peterxcli 4a8b81c
Implement FSO compaction logic in FSOTableCompactor, introducing dire…
peterxcli 71340d6
Merge remote-tracking branch 'upstream/master' into hdds12960-impleme…
peterxcli bc666bd
fix compile error
peterxcli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,4 +97,16 @@ public static String bytes2String(byte[] bytes) { | |
| public static byte[] string2Bytes(String str) { | ||
| return str.getBytes(UTF8); | ||
| } | ||
|
|
||
| public static String getKeyPrefixUpperBound(String key) { | ||
| return key.substring(0, key.length() - 1) + (char)(key.charAt(key.length() - 1) + 1); | ||
| } | ||
|
|
||
| public static String max(String str1, String str2) { | ||
| return str1.compareTo(str2) > 0 ? str1 : str2; | ||
| } | ||
|
Comment on lines
+105
to
+107
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. |
||
|
|
||
| public static String min(String str1, String str2) { | ||
| return str1.compareTo(str2) < 0 ? str1 : str2; | ||
| } | ||
|
Comment on lines
+109
to
+111
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. |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/KeyRange.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdds.utils.db; | ||
|
|
||
| import org.apache.hadoop.hdds.StringUtils; | ||
|
|
||
| /** | ||
| * Represents a range of keys for compaction. | ||
| */ | ||
| public class KeyRange { | ||
| private final String startKey; | ||
| private final String endKey; | ||
|
|
||
| public KeyRange(String startKey, String endKey) { | ||
| this.startKey = startKey; | ||
| this.endKey = endKey; | ||
| } | ||
|
|
||
| public KeyRange(byte[] startKey, byte[] endKey) { | ||
| this.startKey = StringUtils.bytes2String(startKey); | ||
| this.endKey = StringUtils.bytes2String(endKey); | ||
| } | ||
|
|
||
| public String getStartKey() { | ||
| return startKey; | ||
| } | ||
|
|
||
| public String getEndKey() { | ||
| return endKey; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "KeyRange{" + | ||
| "startKey='" + startKey + '\'' + | ||
| ", endKey='" + endKey + '\'' + | ||
| '}'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,22 +34,27 @@ | |
| import java.nio.file.Paths; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import org.apache.hadoop.hdds.StringUtils; | ||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.utils.IOUtils; | ||
| import org.apache.hadoop.hdds.utils.RocksDBStoreMetrics; | ||
| import org.apache.hadoop.hdds.utils.db.RocksDatabase.ColumnFamily; | ||
| import org.apache.hadoop.hdds.utils.db.cache.TableCache; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedCompactRangeOptions; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedSlice; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedStatistics; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedTransactionLogIterator; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedWriteOptions; | ||
| import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer; | ||
| import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer.RocksDBCheckpointDifferHolder; | ||
| import org.rocksdb.Range; | ||
| import org.rocksdb.RocksDBException; | ||
| import org.rocksdb.TableProperties; | ||
| import org.rocksdb.TransactionLogIterator.BatchResult; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -220,6 +225,15 @@ public void compactTable(String tableName) throws RocksDatabaseException { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void compactTable(String tableName, String startKey, String endKey) throws IOException { | ||
| LOG.info("Starting table compaction for table: {}, range: [{} - {}]", tableName, startKey, endKey); | ||
| try (ManagedCompactRangeOptions options = new ManagedCompactRangeOptions()) { | ||
| compactTable(tableName, startKey, endKey, options); | ||
| } | ||
| LOG.info("Completed table compaction for table: {}, range: [{} - {}]", tableName, startKey, endKey); | ||
| } | ||
|
|
||
| @Override | ||
| public void compactTable(String tableName, ManagedCompactRangeOptions options) throws RocksDatabaseException { | ||
| RocksDatabase.ColumnFamily columnFamily = db.getColumnFamily(tableName); | ||
|
|
@@ -229,6 +243,67 @@ public void compactTable(String tableName, ManagedCompactRangeOptions options) t | |
| db.compactRange(columnFamily, null, null, options); | ||
| } | ||
|
|
||
| @Override | ||
| public void compactTable(String tableName, String startKey, String endKey, | ||
| ManagedCompactRangeOptions options) throws IOException { | ||
| LOG.info("Starting table compaction with options for table: {}, range: [{} - {}]", tableName, startKey, endKey); | ||
| ColumnFamily columnFamily = db.getColumnFamily(tableName); | ||
| if (columnFamily == null) { | ||
| LOG.error("Table not found for compaction: {}", tableName); | ||
| throw new IOException("No such table in this DB. TableName : " + tableName); | ||
| } | ||
| db.compactRange(columnFamily, StringUtils.string2Bytes(startKey), | ||
| StringUtils.string2Bytes(endKey), options); | ||
| LOG.info("Completed table compaction with options for table: {}, range: [{} - {}]", tableName, startKey, endKey); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, TableProperties> getPropertiesOfTableInRange(String tableName, String startKey, | ||
| String endKey) throws IOException { | ||
| LOG.info("Getting table properties for table: {}, range: [{} - {}]", tableName, startKey, endKey); | ||
| Map<String, TableProperties> result = getPropertiesOfTableInRange(tableName, | ||
| Collections.singletonList(new KeyRange(startKey, endKey))); | ||
| LOG.info("Retrieved {} table properties for table: {}, range: [{} - {}]", | ||
| result.size(), tableName, startKey, endKey); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, TableProperties> getPropertiesOfTableInRange(String tableName, | ||
| List<KeyRange> ranges) throws IOException { | ||
| LOG.info("Getting table properties for table: {}, number of ranges: {}", tableName, ranges.size()); | ||
| ColumnFamily columnFamily = db.getColumnFamily(tableName); | ||
| if (columnFamily == null) { | ||
| LOG.error("Table not found for getting properties: {}", tableName); | ||
| throw new IOException("No such table in this DB. TableName : " + tableName); | ||
| } | ||
|
|
||
| List<Range> rocksRanges = new ArrayList<>(); | ||
| List<ManagedSlice> managedSlices = new ArrayList<>(); | ||
| try { | ||
| for (KeyRange t : ranges) { | ||
| ManagedSlice start = new ManagedSlice(StringUtils.string2Bytes(t.getStartKey())); | ||
| ManagedSlice end = new ManagedSlice(StringUtils.string2Bytes(t.getEndKey())); | ||
| managedSlices.add(start); | ||
| managedSlices.add(end); | ||
| rocksRanges.add(new Range(start, end)); | ||
| } | ||
| LOG.info("Converted {} ranges to RocksDB ranges, start to get properties", rocksRanges.size()); | ||
| return db.getPropertiesOfColumnFamilyInRange(columnFamily, rocksRanges); | ||
| } catch (RocksDatabaseException e) { | ||
| throw new IOException("Failed to get properties of table in range", e); | ||
| } finally { | ||
| // Close all ManagedSlice objects | ||
| for (ManagedSlice slice : managedSlices) { | ||
| try { | ||
| slice.close(); | ||
| } catch (Exception e) { | ||
| LOG.warn("Failed to close ManagedSlice", e); | ||
| } | ||
| } | ||
|
Comment on lines
+296
to
+303
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. |
||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if (metrics != null) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If the input
keyis an empty string, aStringIndexOutOfBoundsExceptionwill be thrown. Consider adding a check for an empty key at the beginning of the method.