Skip to content
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

session: prepare now prepares on all nodes #266

Merged
merged 3 commits into from
Aug 5, 2022
Merged

session: prepare now prepares on all nodes #266

merged 3 commits into from
Aug 5, 2022

Conversation

Kulezi
Copy link
Contributor

@Kulezi Kulezi commented Aug 1, 2022

Prepare now prepares on all nodes, once per node, as sources suggest:
https://github.com/apache/cassandra/blob/adcff3f630c0d07d1ba33bf23fcb11a6db1b9af1/doc/native_protocol_v4.spec#L738-L740
https://github.com/scylladb/scylladb/blob/4d24097b4b86d484159c011f46b9e43268d342d1/transport/server.cc#L941-L950

Also made the driver fallback from token aware policy to round robin
if both session keyspace and query keyspace are unspecified, this is a temporary fix until #257 is resolved.

@Kulezi Kulezi force-pushed the pp/prepare-fix branch 4 times, most recently from 736459f to 92d9bb2 Compare August 2, 2022 06:37
@Kulezi Kulezi marked this pull request as ready for review August 2, 2022 06:40
Copy link

@piodul piodul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think it is a worthwhile change, it shouldn't declare that it fixes #249. AFAIK #249 points out that the protocol specification technically allows different nodes to use different IDs for the same prepared statement. This PR still works under this assumption, it's just that prepared statements are prepared up-front on all nodes.

IMO it's fine to fix this later. All other drivers that I know, including the Java driver, currently seem to work under that assumption, so I doubt the current behavior will be changed soon by either Cassandra or Scylla.

session.go Outdated
// Find first result that succeeded.
for i := range nodes {
if resErr[i] == nil {
return Query{session: s,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting looks weird here. Is that intentional?

Comment on lines +97 to +100
if c.cfg.Keyspace == "" {
// We don't know anything about the keyspace, fallback to non-token aware query.
return c.NewQueryInfo(), nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary for the purpose of this PR (preparing statements on all nodes)? If not, then perhaps it should be sent as a separate PR, or - at least - as a separate commit?

Copy link
Contributor Author

@Kulezi Kulezi Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating the test i encountered a missing keyspace error that "" was not found in system_schema.keyspaces, currently the driver always assumes it's querying the default session keyspace which needs to be changed with #257, right now the driver doesn't save info about keyspace from prepared results, hence i needed this workaround. I prefer to do this all with #257.

I moved the workaround to another commit.

func TestPrepareIntegration(t *testing.T) {
defer goleak.VerifyNone(t)

cfg := DefaultSessionConfig("", "192.168.100.100:9042")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the TestHost constant instead of the hardcoded address.

if _, err := q.Exec(); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the sleep is here in order to simulate a "wait for schema agreement" operation? I suggest placing a TODO comment here so that it will be easier to find the workaround-sleeps when somebody gets to implement it.

@Kulezi
Copy link
Contributor Author

Kulezi commented Aug 3, 2022

Applied changes suggested by @piodul, also removed leaking goroutines from TLS integration test caused by unclosed session.

@Kulezi Kulezi requested a review from piodul August 3, 2022 10:05
@Kulezi Kulezi merged commit a31dd38 into main Aug 5, 2022
@Kulezi Kulezi deleted the pp/prepare-fix branch August 5, 2022 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants