reifydb_core/interface/catalog/
ringbuffer.rs1use reifydb_type::value::Value;
5use serde::{Deserialize, Serialize};
6
7use crate::interface::catalog::{
8 column::Column,
9 id::{NamespaceId, RingBufferId},
10 key::PrimaryKey,
11};
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct RingBuffer {
15 pub id: RingBufferId,
16 pub namespace: NamespaceId,
17 pub name: String,
18 pub columns: Vec<Column>,
19 pub capacity: u64,
20 pub primary_key: Option<PrimaryKey>,
21 pub partition_by: Vec<String>,
22 pub underlying: bool,
23}
24
25impl RingBuffer {
26 pub fn name(&self) -> &str {
27 &self.name
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32pub struct RingBufferMetadata {
33 pub id: RingBufferId,
34 pub capacity: u64,
35 pub count: u64,
36 pub head: u64, pub tail: u64, }
39
40#[derive(Debug, Clone, PartialEq)]
41pub struct PartitionedMetadata {
42 pub metadata: RingBufferMetadata,
43 pub partition_values: Vec<Value>,
44}
45
46impl RingBufferMetadata {
47 pub fn new(buffer_id: RingBufferId, capacity: u64) -> Self {
48 Self {
49 id: buffer_id,
50 capacity,
51 count: 0,
52 head: 1,
53 tail: 1,
54 }
55 }
56
57 pub fn is_full(&self) -> bool {
58 self.count >= self.capacity
59 }
60
61 pub fn is_empty(&self) -> bool {
62 self.count == 0
63 }
64}