Skip to content

Commit

Permalink
Merge pull request #363 from sylwiaszunejko/invalidate-tablets-data
Browse files Browse the repository at this point in the history
Invalidate tablets for dropped keyspace/table on control connection reconnect
  • Loading branch information
dkropachev authored Dec 1, 2024
2 parents 3e0a01a + 243c71b commit 09e5326
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ func (c *controlConn) reconnect() {
if err != nil {
c.session.logger.Printf("gocql: unable to refresh ring: %v\n", err)
}

err = c.session.metadataDescriber.refreshAllSchema()
if err != nil {
c.session.logger.Printf("gocql: unable to refresh the schema: %v\n", err)
}
}

func (c *controlConn) attemptReconnect() (*Conn, error) {
Expand Down
50 changes: 50 additions & 0 deletions metadata_scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,56 @@ func (s *metadataDescriber) clearSchema(keyspaceName string) {
s.metadata.keyspaceMetadata.remove(keyspaceName)
}

func (s *metadataDescriber) refreshAllSchema() error {
s.mu.Lock()
defer s.mu.Unlock()

copiedMap := make(map[string]*KeyspaceMetadata)

for key, value := range s.metadata.keyspaceMetadata.get() {
if value != nil {
copiedMap[key] = &KeyspaceMetadata{
Name: value.Name,
DurableWrites: value.DurableWrites,
StrategyClass: value.StrategyClass,
StrategyOptions: value.StrategyOptions,
Tables: value.Tables,
Functions: value.Functions,
Aggregates: value.Aggregates,
Types: value.Types,
Indexes: value.Indexes,
Views: value.Views,
CreateStmts: value.CreateStmts,
}
} else {
copiedMap[key] = nil
}
}

for keyspaceName, metadata := range copiedMap {
// refresh the cache for this keyspace
err := s.refreshSchema(keyspaceName)
if err == ErrKeyspaceDoesNotExist {
s.clearSchema(keyspaceName)
s.removeTabletsWithKeyspace(keyspaceName)
} else if err != nil {
return err
}

updatedMetadata, err := s.getSchema(keyspaceName)
if err != nil {
return err
}

for tableName := range metadata.Tables {
if _, ok := updatedMetadata.Tables[tableName]; !ok {
s.removeTabletsWithTable(keyspaceName, tableName)
}
}
}
return nil
}

// forcibly updates the current KeyspaceMetadata held by the schema describer
// for a given named keyspace.
func (s *metadataDescriber) refreshSchema(keyspaceName string) error {
Expand Down

0 comments on commit 09e5326

Please sign in to comment.