Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved replica and dataflow expiration #30162

Merged
merged 27 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5d5931e
DNM WIP replica expiration
antiguru Oct 23, 2024
b21ecd4
wip
antiguru Oct 23, 2024
ddd07d4
Fix determining time dependence of index and materialized views based on
antiguru Oct 24, 2024
dfd10a7
Fix build and remove debug logging
antiguru Oct 24, 2024
2f2db18
Remove unused code
antiguru Oct 24, 2024
8d75057
Rationalize time dependence storage location
antiguru Oct 24, 2024
0ee4b8d
fix time determination
antiguru Oct 24, 2024
24a7b84
Rewrite determine time dependency, fix CTs
antiguru Oct 24, 2024
9c26b1c
Disable for subscribes
antiguru Oct 25, 2024
4cf8428
Correctly support tables on load generator
antiguru Oct 25, 2024
41959e0
Retain shutdown token
antiguru Oct 25, 2024
831e74e
Fix MVs with refresh schedule, don't expire err streams
antiguru Oct 25, 2024
46c65f8
Print warning instead of panicking
antiguru Oct 25, 2024
d02a63f
Relax remaining offset check. Negative numbers are acceptable
antiguru Oct 25, 2024
338ca5e
Restructure, cleanup, warn on reaching expiration frontier, panic in
antiguru Oct 28, 2024
4c5ed04
Oops, inverted panic condition!
antiguru Oct 28, 2024
8046d40
Fix tests
antiguru Oct 28, 2024
36e48a2
Fix findings
antiguru Oct 28, 2024
2ec45cf
Address review comments
antiguru Oct 29, 2024
1a03d65
TimeDependence is a struct
antiguru Oct 29, 2024
8b95002
TimeDependence debug implementation
antiguru Oct 29, 2024
b39174b
Remove unused function
antiguru Oct 29, 2024
9a12b69
Remove helper type, cleanup, apply tests
antiguru Oct 29, 2024
a735903
Address feedback: Enable expiration for subscribes, only set expiration
antiguru Oct 30, 2024
500eb63
Special-case log indexes
antiguru Oct 31, 2024
4cd60c2
Disable for continual tasks
antiguru Oct 31, 2024
d12d3fe
Replica expiration pattern
antiguru Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion misc/python/materialize/cli/ci_annotate_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
| restart-materialized-1\ *|\ thread\ 'coordinator'\ panicked\ at\ 'external\ operation\ .*\ failed\ unrecoverably.*
# Expected in cluster test
| cluster-clusterd[12]-1\ .*\ halting\ process:\ new\ timely\ configuration\ does\ not\ match\ existing\ timely\ configuration
| cluster-clusterd1-1\ .*\ has\ exceeded\ expiration
| cluster-clusterd1-1\ .*\ replica\ expired
# Emitted by tests employing explicit mz_panic()
| forced\ panic
# Emitted by broken_statements.slt in order to stop panic propagation, as 'forced panic' will unwantedly panic the `environmentd` thread.
Expand Down
1 change: 0 additions & 1 deletion src/adapter/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pub(crate) mod consistency;
mod migrate;

mod apply;
mod dataflow_expiration;
mod open;
mod state;
mod transact;
Expand Down
28 changes: 0 additions & 28 deletions src/adapter/src/catalog/dataflow_expiration.rs

This file was deleted.

61 changes: 24 additions & 37 deletions src/adapter/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@
//! ```
//!

use anyhow::Context;
use chrono::{DateTime, Utc};
use ipnet::IpNet;
use mz_adapter_types::dyncfgs::WITH_0DT_DEPLOYMENT_CAUGHT_UP_CHECK_INTERVAL;
use mz_compute_client::as_of_selection;
use mz_ore::channel::trigger::Trigger;
use mz_ore::url::SensitiveUrl;
use mz_sql::names::{ResolvedIds, SchemaSpecifier};
use mz_sql::session::user::User;
use mz_storage_types::read_holds::ReadHold;
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, VecDeque};
use std::fmt;
Expand All @@ -87,17 +77,20 @@ use std::sync::LazyLock;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use thiserror::Error;

