Skip to content

Commit

Permalink
fix: invalidate view info cache after creating view successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 committed May 27, 2024
1 parent f545a55 commit 74f4748
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/common/meta/src/ddl/create_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ use strum::AsRefStr;
use table::metadata::{RawTableInfo, TableId, TableType};
use table::table_reference::TableReference;

use crate::cache_invalidator::Context;
use crate::ddl::utils::handle_retry_error;
use crate::ddl::{DdlContext, TableMetadata, TableMetadataAllocatorContext};
use crate::error::{self, Result};
use crate::instruction::CacheIdent;
use crate::key::table_name::TableNameKey;
use crate::lock_key::{CatalogLock, SchemaLock, TableNameLock};
use crate::rpc::ddl::CreateViewTask;
Expand Down Expand Up @@ -157,6 +159,25 @@ impl CreateViewProcedure {
Ok(Status::executing(true))
}

async fn invalidate_view_cache(&self) -> Result<()> {
let cache_invalidator = &self.context.cache_invalidator;
let ctx = Context {
subject: Some("Invalidate view cache by creating view".to_string()),
};

cache_invalidator
.invalidate(
&ctx,
&[
CacheIdent::TableName(self.data.table_ref().into()),
CacheIdent::TableId(self.view_id()),
],
)
.await?;

Ok(())
}

/// Creates view metadata
///
/// Abort(not-retry):
Expand Down Expand Up @@ -197,6 +218,7 @@ impl CreateViewProcedure {
ctx.procedure_id
);
}
self.invalidate_view_cache().await?;

Ok(Status::done_with_output(view_id))
}
Expand Down

0 comments on commit 74f4748

Please sign in to comment.