Skip to content
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

fix: ignore error when open partition table failed #1220

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use interpreters::{
factory::Factory,
interpreter::{InterpreterPtr, Output},
};
use log::{error, info};
use log::{error, info, warn};
use query_frontend::plan::Plan;
use router::{endpoint::Endpoint, Router};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -320,10 +320,28 @@ impl Proxy {
schema_name: &str,
table_name: &str,
) -> Result<()> {
let catalog = self.get_catalog(catalog_name)?;
if let Err(e) = self
.open_partition_table_inner(catalog_name, schema_name, table_name)
.await
{
warn!("Open partition table failed, err:{e:?}");
}

let schema = self.get_schema(&catalog, schema_name)?;
// When open remote table failed, we currently don't return error outside.
// This is because when sub_table[0] is unhealthy, we can not drop the partition
// table.
// TODO: maybe we can find a more elegant way to deal with this issue.
Ok(())
}

async fn open_partition_table_inner(
&self,
catalog_name: &str,
schema_name: &str,
table_name: &str,
) -> Result<()> {
let catalog = self.get_catalog(catalog_name)?;
let schema = self.get_schema(&catalog, schema_name)?;
let table = self.get_table(&schema, table_name)?;

let table_info_in_meta = self
Expand All @@ -340,12 +358,15 @@ impl Proxy {

match (table, &table_info_in_meta) {
(Some(table), Some(partition_table_info)) => {
let table_id = table.id();
// No need to create partition table when table_id match.
if table.id().as_u64() == partition_table_info.id {
if table_id == partition_table_info.id {
return Ok(());
}
info!("Drop partition table because the id of the table in ceresdb is different from the one in ceresmeta, catalog_name:{catalog_name}, schema_name:{schema_name}, table_name:{table_name}, old_table_id:{}, new_table_id:{}",
table.id().as_u64(), partition_table_info.id);

info!("Drop partition table because the id of the table in ceresdb is different from the one in ceresmeta,\
catalog_name:{catalog_name}, schema_name:{schema_name}, table_name:{table_name}, old_table_id:{table_id}, new_table_id:{}",
partition_table_info.id);
// Drop partition table because the id of the table in ceresdb is different from
// the one in ceresmeta.
self.drop_partition_table(
Expand All @@ -360,7 +381,8 @@ impl Proxy {
// Drop partition table because it does not exist in ceresmeta but exists in
// ceresdb-server.
if table.partition_info().is_some() {
info!("Drop partition table because it does not exist in ceresmeta but exists in ceresdb-server, catalog_name:{catalog_name}, schema_name:{schema_name}, table_name:{table_name}, table_id:{}",table.id());
info!("Drop partition table because it does not exist in ceresmeta but exists in ceresdb-server,\
catalog_name:{catalog_name}, schema_name:{schema_name}, table_name:{table_name}, table_id:{}", table.id());
self.drop_partition_table(
schema.clone(),
catalog_name.to_string(),
Expand Down Expand Up @@ -434,6 +456,7 @@ impl Proxy {
code: StatusCode::INTERNAL_SERVER_ERROR,
msg: format!("Failed to create table, request:{create_table_request:?}"),
})?;

Ok(())
}

Expand Down
6 changes: 6 additions & 0 deletions table_engine/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ impl TableId {
}
}

impl PartialEq<u64> for TableId {
fn eq(&self, other: &u64) -> bool {
self.as_u64() == *other
}
}

impl From<u64> for TableId {
fn from(id: u64) -> TableId {
TableId::new(id)
Expand Down