test(mito2): cover the row-sequence proof of flush and compaction outputs

Covers flush keeping or stamping the allocator's numbers, compaction
keeping them only when every input does, a region edit dropping the proof,
a staging-manifest import keeping it, and a region copy clearing it.

Also lets the purger delete a retired compaction output first, fixing a
delete race in the publication test.

Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
discord9
2026-12-02 22:45:52 +08:00
parent 1b487ed210
commit c74c3b5a06
13 changed files with 876 additions and 53 deletions
+62 -1
View File
@@ -54,7 +54,7 @@ use crate::access_layer::{AccessLayer, Metrics, OperationType, SstWriteRequest,
use crate::cache::{CacheManager, CacheStrategy};
use crate::error::InvalidMultiRegionCompactionSnafu;
use crate::read::FlatSource;
use crate::sst::file::{FileHandle, RegionFileId};
use crate::sst::file::{FileHandle, RegionFileId, RowSequenceProvenance};
use crate::sst::file_purger::NoopFilePurger;
use crate::sst::index::CompletedEntry;
use crate::sst::index::handler::{
@@ -2203,6 +2203,65 @@ async fn test_zero_versions_follow_trust_and_legacy_override(#[case] trusted: bo
assert!(fixture.layer.object_store().exists(&path).await.unwrap());
}
/// Neither a creator-local input whose own numbers are unproved nor a foreign input
/// re-based at a target barrier lets an output state `Original`, even when every
/// input is effective-target trusted.
#[tokio::test]
async fn test_unproved_inputs_never_state_original_row_sequences() {
let fixture = Fixture::new(PrimaryKeyEncoding::Dense, FormatType::Flat, 7).await;
let mut plan = fixture.plan(2);
for target in plan.targets.values_mut() {
for input in target.inputs.values_mut() {
input.preserve_row_sequence = true;
}
}
let output = fixture.compact(plan).await;
for (id, files) in &output.files {
for file in files {
assert_eq!(None, file.row_sequence_provenance);
assert!(
!file.has_original_row_sequences(),
"target {id} stated original row sequences without proof"
);
}
}
}
/// A target-owned source that proves its own numbers lets the target's output state
/// `Original`, and the reader keeps those numbers.
#[tokio::test]
async fn test_proved_target_owned_source_states_original_row_sequences() {
let mut fixture = Fixture::new(PrimaryKeyEncoding::Dense, FormatType::Flat, 7).await;
fixture.source.row_sequence_provenance = Some(RowSequenceProvenance::Original);
let mut plan = fixture.plan(1);
for target in plan.targets.values_mut() {
for input in target.inputs.values_mut() {
input.preserve_row_sequence = true;
}
}
let target = plan.targets[&RegionId::new(1, 0)].clone();
let output = fixture.compact(plan).await;
let files = &output.files[&RegionId::new(1, 0)];
assert!(!files.is_empty());
let mut rows = Vec::new();
for file in files {
assert!(
file.has_original_row_sequences(),
"a proved target-owned source lets its output state original row sequences"
);
rows.extend(
fixture
.read_published_output_rows(file.clone(), target.metadata.clone())
.await,
);
}
assert_eq!(124, rows.len());
assert!(
rows.iter().all(|row| row.2 == 7),
"the stated numbers are the ones the bytes carry"
);
}
struct ObserveOnlineOutput {
protection: Arc<Protection>,
counters: Arc<SourceCounters>,
@@ -2884,6 +2943,7 @@ async fn test_target_writer_sizes_row_groups_from_source_size() {
plan.max_output_file_size,
(64, 256 << 20),
Arc::default(),
false,
);
assert_eq!(32, writer.options().row_group_size);
}
@@ -2937,6 +2997,7 @@ async fn test_limited_writer_fails_instead_of_returning_over_budget_output(
plan.max_output_file_size,
(0, 0),
Arc::default(),
false,
)
.write(source)
.await
@@ -449,6 +449,118 @@ async fn test_apply_staging_manifest_sequence_domain_with_format(
}
}
/// A repartition publishes the source's files by reference, so the holder states the numbering of
/// the region that allocated it, before and after a reopen.
#[tokio::test]
async fn test_apply_staging_manifest_keeps_the_creator_row_sequence_proof() {
let mut env = TestEnv::with_prefix("apply-staging-row-sequence-proof").await;
let engine = env
.create_engine(MitoConfig {
schedule_compaction_after_edit: false,
..Default::default()
})
.await;
let source = RegionId::new(1, 1);
let target = RegionId::new(1, 2);
let request = CreateRequestBuilder::new()
.insert_option("append_mode", "true")
.insert_option("preserve_row_sequence", "true")
.build();
let schema = rows_schema(&request);
engine
.handle_request(source, RegionRequest::Create(request.clone()))
.await
.unwrap();
put_rows(
&engine,
source,
Rows {
schema,
rows: build_rows_for_key("0", 0, 5, 0),
},
)
.await;
engine
.handle_request(source, RegionRequest::Flush(RegionFlushRequest::default()))
.await
.unwrap();
let source_file = engine.get_region(source).unwrap().version().ssts.levels()[0]
.files()
.next()
.expect("the preserving flush writes one file")
.meta_ref()
.clone();
assert!(source_file.has_original_row_sequences());
engine
.set_region_role_state_gracefully(source, SettableRegionRoleState::StagingLeader)
.await
.unwrap();
let partition_expr = col("field_0").lt(Value::from(100.0)).as_json_str().unwrap();
let remapped = engine
.remap_manifests(RemapManifestsRequest {
validate_only: false,
region_id: source,
input_regions: vec![source],
region_mapping: [(source, vec![target])].into_iter().collect(),
new_partition_exprs: [(target, partition_expr.clone())].into_iter().collect(),
})
.await
.unwrap();
engine
.handle_request(target, RegionRequest::Create(request.clone()))
.await
.unwrap();
engine
.handle_request(
target,
RegionRequest::EnterStaging(EnterStagingRequest {
partition_directive: StagingPartitionDirective::UpdatePartitionExpr(
partition_expr.clone(),
),
}),
)
.await
.unwrap();
engine
.handle_request(
target,
RegionRequest::ApplyStagingManifest(ApplyStagingManifestRequest {
partition_expr,
central_region_id: source,
manifest_path: remapped.manifest_paths[&target].clone(),
}),
)
.await
.unwrap();
let installed = engine.get_region(target).unwrap().version();
let imported = installed.ssts.levels()[0].files[&source_file.file_id].meta_ref();
assert_eq!(source, imported.region_id);
assert_eq!(
source_file.row_sequence_provenance, imported.row_sequence_provenance,
"the holder references the creator's object, so it states the creator's own proof"
);
assert!(imported.has_original_row_sequences());
reopen_region(
&engine,
target,
request.table_dir.clone(),
false,
request.options.clone(),
)
.await;
let reopened = engine.get_region(target).unwrap();
let manifest = reopened.manifest_ctx.manifest().await;
assert_eq!(
source_file.row_sequence_provenance,
manifest.files[&source_file.file_id].row_sequence_provenance,
"the proof is persisted, so a reopen states the creator's own proof"
);
assert!(manifest.files[&source_file.file_id].has_original_row_sequences());
}
fn current_file_ids(engine: &crate::engine::MitoEngine, region_id: RegionId) -> HashSet<FileId> {
engine
.get_region(region_id)
+80
View File
@@ -426,6 +426,86 @@ async fn test_compaction_preserves_flush_sequences_across_generations(
assert_eq!(expected, read_sequences(&engine, region_id).await);
}
/// A flush whose encoder keeps the memtable's own numbers proves them; one that
/// stamps a uniform sequence does not, and a merge inherits only proved inputs.
#[rstest::rstest]
#[case(false)]
#[case(true)]
#[tokio::test]
async fn test_flush_and_compaction_row_sequence_provenance(#[case] preserve_row_sequence: bool) {
let mut env = TestEnv::new().await;
let engine = env
.create_engine(MitoConfig {
min_compaction_interval: Duration::from_secs(3600),
..Default::default()
})
.await;
let region_id = RegionId::new(1, 1);
let request = CreateRequestBuilder::new()
.insert_option("append_mode", "true")
.insert_option("preserve_row_sequence", &preserve_row_sequence.to_string())
.insert_option("compaction.type", "twcs")
.insert_option("compaction.twcs.time_window", "1h")
.build();
let columns = crate::test_util::rows_schema(&request);
engine
.handle_request(region_id, RegionRequest::Create(request))
.await
.unwrap();
for start in [0, 10] {
put_rows(
&engine,
region_id,
Rows {
schema: columns.clone(),
rows: build_rows_for_key("a", start, start + 2, 0),
},
)
.await;
flush(&engine, region_id).await;
}
let version = engine.get_region(region_id).unwrap().version();
let flushed: Vec<_> = version.ssts.levels()[0].files().collect();
assert_eq!(2, flushed.len());
assert!(
flushed
.iter()
.all(|file| file.meta_ref().has_original_row_sequences() == preserve_row_sequence)
);
engine
.handle_request(
region_id,
RegionRequest::Compact(RegionCompactRequest {
options: api::v1::region::compact_request::Options::StrictWindow(
api::v1::region::StrictWindow {
window_seconds: 3600,
},
),
..Default::default()
}),
)
.await
.unwrap();
let version = engine.get_region(region_id).unwrap().version();
let merged: Vec<_> = version
.ssts
.levels()
.iter()
.flat_map(|level| level.files())
.collect();
assert_eq!(
1,
merged.len(),
"the strict window must merge both flushed files"
);
assert_eq!(
preserve_row_sequence,
merged[0].meta_ref().has_original_row_sequences()
);
}
#[tokio::test]
async fn test_partial_compaction_preserves_delete_order_flat() {
assert_partial_compaction_preserves_delete_order(true).await;
@@ -252,6 +252,208 @@ async fn test_copy_shared_reference_contract(
);
}
/// A physical copy relabels the bytes under a new creator, so the target inherits no proof of the
/// numbers inside them: the copy states nothing about the numbering it carries.
#[tokio::test]
async fn test_copy_region_from_drops_the_row_sequence_proof() {
use crate::test_util::{build_rows_for_key, flush_region};
let mut env = TestEnv::with_prefix("copy-region-row-sequence-proof").await;
let engine = env
.create_engine(MitoConfig {
schedule_compaction_after_edit: false,
..Default::default()
})
.await;
let source_id = RegionId::new(1, 1);
let target_id = RegionId::new(1, 2);
let request = CreateRequestBuilder::new()
.insert_option("append_mode", "true")
.insert_option("preserve_row_sequence", "true")
.build();
let schema = rows_schema(&request);
for id in [source_id, target_id] {
engine
.handle_request(id, RegionRequest::Create(request.clone()))
.await
.unwrap();
}
put_rows(
&engine,
source_id,
Rows {
schema,
rows: build_rows_for_key("0", 0, 3, 0),
},
)
.await;
flush_region(&engine, source_id, None).await;
let source_file = engine
.get_region(source_id)
.unwrap()
.version()
.ssts
.levels()[0]
.files()
.next()
.expect("the preserving flush writes one file")
.meta_ref()
.clone();
assert!(source_file.has_original_row_sequences());
let copied = engine
.copy_region_from(
target_id,
MitoCopyRegionFromRequest {
source_region_id: source_id,
parallelism: 1,
},
)
.await
.unwrap();
assert_eq!(vec![source_file.file_id], copied.copied_file_ids);
let target = engine.get_region(target_id).unwrap();
let installed = target.version();
let copy = installed.ssts.levels()[0].files[&source_file.file_id].meta_ref();
assert_eq!(target_id, copy.region_id);
assert_eq!(None, copy.row_sequence_provenance);
assert!(!copy.has_original_row_sequences());
let manifest = target.manifest_ctx.manifest().await;
assert_eq!(
None,
manifest.files[&source_file.file_id].row_sequence_provenance
);
}
/// A copy keeps the source's `FileId` but names itself the creator. Re-importing the source's own
/// `(source, file_id)` metadata is an add-only edit whose slot already holds the copy's
/// `(target, file_id)` handle: admission looks the slot up, misses on the creator, and drops the
/// caller's proof, so the slot must end up naming the creator the manifest commits.
#[tokio::test]
async fn test_reimport_of_copied_file_id_replaces_the_copy_handle() {
use crate::manifest::action::RegionEdit;
use crate::sst::file::RegionFileId;
use crate::test_util::{build_rows_for_key, flush_region};
let mut env = TestEnv::with_prefix("copy-region-reimport").await;
let engine = env
.create_engine(MitoConfig {
schedule_compaction_after_edit: false,
..Default::default()
})
.await;
let source_id = RegionId::new(1, 1);
let target_id = RegionId::new(1, 2);
let request = CreateRequestBuilder::new()
.insert_option("append_mode", "true")
.insert_option("preserve_row_sequence", "true")
.build_with_index();
let schema = rows_schema(&request);
for id in [source_id, target_id] {
engine
.handle_request(id, RegionRequest::Create(request.clone()))
.await
.unwrap();
}
put_rows(
&engine,
source_id,
Rows {
schema,
rows: build_rows_for_key("0", 0, 3, 0),
},
)
.await;
flush_region(&engine, source_id, None).await;
let source_file = engine
.get_region(source_id)
.unwrap()
.version()
.ssts
.levels()[0]
.files()
.next()
.expect("the flush writes one file")
.meta_ref()
.clone();
assert!(source_file.has_original_row_sequences());
// The copy carries the source's index, so the slot refresh for an up-to-date index must not
// keep the copied handle.
assert!(source_file.exists_index());
engine
.copy_region_from(
target_id,
MitoCopyRegionFromRequest {
source_region_id: source_id,
parallelism: 1,
},
)
.await
.unwrap();
let target = engine.get_region(target_id).unwrap();
let copy = target.version().ssts.levels()[0].files[&source_file.file_id]
.meta_ref()
.clone();
assert_eq!(target_id, copy.region_id);
assert_eq!(None, copy.row_sequence_provenance);
// The admission lookup runs and misses on the creator, so the incoming `(source, file_id)`
// replaces the copy's `(target, file_id)` handle.
engine
.edit_region(
target_id,
RegionEdit {
files_to_add: vec![source_file.clone()],
..Default::default()
},
)
.await
.unwrap();
let target = engine.get_region(target_id).unwrap();
let version = target.version();
for level in version.ssts.levels() {
if let Some(handle) = level.files.get(&source_file.file_id) {
assert_eq!(
RegionFileId::new(source_id, source_file.file_id),
handle.file_id(),
"the copy's handle must leave its slot instead of staying under another creator"
);
}
}
assert_eq!(
source_id,
version.ssts.levels()[0].files[&source_file.file_id].region_id()
);
let manifest = target.manifest_ctx.manifest().await;
assert_eq!(
source_id, manifest.files[&source_file.file_id].region_id,
"the re-imported creator is what the manifest commits"
);
// The inverse order is handled the same way: re-installing the copy's own metadata takes the
// slot back, so the version never names a creator the manifest does not.
engine
.edit_region(
target_id,
RegionEdit {
files_to_add: vec![copy.clone()],
..Default::default()
},
)
.await
.unwrap();
let target = engine.get_region(target_id).unwrap();
assert_eq!(
target_id,
target.version().ssts.levels()[0].files[&source_file.file_id].region_id()
);
let manifest = target.manifest_ctx.manifest().await;
assert_eq!(target_id, manifest.files[&source_file.file_id].region_id);
}
#[tokio::test]
async fn test_engine_copy_region_from() {
common_telemetry::init_default_ut_logging();
+141 -1
View File
@@ -42,7 +42,7 @@ use crate::region::{MitoRegionRef, RegionLeaderState, RegionRoleState};
use crate::request::{RegionEditRequest, WorkerRequest};
use crate::sst::file::{ColumnIndexMetadata, FileMeta, IndexType};
use crate::sst::location;
use crate::test_util::{CreateRequestBuilder, TestEnv, build_rows, rows_schema};
use crate::test_util::{CreateRequestBuilder, TestEnv, build_rows, put_rows, rows_schema};
use crate::time_provider::mock::MockTimeProvider;
#[tokio::test]
@@ -964,6 +964,146 @@ async fn test_region_edit_clears_preserve_row_sequence() {
assert_eq!(Some(1), file.meta_ref().sequence.map(|s| s.get()));
}
#[tokio::test]
async fn test_region_edit_clears_row_sequence_provenance() {
use crate::sst::file::RowSequenceProvenance;
let mut env = TestEnv::new().await;
let (engine, _) = create_engine_with_request_listener(&mut env).await;
let region_id = RegionId::new(1, 1);
engine
.handle_request(
region_id,
RegionRequest::Create(CreateRequestBuilder::new().build()),
)
.await
.unwrap();
let region = engine.get_region(region_id).unwrap();
let file_id = FileId::random();
let mut edit = test_region_edit(region.region_id, file_id);
// The caller claims the file carries this region's allocator numbers...
edit.files_to_add[0].row_sequence_provenance = Some(RowSequenceProvenance::Original);
engine.edit_region(region.region_id, edit).await.unwrap();
// ...but a generic region edit installs an object this region never saw, so the claim is
// dropped from the version and from the manifest a reopen rebuilds it from.
let version = region.version();
let file = version.ssts.levels()[0]
.files
.iter()
.find(|(id, _)| **id == file_id)
.unwrap()
.1;
assert_eq!(None, file.meta_ref().row_sequence_provenance);
assert!(!file.meta_ref().has_original_row_sequences());
let manifest = region.manifest_ctx.manifest().await;
assert_eq!(
None, manifest.files[&file_id].row_sequence_provenance,
"the persisted metadata must agree with the version"
);
}
/// A region's own indexed, proved L0 file re-imported through the external edit API. The proof is
/// a statement about bytes this region already shows, so re-admission keeps it rather than taking
/// the cleared copy the caller sent.
#[tokio::test]
async fn test_reimport_of_own_l0_meta_keeps_the_visible_proof() {
use crate::sst::file::RowSequenceProvenance;
use crate::test_util::{build_rows_for_key, flush_region, reopen_region};
let mut env = TestEnv::new().await;
let engine = env
.create_engine(MitoConfig {
schedule_compaction_after_edit: false,
..Default::default()
})
.await;
let region_id = RegionId::new(1, 1);
let request = CreateRequestBuilder::new()
.insert_option("append_mode", "true")
.insert_option("preserve_row_sequence", "true")
.build_with_index();
let schema = rows_schema(&request);
let table_dir = request.table_dir.clone();
let options = request.options.clone();
engine
.handle_request(region_id, RegionRequest::Create(request))
.await
.unwrap();
put_rows(
&engine,
region_id,
Rows {
schema,
rows: build_rows_for_key("a", 0, 3, 0),
},
)
.await;
flush_region(&engine, region_id, None).await;
let region = engine.get_region(region_id).unwrap();
let before = region.version().ssts.levels()[0]
.files()
.next()
.expect("the flush writes one file")
.clone();
let own_meta = before.meta_ref().clone();
assert!(own_meta.has_original_row_sequences());
assert!(own_meta.exists_index());
assert!(!own_meta.dedup_marker_trusted);
let mut resubmitted = own_meta.clone();
resubmitted.row_sequence_provenance = None;
engine
.edit_region(
region_id,
RegionEdit {
files_to_add: vec![resubmitted.clone()],
..Default::default()
},
)
.await
.unwrap();
let version = region.version();
let after = &version.ssts.levels()[0].files[&resubmitted.file_id];
assert_eq!(
Some(RowSequenceProvenance::Original),
after.meta_ref().row_sequence_provenance,
"the visible object keeps the proof it already states"
);
assert!(after.meta_ref().has_original_row_sequences());
assert_eq!(before.index_id(), after.index_id());
assert_eq!(
before.meta_ref().index_version,
after.meta_ref().index_version
);
let manifest = region.manifest_ctx.manifest().await;
assert_eq!(
Some(RowSequenceProvenance::Original),
manifest.files[&resubmitted.file_id].row_sequence_provenance,
"the caller states nothing about the bytes the region already shows"
);
reopen_region(&engine, region_id, table_dir, false, options).await;
let reopened = engine.get_region(region_id).unwrap();
let manifest = reopened.manifest_ctx.manifest().await;
assert_eq!(
Some(RowSequenceProvenance::Original),
manifest.files[&resubmitted.file_id].row_sequence_provenance,
"a reopen rebuilds the version from this manifest, so the proof survives"
);
assert_eq!(
Some(RowSequenceProvenance::Original),
reopened.version().ssts.levels()[0].files[&resubmitted.file_id]
.meta_ref()
.row_sequence_provenance
);
}
async fn wait_until_region_is_in_editing(region: &MitoRegionRef) {
tokio::time::timeout(Duration::from_secs(3), async {
while region.state() != RegionRoleState::Leader(RegionLeaderState::Editing) {
+123
View File
@@ -2186,6 +2186,129 @@ async fn test_bulk_flush_keeps_newer_version(#[values(false, true)] delete_newer
assert_eq!(expected, scan_bulk_test_keys(&engine, region_id).await);
}
/// A preserving bulk memtable that flush uploads as one pre-encoded part proves the numbers its
/// rows were assigned: the encoded part holds the memtable's own numbers, and the file the flush
/// publishes states that its bytes carry them, before and after a reopen.
#[tokio::test]
async fn test_bulk_encoded_flush_proves_row_sequences() {
use crate::sst::file::RowSequenceProvenance;
let mut env = TestEnv::new().await;
let config = MitoConfig {
default_flat_format: true,
min_compaction_interval: Duration::from_secs(3600),
..Default::default()
};
let engine = env.create_engine(config.clone()).await;
let region_id = RegionId::new(1, 1);
let request = CreateRequestBuilder::new()
.insert_option("append_mode", "true")
.insert_option("preserve_row_sequence", "true")
.insert_option("sst_format", "flat")
.insert_option("memtable.type", "bulk")
.insert_option("memtable.bulk.merge_threshold", "2")
.insert_option("memtable.bulk.encode_row_threshold", "1")
.insert_option("compaction.type", "twcs")
.insert_option("compaction.twcs.time_window", "1h")
.build();
let schema = rows_schema(&request);
engine
.handle_request(region_id, RegionRequest::Create(request.clone()))
.await
.unwrap();
// Each write is larger than the unordered-part threshold, so both parts merge into one
// pre-encoded part instead of staying in the unsorted tail.
for start in [0, 1024] {
put_rows(
&engine,
region_id,
Rows {
schema: schema.clone(),
rows: build_rows_for_key("a", start, start + 1024, 0),
},
)
.await;
}
compact_bulk_memtables(&engine, region_id);
let encoded = {
let version = engine.get_region(region_id).unwrap().version();
let mut ranges = Vec::new();
for memtable in version.memtables.list_memtables() {
ranges.extend(
memtable
.ranges(None, RangesOptions::for_flush())
.unwrap()
.ranges
.into_values(),
);
}
assert_eq!(1, ranges.len(), "the two parts must merge into one");
ranges[0]
.encoded()
.expect("the merged part must be encoded, so flush uploads it byte-for-byte")
};
flush_region(&engine, region_id, None).await;
let region = engine.get_region(region_id).unwrap();
let file = {
let version = region.version();
let files: Vec<_> = version.ssts.levels()[0].files().collect();
assert_eq!(1, files.len());
files[0].meta_ref().clone()
};
// The option alone marks the file. Only the proof below says its bytes agree.
assert!(file.preserve_row_sequence);
assert!(
file.has_original_row_sequences(),
"the uploaded part keeps the allocator's numbers, so the file must state them: {:?}",
file.row_sequence_provenance
);
assert_eq!(
Some(RowSequenceProvenance::Original),
file.row_sequence_provenance
);
let uploaded = region
.access_layer
.object_store()
.read(&file.file_path(region.table_dir(), region.path_type()))
.await
.unwrap()
.to_bytes();
// The test writes a parquet table, so the encoded part is parquet bytes. `EncodedData`
// gained a Narthex variant that is neither `PartialEq` nor `Debug`, so the comparison
// names the parquet bytes instead of comparing the enum.
let crate::memtable::EncodedData::Parquet(encoded_bytes) = encoded.data else {
panic!("a parquet table must flush a parquet part, not a Narthex one");
};
assert_eq!(
encoded_bytes, uploaded,
"the flush must upload the encoded part byte-for-byte"
);
let engine = env.reopen_engine(engine, config).await;
reopen_region(
&engine,
region_id,
request.table_dir,
false,
request.options,
)
.await;
let manifest = engine
.get_region(region_id)
.unwrap()
.manifest_ctx
.manifest()
.await;
assert_eq!(
Some(RowSequenceProvenance::Original),
manifest.files[&file.file_id].row_sequence_provenance,
"the proof is persisted, so a reopen rebuilds it"
);
}
#[rstest]
#[tokio::test]
async fn test_bulk_last_non_null_merge_and_flush(#[values(false, true)] encoded: bool) {
+20 -6
View File
@@ -310,17 +310,31 @@ async fn test_duplicate_publication_and_later_replacement_do_not_readmit_inputs(
region
.version_control
.apply_edit(Some(edit), &[], region.file_purger.clone());
let store = region.access_layer.object_store();
let path = location::sst_file_path(
region.access_layer.table_dir(),
output.file_id(),
region.path_type(),
);
region
.access_layer
.object_store()
.delete(&path)
.await
.unwrap();
// `apply_edit` drops the retired version, whose purger deletes this same
// object concurrently, so whichever delete runs second sees it absent.
if let Err(err) = store.delete(&path).await {
assert_eq!(
object_store::ErrorKind::NotFound,
err.kind(),
"unexpected error deleting the retired output {path}: {err:?}"
);
}
let replacement_path = location::sst_file_path(
region.access_layer.table_dir(),
replacement.file_id(),
region.path_type(),
);
assert!(!store.exists(&path).await.unwrap(), "{path} still exists");
assert!(
store.exists(&replacement_path).await.unwrap(),
"{replacement_path} is missing"
);
// Neither the removed file nor the new file with its proof omitted matches a replay.
for retry_output in [output.clone(), replacement.clone()] {
assert_eq!(
+3 -33
View File
@@ -17,7 +17,7 @@ use serde_json::json;
use crate::manifest::action::{
RegionCheckpoint, RegionManifest, RegionMetaAction, RegionMetaActionList,
};
use crate::sst::file::{FileMeta, RowSequenceProvenance};
use crate::sst::file::FileMeta;
const EDIT: &str =
include_str!("../../../../../tests/compatibility/manifest/table_compaction/legacy-edit.json");
@@ -126,7 +126,8 @@ fn test_file_meta_row_sequence_provenance_is_optional() {
let RegionMetaAction::Edit(edit) = &actions.actions[0] else {
panic!("expected edit");
};
// Files written before the statement read as unproved and stay byte-identical.
// A manifest that predates the statement still decodes, and re-encoding
// does not invent the field.
let legacy = &edit.files_to_add[0];
assert!(legacy.row_sequence_provenance.is_none());
assert!(!legacy.has_original_row_sequences());
@@ -136,37 +137,6 @@ fn test_file_meta_row_sequence_provenance_is_optional() {
.get("row_sequence_provenance")
.is_none()
);
let original = FileMeta {
row_sequence_provenance: Some(RowSequenceProvenance::original(
legacy.region_id,
legacy.file_id,
)),
..legacy.clone()
};
assert!(original.has_original_row_sequences());
let encoded = serde_json::to_value(&original).unwrap();
assert_eq!(
json!(format!(
"original:{}/{}",
legacy.region_id.as_u64(),
legacy.file_id
)),
encoded["row_sequence_provenance"]
);
assert_eq!(
original,
serde_json::from_value::<FileMeta>(encoded).unwrap()
);
// An unrecognized fact from a newer producer is unproved rather than unreadable.
let mut unknown = serde_json::to_value(&original).unwrap();
unknown["row_sequence_provenance"] = json!("rewritten:1/2");
assert!(
!serde_json::from_value::<FileMeta>(unknown)
.unwrap()
.has_original_row_sequences()
);
}
#[rstest::rstest]
@@ -0,0 +1,8 @@
name = "row_sequence_provenance_old_manifest"
reason = "Verify that a manifest written by an old binary, which cannot carry the FileMeta row_sequence_provenance field, reopens on a binary that has the field for reads, flush, and compaction."
introduced_by = "PR #10822"
topologies = ["distributed", "standalone"]
from_range = ["*"]
to_range = [">=v1.4.0-alpha.0"]
features = ["table", "metadata", "sst", "flush", "compaction"]
owner = "storage"
@@ -0,0 +1,21 @@
CREATE TABLE rs_provenance_table (
host STRING PRIMARY KEY,
ts TIMESTAMP TIME INDEX,
val BIGINT
) ENGINE=mito;
INSERT INTO rs_provenance_table VALUES
('a', 1000, 10),
('a', 2000, 20),
('b', 3000, 30);
ADMIN FLUSH_TABLE('rs_provenance_table');
INSERT INTO rs_provenance_table VALUES
('b', 4000, 40),
('c', 5000, 50),
('c', 6000, 60);
ADMIN FLUSH_TABLE('rs_provenance_table');
ADMIN COMPACT_TABLE('rs_provenance_table');
@@ -0,0 +1,76 @@
SELECT ts, host, val FROM rs_provenance_table ORDER BY ts;
+---------------------+------+-----+
| ts | host | val |
+---------------------+------+-----+
| 1970-01-01T00:00:01 | a | 10 |
| 1970-01-01T00:00:02 | a | 20 |
| 1970-01-01T00:00:03 | b | 30 |
| 1970-01-01T00:00:04 | b | 40 |
| 1970-01-01T00:00:05 | c | 50 |
| 1970-01-01T00:00:06 | c | 60 |
+---------------------+------+-----+
SELECT count(*) AS total FROM rs_provenance_table;
+-------+
| total |
+-------+
| 6 |
+-------+
INSERT INTO rs_provenance_table VALUES ('d', 7000, 70), ('d', 8000, 80);
Affected Rows: 2
ADMIN FLUSH_TABLE('rs_provenance_table');
+------------------------------------------+
| ADMIN FLUSH_TABLE('rs_provenance_table') |
+------------------------------------------+
| 0 |
+------------------------------------------+
ADMIN COMPACT_TABLE('rs_provenance_table');
+--------------------------------------------+
| ADMIN COMPACT_TABLE('rs_provenance_table') |
+--------------------------------------------+
| 0 |
+--------------------------------------------+
-- SQLNESS ARG restart=true
SELECT ts, host, val FROM rs_provenance_table ORDER BY ts;
+---------------------+------+-----+
| ts | host | val |
+---------------------+------+-----+
| 1970-01-01T00:00:01 | a | 10 |
| 1970-01-01T00:00:02 | a | 20 |
| 1970-01-01T00:00:03 | b | 30 |
| 1970-01-01T00:00:04 | b | 40 |
| 1970-01-01T00:00:05 | c | 50 |
| 1970-01-01T00:00:06 | c | 60 |
| 1970-01-01T00:00:07 | d | 70 |
| 1970-01-01T00:00:08 | d | 80 |
+---------------------+------+-----+
INSERT INTO rs_provenance_table VALUES ('e', 9000, 90);
Affected Rows: 1
SELECT ts, host, val FROM rs_provenance_table ORDER BY ts;
+---------------------+------+-----+
| ts | host | val |
+---------------------+------+-----+
| 1970-01-01T00:00:01 | a | 10 |
| 1970-01-01T00:00:02 | a | 20 |
| 1970-01-01T00:00:03 | b | 30 |
| 1970-01-01T00:00:04 | b | 40 |
| 1970-01-01T00:00:05 | c | 50 |
| 1970-01-01T00:00:06 | c | 60 |
| 1970-01-01T00:00:07 | d | 70 |
| 1970-01-01T00:00:08 | d | 80 |
| 1970-01-01T00:00:09 | e | 90 |
+---------------------+------+-----+
@@ -0,0 +1,16 @@
SELECT ts, host, val FROM rs_provenance_table ORDER BY ts;
SELECT count(*) AS total FROM rs_provenance_table;
INSERT INTO rs_provenance_table VALUES ('d', 7000, 70), ('d', 8000, 80);
ADMIN FLUSH_TABLE('rs_provenance_table');
ADMIN COMPACT_TABLE('rs_provenance_table');
-- SQLNESS ARG restart=true
SELECT ts, host, val FROM rs_provenance_table ORDER BY ts;
INSERT INTO rs_provenance_table VALUES ('e', 9000, 90);
SELECT ts, host, val FROM rs_provenance_table ORDER BY ts;
@@ -38,17 +38,17 @@ migration; this version does not resume that prototype's Prepare/Commit protocol
## Optional file facts
`FileMeta` may carry facts that only a producer can prove. Each is optional, is
omitted from the manifest when unproved, and never reaches back into an older
binary's behavior: an older reader ignores the key.
`FileMeta` may carry facts that only a producer can prove. Each is optional and
is omitted from the manifest when unproved.
`row_sequence_provenance` states that a Parquet SST's physical `__sequence`
column keeps the numbers its own region's allocator assigned. Its persisted form
names the file it was proved for (`original:<region_id>/<file_id>`), so a copy,
an adoption, or any other re-labeling of the bytes is unproved. Missing, legacy,
and unrecognized values are all unproved - absence never means "not original" -
and it is independent of the target-effective `preserve_row_sequence` marker,
which says nothing about the encoded bytes.
`row_sequence_provenance` describes a Parquet SST's physical `__sequence`
column. `original` states that the file keeps its own region's allocator numbers;
`substituted_up_to` states that only numbers above a cut are known to be original.
The statement is per-file metadata, and admission clears it on copy and external
edit. A missing value is unproved - absence never means "not
original" - and the statement is independent of the target-effective
`preserve_row_sequence` marker, which says nothing about the encoded bytes.
`cargo nextest run -p mito2 -E 'test(manifest::tests::compatibility)'` covers the
legacy fixture read, the omitted-field re-encoding and an unknown value.
The fixture is a hand-authored schema fixture, not evidence about a released
binary. The test only establishes that a manifest without this new optional field
still decodes and that re-encoding does not invent it.