#![allow(dead_code)]
pub mod simple;
use std::collections::HashSet;
use std::vec::Vec;
use std::time::SystemTime;
use crate::messages::CommitBatchRequest;
#[derive(Debug, Hash, PartialEq, Eq, Clone, Default)]
pub struct TopicIdPartition(pub String, pub Vec<u8>);
#[derive(Debug, Default, Clone)]
pub enum TimestampType {
#[default]
Dummy,
}
#[derive(Debug)]
pub struct CreateTopicAndPartitionsRequest {
pub topic_id: uuid::Uuid,
pub topic_name: String,
pub num_partitions: u32,
}
#[derive(Debug)]
pub struct CommitBatchResponse {
pub errors: Vec<String>, pub assigned_base_offset: u64,
pub log_append_time: u64,
pub log_start_offset: u64,
pub is_duplicate: bool,
pub request: CommitBatchRequest,
}
#[derive(Debug)]
pub struct FindBatchRequest {
pub topic_id_partition: TopicIdPartition,
pub offset: u64,
pub max_partition_fetch_bytes: u32,
}
#[derive(Debug, Clone)]
pub struct FindBatchResponse {
pub errors: Vec<String>, pub batches: Vec<BatchInfo>,
pub log_start_offset: u64,
pub high_watermark: u64,
}
#[derive(Debug, Clone)]
pub struct BatchInfo {
pub batch_id: u64,
pub object_key: String,
pub metadata: BatchMetadata,
}
#[derive(Debug, Default, Clone)]
pub struct BatchMetadata {
pub topic_id_partition: TopicIdPartition,
pub byte_offset: u64,
pub byte_size: u32,
pub base_offset: u64,
pub last_offset: u64,
pub log_append_timestamp: u64,
pub batch_max_timestamp: u64,
pub timestamp_type: TimestampType,
pub producer_id: u64,
pub producer_epoch: i16,
pub base_sequence: u32,
pub last_sequence: u32,
}
#[derive(Debug)]
pub struct ListOffsetsRequest {
pub topic_id_partition: TopicIdPartition,
pub timestamp: u64,
}
#[derive(Debug)]
pub struct ListOffsetsResponse {
pub errors: Vec<String>, pub topic_id_partition: TopicIdPartition,
pub timestamp: u64,
pub offset: u64,
}
#[derive(Debug)]
pub struct DeleteRecordsRequest {
pub topic_id_partition: TopicIdPartition,
pub offset: u64,
}
#[derive(Debug)]
pub struct DeleteRecordsResponse {
pub errors: Vec<String>, pub low_watermark: u64,
}
#[derive(Debug)]
pub struct FileToDelete {
pub object_key: String,
pub marked_for_deletion_at: SystemTime,
}
#[derive(Debug)]
pub struct DeleteFilesRequest {
pub object_key_paths: HashSet<String>,
}
#[async_trait::async_trait]
pub trait CreateTopicAndPartitions {
async fn create_topic_and_partitions(&self, requests: HashSet<CreateTopicAndPartitionsRequest>);
}
#[async_trait::async_trait]
pub trait CommitFile
where
Self: Send + Sync + std::fmt::Debug,
{
async fn commit_file(
&self,
object_key: [u8; 16],
uploader_broker_id: u32,
file_size: u64,
batches: Vec<CommitBatchRequest>,
) -> Vec<CommitBatchResponse>;
}
#[async_trait::async_trait]
pub trait FindBatches
where
Self: Send + Sync + std::fmt::Debug,
{
async fn find_batches(
&self,
find_batch_requests: Vec<FindBatchRequest>,
fetch_max_bytes: u32,
) -> Vec<FindBatchResponse>;
}
#[async_trait::async_trait]
pub trait DeleteFiles
where
Self: Send + Sync + std::fmt::Debug,
{
async fn delete_records(
&self,
requests: Vec<DeleteRecordsRequest>,
) -> Vec<DeleteRecordsResponse>;
async fn delete_topics(&self, topic_ids: HashSet<String>);
async fn get_files_to_delete(&self) -> Vec<FileToDelete>;
async fn delete_files(&self, request: DeleteFilesRequest);
async fn is_safe_to_delete_file(&self, object_key: String) -> bool;
}