-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor EngineBuilder to remove duplicate code #72
Comments
hi, chunshao90. It seems we can make #[async_trait]
pub trait EngineBuilder: Default + Send + Sync {
type Wal: WalManager + Send + Sync + 'static;
/// Build the analytic engine from `config` and `engine_runtimes`.
async fn build(
&self,
config: Config,
engine_runtimes: Arc<EngineRuntimes>,
) -> Result<TableEngineRef> {
assert!(!config.obkv_wal.enable);
match config.storage {
crate::storage_options::StorageOptions::Local(ref opts) => {
let store = open_storage_local(opts.clone()).await?;
let instance = self
.open_instance::<LocalFileSystem>(config.clone(), engine_runtimes, store)
.await?;
Ok(Arc::new(TableEngineImpl::new(instance)))
}
crate::storage_options::StorageOptions::Aliyun(ref opts) => {
let store = open_storage_aliyun(opts.clone()).await?;
let instance = self
.open_instance::<AliyunOSS>(config.clone(), engine_runtimes, store)
.await?;
Ok(Arc::new(TableEngineImpl::new(instance)))
}
}
}
async fn open_instance<Store>(
&self,
config: Config,
engine_runtimes: Arc<EngineRuntimes>,
store: Store,
) -> Result<InstanceRef<Self::Wal, ManifestImpl<Self::Wal>, Store, FactoryImpl>>
where
Store: ObjectStore;
} Is this the expected to this task? |
@ygf11 This is a good proposal but considering that more implements of these components will be provided in the future, |
Thanks for your response. I can think the usage of
pub struct Instance<Wal, Meta, Store, Fa> {
/// Space storage
space_store: Arc<SpaceStore<Wal, Meta, Store, Fa>>,
...
} The main issue is that I still do not have idea about it, what do you think? |
Vote for removing some type params (I prefer to remove all four params) either. Let's make endeavors to achieve this. trait pub trait WalManager: LogWriter + LogReader{
async fn sequence_num(&self, region_id: RegionId) -> Result<SequenceNumber>;
async fn mark_delete_entries_up_to(...) -> Result<()>;
async fn close_gracefully(&self) -> Result<()>;
}
pub trait LogWriter {
async fn write<P: Payload>(...) -> Result<SequenceNumber>;
}
pub trait LogReader {
type BatchIter: BatchLogIterator + Send;
async fn read_batch(...) -> Result<Self::BatchIter>;
}
pub trait BatchLogIterator {
async fn next_log_entries<D: PayloadDecoder + Send + 'static>(...) -> Result<VecDeque<LogEntry<D::Target>>>;
} Besides other constrains, IMO The main issue is pub trait WalManager {
// with some batching operations
async fn read_batch<D: PayloadDecoder>(..., mut buffer: VecDeque<D::Target>) -> Result<VecDeque<D::Target>>;
} |
Sorry for the late repsonse. The trait of |
@waynexia Why the pub trait WalManager {
async fn read_batch<D: PayloadDecoder>(..., buffer: &mut Vec<D::Target>) -> Result<()>;
} |
Wal records need to be consumed from the head ( Take mutable reference is ok to me 👍 |
I'm glad to work on this :D But maybe I need some time to familiar with codebase. |
Thanks! Just take this at your pace and feel free to reach out to us if anything is unclear ❤️ |
I guess no need to do |
that method won't shrink the container so the buffer is still there. But I'm afraid if we don't pop the element out we may need to copy it to get the ownership for the consumer. |
I read the docs about |
I see. So use the element under a reference and copy it if needed is the same with |
I meet some troubles. To make pub trait WalManager {
// read payload
async fn read_batch<D: PayloadDecoder>(..., mut buffer: Vec<D::Target>) -> Result<Vec<D::Target>>;
// write payload
async fn write<P: Payload>(&self, ctx: &WriteContext, batch: &LogWriteBatch<P>,) -> Result<SequenceNumber>;
} We can simply use derives to remove pub trait WalManager {
async fn read_meta_batch(..., mut buffer: ...)...
async fn read_write_batch(..., mut buffer: ...)...
async fn write_payload(&self, ctx: &WriteContext, batch: &LogWriteBatch<WritePayload>)...
async fn write_meta_payload(&self, ctx: &WriteContext, batch: &LogWriteBatch<MetaUpdatePayload>)...
} It has two drawbacks:
I think maybe we can define a trait in pub trait WalManagerWraper {
async fn read_meta_batch(..., mut buffer: ...)...
async fn read_write_batch(..., mut buffer: ...)...
async fn write_payload(&self, ctx: &WriteContext, batch: &LogWriteBatch<WritePayload>)...
async fn write_meta_payload(&self, ctx: &WriteContext, batch: &LogWriteBatch<MetaUpdatePayload>)...
}
// rocks version
pub struct RocksWalManagerWrapper {
inner: RocksImpl,
}
impl WalManagerWraper for RocksWalManagerWrapper {
...
} |
This is doable but enumerating all possible implementations is not a good way in my perspective. I've not considered the object safety problem before. I come up with another way to remove those type parameters:
pub trait WalManager {
// write payload
async fn write(&self, ctx: &WriteContext, batch: &dyn Payload) -> Result<SequenceNumber>;
}
Please tell me what you think about this @ygf11 @ShiKaiWi A side note, changing |
@waynexia Thanks. Your idea is the right direction. For write, we need also make pub trait Payload: Send + Sync + Debug {
type Error: std::error::Error + Send + Sync + 'static;
/// Compute size of the encoded payload.
fn encode_size(&self) -> usize;
/// Append the encoded payload to the `buf`.
fn encode_to<B: MemBufMut>(&self, buf: &mut B) -> Result<(), Self::Error>;
} Shall we replace |
It's ok to do so 👍 |
Description
Refactor EngineBuilder to remove duplicate code
Proposal
code:
https://github.com/CeresDB/ceresdb/blob/890fecf10848a3d09b485af52ff516deccf771fc/analytic_engine/src/setup.rs#L92
https://github.com/CeresDB/ceresdb/blob/890fecf10848a3d09b485af52ff516deccf771fc/analytic_engine/src/setup.rs#L120
https://github.com/CeresDB/ceresdb/blob/890fecf10848a3d09b485af52ff516deccf771fc/analytic_engine/src/setup.rs#L155
Additional context
The text was updated successfully, but these errors were encountered: