dkropachev commented on code in PR #1794:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1794#discussion_r1712553534
##########
metadata.go:
##########
@@ -760,6 +879,37 @@ func getTableMetadata(session *Session, keyspaceName
string) ([]TableMetadata, e
return tables, nil
}
+// query for only the table metadata in the specified keyspace from
system_virtual_schema.tables
+func getVirtualTableMetadata(s *Session, keyspaceName string)
([]VirtualTableMetadata, error) {
+ const stmt = `
+ SELECT
+ table_name,
+ comment
+ FROM system_virtual_schema.tables
+ WHERE keyspace_name = ?`
Review Comment:
Can you please fix indent:
```suggestion
const stmt = `
SELECT
table_name,
comment
FROM system_virtual_schema.tables
WHERE keyspace_name = ?`
```
##########
metadata.go:
##########
@@ -947,6 +1097,52 @@ func getColumnMetadata(session *Session, keyspaceName
string) ([]ColumnMetadata,
return columns, nil
}
+// query for only the column metadata in the specified keyspace from
system_virtual_schema.columns
+func getVirtualColumnMetadata(s *Session, keyspaceName string)
([]VirtualColumnMetadata, error) {
+ const stmt = `
+ SELECT
+ table_name,
+ column_name,
+ clustering_order,
+ kind,
+ type
+ FROM system_virtual_schema.columns
+ WHERE keyspace_name = ?`
Review Comment:
Same ident problem:
```suggestion
const stmt = `
SELECT
table_name,
column_name,
clustering_order,
kind,
type
FROM system_virtual_schema.columns
WHERE keyspace_name = ?`
```
##########
metadata.go:
##########
@@ -240,6 +262,13 @@ type schemaDescriber struct {
cache map[string]*KeyspaceMetadata
}
+// queries the cluster for schema information for a virtual keyspace
+type virtualSchemaDescriber struct {
+ session *Session
+ mu sync.Mutex
+ cache map[string]*VirtualKeyspaceMetadata
Review Comment:
I would recommend, in this particular case, use `sync.Map` instead of Mutex
+ map.
##########
metadata.go:
##########
@@ -269,6 +307,23 @@ func (s *schemaDescriber) getSchema(keyspaceName string)
(*KeyspaceMetadata, err
return metadata, nil
}
+// returns the cached VirtualKeyspaceMetadata held by the describer for the
named
+// keyspace.
+func (s *virtualSchemaDescriber) getSchema(keyspaceName string)
(*VirtualKeyspaceMetadata, error) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ metadata, found := s.cache[keyspaceName]
Review Comment:
Shouldn't you invalidate it at some point.
Say you upgrade cluster from one version to another, driver will still keep
old schema.
Probably on `handleNodeUp` you could read `release_version` `select
release_version from system.local where key = 'local'` and invalidate cache if
it has changed.
Another problem if your cluster half on new version half on another.
Now you depends on where have your control connection landed, if it has
landed on a node with new version, session will give you a new schema, while
old nodes don't support it.
Way to solve it is to run queries not on control connection, but rather on
the node with oldest version available, if you were do so, while you are
picking nodes, you also have to adhere to `HostSelectionPolicy`, say if it is
`dcAwareRR` you will need to filter out all nodes from other datacenters.
--
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]