Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,14 @@ jobs:
cargo test --locked --lib initialized_log_manifest_tests:: -- --test-threads=1 2>&1 | tee /tmp/native-identities.log
grep -q '^test result: ok. 10 passed' /tmp/native-identities.log
cargo test --locked --lib initialized_admission_tests:: -- --test-threads=1 2>&1 | tee /tmp/native-admission.log
grep -q '^test result: ok. 2 passed' /tmp/native-admission.log
grep -q '^test result: ok. 3 passed' /tmp/native-admission.log
- name: native binary commands and checkpoint recovery
run: |
set -euo pipefail
cargo test --locked --lib native_object_outcome_tests:: -- --test-threads=1 2>&1 | tee /tmp/native-outcomes.log
grep -q '^test result: ok. 11 passed' /tmp/native-outcomes.log
cargo test --locked --lib cluster::meta_snapshot_file::tests::native_journal:: -- --test-threads=1 2>&1 | tee /tmp/native-journal.log
grep -q '^test result: ok. 1 passed' /tmp/native-journal.log
- name: per-member initialization survives read repair and restart
run: |
set -euo pipefail
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ The **network chunk consensus** job runs identity, routing, process, recovery, c
capacity, shutdown, and metadata-health tests with the chunk consensus feature. The coupled
quorum test additionally enables metadata consensus and starts three voters for each service.

Across these jobs, the workflow explicitly names 247 individual tests. It also
Across these jobs, the workflow explicitly names 248 individual tests. It also
runs grouped library filters and integration targets.

**CI does not run the suite.** It compiles everything and runs those 247 guards plus grouped tests and integration targets. A green
**CI does not run the suite.** It compiles everything and runs those 248 guards plus grouped tests and integration targets. A green
tick means the tree builds and those guards hold; it does not mean the suite passed. Run
`tools/suite_gate.sh` yourself.

Expand Down
19 changes: 15 additions & 4 deletions docs/native-object-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ allocation positions, shared native storage across objects, overlapping staged
storage and conflicting ownership across manifest catalogs. Earlier snapshots
keep their existing representation when the feature is absent.

This is reader preparation. Feature bit 7 is not advertised or raised by startup.
Native committed outcomes, RPC admission, actual read-pin acquisition, storage
retirement, conditional object operations and default-backend routing still need
their coupled implementation. The default object backend remains unchanged.
Placement outcome version 18 carries one canonical binary protobuf native command.
It binds the leader's captured clock and consecutive metadata positions. Begin,
extend, publish, abort, expiry, read-pin and writer-lease transitions validate private
persistent-table clones before replacing live tables together. The leader checks
admission limits; followers validate the committed transition without local limits.
Legacy mutation commands refuse keys owned by staged or published native objects.

Journal recovery checks checksums, canonical encoding and contiguous positions,
skips the prefix included in its starting snapshot and applies later commands.
Normal command application continues to reject stale positions.

