worryg0d commented on code in PR #1929:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1929#discussion_r2925820673


##########
metadata.go:
##########
@@ -2049,3 +2101,319 @@ func isIdentifierChar(c byte) bool {
                c == '_' ||
                c == '&'
 }
+
+// Handles the full schema changes including table, user type, function, 
aggregate.
+func handleFullSchemaChanges(session *Session, oldKeyspaces, newKeyspaces 
map[string]*KeyspaceMetadata) {
+       for _, oldKsMeta := range oldKeyspaces {
+               newKsMeta, ok := newKeyspaces[oldKsMeta.Name]
+               if !ok {
+                       // Skip, KeyspaceChangeListener is already notified in 
refreshSchemas()
+                       continue
+               }
+
+               if session.schemaChangeListeners.TableChangeListener != nil {
+                       handleSchemaTableChanges(session, oldKsMeta, newKsMeta)
+               }
+               if session.schemaChangeListeners.UserTypeChangeListener != nil {
+                       handleSchemaUserTypeChanges(session, oldKsMeta, 
newKsMeta)
+               }
+               if session.schemaChangeListeners.FunctionChangeListener != nil {
+                       handleSchemaFunctionChanges(session, oldKsMeta, 
newKsMeta)
+               }
+               if session.schemaChangeListeners.AggregateChangeListener != nil 
{
+                       handleSchemaAggregateChanges(session, oldKsMeta, 
newKsMeta)
+               }
+       }
+}
+
+// Computes the schema table changes and notifies the event listener if it is 
set.
+// It is expected that the TableChangeListener is set on the Session.
+func handleSchemaTableChanges(session *Session, oldKeyspace, newKeyspace 
*KeyspaceMetadata) {
+       var createdEvents []OnTableCreatedEvent
+       var droppedEvents []OnTableDroppedEvent
+       var updatedEvents []OnTableUpdatedEvent
+
+       for _, oldTableMeta := range oldKeyspace.Tables {
+               newTableMeta, ok := newKeyspace.Tables[oldTableMeta.Name]
+               if !ok {
+                       droppedEvents = append(droppedEvents, 
OnTableDroppedEvent{Table: oldTableMeta})
+               } else {
+                       if !compareTablesMetadata(oldTableMeta, newTableMeta) {
+                               updatedEvents = append(updatedEvents, 
OnTableUpdatedEvent{Old: oldTableMeta, New: newTableMeta})
+                       }
+               }
+       }
+
+       for _, newTableMeta := range newKeyspace.Tables {
+               _, ok := oldKeyspace.Tables[newTableMeta.Name]
+               if !ok {
+                       createdEvents = append(createdEvents, 
OnTableCreatedEvent{Table: newTableMeta})
+               }
+       }
+
+       session.logger.Debug("Computed schema table change events",
+               NewLogFieldInt("created_table_events_count", 
len(createdEvents)),
+               NewLogFieldInt("updated_table_events_count", 
len(updatedEvents)),
+               NewLogFieldInt("dropped_table_events_count", 
len(droppedEvents)),

Review Comment:
   Added logs for keyspace events 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to