Skip to content

feat(storage): RocksDBWrapper proper size calculation via SST property + /v1/admin/storage/stats endpoint (v1.8.0 #205) - #4274

Merged
makr-code merged 3 commits into
developfrom
copilot/add-rocksdbwrapper-size-calculation
Mar 15, 2026
Merged

makr-code merged 3 commits into
developfrom
copilot/add-rocksdbwrapper-size-calculation

Conversation

Copilot AI commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

RocksDBWrapper::getApproximateSize() returned a hardcoded 0, making disk-space monitoring, compaction triggers, and admin storage metrics entirely unreliable.

Changes

src/storage/rocksdb_wrapper.cpp

  • getApproximateSize(): replaces TODO/0 with GetIntProperty("rocksdb.total-sst-files-size") (primary) and GetApproximateSizes(INCLUDE_FILES) range scan (fallback for builds where the property is unavailable)
  • getStats(): adds total_sst_files_size_bytes as the first field in the "rocksdb" JSON object
uint64_t total_sst_size = 0;
if (db_->GetIntProperty("rocksdb.total-sst-files-size", &total_sst_size))
    return total_sst_size;
// fallback: range scan with INCLUDE_FILES=1
static constexpr uint8_t kIncludeFiles = 1;
db_->GetApproximateSizes(&full_range, 1, &approx_size, kIncludeFiles);

include/storage/disk_space_monitor.h + src/storage/disk_space_monitor.cpp

  • SpaceInfo gains uint64_t rocksdb_size_bytes = 0
  • setRocksDBSize(uint64_t) persists the SST size into current_info_ under mutex_
  • checkSpace() explicitly carries current_info_.rocksdb_size_bytes into the refreshed SpaceInfo so background monitoring loops don't zero it out

src/server/http_server.cpp

  • Adds GET /v1/admin/storage/stats (AdminStorageStatsGet route)
  • Response: rocksdb_sst_size_bytes (top-level) + disk sub-object with OS-level path/total/used/free/available/usage_percent from a one-shot DiskSpaceMonitor::checkSpace()

tests/test_rocksdb_size_calculation.cpp (new, 7 tests)

Test What it covers
GetApproximateSizeIsNonZeroAfterFlush AC-1: non-zero after memtable flush
GetApproximateSizeIncreasesWithData AC-1: monotone growth
GetStatsJsonHasTotalSstFilesSizeKey AC-2: JSON field present
SetRocksDBSizeReflectedInSpaceInfo AC-3: setRocksDBSize → getSpaceInfo
SetRocksDBSizeDefaultsToZero AC-3: zero before first set
CheckSpacePreservesRocksDBSize AC-3: checkSpace() doesn't wipe the value
GetApproximateSizeReturnZeroWhenClosed AC-4: safe on unopened DB

.github/workflows/rocksdb-size-calculation-ci.yml (new)

Matrix: gcc-12/clang-15 on Ubuntu 22.04, gcc-13 on Ubuntu 24.04.

src/storage/FUTURE_ENHANCEMENTS.md

All three roadmap items marked [x].

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>RocksDBWrapper: Implement Proper Size Calculation</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'RocksDBWrapper: Implement Proper Size Calculation' for the storage domain. It is sourced from the consolidated roadmap under 🟡 Medium Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.8.0.

Primary detail section: RocksDBWrapper: Implement Proper Size Calculation

Goal

Deliver the scoped changes for RocksDBWrapper: Implement Proper Size Calculation in src/storage/ and complete the linked detail section in a release-ready state for v1.8.0.

Detailed Scope

RocksDBWrapper: Implement Proper Size Calculation

Priority: Medium
Target Version: v1.8.0

rocksdb_wrapper.cpp line 1445: "TODO: Implement proper size calculation". The RocksDBWrapper::getApproximateSize() or equivalent method returns 0 or a placeholder, making disk-space monitoring, compaction triggers, and admin API storage metrics unreliable.

Implementation Notes:

  • [ ] Use rocksdb::DB::GetApproximateSizes() API to compute the on-disk SST file sizes for a key range.
  • [ ] Alternatively, use rocksdb::DB::GetIntProperty(rocksdb::DB::Properties::kTotalSstFilesSize) for total CF size.
  • [ ] Wire the result into DiskSpaceMonitor and the /v1/admin/storage/stats endpoint.

Acceptance Criteria

  • Use rocksdb::DB::GetApproximateSizes() API to compute the on-disk SST file sizes for a key range.
  • Alternatively, use rocksdb::DB::GetIntProperty(rocksdb::DB::Properties::kTotalSstFilesSize) for total CF size.
  • Wire the result into DiskSpaceMonitor and the /v1/admin/storage/stats endpoint.

Relationships

References

  • src/ROADMAP.md
  • src/storage/FUTURE_ENHANCEMENTS.md#rocksdbwrapper-implement-proper-size-calculation
  • Source key: roadmap:205:storage:v1.8.0:rocksdbwrapper-implement-proper-size-calculation

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ssue #205)

- getApproximateSize() now uses GetIntProperty('rocksdb.total-sst-files-size')
  as primary, with GetApproximateSizes(INCLUDE_FILES) fallback
- getStats() JSON includes new 'total_sst_files_size_bytes' field
- DiskSpaceMonitor: add rocksdb_size_bytes to SpaceInfo + setRocksDBSize() method
- checkSpace() preserves rocksdb_size_bytes across OS disk queries
- Add GET /v1/admin/storage/stats endpoint
- Add focused tests (4 ACs) + CMakeLists registration + CI workflow

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] Implement proper size calculation for RocksDBWrapper feat(storage): RocksDBWrapper — Implement Proper Size Calculation (v1.8.0, #205) Mar 15, 2026
Copilot AI requested a review from makr-code March 15, 2026 19:06
Copilot AI changed the title feat(storage): RocksDBWrapper — Implement Proper Size Calculation (v1.8.0, #205) feat(storage): RocksDBWrapper proper size calculation via SST property + /v1/admin/storage/stats endpoint (v1.8.0 #205) Mar 15, 2026
@makr-code
makr-code marked this pull request as ready for review March 15, 2026 19:14
@makr-code
makr-code merged commit a94df0d into develop Mar 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RocksDBWrapper: Implement Proper Size Calculation

2 participants