Skip to content

Commit

Permalink
[Storage] Also write usage for the last checkpoint in the chunk. (apt…
Browse files Browse the repository at this point in the history
  • Loading branch information
grao1991 authored Nov 16, 2023
1 parent 71137ee commit d813b32
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions storage/aptosdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ impl AptosDB {
// TODO(grao): remove after APIs migrated off the DB to the indexer.
self.state_store.state_kv_db.enabled_sharding(),
skip_index_and_usage,
txns_to_commit
.iter()
.rposition(|txn| txn.is_state_checkpoint()),
)?;

// Write block index if event index is skipped.
Expand Down
1 change: 1 addition & 0 deletions storage/aptosdb/src/pruner/state_merkle_pruner/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn put_value_set(
&state_kv_metadata_batch,
/*put_state_value_indices=*/ false,
/*skip_usage=*/ false,
/*last_checkpoint_index=*/ None,
)
.unwrap();
state_store
Expand Down
10 changes: 8 additions & 2 deletions storage/aptosdb/src/state_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ impl StateStore {
batch,
sharded_state_kv_batches,
/*skip_usage=*/ false,
None,
)?;

self.put_state_values(
Expand All @@ -676,6 +677,7 @@ impl StateStore {
state_kv_metadata_batch: &SchemaBatch,
put_state_value_indices: bool,
skip_usage: bool,
last_checkpoint_index: Option<usize>,
) -> Result<()> {
let _timer = OTHER_TIMERS_SECONDS
.with_label_values(&["put_value_sets"])
Expand All @@ -689,6 +691,7 @@ impl StateStore {
ledger_batch,
sharded_state_kv_batches,
skip_usage,
last_checkpoint_index,
)?;

let _timer = OTHER_TIMERS_SECONDS
Expand Down Expand Up @@ -775,6 +778,7 @@ impl StateStore {
batch: &SchemaBatch,
sharded_state_kv_batches: &ShardedStateKvSchemaBatch,
skip_usage: bool,
last_checkpoint_index: Option<usize>,
) -> Result<()> {
let _timer = OTHER_TIMERS_SECONDS
.with_label_values(&["put_stats_and_indices"])
Expand Down Expand Up @@ -907,9 +911,11 @@ impl StateStore {
(usage.items() as i64 + items_delta) as usize,
(usage.bytes() as i64 + bytes_delta) as usize,
);
if !skip_usage || i == num_versions - 1 {
let should_write_index_for_version =
(i == num_versions - 1) || Some(i) == last_checkpoint_index;
if !skip_usage || should_write_index_for_version {
let version = first_version + i as u64;
if i == num_versions - 1 {
if should_write_index_for_version {
info!("Write usage at version {version}, {usage:?}, skip_usage: {skip_usage}.");
}
batch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ impl StateMerkleBatchCommitter {
.epoch_snapshot_pruner
.maybe_set_pruner_target_db_version(current_version);

if !self.state_db.skip_usage {
self.check_usage_consistency(&state_delta).unwrap();
}
self.check_usage_consistency(&state_delta).unwrap();

state_delta.base.log_generation("buffered_state_commit");
state_delta
.current
Expand Down
1 change: 1 addition & 0 deletions storage/aptosdb/src/state_store/state_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn put_value_set(
&state_kv_metadata_batch,
/*put_state_value_indices=*/ false,
/*skip_usage=*/ false,
/*last_checkpoint_index=*/ None,
)
.unwrap();
state_store
Expand Down
1 change: 1 addition & 0 deletions storage/aptosdb/src/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub(crate) fn update_store(
&state_kv_metadata_batch,
/*put_state_value_indices=*/ false,
/*skip_usage=*/ false,
/*last_checkpoint_index=*/ None,
)
.unwrap();
store
Expand Down

0 comments on commit d813b32

Please sign in to comment.