Skip to content

Commit

Permalink
clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
xudong963 committed Nov 25, 2024
1 parent 24faa0f commit ba5f7d5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/query/catalog/src/table_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ pub trait TableContext: Send + Sync {
async fn get_table(&self, catalog: &str, database: &str, table: &str)
-> Result<Arc<dyn Table>>;

fn remove_table_from_cache(&self, catalog: &str, database: &str, table: &str);

async fn get_table_with_batch(
&self,
catalog: &str,
Expand Down
5 changes: 5 additions & 0 deletions src/query/service/src/sessions/query_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,11 @@ impl TableContext for QueryContext {
.await
}

fn remove_table_from_cache(&self, catalog: &str, database: &str, table: &str) {
self.shared
.remove_table_from_cache(catalog, database, table)
}

#[async_backtrace::framed]
async fn get_table_with_batch(
&self,
Expand Down
10 changes: 10 additions & 0 deletions src/query/service/src/sessions/query_ctx_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ impl QueryContextShared {
Ok(res)
}

pub fn remove_table_from_cache(&self, catalog_name: &str, database: &str, table: &str) {
let table_meta_key = (
catalog_name.to_string(),
database.to_string(),
table.to_string(),
);
let mut tables_refs = self.tables_refs.lock();
tables_refs.remove(&table_meta_key);
}

#[async_backtrace::framed]
async fn get_table_to_cache(
&self,
Expand Down
4 changes: 4 additions & 0 deletions src/query/service/tests/it/sql/exec/get_table_bind_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,10 @@ impl TableContext for CtxDelegation {
}
}

fn remove_table_from_cache(&self, catalog: &str, database: &str, table: &str) {
todo!()
}

async fn get_table_with_batch(
&self,
catalog: &str,
Expand Down
4 changes: 4 additions & 0 deletions src/query/service/tests/it/storages/fuse/operations/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ impl TableContext for CtxDelegation {
todo!()
}

fn remove_table_from_cache(&self, catalog: &str, database: &str, table: &str) {
todo!()
}

async fn get_table_with_batch(
&self,
_catalog: &str,
Expand Down
8 changes: 5 additions & 3 deletions src/query/sql/src/planner/binder/bind_query/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ impl Binder {
Engine::Memory
};
let database = self.ctx.get_current_database();
let catalog = self.ctx.get_current_catalog();
let create_table_stmt = CreateTableStmt {
create_option: CreateOption::CreateOrReplace,
catalog: None,
database: Some(Identifier::from_name(Span::None, database)),
catalog: Some(Identifier::from_name(Span::None, catalog.clone())),
database: Some(Identifier::from_name(Span::None, database.clone())),
table: cte.alias.name.clone(),
source: None,
engine: Some(engine),
Expand All @@ -210,7 +211,8 @@ impl Binder {
};

// Todo: clear the table with the same name in table cache

self.ctx
.remove_table_from_cache(&catalog, &database, &cte.alias.name.name);
Ok(())
}
}

0 comments on commit ba5f7d5

Please sign in to comment.