mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-22 07:50:38 +00:00
refactor: remove constructors from trait (#121)
* refactor: remove constructors from trait * refactor: move PutOp into its parent type * refactor: move put constructor to write request * refactor: change visibility of PutData constructors call from WriteRequest instead * refactor: consistent naming for entry constructor * refactor: fix constructor form Namespace trait * refactor: remove comment code * doc: fix doc comments
This commit is contained in:
@@ -25,28 +25,36 @@ pub trait LogStore: Send + Sync + 'static + std::fmt::Debug {
|
||||
mut e: Self::Entry,
|
||||
) -> Result<Self::AppendResponse, Self::Error>;
|
||||
|
||||
// Append a batch of entries atomically and return the offset of first entry.
|
||||
/// Append a batch of entries atomically and return the offset of first entry.
|
||||
async fn append_batch(
|
||||
&self,
|
||||
ns: &Self::Namespace,
|
||||
e: Vec<Self::Entry>,
|
||||
) -> Result<Id, Self::Error>;
|
||||
|
||||
// Create a new `EntryStream` to asynchronously generates `Entry` with ids starting from `id`.
|
||||
/// Create a new `EntryStream` to asynchronously generates `Entry` with ids
|
||||
/// starting from `id`.
|
||||
async fn read(
|
||||
&self,
|
||||
ns: &Self::Namespace,
|
||||
id: Id,
|
||||
) -> Result<SendableEntryStream<Self::Entry, Self::Error>, Self::Error>;
|
||||
|
||||
// Create a new `Namespace`.
|
||||
/// Create a new `Namespace`.
|
||||
async fn create_namespace(&mut self, ns: &Self::Namespace) -> Result<(), Self::Error>;
|
||||
|
||||
// Delete an existing `Namespace` with given ref.
|
||||
/// Delete an existing `Namespace` with given ref.
|
||||
async fn delete_namespace(&mut self, ns: &Self::Namespace) -> Result<(), Self::Error>;
|
||||
|
||||
// List all existing namespaces.
|
||||
/// List all existing namespaces.
|
||||
async fn list_namespaces(&self) -> Result<Vec<Self::Namespace>, Self::Error>;
|
||||
|
||||
/// Create an entry of the associate Entry type
|
||||
fn entry<D: AsRef<[u8]>>(&self, data: D) -> Self::Entry;
|
||||
|
||||
/// Create a namespace of the associate Namespace type
|
||||
// TODO(sunng87): confusion with `create_namespace`
|
||||
fn namespace(&self, name: &str) -> Self::Namespace;
|
||||
}
|
||||
|
||||
pub trait AppendResponse: Send + Sync {
|
||||
|
||||
@@ -8,9 +8,6 @@ pub type Id = u64;
|
||||
/// Entry is the minimal data storage unit in `LogStore`.
|
||||
pub trait Entry: Encode + Send + Sync {
|
||||
type Error: ErrorExt + Send + Sync;
|
||||
|
||||
fn new(data: impl AsRef<[u8]>) -> Self;
|
||||
|
||||
/// Return contained data of entry.
|
||||
fn data(&self) -> &[u8];
|
||||
|
||||
|
||||
@@ -71,14 +71,6 @@ mod tests {
|
||||
impl Entry for SimpleEntry {
|
||||
type Error = Error;
|
||||
|
||||
fn new(data: impl AsRef<[u8]>) -> Self {
|
||||
Self {
|
||||
data: data.as_ref().to_vec(),
|
||||
offset: 0,
|
||||
epoch: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn data(&self) -> &[u8] {
|
||||
&self.data
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
pub trait Namespace: Send + Sync + Clone + std::fmt::Debug {
|
||||
fn new(name: &str) -> Self;
|
||||
|
||||
fn name(&self) -> &str;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ mod storage;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use common_error::ext::ErrorExt;
|
||||
use object_store::ObjectStore;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
pub use crate::manifest::storage::*;
|
||||
@@ -26,8 +25,6 @@ pub trait Manifest: Send + Sync + Clone + 'static {
|
||||
type MetaAction: MetaAction;
|
||||
type Metadata: Metadata;
|
||||
|
||||
fn new(manifest_dir: &str, object_store: ObjectStore) -> Self;
|
||||
|
||||
/// Update metadata by the action
|
||||
async fn update(&self, action: Self::MetaAction) -> Result<ManifestVersion, Self::Error>;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
use async_trait::async_trait;
|
||||
use common_error::ext::ErrorExt;
|
||||
use datatypes::schema::SchemaRef;
|
||||
|
||||
use crate::storage::engine::OpenOptions;
|
||||
use crate::storage::metadata::RegionMeta;
|
||||
@@ -50,6 +51,9 @@ pub trait Region: Send + Sync + Clone + std::fmt::Debug + 'static {
|
||||
|
||||
/// Create a snapshot for read.
|
||||
fn snapshot(&self, ctx: &ReadContext) -> Result<Self::Snapshot, Self::Error>;
|
||||
|
||||
/// Create write request
|
||||
fn write_request(&self, schema: SchemaRef) -> Self::WriteRequest;
|
||||
}
|
||||
|
||||
/// Context for write operations.
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::time::Duration;
|
||||
|
||||
use common_error::ext::ErrorExt;
|
||||
use common_time::RangeMillis;
|
||||
use datatypes::schema::SchemaRef;
|
||||
use datatypes::vectors::VectorRef;
|
||||
|
||||
use crate::storage::SequenceNumber;
|
||||
@@ -12,24 +11,22 @@ pub trait WriteRequest: Send {
|
||||
type Error: ErrorExt + Send + Sync;
|
||||
type PutOp: PutOperation;
|
||||
|
||||
fn new(schema: SchemaRef) -> Self;
|
||||
|
||||
fn put(&mut self, put: Self::PutOp) -> Result<(), Self::Error>;
|
||||
|
||||
/// Returns all possible time ranges that contain the timestamp in this batch.
|
||||
///
|
||||
/// Each time range is aligned to given `duration`.
|
||||
fn time_ranges(&self, duration: Duration) -> Result<Vec<RangeMillis>, Self::Error>;
|
||||
|
||||
fn put_op(&self) -> Self::PutOp;
|
||||
|
||||
fn put_op_with_columns(num_columns: usize) -> Self::PutOp;
|
||||
}
|
||||
|
||||
/// Put multiple rows.
|
||||
pub trait PutOperation: Send {
|
||||
type Error: ErrorExt + Send + Sync;
|
||||
|
||||
fn new() -> Self;
|
||||
|
||||
fn with_num_columns(num_columns: usize) -> Self;
|
||||
|
||||
fn add_key_column(&mut self, name: &str, vector: VectorRef) -> Result<(), Self::Error>;
|
||||
|
||||
fn add_version_column(&mut self, vector: VectorRef) -> Result<(), Self::Error>;
|
||||
|
||||
Reference in New Issue
Block a user