AccountsDb plugin framework (#20047)

Summary of Changes

Create a plugin mechanism in the accounts update path so that accounts data can be streamed out to external data stores (be it Kafka or Postgres). The plugin mechanism allows

Data stores of connection strings/credentials to be configured,
Accounts with patterns to be streamed
PostgreSQL implementation of the streaming for different destination stores to be plugged in.

The code comprises 4 major parts:

accountsdb-plugin-intf: defines the plugin interface which concrete plugin should implement.
accountsdb-plugin-manager: manages the load/unload of plugins and provide interfaces which the validator can notify of accounts update to plugins.
accountsdb-plugin-postgres: the concrete plugin implementation for PostgreSQL
The validator integrations: updated streamed right after snapshot restore and after account update from transaction processing or other real updates.
The plugin is optionally loaded on demand by new validator CLI argument -- there is no impact if the plugin is not loaded.
This commit is contained in:
Lijun Wang
2021-09-30 14:26:17 -07:00
committed by GitHub
parent 9ef1f06b3f
commit fe97cb2ddf
41 changed files with 1512 additions and 35 deletions

View File

@ -6,11 +6,13 @@ use crate::{
},
leader_schedule_cache::LeaderScheduleCache,
};
use log::*;
use solana_entry::entry::VerifyRecyclers;
use solana_runtime::{
bank_forks::BankForks, snapshot_archive_info::SnapshotArchiveInfoGetter,
snapshot_config::SnapshotConfig, snapshot_package::AccountsPackageSender, snapshot_utils,
accounts_update_notifier_interface::AccountsUpdateNotifier, bank_forks::BankForks,
snapshot_archive_info::SnapshotArchiveInfoGetter, snapshot_config::SnapshotConfig,
snapshot_package::AccountsPackageSender, snapshot_utils,
};
use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash};
use std::{fs, path::PathBuf, process, result};
@ -45,6 +47,7 @@ fn to_loadresult(
///
/// If a snapshot config is given, and a snapshot is found, it will be loaded. Otherwise, load
/// from genesis.
#[allow(clippy::too_many_arguments)]
pub fn load(
genesis_config: &GenesisConfig,
blockstore: &Blockstore,
@ -55,6 +58,7 @@ pub fn load(
transaction_status_sender: Option<&TransactionStatusSender>,
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
accounts_package_sender: AccountsPackageSender,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
) -> LoadResult {
if let Some(snapshot_config) = snapshot_config {
info!(
@ -80,6 +84,7 @@ pub fn load(
transaction_status_sender,
cache_block_meta_sender,
accounts_package_sender,
accounts_update_notifier,
);
} else {
info!("No snapshot package available; will load from genesis");
@ -96,6 +101,7 @@ pub fn load(
cache_block_meta_sender,
snapshot_config,
accounts_package_sender,
accounts_update_notifier,
)
}
@ -107,6 +113,7 @@ fn load_from_genesis(
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
snapshot_config: Option<&SnapshotConfig>,
accounts_package_sender: AccountsPackageSender,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
) -> LoadResult {
info!("Processing ledger from genesis");
to_loadresult(
@ -118,6 +125,7 @@ fn load_from_genesis(
cache_block_meta_sender,
snapshot_config,
accounts_package_sender,
accounts_update_notifier,
),
None,
)
@ -134,6 +142,7 @@ fn load_from_snapshot(
transaction_status_sender: Option<&TransactionStatusSender>,
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
accounts_package_sender: AccountsPackageSender,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
) -> LoadResult {
// Fail hard here if snapshot fails to load, don't silently continue
if account_paths.is_empty() {
@ -158,6 +167,7 @@ fn load_from_snapshot(
process_options.accounts_db_skip_shrink,
process_options.verify_index,
process_options.accounts_db_config.clone(),
accounts_update_notifier,
)
.expect("Load from snapshot failed");

View File

@ -18,6 +18,7 @@ use solana_rayon_threadlimit::get_thread_count;
use solana_runtime::{
accounts_db::{AccountShrinkThreshold, AccountsDbConfig},
accounts_index::AccountSecondaryIndexes,
accounts_update_notifier_interface::AccountsUpdateNotifier,
bank::{
Bank, ExecuteTimings, InnerInstructionsList, RentDebits, TransactionBalancesSet,
TransactionExecutionResult, TransactionLogMessages, TransactionResults,
@ -483,6 +484,7 @@ pub fn process_blockstore(
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
snapshot_config: Option<&SnapshotConfig>,
accounts_package_sender: AccountsPackageSender,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
) -> BlockstoreProcessorResult {
if let Some(num_threads) = opts.override_num_threads {
PAR_THREAD_POOL.with(|pool| {
@ -505,6 +507,7 @@ pub fn process_blockstore(
opts.shrink_ratio,
false,
opts.accounts_db_config.clone(),
accounts_update_notifier,
);
let bank0 = Arc::new(bank0);
info!("processing ledger for slot 0...");
@ -1513,6 +1516,7 @@ pub mod tests {
None,
None,
accounts_package_sender,
None,
)
.unwrap()
}