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:
Ning Sun
2022-08-02 16:25:03 +08:00
committed by GitHub
parent b5fcdae01d
commit cd42f308a8
18 changed files with 88 additions and 59 deletions

View File

@@ -22,18 +22,20 @@ pub struct RegionManifest {
inner: Arc<RegionManifestInner>,
}
impl RegionManifest {
pub fn new(manifest_dir: &str, object_store: ObjectStore) -> Self {
RegionManifest {
inner: Arc::new(RegionManifestInner::new(manifest_dir, object_store)),
}
}
}
#[async_trait]
impl Manifest for RegionManifest {
type Error = Error;
type MetaAction = RegionMetaActionList;
type Metadata = RegionManifestData;
fn new(manifest_dir: &str, object_store: ObjectStore) -> Self {
RegionManifest {
inner: Arc::new(RegionManifestInner::new(manifest_dir, object_store)),
}
}
async fn update(&self, action_list: RegionMetaActionList) -> Result<ManifestVersion> {
self.inner.save(action_list).await
}

View File

@@ -5,6 +5,7 @@ mod writer;
use std::sync::Arc;
use async_trait::async_trait;
use datatypes::schema::SchemaRef;
use snafu::ensure;
use store_api::logstore::LogStore;
use store_api::manifest::Manifest;
@@ -60,6 +61,10 @@ impl<S: LogStore> Region for RegionImpl<S> {
fn snapshot(&self, _ctx: &ReadContext) -> Result<SnapshotImpl> {
Ok(self.inner.create_snapshot())
}
fn write_request(&self, schema: SchemaRef) -> Self::WriteRequest {
WriteBatch::new(schema)
}
}
/// Storage related config for region.

View File

@@ -2,7 +2,6 @@ use std::sync::Arc;
use log_store::fs::noop::NoopLogStore;
use object_store::{backend::fs::Backend, ObjectStore};
use store_api::manifest::Manifest;
use crate::background::JobPoolImpl;
use crate::engine;

View File

@@ -1,5 +1,3 @@
use store_api::storage::WriteRequest;
use crate::test_util::schema_util::{self, ColumnDef};
use crate::write_batch::WriteBatch;

View File

@@ -39,7 +39,7 @@ impl<S: LogStore> Clone for Wal<S> {
impl<S: LogStore> Wal<S> {
pub fn new(region_name: impl Into<String>, store: Arc<S>) -> Self {
let region_name = region_name.into();
let namespace = S::Namespace::new(&region_name);
let namespace = store.namespace(&region_name);
Self { namespace, store }
}
@@ -122,7 +122,7 @@ impl<S: LogStore> Wal<S> {
async fn write(&self, seq: SequenceNumber, bytes: &[u8]) -> Result<(u64, usize)> {
let ns = self.namespace.clone();
let mut e = S::Entry::new(bytes);
let mut e = self.store.entry(bytes);
e.set_id(seq);
let res = self

View File

@@ -130,17 +130,19 @@ pub struct WriteBatch {
num_rows: usize,
}
impl WriteRequest for WriteBatch {
type Error = Error;
type PutOp = PutData;
fn new(schema: SchemaRef) -> Self {
impl WriteBatch {
pub fn new(schema: SchemaRef) -> Self {
Self {
schema,
mutations: Vec::new(),
num_rows: 0,
}
}
}
impl WriteRequest for WriteBatch {
type Error = Error;
type PutOp = PutData;
fn put(&mut self, data: PutData) -> Result<()> {
if data.is_empty() {
@@ -193,6 +195,14 @@ impl WriteRequest for WriteBatch {
Ok(ranges)
}
fn put_op(&self) -> Self::PutOp {
PutData::new()
}
fn put_op_with_columns(num_columns: usize) -> Self::PutOp {
PutData::with_num_columns(num_columns)
}
}
/// Aligns timestamp to nearest time interval.
@@ -231,18 +241,20 @@ pub struct PutData {
columns: HashMap<String, VectorRef>,
}
impl PutOperation for PutData {
type Error = Error;
fn new() -> PutData {
impl PutData {
pub(crate) fn new() -> PutData {
PutData::default()
}
fn with_num_columns(num_columns: usize) -> PutData {
pub(crate) fn with_num_columns(num_columns: usize) -> PutData {
PutData {
columns: HashMap::with_capacity(num_columns),
}
}
}
impl PutOperation for PutData {
type Error = Error;
fn add_key_column(&mut self, name: &str, vector: VectorRef) -> Result<()> {
self.add_column_by_name(name, vector)
@@ -407,7 +419,7 @@ pub mod codec {
vectors::Helper,
};
use snafu::ensure;
use store_api::storage::{PutOperation, WriteRequest};
use store_api::storage::WriteRequest;
use super::{
DataCorruptionSnafu, DecodeArrowSnafu, DecodeVectorSnafu, EncodeArrowSnafu,