solana/ledger/src/bigtable_upload_service.rs

97 lines
2.9 KiB
Rust
Raw Normal View History

use {
crate::{bigtable_upload, blockstore::Blockstore},
solana_runtime::commitment::BlockCommitmentCache,
std::{
sync::atomic::{AtomicBool, Ordering},
sync::{Arc, RwLock},
thread::{self, Builder, JoinHandle},
},
tokio::runtime::Runtime,
2020-09-03 19:39:05 -07:00
};
// Delay uploading the largest confirmed root for this many slots. This is done in an attempt to
// ensure that the `CacheBlockMetaService` has had enough time to add the block time for the root
// before it's uploaded to BigTable.
//
// A more direct connection between CacheBlockMetaService and BigTableUploadService would be
// preferable...
const LARGEST_CONFIRMED_ROOT_UPLOAD_DELAY: usize = 100;
2020-09-03 19:39:05 -07:00
pub struct BigTableUploadService {
thread: JoinHandle<()>,
}
impl BigTableUploadService {
pub fn new(
runtime: Arc<Runtime>,
2020-09-03 19:39:05 -07:00
bigtable_ledger_storage: solana_storage_bigtable::LedgerStorage,
blockstore: Arc<Blockstore>,
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
exit: Arc<AtomicBool>,
) -> Self {
info!("Starting BigTable upload service");
let thread = Builder::new()
.name("bigtable-upload".to_string())
.spawn(move || {
Self::run(
runtime,
2020-09-03 19:39:05 -07:00
bigtable_ledger_storage,
blockstore,
block_commitment_cache,
exit,
)
})
.unwrap();
Self { thread }
}
fn run(
runtime: Arc<Runtime>,
2020-09-03 19:39:05 -07:00
bigtable_ledger_storage: solana_storage_bigtable::LedgerStorage,
blockstore: Arc<Blockstore>,
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
exit: Arc<AtomicBool>,
) {
let mut start_slot = 0;
2020-09-03 19:39:05 -07:00
loop {
if exit.load(Ordering::Relaxed) {
break;
}
let end_slot = block_commitment_cache
2020-09-03 19:39:05 -07:00
.read()
.unwrap()
.highest_confirmed_root()
.saturating_sub(LARGEST_CONFIRMED_ROOT_UPLOAD_DELAY as u64);
2020-09-03 19:39:05 -07:00
if end_slot <= start_slot {
2020-09-04 09:52:02 -07:00
std::thread::sleep(std::time::Duration::from_secs(1));
continue;
}
let result = runtime.block_on(bigtable_upload::upload_confirmed_blocks(
2020-09-03 19:39:05 -07:00
blockstore.clone(),
bigtable_ledger_storage.clone(),
start_slot,
Some(end_slot),
2020-09-03 19:39:05 -07:00
true,
2021-02-16 13:46:02 -08:00
false,
exit.clone(),
2020-09-03 19:39:05 -07:00
));
match result {
Ok(()) => start_slot = end_slot,
2020-09-03 19:39:05 -07:00
Err(err) => {
warn!("bigtable: upload_confirmed_blocks: {}", err);
std::thread::sleep(std::time::Duration::from_secs(2));
}
}
}
}
pub fn join(self) -> thread::Result<()> {
self.thread.join()
}
}