-
Notifications
You must be signed in to change notification settings - Fork 882
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
[WIP] Trie log pruning #6000
Closed
Closed
[WIP] Trie log pruning #6000
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6298a6a
WIP - Add TrieLogSubCommand to get and delete trie log using TrieLogM…
siladu 4ecc1f2
WIP - list trie logs
siladu dad1b64
Add RocksDbSubCommand to print disk usage and count trie logs
siladu c978279
Tidy up printouts
siladu e3e162f
List and Delete by block number range
siladu 3c18d76
Reorder methods
siladu 8142eb6
Add prune subcommand to prune below a specified block number
siladu e197c5c
Add WIP comments
siladu fba6eeb
Print TRIE_LOG_STORAGE usage before and after prune
siladu 8722162
Logging
siladu a20375c
More logging
siladu 797e55d
Revert "Logging"
siladu 9a15a2a
Layers to retain rather than below block number
siladu dfdf0f1
Logging and +1 error
siladu 7212761
Append counts to list subcommand
siladu 6acc998
Remove per trie log layer logging to test timings
siladu 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 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 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
112 changes: 112 additions & 0 deletions
112
besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RocksDbSubCommand.java
This file contains 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,112 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.cli.subcommands.operator; | ||
|
||
import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH; | ||
|
||
import org.hyperledger.besu.cli.util.VersionProvider; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.rocksdb.ColumnFamilyDescriptor; | ||
import org.rocksdb.ColumnFamilyHandle; | ||
import org.rocksdb.Options; | ||
import org.rocksdb.RocksDB; | ||
import org.rocksdb.RocksDBException; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.ParentCommand; | ||
|
||
/** The RocksDB subcommand. */ | ||
@Command( | ||
name = "x-rocksdb", | ||
description = "Print RocksDB information", | ||
mixinStandardHelpOptions = true, | ||
versionProvider = VersionProvider.class, | ||
subcommands = {RocksDbSubCommand.RocksDbUsage.class}) | ||
public class RocksDbSubCommand implements Runnable { | ||
|
||
@ParentCommand private OperatorSubCommand parentCommand; | ||
|
||
@SuppressWarnings("unused") | ||
@CommandLine.Spec | ||
private CommandLine.Model.CommandSpec spec; | ||
|
||
@Override | ||
public void run() { | ||
spec.commandLine().usage(System.out); | ||
} | ||
|
||
@Command( | ||
name = "usage", | ||
description = "Prints disk usage", | ||
mixinStandardHelpOptions = true, | ||
versionProvider = VersionProvider.class) | ||
static class RocksDbUsage implements Runnable { | ||
|
||
@SuppressWarnings("unused") | ||
@CommandLine.Spec | ||
private CommandLine.Model.CommandSpec spec; | ||
|
||
@SuppressWarnings("unused") | ||
@ParentCommand | ||
private RocksDbSubCommand parentCommand; | ||
|
||
@Override | ||
public void run() { | ||
|
||
final PrintWriter out = spec.commandLine().getOut(); | ||
|
||
final String dbPath = | ||
parentCommand | ||
.parentCommand | ||
.parentCommand | ||
.dataDir() | ||
.toString() | ||
.concat("/") | ||
.concat(DATABASE_PATH); | ||
|
||
RocksDB.loadLibrary(); | ||
Options options = new Options(); | ||
options.setCreateIfMissing(true); | ||
|
||
// Open the RocksDB database with multiple column families | ||
List<byte[]> cfNames; | ||
try { | ||
cfNames = RocksDB.listColumnFamilies(options, dbPath); | ||
} catch (RocksDBException e) { | ||
throw new RuntimeException(e); | ||
} | ||
List<ColumnFamilyHandle> cfHandles = new ArrayList<>(); | ||
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>(); | ||
for (byte[] cfName : cfNames) { | ||
cfDescriptors.add(new ColumnFamilyDescriptor(cfName)); | ||
} | ||
try (final RocksDB rocksdb = RocksDB.openReadOnly(dbPath, cfDescriptors, cfHandles)) { | ||
for (ColumnFamilyHandle cfHandle : cfHandles) { | ||
RocksDbUsageHelper.printUsageForColumnFamily(rocksdb, cfHandle, out); | ||
} | ||
} catch (RocksDBException e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
for (ColumnFamilyHandle cfHandle : cfHandles) { | ||
cfHandle.close(); | ||
} | ||
} | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RocksDbUsageHelper.java
This file contains 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,96 @@ | ||
/* | ||
* Copyright contributors to Hyperledger Besu. | ||
* | ||
* Licensed 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.hyperledger.besu.cli.subcommands.operator; | ||
|
||
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import org.bouncycastle.util.Arrays; | ||
import org.rocksdb.ColumnFamilyHandle; | ||
import org.rocksdb.ColumnFamilyMetaData; | ||
import org.rocksdb.RocksDB; | ||
import org.rocksdb.RocksDBException; | ||
|
||
public class RocksDbUsageHelper { | ||
|
||
static void printUsageForColumnFamily( | ||
final RocksDB rocksdb, final ColumnFamilyHandle cfHandle, final PrintWriter out) | ||
throws RocksDBException { | ||
String size = rocksdb.getProperty(cfHandle, "rocksdb.estimate-live-data-size"); | ||
boolean emptyColumnFamily = false; | ||
if (!size.isEmpty() && !size.isBlank()) { | ||
long sizeLong = Long.parseLong(size); | ||
if (sizeLong == 0) emptyColumnFamily = true; | ||
if (!emptyColumnFamily) { | ||
out.println( | ||
"****** Column family '" | ||
+ getNameById(cfHandle.getName()) | ||
+ "' size: " | ||
+ formatOutputSize(sizeLong) | ||
+ " ******"); | ||
// System.out.println("SST table : "+ rocksdb.getProperty(cfHandle, | ||
// "rocksdb.sstables")); | ||
|
||
out.println( | ||
"Number of live snapshots : " + rocksdb.getProperty(cfHandle, "rocksdb.num-snapshots")); | ||
out.println( | ||
"Number of keys : " + rocksdb.getProperty(cfHandle, "rocksdb.estimate-num-keys")); | ||
|
||
String totolSstFilesSize = rocksdb.getProperty(cfHandle, "rocksdb.total-sst-files-size"); | ||
if (!totolSstFilesSize.isEmpty() && !totolSstFilesSize.isBlank()) { | ||
out.println( | ||
"Total size of SST Files : " + formatOutputSize(Long.parseLong(totolSstFilesSize))); | ||
Check notice Code scanning / CodeQL Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
|
||
} | ||
String liveSstFilesSize = rocksdb.getProperty(cfHandle, "rocksdb.live-sst-files-size"); | ||
if (!liveSstFilesSize.isEmpty() && !liveSstFilesSize.isBlank()) { | ||
out.println( | ||
"Size of live SST Filess : " + formatOutputSize(Long.parseLong(liveSstFilesSize))); | ||
Check notice Code scanning / CodeQL Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
|
||
} | ||
|
||
ColumnFamilyMetaData columnFamilyMetaData = rocksdb.getColumnFamilyMetaData(cfHandle); | ||
long sizeBytes = columnFamilyMetaData.size(); | ||
out.println( | ||
"Column family size (with getColumnFamilyMetaData) : " + formatOutputSize(sizeBytes)); | ||
out.println(""); | ||
} | ||
} | ||
} | ||
|
||
private static String formatOutputSize(final long size) { | ||
if (size > (1024 * 1024 * 1024)) { | ||
long sizeInGiB = size / (1024 * 1024 * 1024); | ||
return sizeInGiB + " GiB"; | ||
} else if (size > (1024 * 1024)) { | ||
long sizeInMiB = size / (1024 * 1024); | ||
return sizeInMiB + " MiB"; | ||
} else if (size > 1024) { | ||
long sizeInKiB = size / 1024; | ||
return sizeInKiB + " KiB"; | ||
} else { | ||
return size + " B"; | ||
} | ||
} | ||
|
||
public static String getNameById(final byte[] id) { | ||
for (KeyValueSegmentIdentifier segment : KeyValueSegmentIdentifier.values()) { | ||
if (Arrays.areEqual(segment.getId(), id)) { | ||
return segment.getName(); | ||
} | ||
} | ||
return null; // id not found | ||
} | ||
} |
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.
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException