rocketmq_store_api/capability/release_checkpoint.rs
1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use rocketmq_security_api::MaintenanceAuthorizationGrant;
16
17use crate::checkpoint::CheckpointManifest;
18use crate::checkpoint::CheckpointRequest;
19use crate::checkpoint::CheckpointRestoreVerification;
20use crate::StoreError;
21
22/// Result of attempting to create a release checkpoint.
23#[derive(Clone, Debug, Eq, PartialEq)]
24#[allow(
25 clippy::large_enum_variant,
26 reason = "the public checkpoint outcome contract requires an inline manifest payload"
27)]
28pub enum ReleaseCheckpointCreateOutcome {
29 /// The checkpoint was created successfully.
30 Created(CheckpointManifest),
31 /// The request was rejected without an operational storage failure.
32 Rejected(ReleaseCheckpointCreateRejection),
33}
34
35/// Expected rejection from release-checkpoint creation.
36#[derive(Clone, Copy, Debug, Eq, PartialEq)]
37pub enum ReleaseCheckpointCreateRejection {
38 /// The authorization grant expired before the operation began.
39 AuthorizationExpired,
40 /// The grant does not authorize release-checkpoint creation.
41 CapabilityNotGranted,
42 /// The requested checkpoint already exists.
43 AlreadyExists,
44 /// The checkpoint exceeded its authorized resource budget.
45 CapacityExceeded {
46 /// Bytes observed before the operation was rejected.
47 actual_bytes: u64,
48 /// Maximum bytes allowed for this checkpoint.
49 maximum_bytes: u64,
50 },
51}
52
53/// Result of verifying a release checkpoint for restoration.
54#[derive(Clone, Debug, Eq, PartialEq)]
55pub enum ReleaseCheckpointRestoreOutcome {
56 /// The checkpoint was verified successfully.
57 Verified(CheckpointRestoreVerification),
58 /// The request was rejected without an operational storage failure.
59 Rejected(ReleaseCheckpointRestoreRejection),
60}
61
62/// Expected rejection from release-checkpoint restore verification.
63#[derive(Clone, Copy, Debug, Eq, PartialEq)]
64pub enum ReleaseCheckpointRestoreRejection {
65 /// The authorization grant expired before the operation began.
66 AuthorizationExpired,
67 /// The grant does not authorize release-checkpoint verification.
68 CapabilityNotGranted,
69}
70
71/// Authorized, deadline-bounded Store checkpoint capability.
72///
73/// The non-forgeable [`MaintenanceAuthorizationGrant`] keeps this API separate
74/// from ordinary administrative storage operations.
75#[allow(async_fn_in_trait)]
76pub trait ReleaseCheckpointStore: Send + Sync {
77 /// Flushes the Store barrier and creates a checksummed checkpoint artifact.
78 ///
79 /// # Errors
80 ///
81 /// Returns an expected rejection for authorization, conflicts, or resource
82 /// limits. Operational failures are returned as [`StoreError`] with
83 /// [`crate::StoreOperation::Flush`].
84 async fn create_release_checkpoint(
85 &self,
86 authorization: &MaintenanceAuthorizationGrant,
87 request: CheckpointRequest,
88 ) -> Result<ReleaseCheckpointCreateOutcome, StoreError>;
89
90 /// Verifies that a checkpoint can be restored without replacing its WAL or
91 /// persistent volume identity.
92 ///
93 /// # Errors
94 ///
95 /// Returns an expected rejection for authorization decisions. Operational
96 /// verification failures are returned as [`StoreError`] with
97 /// [`crate::StoreOperation::Read`].
98 async fn restore_verify_release_checkpoint(
99 &self,
100 authorization: &MaintenanceAuthorizationGrant,
101 manifest: &CheckpointManifest,
102 ) -> Result<ReleaseCheckpointRestoreOutcome, StoreError>;
103}