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

Getting the following warning when migrating: "This is an anti-pattern that should be avoided in production" #78

Open
tadchristiansen opened this issue Apr 28, 2023 · 1 comment

Comments

@tadchristiansen
Copy link

More context around the log:

{"timestamp":"2023-04-28 17:01:13.476","level":"INFO","thread":"main","logger":"org.cognitor.cassandra.migration.Database","message":"Changing keyspace of the session to 'payment'","context":"default"}
{"timestamp":"2023-04-28 17:01:13.478","level":"WARN","thread":"s0-io-11","logger":"com.datastax.oss.driver.internal.core.session.PoolManager","message":"[s0] Detected a keyspace change at runtime (<none> => payment). This is an anti-pattern that should be avoided in production (see 'advanced.request.warn-if-set-keyspace' in the configuration).","context":"default"}
{"timestamp":"2023-04-28 17:01:13.623","level":"INFO","thread":"main","logger":"org.cognitor.cassandra.migration.MigrationRepository","message":"Found 1 migration scripts","context":"default"}

The application.conf docs here: https://java-driver.docs.scylladb.com/stable/manual/core/configuration/reference/README.html
Say:

 # Whether a warning is logged when a request (such as a CQL `USE ...`) changes the active
    # keyspace.
    # Switching keyspace at runtime is highly discouraged, because it is inherently unsafe (other
    # requests expecting the old keyspace might be running concurrently), and may cause statements
    # prepared before the change to fail.
    # It should only be done in very specific use cases where there is only a single client thread
    # executing synchronous queries (such as a cqlsh-like interpreter). In other cases, clients
    # should prefix table names in their queries instead.
    #
    # Note that CASSANDRA-10145 (scheduled for C* 4.0) will introduce a per-request keyspace option
    # as a workaround to this issue.
    #
    # Required: yes
    # Modifiable at runtime: yes, the new value will be used for keyspace switches occurring after
    #   the change.
    # Overridable in a profile: no
    warn-if-set-keyspace = true

The referenced per-request docs for Scylla (Cassandra compatible) are here
https://java-driver.docs.scylladb.com/stable/manual/core/statements/per_query_keyspace/

Is there a better way to get rid of this warning?

@patka
Copy link
Owner

patka commented May 10, 2023

Hello,

I am not sure if this warning can be avoided from your end. The reason is that the Database executes a "use keyspace" statement. This is required if you would start with an empty database and use cassandra migration to create the keyspace in the first place. After it is created you need to use it if you do not want to rely for all scripts to always put the keyspace before the table name.

I can investigate if it is possible to check if we are already in the keyspace we want to modify and not always execute the "use keyspace" statement.

That being said, I would not configure Cassandra to not print this warning. In this context you know why the warning is coming but if you see it again outside of the context of Cassandra Migration it would be a good thing to investigate it further.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants