Skip to content

Commit

Permalink
remove state snapshot compaction_enabled config options
Browse files Browse the repository at this point in the history
This was added in near#9090
to provide a way to reduce the size of snapshots, as the commit
message said. But that's not needed anymore when we just drop the
unneeded column families and have a smaller snapshot to begin with
  • Loading branch information
marcelo-gonzalez committed Mar 15, 2024
1 parent 44ed6d5 commit ef29c05
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 78 deletions.
2 changes: 0 additions & 2 deletions chain/chain/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl NightshadeRuntime {
home_dir: home_dir.to_path_buf(),
hot_store_path: PathBuf::from("data"),
state_snapshot_subdir: PathBuf::from("state_snapshot"),
compaction_enabled: false,
},
)
}
Expand All @@ -177,7 +176,6 @@ impl NightshadeRuntime {
home_dir: home_dir.to_path_buf(),
hot_store_path: PathBuf::from("data"),
state_snapshot_subdir: PathBuf::from("state_snapshot"),
compaction_enabled: false,
},
)
}
Expand Down
1 change: 0 additions & 1 deletion chain/chain/src/runtime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ impl TestEnv {
home_dir: PathBuf::from(dir.path()),
hot_store_path: PathBuf::from("data"),
state_snapshot_subdir: PathBuf::from("state_snapshot"),
compaction_enabled: false,
},
);
let state_roots = get_genesis_state_roots(&store).unwrap().unwrap();
Expand Down
32 changes: 2 additions & 30 deletions chain/chain/src/state_snapshot_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use std::sync::Arc;
/// Runs tasks related to state snapshots.
/// There are three main handlers in StateSnapshotActor and they are called in sequence
/// 1. DeleteSnapshotRequest: deletes a snapshot and optionally calls CreateSnapshotRequest.
/// 2. CreateSnapshotRequest: creates a new snapshot and optionally calls CompactSnapshotRequest based on config.
/// 3. CompactSnapshotRequest: compacts a snapshot store.
/// 2. CreateSnapshotRequest: creates a new snapshot.
pub struct StateSnapshotActor {
flat_storage_manager: FlatStorageManager,
network_adapter: PeerManagerAdapter,
Expand Down Expand Up @@ -56,10 +55,6 @@ struct CreateSnapshotRequest {
block: Block,
}

#[derive(actix::Message, Debug)]
#[rtype(result = "()")]
struct CompactSnapshotRequest {}

impl actix::Handler<WithSpanContext<DeleteAndMaybeCreateSnapshotRequest>> for StateSnapshotActor {
type Result = ();

Expand Down Expand Up @@ -87,7 +82,7 @@ impl actix::Handler<WithSpanContext<CreateSnapshotRequest>> for StateSnapshotAct
type Result = ();

#[perf]
fn handle(&mut self, msg: WithSpanContext<CreateSnapshotRequest>, context: &mut Context<Self>) {
fn handle(&mut self, msg: WithSpanContext<CreateSnapshotRequest>, _context: &mut Context<Self>) {
let (_span, msg) = handler_debug_span!(target: "state_snapshot", msg);
tracing::debug!(target: "state_snapshot", ?msg);

Expand All @@ -113,12 +108,6 @@ impl actix::Handler<WithSpanContext<CreateSnapshotRequest>> for StateSnapshotAct
},
));
}

if self.tries.state_snapshot_config().compaction_enabled {
context.address().do_send(CompactSnapshotRequest {}.with_span_context());
} else {
tracing::info!(target: "state_snapshot", "State snapshot ready, not running compaction.");
}
}
Err(err) => {
tracing::error!(target: "state_snapshot", ?err, "State snapshot creation failed")
Expand All @@ -127,23 +116,6 @@ impl actix::Handler<WithSpanContext<CreateSnapshotRequest>> for StateSnapshotAct
}
}

/// Runs compaction of the snapshot store.
impl actix::Handler<WithSpanContext<CompactSnapshotRequest>> for StateSnapshotActor {
type Result = ();

#[perf]
fn handle(&mut self, msg: WithSpanContext<CompactSnapshotRequest>, _: &mut Context<Self>) {
let (_span, msg) = handler_debug_span!(target: "state_snapshot", msg);
tracing::debug!(target: "state_snapshot", ?msg);

if let Err(err) = self.tries.compact_state_snapshot() {
tracing::error!(target: "state_snapshot", ?err, "State snapshot compaction failed");
} else {
tracing::info!(target: "state_snapshot", "State snapshot compaction succeeded");
}
}
}

type MakeSnapshotCallback =
Arc<dyn Fn(CryptoHash, EpochHeight, Vec<ShardUId>, Block) -> () + Send + Sync + 'static>;

Expand Down
11 changes: 0 additions & 11 deletions core/store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,13 @@ pub struct StoreConfig {

// TODO (#9989): To be phased out in favor of state_snapshot_config
pub state_snapshot_enabled: bool,

// TODO (#9989): To be phased out in favor of state_snapshot_config
pub state_snapshot_compaction_enabled: bool,
}

/// Config used to control state snapshot creation. This is used for state sync and resharding.
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
#[serde(default)]
pub struct StateSnapshotConfig {
pub state_snapshot_type: StateSnapshotType,
/// State Snapshot compaction usually is a good thing but is heavy on IO and can take considerable
/// amount of time.
/// It makes state snapshots tiny (10GB) over the course of an epoch.
/// We may want to disable it for archival nodes during resharding
pub compaction_enabled: bool,
}

