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

Invalidate schema name key cache after dropping database #3695

Closed
WenyXu opened this issue Apr 11, 2024 · 0 comments · Fixed by #3725
Closed

Invalidate schema name key cache after dropping database #3695

WenyXu opened this issue Apr 11, 2024 · 0 comments · Fixed by #3725
Labels
good first issue Good for newcomers

Comments

@WenyXu
Copy link
Member

WenyXu commented Apr 11, 2024

What type of enhancement is this?

Tech debt reduction

What does the enhancement do?

After dropping the database(After the L41), we should invalidate the schema name key cache on the frontend node.

async fn next(
&mut self,
ddl_ctx: &DdlContext,
ctx: &mut DropDatabaseContext,
) -> Result<(Box<dyn State>, Status)> {
ddl_ctx
.table_metadata_manager
.schema_manager()
.delete(SchemaNameKey::new(&ctx.catalog, &ctx.schema))
.await?;
return Ok((Box::new(DropDatabaseEnd), Status::done()));

Here is an example of how we invalidate table cache on the frontend node.

  1. Invoking the invalidate on the Metasrv; The metasrv will broadcast cache invalidation notifications to frontend nodes.
    pub async fn invalidate_table_cache(&self, ctx: &DdlContext) -> Result<()> {
    let cache_invalidator = &ctx.cache_invalidator;
    let ctx = Context {
    subject: Some("Invalidate table cache by dropping table".to_string()),
    };
    cache_invalidator
    .invalidate(
    &ctx,
    vec![
    CacheIdent::TableName(self.table.table_ref().into()),
    CacheIdent::TableId(self.table_id),
    ],
    )
    .await?;
    Ok(())
    }
  2. The frontend node handles cache invalidation notifications.
    async fn handle(&self, ctx: &mut HeartbeatResponseHandlerContext) -> MetaResult<HandleControl> {
    let Some((_, Instruction::InvalidateCaches(caches))) = ctx.incoming_message.take() else {
    unreachable!("InvalidateTableCacheHandler: should be guarded by 'is_acceptable'")
    };
    debug!(
    "InvalidateTableCacheHandler: invalidating caches: {:?}",
    caches
    );
    // Invalidate local cache always success
    let _ = self
    .cache_invalidator
    .invalidate(&Context::default(), caches)
    .await?;
    Ok(HandleControl::Done)
    }
    }

Implementation challenges

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant