-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add LSM timeline support with timeline layout management for old and new table versions #395
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
dbb89ef
82030a9
82da83a
555d9b0
988fa21
3fadc99
f7ef1af
ad2062a
46cf94a
c4494fd
0a3eefe
ab41315
4f2eded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
use crate::config::table::HudiTableConfig::{TableVersion, TimelineLayoutVersion}; | ||
use crate::config::HudiConfigs; | ||
use crate::error::CoreError; | ||
use crate::storage::Storage; | ||
use crate::timeline::loader::TimelineLoader; | ||
use crate::timeline::Timeline; | ||
use crate::Result; | ||
use std::sync::Arc; | ||
|
||
pub struct TimelineBuilder { | ||
hudi_configs: Arc<HudiConfigs>, | ||
storage: Arc<Storage>, | ||
} | ||
|
||
impl TimelineBuilder { | ||
pub fn new(hudi_configs: Arc<HudiConfigs>, storage: Arc<Storage>) -> Self { | ||
Self { | ||
hudi_configs, | ||
storage, | ||
} | ||
} | ||
|
||
pub async fn build(self) -> Result<Timeline> { | ||
let (active_loader, archived_loader) = self.resolve_loader_config()?; | ||
let timeline = Timeline::new( | ||
self.hudi_configs, | ||
self.storage, | ||
active_loader, | ||
archived_loader, | ||
); | ||
Ok(timeline) | ||
} | ||
|
||
fn resolve_loader_config(&self) -> Result<(TimelineLoader, Option<TimelineLoader>)> { | ||
let table_version = match self.hudi_configs.get(TableVersion) { | ||
Ok(v) => v.to::<isize>(), | ||
Err(_) => { | ||
return Ok(( | ||
TimelineLoader::LayoutOneActive(self.storage.clone()), | ||
Some(TimelineLoader::LayoutOneArchived(self.storage.clone())), | ||
)) | ||
} | ||
}; | ||
|
||
let layout_version = self | ||
.hudi_configs | ||
.try_get(TimelineLayoutVersion) | ||
.map(|v| v.to::<isize>()) | ||
.unwrap_or_else(|| if table_version == 8 { 2 } else { 1 }); | ||
|
||
match layout_version { | ||
1 => { | ||
if !(5..=8).contains(&table_version) { | ||
xushiyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return Err(CoreError::Unsupported(format!( | ||
"Unsupported table version {} with timeline layout version {}", | ||
table_version, layout_version | ||
))); | ||
} | ||
Ok(( | ||
TimelineLoader::LayoutOneActive(self.storage.clone()), | ||
Some(TimelineLoader::LayoutOneArchived(self.storage.clone())), | ||
)) | ||
} | ||
2 => { | ||
if table_version != 8 { | ||
return Err(CoreError::Unsupported(format!( | ||
"Unsupported table version {} with timeline layout version {}", | ||
table_version, layout_version | ||
))); | ||
} | ||
Ok(( | ||
TimelineLoader::LayoutTwoActive(self.storage.clone()), | ||
Some(TimelineLoader::LayoutTwoCompacted(self.storage.clone())), | ||
)) | ||
} | ||
_ => Err(CoreError::Unsupported(format!( | ||
"Unsupported timeline layout version: {}", | ||
layout_version | ||
))), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
use crate::error::CoreError; | ||
use crate::metadata::HUDI_METADATA_DIR; | ||
use crate::storage::Storage; | ||
use crate::timeline::instant::Instant; | ||
use crate::timeline::lsm_tree::LSM_TIMELINE_DIR; | ||
use crate::timeline::selector::TimelineSelector; | ||
use crate::Result; | ||
use log::debug; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum TimelineLoader { | ||
LayoutOneActive(Arc<Storage>), | ||
LayoutOneArchived(Arc<Storage>), | ||
LayoutTwoActive(Arc<Storage>), | ||
LayoutTwoCompacted(Arc<Storage>), | ||
codope marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
impl TimelineLoader { | ||
pub async fn load_instants( | ||
&self, | ||
selector: &TimelineSelector, | ||
desc: bool, | ||
) -> Result<Vec<Instant>> { | ||
match self { | ||
TimelineLoader::LayoutOneActive(storage) => { | ||
let files = storage.list_files(Some(HUDI_METADATA_DIR)).await?; | ||
let mut instants = Vec::with_capacity(files.len() / 3); | ||
|
||
for file_info in files { | ||
match selector.try_create_instant(file_info.name.as_str()) { | ||
Ok(instant) => instants.push(instant), | ||
Err(e) => { | ||
debug!( | ||
"Instant not created from file {:?} due to: {:?}", | ||
file_info, e | ||
); | ||
} | ||
} | ||
} | ||
|
||
instants.sort_unstable(); | ||
instants.shrink_to_fit(); | ||
|
||
if desc { | ||
Ok(instants.into_iter().rev().collect()) | ||
} else { | ||
Ok(instants) | ||
} | ||
} | ||
TimelineLoader::LayoutTwoActive(storage) => { | ||
let files = storage.list_files(Some(LSM_TIMELINE_DIR)).await?; | ||
let mut instants = Vec::new(); | ||
|
||
for file_info in files { | ||
if file_info.name.starts_with("history/") || file_info.name.starts_with('_') { | ||
|
||
continue; | ||
} | ||
match selector.try_create_instant(file_info.name.as_str()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this API needs to handle v8 instants as the completed ones have completion ts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codope this is the only blocker for merging. if we need to pass v8 timeline loading test cases, this parsing needs to be there. |
||
Ok(instant) => instants.push(instant), | ||
Err(e) => { | ||
debug!( | ||
"Instant not created from file {:?} due to: {:?}", | ||
file_info, e | ||
); | ||
} | ||
} | ||
} | ||
Ok(instants) | ||
} | ||
_ => Err(CoreError::Unsupported( | ||
"Loading from this timeline layout is not implemented yet.".to_string(), | ||
)), | ||
} | ||
} | ||
|
||
pub async fn load_archived_instants( | ||
&self, | ||
_selector: &TimelineSelector, | ||
_desc: bool, | ||
) -> Result<Vec<Instant>> { | ||
match self { | ||
TimelineLoader::LayoutOneArchived(_) => Err(CoreError::Unsupported( | ||
"Archived timeline for layout v1 not implemented yet".to_string(), | ||
)), | ||
TimelineLoader::LayoutTwoCompacted(_) => Err(CoreError::Unsupported( | ||
"Compacted timeline for layout v2 not implemented yet".to_string(), | ||
xushiyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
)), | ||
_ => Ok(Vec::new()), // Active loaders don't have archived parts. | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.