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
351 changes: 351 additions & 0 deletions src/cluster/features_commands.rs

Large diffs are not rendered by default.

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 @@ -154,6 +154,7 @@ fn catalog_journal_recovers_mixed_records_and_every_torn_tail() {
read_session_removal: None,
manifest_append: None,
reserved: None,
features: None,
};
expiry.apply(&mut service).unwrap();
let (second, _) = prepare_at(&mut service, &groups, &report(2), 65536, 110).unwrap();
Expand Down
19 changes: 19 additions & 0 deletions src/cluster/meta_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,25 @@ impl RemoteMetaClient {
reply => Err(unexpected_reply("metadata membership", &reply)),
}
}
/// The cluster feature set as committed.
pub fn read_cluster_features(&mut self) -> Result<crate::cluster_features::ClusterFeatures, ObjectError> {
self.feature_call(super::FeaturesRequest::read())
}
/// Record the feature bits `voter` reads. A repeat of what is already recorded changes nothing.
pub fn declare_voter_features(&mut self, voter: u64, bits: u64) -> Result<crate::cluster_features::ClusterFeatures, ObjectError> {
self.feature_call(super::FeaturesRequest::declare(voter, bits))
}
/// Raise `bits`. Refused unless every voter in `voters` (the whole membership, ascending) has
/// declared every one of them.
pub fn raise_cluster_features(&mut self, bits: u64, voters: Vec<u64>) -> Result<crate::cluster_features::ClusterFeatures, ObjectError> {
self.feature_call(super::FeaturesRequest::raise(bits, voters))
}
fn feature_call(&mut self, request: super::FeaturesRequest) -> Result<crate::cluster_features::ClusterFeatures, ObjectError> {
match self.call(MetaRequest::Features(request))? {
MetaReply::Features(table) => table.to_features(),
other => Err(unexpected_reply("a cluster feature set", &other)),
}
}
/// Describe this voter without leader routing or a read barrier.
pub fn metadata_group_identity(&mut self) -> Result<super::MetaGroupIdentity, ObjectError> {
match self.call_one(&MetaRequest::GroupIdentity).into_result()? {
Expand Down
13 changes: 13 additions & 0 deletions src/cluster/meta_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ fn read_only(request: &MetaRequest) -> bool {
MetaRequest::StagedAllocation(command) => command.is_read(),
MetaRequest::ManifestRetention(command) => command.is_read(),
MetaRequest::Membership(command) => command.is_read(),
MetaRequest::Features(command) => command.is_read(),
MetaRequest::ReadManifest { .. }
| MetaRequest::ReadManifestRoutes { .. }
| MetaRequest::ReadManifestRoutesWide { .. }
Expand Down Expand Up @@ -1147,6 +1148,18 @@ fn prepare(
let (outcome, reply) = super::manifest_copy_commands::prepare(service, groups, command, limit)?;
return Ok((outcome.to_payload()?, Some(reply)));
}
if let MetaRequest::Features(command) = request {
if !command.is_read() {
return Ok(match super::features_commands::prepare(service, command)? {
Some(outcome) => {
let after = outcome.features.as_ref().and_then(|change| change.after.clone())
.ok_or_else(|| ObjectError::Corruption("feature outcome lacks its result".into()))?;
(outcome.to_payload()?, Some(MetaReply::Features(after)))
}
None => (Vec::new(), Some(super::features_commands::reply(&service.cluster_features))),
});
}
}
if let MetaRequest::StagedAllocation(command) = request {
if !command.is_read() {
let (outcome, reply) = super::staged_allocation_commands::prepare(service, groups, command, limit)?;
Expand Down
14 changes: 14 additions & 0 deletions src/cluster/meta_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub fn object_id(bucket: &str, key: &str) -> ObjectId {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MetaRequest {
CopyManifest(crate::manifest_copy::ManifestCopyRequest),
Features(super::features_commands::FeaturesRequest),
PlanAppendRoutes(super::append_plan::AppendPlanRequest),
StagedAllocation(crate::staged_allocation::StagedAllocationRequest),
ManifestRetention(crate::manifest_retention::ManifestRetentionRequest),
Expand Down Expand Up @@ -331,6 +332,7 @@ impl MetaRequest {
MetaRequest::ManifestRetention(_) => MetaRequestCode::ManifestRetention,
MetaRequest::StagedAllocation(_) => MetaRequestCode::StagedAllocation,
MetaRequest::CopyManifest(_) => MetaRequestCode::CopyManifest,
MetaRequest::Features(_) => MetaRequestCode::Features,
MetaRequest::PlanAppendRoutes(_) => MetaRequestCode::PlanAppendRoutes,
MetaRequest::GroupIdentity => MetaRequestCode::GroupIdentity,
MetaRequest::HeartbeatRootNode { .. } => MetaRequestCode::HeartbeatRootNode,
Expand Down Expand Up @@ -407,6 +409,7 @@ impl MetaRequest {
MetaRequest::ManifestRetention(request) => return request.encode_to_vec(),
MetaRequest::StagedAllocation(request) => return request.encode_to_vec(),
MetaRequest::CopyManifest(request) => return request.encode_to_vec(),
MetaRequest::Features(request) => return request.encode_to_vec(),
MetaRequest::PlanAppendRoutes(request) => return request.encode_to_vec(),
MetaRequest::GroupIdentity => {}
MetaRequest::CommitObjectPlacementIfCurrent {
Expand Down Expand Up @@ -559,6 +562,9 @@ impl MetaRequest {
if code == MetaRequestCode::CopyManifest {
return crate::manifest_copy::ManifestCopyRequest::from_payload(payload).map(Self::CopyManifest);
}
if code == MetaRequestCode::Features {
return super::features_commands::FeaturesRequest::from_payload(payload).map(Self::Features);
}
if code == MetaRequestCode::ListChunkRoutes {
let request = super::chunk_group_route::RoutePageRead::from_payload(payload)?;
return Ok(Self::ListChunkRoutes { after: request.after, limit: request.limit });
Expand Down Expand Up @@ -692,6 +698,7 @@ impl MetaRequest {
| MetaRequestCode::ManifestRetention
| MetaRequestCode::StagedAllocation
| MetaRequestCode::CopyManifest
| MetaRequestCode::Features
| MetaRequestCode::PlanAppendRoutes
| MetaRequestCode::ReportChunkNode
| MetaRequestCode::AllocateObjectPages
Expand Down Expand Up @@ -859,6 +866,7 @@ fn validate_manifest_route_payload(
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MetaReply {
StagedAllocation(crate::staged_allocation::StagedAllocationReply),
Features(crate::placement_outcome::FeatureTable),
AppendPlan(super::append_plan::AppendPlanReply),
ManifestRetention(crate::manifest_retention::ManifestRetentionReply),
Manifests(crate::object_manifest::ManifestListPage),
Expand Down Expand Up @@ -923,6 +931,7 @@ impl MetaReply {
Self::Manifests(page) => page.encoded_len(),
Self::ManifestRetention(reply) => reply.encoded_len(),
Self::StagedAllocation(reply) => reply.encoded_len(),
Self::Features(reply) => reply.encoded_len(),
Self::AppendPlan(reply) => reply.encoded_len(),
Self::PlacementNode(node) => node_payload_len(
&node.node_id,
Expand Down Expand Up @@ -987,6 +996,7 @@ impl MetaReply {
MetaReply::Manifests(page) => return page.encode_to_vec(),
MetaReply::ManifestRetention(reply) => return reply.encode_to_vec(),
MetaReply::StagedAllocation(reply) => return reply.encode_to_vec(),
MetaReply::Features(reply) => return reply.encode_to_vec(),
MetaReply::AppendPlan(reply) => return reply.encode_to_vec(),
MetaReply::PlacementNode(node) => put_node(&mut out, node),
MetaReply::RootNodes(nodes) => {
Expand Down Expand Up @@ -1184,6 +1194,9 @@ impl MetaReply {
if code == MetaRequestCode::StagedAllocation {
return crate::staged_allocation::StagedAllocationReply::from_payload(payload).map(Self::StagedAllocation);
}
if code == MetaRequestCode::Features {
return super::features_commands::reply_from_payload(payload).map(Self::Features);
}
if code == MetaRequestCode::ListChunkRoutes {
return super::chunk_group_route::RoutePage::from_payload(payload)
.map(Self::ChunkRoutePage);
Expand Down Expand Up @@ -1226,6 +1239,7 @@ impl MetaReply {
| MetaRequestCode::ManifestRetention
| MetaRequestCode::StagedAllocation
| MetaRequestCode::CopyManifest
| MetaRequestCode::Features
| MetaRequestCode::PlanAppendRoutes
| MetaRequestCode::GroupIdentity => unreachable!(),
MetaRequestCode::ChunkCatalog
Expand Down
24 changes: 24 additions & 0 deletions src/cluster/meta_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,14 @@ fn apply(
let decision = match &request {
MetaRequest::CopyManifest(command) => Some(super::manifest_copy_commands::prepare(
&guard.service, &guard.groups, command, max_payload_bytes)?),
MetaRequest::Features(command) if !command.is_read() => match super::features_commands::prepare(&guard.service, command)? {
Some(outcome) => {
let after = outcome.features.as_ref().and_then(|change| change.after.clone())
.ok_or_else(|| ObjectError::Corruption("feature outcome lacks its result".into()))?;
Some((outcome, MetaReply::Features(after)))
}
None => return Ok(super::features_commands::reply(&guard.service.cluster_features)),
},
MetaRequest::StagedAllocation(command) if !command.is_read() => {
if guard.storage.is_none() {
return Err(ObjectError::PreconditionFailed("staged allocation requires durable metadata storage".into()));
Expand Down Expand Up @@ -1050,6 +1058,7 @@ pub(super) fn decide_allocation(
read_session_removal: None,
manifest_append: None,
reserved: None,
features: None,
};
outcome.to_payload()?;
Ok((outcome, reply))
Expand Down Expand Up @@ -1143,6 +1152,19 @@ pub(super) fn apply_with_groups(
outcome.apply(service)?;
return Ok(reply);
}
if let MetaRequest::Features(command) = &request {
if !command.is_read() {
return match super::features_commands::prepare(service, command)? {
Some(outcome) => {
let after = outcome.features.as_ref().and_then(|change| change.after.clone())
.ok_or_else(|| ObjectError::Corruption("feature outcome lacks its result".into()))?;
outcome.apply(service)?;
Ok(MetaReply::Features(after))
}
None => Ok(super::features_commands::reply(&service.cluster_features)),
};
}
}
if let MetaRequest::StagedAllocation(command) = &request {
if !command.is_read() {
let (outcome, reply) = super::staged_allocation_commands::prepare(service, groups, command, limit)?;
Expand Down Expand Up @@ -1363,6 +1385,8 @@ pub(super) fn apply_to_meta(
) -> Result<MetaReply, ObjectError> {
match request {
MetaRequest::CopyManifest(_) => Err(ObjectError::InvalidArgument("atomic copy requires catalog dispatch".into())),
MetaRequest::Features(command) if command.is_read() => super::features_commands::read(guard, &command),
MetaRequest::Features(_) => Err(ObjectError::InvalidArgument("feature changes require catalog dispatch".into())),
MetaRequest::StagedAllocation(command) => super::staged_allocation_commands::read(guard, &command, max_payload_bytes),
MetaRequest::ManifestRetention(command) => {
command.validate()?;
Expand Down
4 changes: 4 additions & 0 deletions src/cluster/meta_wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub enum MetaRequestCode {
StagedAllocation = 93,
CopyManifest = 94,
PlanAppendRoutes = 95,
/// Declare, raise or read the cluster feature set.
Features = 96,
}

impl MetaRequestCode {
Expand Down Expand Up @@ -151,6 +153,7 @@ impl MetaRequestCode {
93 => Some(MetaRequestCode::StagedAllocation),
94 => Some(MetaRequestCode::CopyManifest),
95 => Some(MetaRequestCode::PlanAppendRoutes),
96 => Some(MetaRequestCode::Features),
_ => None,
}
}
Expand Down Expand Up @@ -190,6 +193,7 @@ impl MetaRequestCode {
MetaRequestCode::StagedAllocation,
MetaRequestCode::CopyManifest,
MetaRequestCode::PlanAppendRoutes,
MetaRequestCode::Features,
]
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ mod staged_allocation_commands;
#[cfg(feature = "meta-server")]
mod staged_lease_sweeper;
#[cfg(feature = "meta-server")]
mod features_commands;
#[cfg(feature = "meta-server")]
pub use features_commands::FeaturesRequest;
#[cfg(feature = "meta-server")]
pub use meta_identity::MetaGroupIdentity;

pub use message::{ChunkGroupIdentity, ReplicaReply, ReplicaRequest};
Expand Down
1 change: 1 addition & 0 deletions src/cluster/placement_journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ mod tests {
read_session_removal: None,
manifest_append: None,
reserved: None,
features: None,
};
let second = PlacementOutcome {
before_index: base + 1,
Expand Down
Loading
Loading