-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datastore: changes to match changes in Core kit datastore
Updated the `commit_transaction` function to enable committing metadata from pending transactions. In commit transaction we will first commit metadata and then pending keys to correctly perform the check to identify if key exists or not. The strength handling among pending and committed transaction is as: If pending metadata is strong and committed metadata is weak, commit the pending setting. If pending metadata is weak, committed metadata is strong and the setting is already available, do not downgrade from strong to weak. Otherwise add the strength file with value as weak. If pending and committed metadata are the same, no action is performed. Additionally, made minor changes to metadata functions for improved access and flexibility: Introduced a `committed` field to dynamically access metadata in pending transactions. Replaced the hardcoded use of live committed metadata with this committed variable ans pass Committed::Live from previous usages. Refer commit: bottlerocket-os/bottlerocket-core-kit@20a435e Refer PR: bottlerocket-os/bottlerocket-core-kit#294
- Loading branch information
Showing
7 changed files
with
400 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! The outcome of the constraint check determines whether the transaction can proceed to commit. | ||
//! A ‘rejected’ result means that one or more constraints have not been satisfied, | ||
//! preventing the transaction from being committed. On the other hand, an ‘approved’ | ||
//! result confirms that all constraints are satisfied and provides the required | ||
//! settings and metadata for the commit. | ||
//! Constraint checks can alter the write. | ||
use std::collections::HashMap; | ||
|
||
use crate::{error, Key}; | ||
|
||
type RejectReason = String; | ||
|
||
/// Represents a successful write operation after constraints have been approved. | ||
/// Contains the following fields: | ||
/// - `settings`: A collection of key-value pairs representing the settings to be committed. | ||
/// - `metadata`: A collection of metadata entries. | ||
#[derive(PartialEq)] | ||
pub struct ApprovedWrite { | ||
pub settings: HashMap<Key, String>, | ||
pub metadata: Vec<(Key, Key, String)>, | ||
} | ||
|
||
/// Represents the result of a constraint check. | ||
/// The result can either reject the operation or approve it with the required data. | ||
#[derive(PartialEq)] | ||
pub enum ConstraintCheckResult { | ||
Reject(RejectReason), | ||
Approve(ApprovedWrite), | ||
} | ||
|
||
impl TryFrom<ConstraintCheckResult> for ApprovedWrite { | ||
type Error = error::Error; | ||
|
||
fn try_from(constraint_check_result: ConstraintCheckResult) -> Result<Self, Self::Error> { | ||
match constraint_check_result { | ||
ConstraintCheckResult::Reject(err) => error::ConstraintCheckRejectSnafu { err }.fail(), | ||
ConstraintCheckResult::Approve(approved_write) => Ok(approved_write), | ||
} | ||
} | ||
} | ||
|
||
impl From<Option<ApprovedWrite>> for ConstraintCheckResult { | ||
fn from(approved_write: Option<ApprovedWrite>) -> Self { | ||
match approved_write { | ||
None => ConstraintCheckResult::Reject( | ||
"The write for the given transaction is rejected".to_string(), | ||
), | ||
Some(approved_write) => ConstraintCheckResult::Approve(approved_write), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.