mirror of
https://github.com/neondatabase/neon.git
synced 2026-06-03 13:30:38 +00:00
Fix loading logical database size
This commit is contained in:
@@ -543,8 +543,6 @@ impl Tenant {
|
||||
}
|
||||
};
|
||||
|
||||
timeline.init_logical_size().await;
|
||||
|
||||
if self.remote_storage.is_some() {
|
||||
// Reconcile local state with remote storage, downloading anything that's
|
||||
// missing locally, and scheduling uploads for anything that's missing
|
||||
@@ -1043,11 +1041,29 @@ impl Tenant {
|
||||
// The loops will shut themselves down when they notice that the tenant is inactive.
|
||||
self.activate(ctx)?;
|
||||
|
||||
self.load_logical_sizes().await?;
|
||||
|
||||
info!("Done");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_logical_sizes(&self) -> anyhow::Result<()> {
|
||||
let not_broken_timelines: Vec<Arc<Timeline>>;
|
||||
{
|
||||
let timelines_accessor = self.timelines.lock().unwrap();
|
||||
not_broken_timelines = timelines_accessor
|
||||
.values()
|
||||
.filter(|timeline| timeline.current_state() != TimelineState::Broken)
|
||||
.cloned()
|
||||
.collect();
|
||||
}
|
||||
for timeline in not_broken_timelines {
|
||||
timeline.load_inmem_logical_size().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Subroutine of `load_tenant`, to load an individual timeline
|
||||
///
|
||||
/// NB: The parent is assumed to be already loaded!
|
||||
@@ -2516,7 +2532,6 @@ impl Tenant {
|
||||
ancestor: Option<Arc<Timeline>>,
|
||||
) -> anyhow::Result<UninitializedTimeline> {
|
||||
let tenant_id = self.tenant_id;
|
||||
|
||||
let remote_client = if let Some(remote_storage) = self.remote_storage.as_ref() {
|
||||
let remote_client = RemoteTimelineClient::new(
|
||||
remote_storage.clone(),
|
||||
|
||||
@@ -713,13 +713,19 @@ impl Timeline {
|
||||
self.current_logical_size.load(AtomicOrdering::Relaxed) as u64
|
||||
}
|
||||
|
||||
pub async fn init_logical_size(&self) {
|
||||
let ctx = RequestContext::todo_child(TaskKind::Startup, DownloadBehavior::Error);
|
||||
let last_record_lsn = self.get_last_record_lsn();
|
||||
if let Ok(size) = self.get_logical_size(last_record_lsn, &ctx).await {
|
||||
self.current_logical_size
|
||||
.store(size as i64, AtomicOrdering::Relaxed);
|
||||
/// Load from KV storage value of logical timeline size and store it in inmemory atomic variable
|
||||
pub async fn load_inmem_logical_size(&self) -> anyhow::Result<()> {
|
||||
let lsn = self.get_disk_consistent_lsn();
|
||||
if lsn != Lsn::INVALID {
|
||||
let ctx = RequestContext::todo_child(TaskKind::Startup, DownloadBehavior::Error);
|
||||
match self.get_logical_size(lsn, &ctx).await {
|
||||
Ok(size) => self
|
||||
.current_logical_size
|
||||
.store(size as i64, AtomicOrdering::Relaxed),
|
||||
Err(e) => info!("Failed to load logical size: {:?}", e),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if more than 'checkpoint_distance' of WAL has been accumulated in
|
||||
|
||||
Reference in New Issue
Block a user