Feature bit 7 is not advertised or raised by startup. RPC admission, actual read-pin
acquisition, storage retirement, conditional object operations and default-backend
routing still need their coupled implementation. The default object backend remains
unchanged.
4 changes: 4 additions & 0 deletions src/cluster/chunk_catalog_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl ChunkCatalogOutcome {
}
Ok(value)
}
pub(super) fn positions(&self) -> Result<(u64, u64), ObjectError> {
let placement = self.validated_placement()?;
Ok((placement.before_index, placement.after_index))
}
pub(super) fn apply(
&self,
service: &mut MatrixMetaService,
Expand Down
2 changes: 2 additions & 0 deletions src/cluster/chunk_manifest_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(super) enum Decision {
/// objects, which a voter never applies to a committed entry.
pub(super) fn prepare(service: &MatrixMetaService, outcome: &ChunkOutcome) -> Result<Decision, ObjectError> {
reject_initialized(outcome)?;
crate::native_object_outcome::reject_legacy_write(service, &outcome.object_id()?)?;
let after = outcome.after()?.clone();
if service.chunk_catalog.check(outcome, Some(crate::object_manifest::admission_cap()))? {
Ok(Decision::Change(outcome.clone(), after))
Expand All @@ -45,6 +46,7 @@ pub(super) fn prepare(service: &MatrixMetaService, outcome: &ChunkOutcome) -> Re
/// Apply a committed outcome. Returns whether the catalog changed.
pub(super) fn apply(service: &mut MatrixMetaService, outcome: &ChunkOutcome) -> Result<bool, ObjectError> {
reject_initialized(outcome)?;
crate::native_object_outcome::reject_legacy_write(service, &outcome.object_id()?)?;
let changed = service.chunk_catalog.apply(outcome)?;
if changed {
service.invalidate_snapshot_export_cache();
Expand Down
18 changes: 18 additions & 0 deletions src/cluster/initialized_manifest_admission_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ fn old_writer_outcomes_cannot_create_initialized_objects() {
let error = change.validate(0, 1).unwrap_err().to_string();
assert!(error.contains("native writer outcomes"), "{error}");
}

#[test]
fn legacy_chunk_commands_cannot_enter_a_staged_native_namespace() {
let mut service = crate::native_object_outcome_tests::service();
let (op, now) = crate::native_object_outcome_tests::commands().remove(0);
crate::native_object_outcome::NativeObjectChange::decide(&service, op, now)
.unwrap()
.apply(&mut service)
.unwrap();
let mut manifest = fixture();
manifest.format_version = crate::chunk_manifest::CHUNK_MANIFEST_FORMAT;
manifest.initialized_log = None;
let outcome = ChunkOutcome::decide(None, manifest).unwrap();
let before = service.export_snapshot().to_bytes().unwrap();
assert!(prepare(&service, &outcome).is_err());
assert!(apply(&mut service, &outcome).is_err());
assert_eq!(service.export_snapshot().to_bytes().unwrap(), before);
}
1 change: 1 addition & 0 deletions src/cluster/meta_catalog_command_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn catalog_journal_recovers_mixed_records_and_every_torn_tail() {
log_chunk: None,
lease_batch: None,
chunk_writer: None,
native: None,
forget: false,
};
expiry.apply(&mut service).unwrap();
Expand Down
19 changes: 19 additions & 0 deletions src/cluster/meta_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,25 @@ fn prepare_with(
limit: usize,
groups: &super::ChunkGroupCatalog,
live: Option<&LeaderLiveness>,
) -> Result<(Vec<u8>, Option<MetaReply>), ObjectError> {
let result = prepare_with_inner(service, request, limit, groups, live)?;
if service
.cluster_features
.has(crate::cluster_features::FEATURE_NATIVE_OBJECT_STATE)
&& result
.0
.starts_with(crate::placement_outcome::PLACEMENT_OUTCOME_MAGIC)
{
PlacementOutcome::from_payload(&result.0)?.check_legacy_namespace(service)?;
}
Ok(result)
}
fn prepare_with_inner(
service: &mut MatrixMetaService,
request: &MetaRequest,
limit: usize,
groups: &super::ChunkGroupCatalog,
live: Option<&LeaderLiveness>,
) -> Result<(Vec<u8>, Option<MetaReply>), ObjectError> {
let stamped = if matches!(request, MetaRequest::ReportChunkNode { .. }) {
Some(super::health_report::stamp(request.clone(), service)?)
Expand Down
2 changes: 2 additions & 0 deletions src/cluster/meta_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ fn apply(
_ => None,
};
if let Some((decided, reply)) = decision {
decided.check_legacy_namespace(&guard.service)?;
if guard.storage.is_some() {
// Preflight the local snapshot bound before persisting an outcome.
let renewal_grows = decided.retention_deadline.as_ref().is_some_and(|change|
Expand Down Expand Up @@ -1104,6 +1105,7 @@ pub(super) fn decide_allocation(
log_chunk: None,
lease_batch: None,
chunk_writer: None,
native: None,
forget: false,
};
outcome.to_payload()?;
Expand Down
1 change: 1 addition & 0 deletions src/cluster/meta_snapshot_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn invalid(error: impl ToString) -> io::Error {

#[cfg(test)]
mod tests {
include!("native_outcome_journal_tests.rs");
use super::*;
use crate::object_manifest::{ManifestOutcome, ObjectManifest};

Expand Down
81 changes: 81 additions & 0 deletions src/cluster/native_outcome_journal_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 MatrixArkAI
mod native_journal {
use super::*;
use crate::native_object_outcome::NativeObjectChange;
use crate::native_object_outcome_tests::{commands, service};
#[test]
fn native_staging_and_publication_survive_actual_journal_and_snapshot_restarts() {
let directory = std::env::temp_dir().join(format!(
"native-journal-{}-{}",
std::process::id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos()
));
std::fs::create_dir(&directory).unwrap();
struct Cleanup(PathBuf);
impl Drop for Cleanup {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
let _cleanup = Cleanup(directory.clone());
let mut current = service();
let (mut store, recovered) = MetaSnapshotFile::open(&directory, &mut current).unwrap();
assert!(!recovered);
store.persist(&current, &Default::default()).unwrap();
for (op, now) in commands().into_iter().take(2) {
let decided = NativeObjectChange::decide(&current, op, now).unwrap();
store.append_outcome(&decided).unwrap();
decided.apply(&mut current).unwrap();
}
let pending = current.export_snapshot().to_bytes().unwrap();
assert!(current.chunk_catalog.is_empty());
drop(store);
let mut restarted = MatrixMetaService::new();
let (mut store, recovered) = MetaSnapshotFile::open(&directory, &mut restarted).unwrap();
assert!(recovered);
assert_eq!(restarted.export_snapshot().to_bytes().unwrap(), pending);
assert_eq!(restarted.native_objects.owned_chunks(2).count(), 1);
let (op, now) = commands().remove(2);
let decided = NativeObjectChange::decide(&restarted, op, now).unwrap();
store.append_outcome(&decided).unwrap();
decided.apply(&mut restarted).unwrap();
let published = restarted.export_snapshot().to_bytes().unwrap();
drop(store);
let mut replayed = MatrixMetaService::new();
let (store, recovered) = MetaSnapshotFile::open(&directory, &mut replayed).unwrap();
assert!(recovered);
assert_eq!(replayed.export_snapshot().to_bytes().unwrap(), published);
store.persist(&replayed, &Default::default()).unwrap();
drop(store);
let mut snapshotted = MatrixMetaService::new();
let (_store, recovered) = MetaSnapshotFile::open(&directory, &mut snapshotted).unwrap();
assert!(recovered);
assert_eq!(snapshotted.export_snapshot().to_bytes().unwrap(), published);
assert_eq!(snapshotted.native_objects.stage_count(), 0);
assert_eq!(snapshotted.chunk_catalog.len(), 1);
drop(_store);
let path = directory.join("metadata.outcomes");
let journal = std::fs::read(&path).unwrap();
let mut torn = journal.clone();
torn.push(b'M');
std::fs::write(&path, torn).unwrap();
let mut recovered = MatrixMetaService::new();
let (store, _) = MetaSnapshotFile::open(&directory, &mut recovered).unwrap();
assert_eq!(recovered.export_snapshot().to_bytes().unwrap(), published);
assert_eq!(std::fs::read(&path).unwrap(), journal);
drop(store);
let mut duplicate = journal.clone();
duplicate.extend_from_slice(&journal);
std::fs::write(&path, duplicate).unwrap();
assert!(MetaSnapshotFile::open(&directory, &mut MatrixMetaService::new()).is_err());
let mut corrupt = journal.clone();
corrupt[24] ^= 1;
std::fs::write(&path, corrupt).unwrap();
assert!(MetaSnapshotFile::open(&directory, &mut MatrixMetaService::new()).is_err());
std::fs::write(&path, journal).unwrap();
}
}
41 changes: 32 additions & 9 deletions src/cluster/placement_journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl PlacementJournal {
File::open(path.parent().unwrap())?.sync_all()?;
let length = file.metadata()?.len();
let mut offset = 0;
// A durable snapshot can include an intact prefix of this journal. Keep normal
// command application strict; only recovery skips records covered at entry.
let checkpoint = service.placement_commit_index;
let mut prior_position = None;

while offset < length {
let remaining = length - offset;
if remaining < HEADER as u64 {
Expand Down Expand Up @@ -77,16 +82,33 @@ impl PlacementJournal {
if fnv1a64(&bytes) != u64::from_be_bytes(header[16..24].try_into().unwrap()) {
return Err(invalid("placement journal checksum mismatch"));
}
if &header[..4] == MAGIC {
PlacementOutcome::from_payload(&bytes)
.map_err(invalid)?
.apply(service)
.map_err(invalid)?;
let placement = if &header[..4] == MAGIC {
Some(PlacementOutcome::from_payload(&bytes).map_err(invalid)?)
} else {
None
};
let membership = if placement.is_none() {
Some(super::chunk_catalog_outcome::ChunkCatalogOutcome::from_payload(&bytes).map_err(invalid)?)
} else {
None
};
let (before, after) = if let Some(outcome) = &placement {
(outcome.before_index, outcome.after_index)
} else {
super::chunk_catalog_outcome::ChunkCatalogOutcome::from_payload(&bytes)
.map_err(invalid)?
.apply(service, catalog)
.map_err(invalid)?;
membership.as_ref().unwrap().positions().map_err(invalid)?
};
if !(after == before || before.checked_add(1) == Some(after))
|| prior_position.is_some_and(|prior| prior != before)
{
return Err(invalid("placement journal positions are not contiguous"));
}
prior_position = Some(after);
if after > checkpoint {
if let Some(outcome) = placement {
outcome.apply(service).map_err(invalid)?;
} else {
membership.unwrap().apply(service, catalog).map_err(invalid)?;
}
}
offset += HEADER as u64 + size as u64;
}
Expand Down Expand Up @@ -209,6 +231,7 @@ mod tests {
log_chunk: None,
lease_batch: None,
chunk_writer: None,
native: None,
forget: false,
};
let second = PlacementOutcome {
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod chunk_catalog_snapshot_tests;
pub mod chunk_manifest;
pub mod initialized_log_manifest;
pub mod native_object_state;
pub mod native_object_outcome;
#[cfg(test)]
mod native_object_state_tests;
#[cfg(test)]
Expand Down Expand Up @@ -313,3 +314,6 @@ pub mod cluster;

#[cfg(test)]
mod repo_guard_tests;

#[cfg(test)]
mod native_object_outcome_tests;
Loading
Loading