#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
Expand Down Expand Up @@ -274,9 +266,6 @@ impl Default for StoreConfig {

// TODO: To be phased out in favor of state_snapshot_config
state_snapshot_enabled: false,

// TODO: To be phased out in favor of state_snapshot_config
state_snapshot_compaction_enabled: false,
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions core/store/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,6 @@ pub(crate) static DELETE_STATE_SNAPSHOT_ELAPSED: Lazy<Histogram> = Lazy::new(||
.unwrap()
});

pub(crate) static COMPACT_STATE_SNAPSHOT_ELAPSED: Lazy<Histogram> = Lazy::new(|| {
try_create_histogram_with_buckets(
"near_compact_state_snapshot_elapsed_sec",
"Latency of compaction of a state snapshot, in seconds",
exponential_buckets(0.001, 1.6, 40).unwrap(),
)
.unwrap()
});

pub(crate) static MOVE_STATE_SNAPSHOT_FLAT_HEAD_ELAPSED: Lazy<HistogramVec> = Lazy::new(|| {
try_create_histogram_vec(
"near_move_state_snapshot_flat_head_elapsed_sec",
Expand Down
16 changes: 0 additions & 16 deletions core/store/src/trie/state_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ pub struct StateSnapshotConfig {
pub home_dir: PathBuf,
pub hot_store_path: PathBuf,
pub state_snapshot_subdir: PathBuf,
pub compaction_enabled: bool,
}

impl ShardTries {
Expand Down Expand Up @@ -240,21 +239,6 @@ impl ShardTries {
Ok(Some(state_snapshot_lock.as_ref().unwrap().get_shard_uids()))
}

/// Runs compaction on the snapshot.
pub fn compact_state_snapshot(&self) -> Result<(), anyhow::Error> {
let _span =
tracing::info_span!(target: "state_snapshot", "compact_state_snapshot").entered();
// It's fine if the access to state snapshot blocks.
let state_snapshot_lock = self.state_snapshot().read().unwrap();
if let Some(state_snapshot) = &*state_snapshot_lock {
let _timer = metrics::COMPACT_STATE_SNAPSHOT_ELAPSED.start_timer();
state_snapshot.store.compact()?;
} else {
tracing::error!(target: "state_snapshot", "Requested compaction but no state snapshot is available.");
};
Ok(())
}

/// Deletes all snapshots and unsets the STATE_SNAPSHOT_KEY.
pub fn delete_state_snapshot(&self) {
let _span =
Expand Down
1 change: 0 additions & 1 deletion integration-tests/src/tests/client/state_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl StateSnaptshotTestEnv {
home_dir: home_dir.clone(),
hot_store_path: hot_store_path.clone(),
state_snapshot_subdir: state_snapshot_subdir.clone(),
compaction_enabled: true,
};
let shard_tries = ShardTries::new(
store.clone(),
Expand Down
4 changes: 0 additions & 4 deletions integration-tests/src/tests/client/sync_state_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ fn sync_state_dump() {
credentials_file: None,
});
near1.config.store.state_snapshot_enabled = true;
near1.config.store.state_snapshot_compaction_enabled = false;

let dir1 = tempfile::Builder::new().prefix("sync_nodes_1").tempdir().unwrap();
let nearcore::NearNode {
Expand Down Expand Up @@ -738,7 +737,6 @@ fn test_state_sync_headers() {
let dir1 =
tempfile::Builder::new().prefix("test_state_sync_headers").tempdir().unwrap();
near1.config.store.state_snapshot_enabled = true;
near1.config.store.state_snapshot_compaction_enabled = false;

let nearcore::NearNode { view_client: view_client1, .. } =
start_with_config(dir1.path(), near1).expect("start_with_config");
Expand Down Expand Up @@ -935,7 +933,6 @@ fn test_state_sync_headers_no_tracked_shards() {
.tempdir()
.unwrap();
near1.config.store.state_snapshot_enabled = false;
near1.config.store.state_snapshot_compaction_enabled = false;
near1.config.state_sync_enabled = false;
near1.client_config.state_sync_enabled = false;

Expand All @@ -953,7 +950,6 @@ fn test_state_sync_headers_no_tracked_shards() {
.tempdir()
.unwrap();
near2.config.store.state_snapshot_enabled = true;
near2.config.store.state_snapshot_compaction_enabled = false;
near2.config.state_sync_enabled = false;
near2.client_config.state_sync_enabled = false;

Expand Down
4 changes: 0 additions & 4 deletions nearcore/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,6 @@ impl NightshadeRuntime {
if config.config.store.state_snapshot_enabled {
state_snapshot_type = StateSnapshotType::EveryEpoch;
}
// TODO (#9989): directly use the new state snapshot config once the migration is done.
let compaction_enabled = config.config.store.state_snapshot_compaction_enabled
|| config.config.store.state_snapshot_config.compaction_enabled;
let state_snapshot_config = StateSnapshotConfig {
state_snapshot_type,
home_dir: home_dir.to_path_buf(),
Expand All @@ -634,7 +631,6 @@ impl NightshadeRuntime {
.clone()
.unwrap_or_else(|| PathBuf::from("data")),
state_snapshot_subdir: PathBuf::from("state_snapshot"),
compaction_enabled,
};
NightshadeRuntime::new(
store,
Expand Down

0 comments on commit ef29c05

Please sign in to comment.