raj-ummadisetty commented on code in PR #1926:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1926#discussion_r2829796089


##########
metadata.go:
##########
@@ -243,51 +245,66 @@ const (
 
 // queries the cluster for schema information for a specific keyspace
 type schemaDescriber struct {
-       session *Session
-       mu      sync.Mutex
+       session         *Session
+       mu              sync.Mutex
+       schemaRefresher *refreshDebouncer
+       schemaMeta      atomic.Value // *schemaMeta
+}
 
-       cache map[string]*KeyspaceMetadata
+type schemaMeta struct {
+       keyspaceMeta map[string]*KeyspaceMetadata
 }
 
 // creates a session bound schema describer which will query and cache
 // keyspace metadata
 func newSchemaDescriber(session *Session) *schemaDescriber {
-       return &schemaDescriber{
+       meta := new(schemaMeta)
+       describer := &schemaDescriber{
                session: session,
-               cache:   map[string]*KeyspaceMetadata{},
        }
+       describer.schemaMeta.Store(meta)
+       return describer
+}
+
+func (s *schemaDescriber) getSchemaMetaForRead() *schemaMeta {
+       meta, _ := s.schemaMeta.Load().(*schemaMeta)
+       return meta
+}
+
+func (s *schemaDescriber) getSchemaMetaForUpdate() *schemaMeta {
+       meta := s.getSchemaMetaForRead()
+       metaNew := new(schemaMeta)
+       if meta != nil {
+               *metaNew = *meta
+       }
+       return metaNew
 }
 
 // returns the cached KeyspaceMetadata held by the describer for the named
 // keyspace.
 func (s *schemaDescriber) getSchema(keyspaceName string) (*KeyspaceMetadata, 
error) {
-       s.mu.Lock()
-       defer s.mu.Unlock()
-
-       metadata, found := s.cache[keyspaceName]
+       metadata, found := s.getSchemaMetaForRead().keyspaceMeta[keyspaceName]
        if !found {
-               // refresh the cache for this keyspace
-               err := s.refreshSchema(keyspaceName)
+               // refresh the cache
+               err := s.refreshSchemaMetadata()
                if err != nil {
                        return nil, err
                }
-
-               metadata = s.cache[keyspaceName]
+               metadata, found = 
s.getSchemaMetaForRead().keyspaceMeta[keyspaceName]
+               if !found {
+                       return nil, ErrKeyspaceDoesNotExist
+               }
        }
 
        return metadata, nil
 }
 
-// clears the already cached keyspace metadata
-func (s *schemaDescriber) clearSchema(keyspaceName string) {
-       s.mu.Lock()
-       defer s.mu.Unlock()
-
-       delete(s.cache, keyspaceName)
-}
-
 // forcibly updates the current KeyspaceMetadata held by the schema describer
 // for a given named keyspace.
+//
+// Deprecated: Schema refreshes should be triggered through the schemaRefresher
+// refreshDebouncer (debounceRefreshSchemaMetadata) which batches and debounces
+// refresh requests for all keyspaces via refreshSchemas.
 func (s *schemaDescriber) refreshSchema(keyspaceName string) error {

Review Comment:
   As discussed in the thread, we will need it for `KeyspaceMetadata(keyspace 
string)` when caching is disabled. 



-- 
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