|
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.List; |
23 | 23 | import java.util.function.BiConsumer; |
| 24 | +import java.util.stream.Stream; |
24 | 25 |
|
25 | 26 | import org.bouncycastle.util.Arrays; |
26 | 27 | import org.rocksdb.ColumnFamilyDescriptor; |
@@ -66,36 +67,210 @@ static void forEachColumnFamily( |
66 | 67 | } |
67 | 68 | } |
68 | 69 |
|
69 | | - static void printUsageForColumnFamily( |
| 70 | + static void printStatsForColumnFamily( |
70 | 71 | final RocksDB rocksdb, final ColumnFamilyHandle cfHandle, final PrintWriter out) |
71 | | - throws RocksDBException, NumberFormatException { |
| 72 | + throws RocksDBException { |
72 | 73 | final String size = rocksdb.getProperty(cfHandle, "rocksdb.estimate-live-data-size"); |
73 | 74 | final String numberOfKeys = rocksdb.getProperty(cfHandle, "rocksdb.estimate-num-keys"); |
74 | | - boolean emptyColumnFamily = false; |
75 | | - if (!size.isBlank() && !numberOfKeys.isBlank()) { |
| 75 | + final long sizeLong = Long.parseLong(size); |
| 76 | + final long numberOfKeysLong = Long.parseLong(numberOfKeys); |
| 77 | + if (!size.isBlank() |
| 78 | + && !numberOfKeys.isBlank() |
| 79 | + && isPopulatedColumnFamily(sizeLong, numberOfKeysLong)) { |
| 80 | + out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); |
| 81 | + out.println("Column Family: " + getNameById(cfHandle.getName())); |
| 82 | + |
| 83 | + final String prefix = "rocksdb."; |
| 84 | + final String cfstats = "cfstats"; |
| 85 | + final String cfstats_no_file_histogram = "cfstats-no-file-histogram"; |
| 86 | + final String cf_file_histogram = "cf-file-histogram"; |
| 87 | + final String cf_write_stall_stats = "cf-write-stall-stats"; |
| 88 | + final String dbstats = "dbstats"; |
| 89 | + final String db_write_stall_stats = "db-write-stall-stats"; |
| 90 | + final String levelstats = "levelstats"; |
| 91 | + final String block_cache_entry_stats = "block-cache-entry-stats"; |
| 92 | + final String fast_block_cache_entry_stats = "fast-block-cache-entry-stats"; |
| 93 | + final String num_immutable_mem_table = "num-immutable-mem-table"; |
| 94 | + final String num_immutable_mem_table_flushed = "num-immutable-mem-table-flushed"; |
| 95 | + final String mem_table_flush_pending = "mem-table-flush-pending"; |
| 96 | + final String compaction_pending = "compaction-pending"; |
| 97 | + final String background_errors = "background-errors"; |
| 98 | + final String cur_size_active_mem_table = "cur-size-active-mem-table"; |
| 99 | + final String cur_size_all_mem_tables = "cur-size-all-mem-tables"; |
| 100 | + final String size_all_mem_tables = "size-all-mem-tables"; |
| 101 | + final String num_entries_active_mem_table = "num-entries-active-mem-table"; |
| 102 | + final String num_entries_imm_mem_tables = "num-entries-imm-mem-tables"; |
| 103 | + final String num_deletes_active_mem_table = "num-deletes-active-mem-table"; |
| 104 | + final String num_deletes_imm_mem_tables = "num-deletes-imm-mem-tables"; |
| 105 | + final String estimate_num_keys = "estimate-num-keys"; |
| 106 | + final String estimate_table_readers_mem = "estimate-table-readers-mem"; |
| 107 | + final String is_file_deletions_enabled = "is-file-deletions-enabled"; |
| 108 | + final String num_snapshots = "num-snapshots"; |
| 109 | + final String oldest_snapshot_time = "oldest-snapshot-time"; |
| 110 | + final String oldest_snapshot_sequence = "oldest-snapshot-sequence"; |
| 111 | + final String num_live_versions = "num-live-versions"; |
| 112 | + final String current_version_number = "current-super-version-number"; |
| 113 | + final String estimate_live_data_size = "estimate-live-data-size"; |
| 114 | + final String min_log_number_to_keep_str = "min-log-number-to-keep"; |
| 115 | + final String min_obsolete_sst_number_to_keep_str = "min-obsolete-sst-number-to-keep"; |
| 116 | + final String base_level_str = "base-level"; |
| 117 | + final String total_sst_files_size = "total-sst-files-size"; |
| 118 | + final String live_sst_files_size = "live-sst-files-size"; |
| 119 | + final String obsolete_sst_files_size = "obsolete-sst-files-size"; |
| 120 | + final String live_sst_files_size_at_temperature = "live-sst-files-size-at-temperature"; |
| 121 | + final String estimate_pending_comp_bytes = "estimate-pending-compaction-bytes"; |
| 122 | + final String aggregated_table_properties = "aggregated-table-properties"; |
| 123 | + final String num_running_compactions = "num-running-compactions"; |
| 124 | + final String num_running_flushes = "num-running-flushes"; |
| 125 | + final String actual_delayed_write_rate = "actual-delayed-write-rate"; |
| 126 | + final String is_write_stopped = "is-write-stopped"; |
| 127 | + final String estimate_oldest_key_time = "estimate-oldest-key-time"; |
| 128 | + final String block_cache_capacity = "block-cache-capacity"; |
| 129 | + final String block_cache_usage = "block-cache-usage"; |
| 130 | + final String block_cache_pinned_usage = "block-cache-pinned-usage"; |
| 131 | + final String options_statistics = "options-statistics"; |
| 132 | + final String num_blob_files = "num-blob-files"; |
| 133 | + final String blob_stats = "blob-stats"; |
| 134 | + final String total_blob_file_size = "total-blob-file-size"; |
| 135 | + final String live_blob_file_size = "live-blob-file-size"; |
| 136 | + final String live_blob_file_garbage_size = "live-blob-file-garbage-size"; |
| 137 | + final String blob_cache_capacity = "blob-cache-capacity"; |
| 138 | + final String blob_cache_usage = "blob-cache-usage"; |
| 139 | + final String blob_cache_pinned_usage = "blob-cache-pinned-usage"; |
| 140 | + Stream.of( |
| 141 | + cfstats, |
| 142 | + cfstats_no_file_histogram, |
| 143 | + cf_file_histogram, |
| 144 | + cf_write_stall_stats, |
| 145 | + dbstats, |
| 146 | + db_write_stall_stats, |
| 147 | + levelstats, |
| 148 | + block_cache_entry_stats, |
| 149 | + fast_block_cache_entry_stats, |
| 150 | + num_immutable_mem_table, |
| 151 | + num_immutable_mem_table_flushed, |
| 152 | + mem_table_flush_pending, |
| 153 | + compaction_pending, |
| 154 | + background_errors, |
| 155 | + cur_size_active_mem_table, |
| 156 | + cur_size_all_mem_tables, |
| 157 | + size_all_mem_tables, |
| 158 | + num_entries_active_mem_table, |
| 159 | + num_entries_imm_mem_tables, |
| 160 | + num_deletes_active_mem_table, |
| 161 | + num_deletes_imm_mem_tables, |
| 162 | + estimate_num_keys, |
| 163 | + estimate_table_readers_mem, |
| 164 | + is_file_deletions_enabled, |
| 165 | + num_snapshots, |
| 166 | + oldest_snapshot_time, |
| 167 | + oldest_snapshot_sequence, |
| 168 | + num_live_versions, |
| 169 | + current_version_number, |
| 170 | + estimate_live_data_size, |
| 171 | + min_log_number_to_keep_str, |
| 172 | + min_obsolete_sst_number_to_keep_str, |
| 173 | + base_level_str, |
| 174 | + total_sst_files_size, |
| 175 | + live_sst_files_size, |
| 176 | + obsolete_sst_files_size, |
| 177 | + live_sst_files_size_at_temperature, |
| 178 | + estimate_pending_comp_bytes, |
| 179 | + aggregated_table_properties, |
| 180 | + num_running_compactions, |
| 181 | + num_running_flushes, |
| 182 | + actual_delayed_write_rate, |
| 183 | + is_write_stopped, |
| 184 | + estimate_oldest_key_time, |
| 185 | + block_cache_capacity, |
| 186 | + block_cache_usage, |
| 187 | + block_cache_pinned_usage, |
| 188 | + options_statistics, |
| 189 | + num_blob_files, |
| 190 | + blob_stats, |
| 191 | + total_blob_file_size, |
| 192 | + live_blob_file_size, |
| 193 | + live_blob_file_garbage_size, |
| 194 | + blob_cache_capacity, |
| 195 | + blob_cache_usage, |
| 196 | + blob_cache_pinned_usage) |
| 197 | + .forEach( |
| 198 | + prop -> { |
| 199 | + try { |
| 200 | + final String value = rocksdb.getProperty(cfHandle, prefix + prop); |
| 201 | + if (!value.isBlank()) { |
| 202 | + out.println(prop + ": " + value); |
| 203 | + } |
| 204 | + } catch (RocksDBException e) { |
| 205 | + LOG.debug("couldn't get property {}", prop); |
| 206 | + } |
| 207 | + }); |
| 208 | + out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | + static ColumnFamilyUsage getAndPrintUsageForColumnFamily( |
| 213 | + final RocksDB rocksdb, final ColumnFamilyHandle cfHandle, final PrintWriter out) |
| 214 | + throws RocksDBException, NumberFormatException { |
| 215 | + final String numberOfKeys = rocksdb.getProperty(cfHandle, "rocksdb.estimate-num-keys"); |
| 216 | + if (!numberOfKeys.isBlank()) { |
76 | 217 | try { |
77 | | - final long sizeLong = Long.parseLong(size); |
78 | 218 | final long numberOfKeysLong = Long.parseLong(numberOfKeys); |
79 | 219 | final String totalSstFilesSize = |
80 | 220 | rocksdb.getProperty(cfHandle, "rocksdb.total-sst-files-size"); |
81 | 221 | final long totalSstFilesSizeLong = |
82 | 222 | !totalSstFilesSize.isBlank() ? Long.parseLong(totalSstFilesSize) : 0; |
83 | | - if (sizeLong == 0 && numberOfKeysLong == 0) { |
84 | | - emptyColumnFamily = true; |
85 | | - } |
86 | 223 |
|
87 | | - if (!emptyColumnFamily) { |
| 224 | + final String totalBlobFilesSize = |
| 225 | + rocksdb.getProperty(cfHandle, "rocksdb.total-blob-file-size"); |
| 226 | + final long totalBlobFilesSizeLong = |
| 227 | + !totalBlobFilesSize.isBlank() ? Long.parseLong(totalBlobFilesSize) : 0; |
| 228 | + |
| 229 | + final long totalFilesSize = totalSstFilesSizeLong + totalBlobFilesSizeLong; |
| 230 | + if (isPopulatedColumnFamily(0, numberOfKeysLong)) { |
88 | 231 | printLine( |
89 | 232 | out, |
90 | 233 | getNameById(cfHandle.getName()), |
91 | 234 | rocksdb.getProperty(cfHandle, "rocksdb.estimate-num-keys"), |
92 | | - formatOutputSize(sizeLong), |
93 | | - formatOutputSize(totalSstFilesSizeLong)); |
| 235 | + formatOutputSize(totalFilesSize), |
| 236 | + formatOutputSize(totalSstFilesSizeLong), |
| 237 | + formatOutputSize(totalBlobFilesSizeLong)); |
94 | 238 | } |
| 239 | + return new ColumnFamilyUsage( |
| 240 | + getNameById(cfHandle.getName()), |
| 241 | + numberOfKeysLong, |
| 242 | + totalFilesSize, |
| 243 | + totalSstFilesSizeLong, |
| 244 | + totalBlobFilesSizeLong); |
95 | 245 | } catch (NumberFormatException e) { |
96 | 246 | LOG.error("Failed to parse string into long: " + e.getMessage()); |
97 | 247 | } |
98 | 248 | } |
| 249 | + // return empty usage on error |
| 250 | + return new ColumnFamilyUsage(getNameById(cfHandle.getName()), 0, 0, 0, 0); |
| 251 | + } |
| 252 | + |
| 253 | + static void printTotals(final PrintWriter out, final List<ColumnFamilyUsage> columnFamilyUsages) { |
| 254 | + final long totalKeys = columnFamilyUsages.stream().mapToLong(ColumnFamilyUsage::keys).sum(); |
| 255 | + final long totalSize = |
| 256 | + columnFamilyUsages.stream().mapToLong(ColumnFamilyUsage::totalSize).sum(); |
| 257 | + final long totalSsts = |
| 258 | + columnFamilyUsages.stream().mapToLong(ColumnFamilyUsage::sstFilesSize).sum(); |
| 259 | + final long totalBlobs = |
| 260 | + columnFamilyUsages.stream().mapToLong(ColumnFamilyUsage::blobFilesSize).sum(); |
| 261 | + printSeparator(out); |
| 262 | + printLine( |
| 263 | + out, |
| 264 | + "ESTIMATED TOTAL", |
| 265 | + String.valueOf(totalKeys), |
| 266 | + formatOutputSize(totalSize), |
| 267 | + formatOutputSize(totalSsts), |
| 268 | + formatOutputSize(totalBlobs)); |
| 269 | + printSeparator(out); |
| 270 | + } |
| 271 | + |
| 272 | + private static boolean isPopulatedColumnFamily(final long size, final long numberOfKeys) { |
| 273 | + return size != 0 || numberOfKeys != 0; |
99 | 274 | } |
100 | 275 |
|
101 | 276 | static String formatOutputSize(final long size) { |
@@ -123,19 +298,28 @@ private static String getNameById(final byte[] id) { |
123 | 298 | } |
124 | 299 |
|
125 | 300 | static void printTableHeader(final PrintWriter out) { |
| 301 | + printSeparator(out); |
126 | 302 | out.format( |
127 | | - "| Column Family | Keys | Column Size | SST Files Size |\n"); |
| 303 | + "| Column Family | Keys | Total Size | SST Files Size | Blob Files Size | \n"); |
| 304 | + printSeparator(out); |
| 305 | + } |
| 306 | + |
| 307 | + private static void printSeparator(final PrintWriter out) { |
128 | 308 | out.format( |
129 | | - "|--------------------------------|-----------------|--------------|-----------------|\n"); |
| 309 | + "|--------------------------------|-----------------|-------------|-----------------|------------------|\n"); |
130 | 310 | } |
131 | 311 |
|
132 | 312 | static void printLine( |
133 | 313 | final PrintWriter out, |
134 | 314 | final String cfName, |
135 | 315 | final String keys, |
136 | | - final String columnSize, |
137 | | - final String sstFilesSize) { |
138 | | - final String format = "| %-30s | %-15s | %-12s | %-15s |\n"; |
139 | | - out.format(format, cfName, keys, columnSize, sstFilesSize); |
| 316 | + final String totalFilesSize, |
| 317 | + final String sstFilesSize, |
| 318 | + final String blobFilesSize) { |
| 319 | + final String format = "| %-30s | %-15s | %-11s | %-15s | %-16s |\n"; |
| 320 | + out.format(format, cfName, keys, totalFilesSize, sstFilesSize, blobFilesSize); |
140 | 321 | } |
| 322 | + |
| 323 | + record ColumnFamilyUsage( |
| 324 | + String name, long keys, long totalSize, long sstFilesSize, long blobFilesSize) {} |
141 | 325 | } |
0 commit comments