···
db::handle::{ItemDecoder, LexiconHandle},
error::{AppError, AppResult},
jetstream::JetstreamEvent,
-
utils::{RateTracker, ReadVariableExt, varints_unsigned_encoded},
···
pub fn sync(&self, all: bool) -> AppResult<()> {
let mut data = Vec::with_capacity(self.hits.len());
let _guard = scc::ebr::Guard::new();
···
let count = handle.item_count();
let data_count = count / block_size;
if count > 0 && (all || data_count > 0 || is_too_old) {
-
for i in 0..data_count {
-
nsid_data.push((i, handle.clone(), block_size));
total_count += block_size;
// only sync remainder if we haven't met block size
let remainder = count % block_size;
if (all || data_count == 0) && remainder > 0 {
-
nsid_data.push((data_count, handle.clone(), remainder));
total_count += remainder;
-
"{}: will sync {} blocks ({} count)",
···
-
.map(|(i, handle, max_block_size)| {
-
(i, handle.take_block_items(max_block_size), handle)
-
.map(|(i, items, handle)| {
let block = LexiconHandle::encode_block_from_items(items, count)?;
-
"{}: encoded block with {} items",
-
AppResult::Ok((i, block, handle))
.collect::<Result<Vec<_>, _>>()
-
for (i, block, handle) in chunk {
-
.execute(move || match handle.insert(block.key, block.data) {
-
tracing::info!("{}: [{i}] synced {}", handle.nsid(), block.written)
-
Err(err) => tracing::error!("failed to sync block: {}", err),
···
db::handle::{ItemDecoder, LexiconHandle},
error::{AppError, AppResult},
jetstream::JetstreamEvent,
+
utils::{CLOCK, RateTracker, ReadVariableExt, varints_unsigned_encoded},
···
pub fn sync(&self, all: bool) -> AppResult<()> {
+
let start = CLOCK.now();
let mut data = Vec::with_capacity(self.hits.len());
let _guard = scc::ebr::Guard::new();
···
let count = handle.item_count();
let data_count = count / block_size;
if count > 0 && (all || data_count > 0 || is_too_old) {
+
for _ in 0..data_count {
+
nsid_data.push((handle.clone(), block_size));
total_count += block_size;
// only sync remainder if we haven't met block size
let remainder = count % block_size;
if (all || data_count == 0) && remainder > 0 {
+
nsid_data.push((handle.clone(), remainder));
total_count += remainder;
+
let _span = handle.span().entered();
+
{blocks = %nsid_data.len(), count = %total_count},
···
+
.map(|(handle, max_block_size)| {
+
(handle.take_block_items(max_block_size), handle)
+
.map(|(items, handle)| {
let block = LexiconHandle::encode_block_from_items(items, count)?;
+
AppResult::Ok((block, handle))
.collect::<Result<Vec<_>, _>>()
+
for (block, handle) in chunk {
+
self.sync_pool.execute(move || {
+
let _span = handle.span().entered();
+
match handle.insert(block.key, block.data) {
+
tracing::info!({count = %block.written}, "synced")
+
Err(err) => tracing::error!({ err = %err }, "failed to sync block"),
+
tracing::info!(time = %start.elapsed().as_secs_f64(), "synced all blocks");