common_meta/key/
datanode_epoch.rs1use std::fmt::Display;
16
17use serde::{Deserialize, Serialize};
18
19use crate::DatanodeId;
20use crate::key::DATANODE_EPOCH_KEY_PREFIX;
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub struct DatanodeEpochKey {
27 pub node_id: DatanodeId,
28}
29
30impl DatanodeEpochKey {
31 pub fn new(node_id: DatanodeId) -> Self {
32 Self { node_id }
33 }
34
35 pub fn to_bytes(&self) -> Vec<u8> {
36 self.to_string().into_bytes()
37 }
38}
39
40impl Display for DatanodeEpochKey {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(f, "{}/{}", DATANODE_EPOCH_KEY_PREFIX, self.node_id)
43 }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
48pub struct DatanodeEpochValue {
49 pub node_epoch: u64,
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55 use crate::key::MetadataValue;
56
57 #[test]
58 fn test_frozen_datanode_epoch_record() {
59 let value =
60 include_bytes!("../../../../../tests/compatibility/meta/datanode_epoch/value.json");
61 assert_eq!(DatanodeEpochKey::new(7).to_bytes(), b"__datanode_epoch/7");
62 let decoded = DatanodeEpochValue::try_from_raw_value(value).unwrap();
63 assert_eq!(decoded.node_epoch, 1761091200000);
64 assert_eq!(decoded.try_as_raw_value().unwrap(), value);
65 }
66}