use anyhow::Context;
use chrono::{DateTime, Utc};
use derivative::Derivative;
use differential_dataflow::lattice::Lattice;
use fail::fail_point;
use futures::future::{BoxFuture, FutureExt, LocalBoxFuture};
use futures::StreamExt;
use http::Uri;
use ipnet::IpNet;
use itertools::{Either, Itertools};
use mz_adapter_types::compaction::CompactionWindow;
use mz_adapter_types::connection::ConnectionId;
use mz_adapter_types::dyncfgs::WITH_0DT_DEPLOYMENT_CAUGHT_UP_CHECK_INTERVAL;
use mz_build_info::BuildInfo;
use mz_catalog::builtin::{BUILTINS, BUILTINS_STATIC, MZ_STORAGE_USAGE_BY_SHARD};
use mz_catalog::config::{AwsPrincipalContext, BuiltinItemMigrationConfig, ClusterReplicaSizeMap};
Expand All @@ -107,6 +100,7 @@ use mz_catalog::memory::objects::{
DataSourceDesc, TableDataSource,
};
use mz_cloud_resources::{CloudResourceController, VpcEndpointConfig, VpcEndpointEvent};
use mz_compute_client::as_of_selection;
use mz_compute_client::controller::error::InstanceMissing;
use mz_compute_types::dataflows::DataflowDescription;
use mz_compute_types::plan::Plan;
Expand All @@ -117,12 +111,14 @@ use mz_controller_types::{ClusterId, ReplicaId, WatchSetId};
use mz_expr::{MapFilterProject, OptimizedMirRelationExpr, RowSetFinishing};
use mz_orchestrator::{OfflineReason, ServiceProcessMetrics};
use mz_ore::cast::{CastFrom, CastLossy};
use mz_ore::channel::trigger::Trigger;
use mz_ore::future::TimeoutError;
use mz_ore::metrics::MetricsRegistry;
use mz_ore::now::{EpochMillis, NowFn};
use mz_ore::task::{spawn, JoinHandle};
use mz_ore::thread::JoinHandleExt;
use mz_ore::tracing::{OpenTelemetryContext, TracingHandle};
use mz_ore::url::SensitiveUrl;
use mz_ore::vec::VecExt;
use mz_ore::{assert_none, instrument, soft_assert_or_log, soft_panic_or_log, stack};
use mz_persist_client::usage::{ShardsUsageReferenced, StorageUsageClient};
Expand All @@ -134,11 +130,13 @@ use mz_secrets::cache::CachingSecretsReader;
use mz_secrets::{SecretsController, SecretsReader};
use mz_sql::ast::{Raw, Statement};
use mz_sql::catalog::{CatalogCluster, EnvironmentId};
use mz_sql::names::{ResolvedIds, SchemaSpecifier};
use mz_sql::optimizer_metrics::OptimizerMetrics;
use mz_sql::plan::{
self, AlterSinkPlan, ConnectionDetails, CreateConnectionPlan, OnTimeoutAction, Params,
QueryWhen,
};
use mz_sql::session::user::User;
use mz_sql::session::vars::{ConnectionCounter, SystemVars};
use mz_sql_parser::ast::display::AstDisplay;
use mz_sql_parser::ast::ExplainStage;
Expand All @@ -147,6 +145,7 @@ use mz_storage_client::controller::{CollectionDescription, DataSource};
use mz_storage_types::connections::inline::{IntoInlineConnection, ReferencedConnection};
use mz_storage_types::connections::Connection as StorageConnection;
use mz_storage_types::connections::ConnectionContext;
use mz_storage_types::read_holds::ReadHold;
use mz_storage_types::sinks::S3SinkFormat;
use mz_storage_types::sources::Timeline;
use mz_timestamp_oracle::postgres_oracle::{
Expand All @@ -156,6 +155,7 @@ use mz_timestamp_oracle::WriteTimestamp;
use mz_transform::dataflow::DataflowMetainfo;
use opentelemetry::trace::TraceContextExt;
use serde::Serialize;
use thiserror::Error;
use timely::progress::{Antichain, Timestamp as _};
use tokio::runtime::Handle as TokioHandle;
use tokio::select;
Expand All @@ -178,13 +178,15 @@ use crate::coord::cluster_scheduling::SchedulingDecision;
use crate::coord::id_bundle::CollectionIdBundle;
use crate::coord::introspection::IntrospectionSubscribe;
use crate::coord::peek::PendingPeek;
use crate::coord::statement_logging::{StatementLogging, StatementLoggingId};
use crate::coord::timeline::{TimelineContext, TimelineState};
use crate::coord::timestamp_selection::{TimestampContext, TimestampDetermination};
use crate::coord::validity::PlanValidity;
use crate::error::AdapterError;
use crate::explain::insights::PlanInsightsContext;
use crate::explain::optimizer_trace::{DispatchGuard, OptimizerTrace};
use crate::metrics::Metrics;
use crate::optimize::dataflow_expiration::time_dependence;
use crate::optimize::dataflows::{
dataflow_import_id_bundle, ComputeInstanceSnapshot, DataflowBuilder,
};
Expand All @@ -195,8 +197,6 @@ use crate::util::{ClientTransmitter, ResultExt};
use crate::webhook::{WebhookAppenderInvalidator, WebhookConcurrencyLimiter};
use crate::{flags, AdapterNotice, ReadHolds};

use self::statement_logging::{StatementLogging, StatementLoggingId};

pub(crate) mod id_bundle;
pub(crate) mod in_memory_oracle;
pub(crate) mod peek;
Expand Down Expand Up @@ -743,10 +743,6 @@ pub struct CreateMaterializedViewOptimize {
/// An optional context set iff the state machine is initiated from
/// sequencing an EXPLAIN for this statement.
explain_ctx: ExplainContext,
/// Whether the timeline is [`mz_storage_types::sources::Timeline::EpochMilliseconds`].
///
/// Used to determine if it is safe to enable dataflow expiration.
is_timeline_epoch_ms: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -2587,15 +2583,8 @@ impl Coordinator {
.catalog()
.resolve_full_name(entry.name(), None)
.to_string();
let is_timeline_epoch_ms = self.get_timeline_context(*id).is_timeline_epoch_ms();
let (_optimized_plan, physical_plan, _metainfo) = self
.optimize_create_continual_task(
&ct,
*id,
self.owned_catalog(),
debug_name,
is_timeline_epoch_ms,
)
.optimize_create_continual_task(&ct, *id, self.owned_catalog(), debug_name)
.expect("builtin CT should optimize successfully");

// Determine an as of for the new continual task.
Expand Down Expand Up @@ -2638,7 +2627,6 @@ impl Coordinator {

for entry in ordered_catalog_entries {
let id = entry.id();
let is_timeline_epoch_ms = self.get_timeline_context(id).is_timeline_epoch_ms();
match entry.item() {
CatalogItem::Index(idx) => {
// Collect optimizer parameters.
Expand Down Expand Up @@ -2669,7 +2657,6 @@ impl Coordinator {
entry.name().clone(),
idx.on,
idx.keys.to_vec(),
is_timeline_epoch_ms,
);
let global_mir_plan = optimizer.optimize(index_plan)?;
let optimized_plan = global_mir_plan.df_desc().clone();
Expand All @@ -2680,7 +2667,9 @@ impl Coordinator {
(optimized_plan, global_lir_plan)
};

let (physical_plan, metainfo) = global_lir_plan.unapply();
let (mut physical_plan, metainfo) = global_lir_plan.unapply();
physical_plan.time_dependence =
time_dependence(self.catalog(), physical_plan.import_ids(), None);
let metainfo = {
// Pre-allocate a vector of transient GlobalIds for each notice.
let notice_ids = std::iter::repeat_with(|| self.allocate_transient_id())
Expand Down Expand Up @@ -2725,7 +2714,6 @@ impl Coordinator {
debug_name,
optimizer_config.clone(),
self.optimizer_metrics(),
is_timeline_epoch_ms,
force_non_monotonic,
);

Expand All @@ -2740,7 +2728,12 @@ impl Coordinator {
(optimized_plan, global_lir_plan)
};

let (physical_plan, metainfo) = global_lir_plan.unapply();
let (mut physical_plan, metainfo) = global_lir_plan.unapply();
physical_plan.time_dependence = time_dependence(
self.catalog(),
physical_plan.import_ids(),
mv.refresh_schedule.clone(),
);
let metainfo = {
// Pre-allocate a vector of transient GlobalIds for each notice.
let notice_ids = std::iter::repeat_with(|| self.allocate_transient_id())
Expand Down Expand Up @@ -2770,13 +2763,7 @@ impl Coordinator {
.resolve_full_name(entry.name(), None)
.to_string();
let (optimized_plan, physical_plan, metainfo) = self
.optimize_create_continual_task(
ct,
id,
self.owned_catalog(),
debug_name,
is_timeline_epoch_ms,
)?;
.optimize_create_continual_task(ct, id, self.owned_catalog(), debug_name)?;

let catalog = self.catalog_mut();
catalog.set_optimized_plan(id, optimized_plan);
Expand Down
6 changes: 1 addition & 5 deletions src/adapter/src/coord/introspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,7 @@ impl Coordinator {
let read_holds = self.acquire_read_holds(&id_bundle);
let as_of = read_holds.least_valid_read();

// Introspection subscribes only read from system collections, which are always in
// the `EpochMilliseconds` timeline.
let is_timeline_epoch_ms = true;

let global_mir_plan = global_mir_plan.resolve(as_of, is_timeline_epoch_ms);
let global_mir_plan = global_mir_plan.resolve(as_of);

let span = Span::current();
Ok(StageResult::Handle(mz_ore::task::spawn_blocking(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ impl Coordinator {
},
};

let is_timeline_epoch_ms = self
.validate_timeline_context(resolved_ids.0.clone())?
.is_timeline_epoch_ms();

// Construct the CatalogItem for this CT and optimize it.
let mut item = crate::continual_task::ct_item_from_plan(plan, sink_id, resolved_ids)?;
let full_name = bootstrap_catalog.resolve_full_name(&name, Some(session.conn_id()));
Expand All @@ -96,7 +92,6 @@ impl Coordinator {
sink_id,
Arc::new(bootstrap_catalog),
full_name.to_string(),
is_timeline_epoch_ms,
)?;

// Timestamp selection
Expand Down Expand Up @@ -166,7 +161,6 @@ impl Coordinator {
output_id: GlobalId,
catalog: Arc<dyn OptimizerCatalog>,
debug_name: String,
is_timeline_epoch_ms: bool,
) -> Result<
(
DataflowDescription<OptimizedMirRelationExpr>,
Expand Down Expand Up @@ -200,7 +194,6 @@ impl Coordinator {
debug_name,
optimizer_config,
self.optimizer_metrics(),
is_timeline_epoch_ms,
force_non_monotonic,
);

Expand Down
23 changes: 8 additions & 15 deletions src/adapter/src/coord/sequencer/inner/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::coord::{
use crate::error::AdapterError;
use crate::explain::explain_dataflow;
use crate::explain::optimizer_trace::OptimizerTrace;
use crate::optimize::dataflow_expiration::time_dependence;
use crate::optimize::dataflows::dataflow_import_id_bundle;
use crate::optimize::{self, Optimize};
use crate::session::Session;
Expand Down Expand Up @@ -295,7 +296,7 @@ impl Coordinator {
}: CreateIndexOptimize,
) -> Result<StageResult<Box<CreateIndexStage>>, AdapterError> {
let plan::CreateIndexPlan {
index: plan::Index { cluster_id, on, .. },
index: plan::Index { cluster_id, .. },
..
} = &plan;

Expand All @@ -321,7 +322,6 @@ impl Coordinator {
self.optimizer_metrics(),
);
let span = Span::current();
let is_timeline_epoch_ms = self.get_timeline_context(*on).is_timeline_epoch_ms();
Ok(StageResult::Handle(mz_ore::task::spawn_blocking(
|| "optimize create index",
move || {
Expand All @@ -333,7 +333,7 @@ impl Coordinator {
let _dispatch_guard = explain_ctx.dispatch_guard();

let index_plan =
optimize::index::Index::new(plan.name.clone(), plan.index.on, plan.index.keys.clone(), is_timeline_epoch_ms);
optimize::index::Index::new(plan.name.clone(), plan.index.on, plan.index.keys.clone());

// MIR ⇒ MIR optimization (global)
let global_mir_plan = optimizer.catch_unwind_optimize(index_plan)?;
Expand Down Expand Up @@ -440,26 +440,24 @@ impl Coordinator {
owner_id: *self.catalog().get_entry(&on).owner_id(),
}];

// Collect properties for `DataflowExpirationDesc`.
let transitive_upper = self.least_valid_write(&id_bundle);
let has_transitive_refresh_schedule = self.catalog.item_has_transitive_refresh_schedule(on);

// Pre-allocate a vector of transient GlobalIds for each notice.
let notice_ids = std::iter::repeat_with(|| self.allocate_transient_id())
.take(global_lir_plan.df_meta().optimizer_notices.len())
.collect::<Vec<_>>();

let transact_result = self
.catalog_transact_with_side_effects(Some(session), ops, |coord| async {
let (mut df_desc, df_meta) = global_lir_plan.unapply();
df_desc.time_dependence =
time_dependence(coord.catalog(), df_desc.import_ids(), None);

// Save plan structures.
coord
.catalog_mut()
.set_optimized_plan(exported_index_id, global_mir_plan.df_desc().clone());
coord
.catalog_mut()
.set_physical_plan(exported_index_id, global_lir_plan.df_desc().clone());

let (mut df_desc, df_meta) = global_lir_plan.unapply();
.set_physical_plan(exported_index_id, df_desc.clone());

let notice_builtin_updates_fut = coord
.process_dataflow_metainfo(df_meta, exported_index_id, session, notice_ids)
Expand All @@ -476,11 +474,6 @@ impl Coordinator {
let since = coord.least_valid_read(&read_holds);
df_desc.set_as_of(since);

df_desc.dataflow_expiration_desc.transitive_upper = Some(transitive_upper);
df_desc
.dataflow_expiration_desc
.has_transitive_refresh_schedule = has_transitive_refresh_schedule;

coord
.ship_dataflow_and_notice_builtin_table_updates(
df_desc,
Expand Down
Loading
Loading