use std::path::PathBuf;
use crate::common::counter::hardware_counter::HardwareCounterCell;
use crate::common::generic_consts::AccessPattern;
use crate::common::types::PointOffsetType;
use serde_json::Value;
use crate::segment::common::Flusher;
use crate::segment::common::operation_error::OperationResult;
use crate::segment::json_path::JsonPath;
use crate::segment::types::{IoBackend, OwnedPayloadRef, Payload};
pub trait PayloadStorageRead {
fn get(
&self,
point_offset: PointOffsetType,
hw_counter: &HardwareCounterCell,
) -> OperationResult<Payload>;
fn get_sequential(
&self,
point_offset: PointOffsetType,
hw_counter: &HardwareCounterCell,
) -> OperationResult<Payload>;
fn payload_ref(
&self,
point_offset: PointOffsetType,
hw_counter: &HardwareCounterCell,
) -> OperationResult<OwnedPayloadRef<'_>>;
fn read_payloads<P: AccessPattern, U: crate::common::universal_io::UserData>(
&self,
point_offsets: impl Iterator<Item = (U, PointOffsetType)>,
callback: impl FnMut(U, Payload) -> OperationResult<()>,
hw_counter: &HardwareCounterCell,
) -> OperationResult<()>;
fn iter<F>(&self, callback: F, hw_counter: &HardwareCounterCell) -> OperationResult<()>
where
F: FnMut(PointOffsetType, &Payload) -> OperationResult<bool>;
fn get_storage_size_bytes(&self) -> OperationResult<usize>;
fn is_on_disk(&self) -> bool;
fn io_backend(&self) -> Option<IoBackend> {
None
}
}
pub trait PayloadStorage: PayloadStorageRead {
fn overwrite(
&mut self,
point_id: PointOffsetType,
payload: &Payload,
hw_counter: &HardwareCounterCell,
) -> OperationResult<()>;
fn set(
&mut self,
point_id: PointOffsetType,
payload: &Payload,
hw_counter: &HardwareCounterCell,
) -> OperationResult<()>;
fn set_by_key(
&mut self,
point_id: PointOffsetType,
payload: &Payload,
key: &JsonPath,
hw_counter: &HardwareCounterCell,
) -> OperationResult<()>;
fn delete(
&mut self,
point_id: PointOffsetType,
key: &JsonPath,
hw_counter: &HardwareCounterCell,
) -> OperationResult<Vec<Value>>;
fn clear(
&mut self,
point_id: PointOffsetType,
hw_counter: &HardwareCounterCell,
) -> OperationResult<Option<Payload>>;
#[cfg(test)]
fn clear_all(&mut self, hw_counter: &HardwareCounterCell) -> OperationResult<()>;
fn flusher(&self) -> Flusher;
fn files(&self) -> Vec<PathBuf>;
fn immutable_files(&self) -> Vec<PathBuf> {
Vec::new()
}
}