Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/rdb_serialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstddef>
#include <cstdlib>

#include "absl/cleanup/cleanup.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
Expand Down Expand Up @@ -173,6 +174,15 @@ absl::Status PerformRDBLoad(ValkeyModuleCtx *ctx, SafeRDB *rdb, int encver) {
Metrics::GetStats().rdb_restore_completed_indexes = 0;
Metrics::GetStats().rdb_restore_current_index_keys_total = 0;
Metrics::GetStats().rdb_restore_current_index_keys_loaded = 0;
// Clear progress tracking on every exit path (success or failure) so a
// stale residual can't leak into the at-rest number_of_indexes metric.
absl::Cleanup clear_restore_progress = [] {
Metrics::GetStats().rdb_restore_in_progress = false;
Metrics::GetStats().rdb_restore_total_indexes = 0;
Metrics::GetStats().rdb_restore_completed_indexes = 0;
Metrics::GetStats().rdb_restore_current_index_keys_total = 0;
Metrics::GetStats().rdb_restore_current_index_keys_loaded = 0;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Comment thread
greptile-apps[bot] marked this conversation as resolved.

// Begin RDBSection iteration
RDBSectionIter it(rdb, rdb_section_count);
Expand Down Expand Up @@ -200,8 +210,7 @@ absl::Status PerformRDBLoad(ValkeyModuleCtx *ctx, SafeRDB *rdb, int encver) {
}
}

// Mark restore as complete (all indexes loaded successfully)
Metrics::GetStats().rdb_restore_in_progress = false;
// Restore progress counters are cleared by clear_restore_progress above.
Metrics::GetStats().rdb_last_restore_aux_load_duration_ms =
absl::ToInt64Milliseconds(absl::Now() - rdb_load_start);

Expand Down
17 changes: 12 additions & 5 deletions src/schema_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,19 @@ absl::Status SchemaManager::ShowIndexSchemas(ValkeyModuleCtx *ctx,
static vmsdk::info_field::Integer number_of_indexes(
"index_stats", "number_of_indexes",
vmsdk::info_field::IntegerBuilder().App().Computed([]() -> long long {
// Consider indexes pending RDB load
// Consider indexes pending RDB load. The residual is only meaningful
// while a load is actually in progress. RDB sections can include
// non-index sections, so this residual must not affect the at-rest
// count.
auto &stats = Metrics::GetStats();
return SchemaManager::Instance().GetNumberOfIndexSchemas() +
std::max(stats.rdb_restore_total_indexes.load() -
stats.rdb_restore_completed_indexes.load(),
uint64_t{0});
uint64_t pending = 0;
if (stats.rdb_restore_in_progress.load()) {
uint64_t total = stats.rdb_restore_total_indexes.load();
uint64_t completed = stats.rdb_restore_completed_indexes.load();
// Unsigned subtraction: guard rather than let it wrap.
pending = total > completed ? total - completed : 0;
}
return SchemaManager::Instance().GetNumberOfIndexSchemas() + pending;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}));
static vmsdk::info_field::Integer number_of_attributes(
"index_stats", "number_of_attributes",
Expand Down
Loading