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
KeyspaceMetadata causes panic when describing aggregates #1587
Comments
Hello @evildecay, sorry for the late reply. Based on the stack trace above it seems that there is a final_function function referenced in user defined aggregates as returned by: SELECT
aggregate_name,
argument_types,
final_func,
initcond,
return_type,
state_func,
state_type
FROM system_schema.aggregates
WHERE keyspace_name = ? but that function is not present in the list of functions as returned by: SELECT
function_name,
argument_types,
argument_names,
body,
called_on_null_input,
language,
return_type
FROM system_schema.functions
WHERE keyspace_name = ? Could you please try to check the results of these statements on your instance if you still can reproduce and verify that it's the case? Of course the driver should not panic in this case, so we should handle this in some way. It is not clear to me at this point what the correct handling is though. I don't have experience with aggregates in Cassandra. Is it possible this state regularly happens or is it some inconsistency on server side? In other words, should we just ignore the aggregate or do we want to return an error from |
Query result:
|
Ah, there is |
There were the following issues with handling of aggregates: - compileMetadata panicked if final_func was null. final_func is optional[1], so null is perfectly valid value. - The AggregateMetadata FinalFunc field could not store nil, so it is not possible to represent the null. - Functions and aggregates are not uniquely identified just by name. There could be two functions with the same name, but different argument types. I'm adding a new version of function and aggregate metadata to fix those shortcomings. For backward compatibility, I leave the V1 metadata filled-in where possible. Fixes gocql#1587 [1] https://cassandra.apache.org/doc/latest/cassandra/cql/functions.html#user-defined-aggregates-functions
Hello @evildecay! I think I have a fix. Could you please verify that #1590 fixes the issue for you? |
There were the following issues with handling of aggregates: - compileMetadata panicked if final_func was null. final_func is optional[1], so null is perfectly valid value. - The AggregateMetadata FinalFunc field could not store nil, so it is not possible to represent the null. - Functions and aggregates are not uniquely identified just by name. There could be two functions with the same name, but different argument types. I'm adding a new version of function and aggregate metadata to fix those shortcomings. For backward compatibility, I leave the V1 metadata filled-in where possible. Fixes gocql#1587 [1] https://cassandra.apache.org/doc/latest/cassandra/cql/functions.html#user-defined-aggregates-functions
@martin-sucha Tested the gocql 1.2.0 version, it should have fixed this problem. awesome! This issue can be closed |
@evildecay gocql 1.2.0 does not include the changes from #1590 though, so I'm not sure if we can close this. Is it possible that the data in your |
I will try to reproduce this panic with given information, to make sure if this issue could be closed |
I have tested this case, but it works properly, so the final_func could be null. I think this issue should be closed. ProtoVersion :4 What version of Gocql are you using? What version of Go are you using? package gocql_test
import (
"fmt"
"log"
"testing"
"time"
"github.com/gocql/gocql"
)
func TestGetClusterAndSession(t *testing.T) {
cluster := gocql.NewCluster("localhost:9042")
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: "cassandra",
Password: "cassandra",
}
cluster.NumConns = 2
cluster.SocketKeepalive = time.Millisecond * 500
cluster.Timeout = 15 * time.Second
cluster.ProtoVersion = 4
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.RoundRobinHostPolicy()) // according to issue this code causes panic, it`s not though.
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: 5}
cluster.DisableInitialHostLookup = true
// "ANY", "ONE", "TWO", "THREE", "QUORUM", "ALL", "LOCAL_QUORUM", "EACH_QUORUM", "LOCAL_ONE"
cluster.Consistency = gocql.Any // tested on diferent consistencyes
if session, err := cluster.CreateSession(); err != nil {
panic(err)
} else {
// Create a keyspace
keyspace := "my_keyspace"
replication := "{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }"
err = session.Query(fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = %s", keyspace, replication)).Exec()
if err != nil {
log.Fatal("Unable to create keyspace: ", err)
}
fmt.Println("Keyspace created successfully")
}
} The output for test
Output for cql requests SELECT function_name, argument_types, argument_names, body, called_on_null_input, language, return_type FROM system_schema.functions WHERE keyspace_name = 'test';
SELECT aggregate_name, argument_types, final_func, initcond, return_type, state_func, state_type FROM system_schema.aggregates WHERE keyspace_name ='test';
SELECT peer, rpc_address FROM system.peers;
|
Please answer these questions before submitting your issue. Thanks!
What version of Cassandra are you using?
Cassandra 3.11.11
What version of Gocql are you using?
github.com/gocql/gocql@latest
What version of Go are you using?
go version go1.15.14 windows/amd64
What did you do?
What did you expect to see?
I hope it can create the connection normally
What did you see instead?
If you are having connectivity related issues please share the following additional information
Describe your Cassandra cluster
please provide the following information
nodetool status
SELECT peer, rpc_address FROM system.peers
gocql_debug
tag and post the outputThe text was updated successfully, but these errors were encountered: