forked from restatedev/restate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces some helper types that will be used to configure the replicated loglet. At the moment this doesn't include any object-store related configuration as it's unclear still what configuration parameters will need to be there.
- Loading branch information
1 parent
4712c64
commit bbe0ac8
Showing
3 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
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
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,123 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH. | ||
// All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
// todo: remove when fleshed out | ||
#![allow(unused)] | ||
|
||
use std::collections::HashSet; | ||
use std::num::NonZeroU8; | ||
|
||
use serde_with::{DisplayFromStr, VecSkipError}; | ||
|
||
use crate::{GenerationalNodeId, PlainNodeId}; | ||
|
||
/// Configuration parameters of a replicated loglet segment | ||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
pub struct ReplicatedLogletParams { | ||
/// Unique identifier for this loglet | ||
loglet_id: ReplicatedLogletId, | ||
/// The sequencer node | ||
#[serde(with = "serde_with::As::<serde_with::DisplayFromStr>")] | ||
sequencer: GenerationalNodeId, | ||
/// Replication properties of this loglet | ||
replication: Replication, | ||
nodeset: NodeSet, | ||
/// The set of nodes the sequencer has been considering for writes after the last LGC advance | ||
/// If unset, the entire nodeset is considered as part of the write set | ||
/// If set, tail repair will attempt reading only from this set. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
write_set: Option<NodeSet>, | ||
} | ||
|
||
impl ReplicatedLogletParams { | ||
pub fn deserialize_from(slice: &[u8]) -> Result<Self, serde_json::Error> { | ||
serde_json::from_slice(slice) | ||
} | ||
|
||
pub fn serialize(&self) -> Result<String, serde_json::Error> { | ||
serde_json::to_string(self) | ||
} | ||
} | ||
|
||
#[derive( | ||
serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Clone, Copy, | ||
)] | ||
#[serde(transparent)] | ||
#[repr(transparent)] | ||
pub struct ReplicatedLogletId(u64); | ||
|
||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
pub struct Replication { | ||
/// The write-quorum for appends | ||
replication_factor: NonZeroU8, | ||
/// The number of extra copies (best effort) to be replicated in addition to the | ||
/// replication_factor. | ||
/// | ||
/// default is 0 | ||
#[serde(default)] | ||
extra_copies: u8, | ||
#[serde(default)] | ||
durability: DurabilityLevel, | ||
} | ||
|
||
impl Replication { | ||
pub fn read_quorum_size(&self, nodeset: &NodeSet) -> u8 { | ||
// N - replication_factor + 1 | ||
nodeset.len() - self.replication_factor.get() + 1 | ||
} | ||
} | ||
|
||
#[serde_with::serde_as] | ||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)] | ||
pub struct NodeSet(#[serde_as(as = "HashSet<DisplayFromStr>")] HashSet<PlainNodeId>); | ||
|
||
impl NodeSet { | ||
pub fn from_single(node: PlainNodeId) -> Self { | ||
let mut set = HashSet::new(); | ||
set.insert(node); | ||
Self(set) | ||
} | ||
|
||
pub fn len(&self) -> u8 { | ||
self.0 | ||
.len() | ||
.try_into() | ||
.expect("nodeset cannot exceed 255 nodes") | ||
} | ||
|
||
pub fn iter(&self) -> impl Iterator<Item = &PlainNodeId> { | ||
self.0.iter() | ||
} | ||
} | ||
|
||
/// Durability level from lowest to highest | ||
#[derive( | ||
serde::Serialize, | ||
serde::Deserialize, | ||
Debug, | ||
Clone, | ||
Copy, | ||
Ord, | ||
PartialOrd, | ||
Eq, | ||
PartialEq, | ||
Default, | ||
)] | ||
#[serde(rename_all = "kebab-case")] | ||
#[repr(u8)] | ||
pub enum DurabilityLevel { | ||
/// WAL is disabled, Commit to memory only and acknowledge | ||
Memory = 1, | ||
/// Commit to WAL but do not wait for fllesystem buffer cache to be flushed | ||
#[default] | ||
WalAsync = 2, | ||
/// Commit to WAL and only acknowledge after filesystem buffer cache flush is complete | ||
WalSync = 3, | ||
} |