Skip to content

Commit

Permalink
Remove deprecated db migration options (near#8885)
Browse files Browse the repository at this point in the history
`assert_no_deprecated_config()` was introduced in near#7584, more than 6 months ago.
Should be safe to delete.
  • Loading branch information
nikurt authored Apr 5, 2023
1 parent 8766f06 commit 20d1dcc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 65 deletions.
48 changes: 17 additions & 31 deletions nearcore/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
use anyhow::{anyhow, bail, Context};
use near_primitives::static_clock::StaticClock;
use near_primitives::test_utils::create_test_signer;
use num_rational::Rational32;
use std::fs;
use std::fs::File;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

use near_config_utils::{ValidationError, ValidationErrors};

#[cfg(test)]
use tempfile::tempdir;
use tracing::{info, warn};

use crate::download_file::{run_download_file, FileDownloadError};
use anyhow::{anyhow, bail, Context};
use near_chain_configs::{
get_initial_supply, ClientConfig, GCConfig, Genesis, GenesisConfig, GenesisValidationMode,
LogSummaryStyle, MutableConfigValue,
};
use near_config_utils::{ValidationError, ValidationErrors};
use near_crypto::{InMemorySigner, KeyFile, KeyType, PublicKey, Signer};
#[cfg(feature = "json_rpc")]
use near_jsonrpc::RpcConfig;
Expand All @@ -32,6 +16,8 @@ use near_primitives::hash::CryptoHash;
use near_primitives::shard_layout::account_id_to_shard_id;
use near_primitives::shard_layout::ShardLayout;
use near_primitives::state_record::StateRecord;
use near_primitives::static_clock::StaticClock;
use near_primitives::test_utils::create_test_signer;
use near_primitives::types::{
AccountId, AccountInfo, Balance, BlockHeight, BlockHeightDelta, Gas, NumBlocks, NumSeats,
NumShards, ShardId,
Expand All @@ -42,6 +28,17 @@ use near_primitives::version::PROTOCOL_VERSION;
#[cfg(feature = "rosetta_rpc")]
use near_rosetta_rpc::RosettaRpcConfig;
use near_telemetry::TelemetryConfig;
use num_rational::Rational32;
use std::fs;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
#[cfg(test)]
use tempfile::tempdir;
use tracing::{info, warn};

/// Initial balance used in tests.
pub const TESTING_INIT_BALANCE: Balance = 1_000_000_000 * NEAR_BASE;
Expand Down Expand Up @@ -327,17 +324,8 @@ pub struct Config {
/// Configuration for the
#[serde(default, skip_serializing_if = "Option::is_none")]
pub split_storage: Option<SplitStorageConfig>,
// TODO(mina86): Remove those two altogether at some point. We need to be
// somewhat careful though and make sure that we don’t start silently
// ignoring this option without users setting corresponding store option.
// For the time being, we’re failing inside of create_db_checkpoint if this
// option is set.
/// Deprecated; use `store.migration_snapshot` instead.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub use_db_migration_snapshot: Option<bool>,
/// Deprecated; use `store.migration_snapshot` instead.
#[serde(skip_serializing_if = "Option::is_none")]
pub db_migration_snapshot_path: Option<PathBuf>,
/// The node will stop after the head exceeds this height.
/// The node usually stops within several seconds after reaching the target height.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expected_shutdown: Option<BlockHeight>,
/// Options for dumping state of every epoch to S3.
Expand Down Expand Up @@ -377,8 +365,6 @@ impl Default for Config {
view_client_throttle_period: default_view_client_throttle_period(),
trie_viewer_state_size_limit: default_trie_viewer_state_size_limit(),
max_gas_burnt_view: None,
db_migration_snapshot_path: None,
use_db_migration_snapshot: None,
store: near_store::StoreConfig::default(),
cold_store: None,
split_storage: None,
Expand Down
34 changes: 0 additions & 34 deletions nearcore/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,8 @@ impl<'a> Migrator<'a> {
}
}

/// Asserts that node’s configuration does not use deprecated snapshot config
/// options.
///
/// The `use_db_migration_snapshot` and `db_migration_snapshot_path`
/// configuration options have been deprecated in favour of
/// `store.migration_snapshot`.
///
/// This function panics if the old options are set and shows instruction how to
/// migrate to the new options.
///
/// This is a hack which stops `StoreOpener` before it attempts migration.
/// Ideally we would propagate errors nicely but that would complicate the API
/// a wee bit so instead we’re panicking. This shouldn’t be a big deal since
/// the deprecated options are going away ‘soon’.
fn assert_no_deprecated_config(config: &crate::config::NearConfig) {
use near_store::config::MigrationSnapshot;

let example = match (
config.config.use_db_migration_snapshot,
config.config.db_migration_snapshot_path.as_ref(),
) {
(None, None) => return,
(Some(false), _) => MigrationSnapshot::Enabled(false),
(_, None) => MigrationSnapshot::Enabled(true),
(_, Some(path)) => MigrationSnapshot::Path(path.join("migration-snapshot")),
};
panic!(
"‘use_db_migration_snapshot’ and ‘db_migration_snapshot_path’ options \
are deprecated.\nSet ‘store.migration_snapshot’ to instead, e.g.:\n{}",
example.format_example()
)
}

impl<'a> near_store::StoreMigrator for Migrator<'a> {
fn check_support(&self, version: DbVersion) -> Result<(), &'static str> {
assert_no_deprecated_config(self.config);
// TODO(mina86): Once open ranges in match are stabilised, get rid of
// this constant and change the match to be 27..DB_VERSION.
const LAST_SUPPORTED: DbVersion = DB_VERSION - 1;
Expand Down

0 comments on commit 20d1dcc

Please sign in to comment.