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

Acquiring lock for Azure CosmosDB using Cassandra API not working #214

Open
marshall-lamb opened this issue Oct 2, 2023 · 14 comments
Open
Assignees

Comments

@marshall-lamb
Copy link
Contributor

For Azure's CosmosDB emulating Cassandra APIs, there is some odd, as-of-yet unexplained behavior where updates to a table are not immediately available to query, potentially having to do with quorum data consistency. This manifests itself as failure for liquibase to acquire the lock in the DATABASECHANGELOGLOCK table even though queries of the table clearly show the lock was acquired by the liquibase process.

In the 4.23.1 version of this library, in src/main/java/liquibase/ext/cassandra/lockservice/LockServiceCassandra.java, a method was added (isLockedbyCurrentInstance()) that adds a check to see if the lock is held by the current process (by hostname and IP address) that requested it. This seems to have been added to address the behavior observed. This almost works for Azure CosmosDB, however the very next call to acquireLock() from the next changeset operation fails because isLocked() returns true.

To address the problem, I added a call to isLockedbyCurrentInstance() to method isLocked() so that on each iteration of the check for the presence of the lock, it also checks to see if the lock is held by the current process. This resolved the issue.

A separate PR will be created and linked to this issue for review of the actual change.

@marshall-lamb
Copy link
Contributor Author

Would you please add my ID to authorization to create pull requests? I'm getting denied for marshall-lamb.

@dinchand
Copy link

I encounter the same issue. @marshall-lamb could you may be share your PR ?

@marshall-lamb
Copy link
Contributor Author

As an optimization, I'm removing the return call to executor.queryForInt() as the call to isLockedByCurrentInstance() should be sufficient to indicate whether or not the current process holds the lock.

@marshall-lamb
Copy link
Contributor Author

@dinchand I'm trying to submit a PR, but I'm getting a 403 access denied error on the push. So far nothing I've tried fixes that.

@r2-lf Can you help me with this? Do I need permissions to push added for my ID?

@giejay
Copy link

giejay commented Oct 25, 2023

@marshall-lamb You are not able to create a PR from your forked repo to this one?

@marshall-lamb
Copy link
Contributor Author

@giejay I got it working. Thanks.

@dinchand Here is the PR: #229

@filipelautert filipelautert self-assigned this Nov 15, 2023
@dinchand
Copy link

@marshall-lamb Do you have liquibase working with cosmos(Cassandra) ? I tried but still facing issues...If you have it could you may be share an example ?

@giejay
Copy link

giejay commented Nov 21, 2023

I'm using the 4.25 with your fix, and after spending some time on fixing SSL errors, I'm now getting these errors:

Unexpected error running Liquibase: Error executing SQL SELECT TABLE_NAME, KEYSPACE_NAME, COMMENT FROM system_schema.tables WHERE keyspace_name = 'mykeyspace' AND TABLE_NAME = 'databasechangelog': com.datastax.oss.driver.api.core.NoNodeAvailableException: No node was available to execute the query

@marshall-lamb You did not face this issue? There is another blocking issue in the 4.25 release: #242, but I fixed that class cast exception locally.

@maximevw
Copy link
Contributor

Hello @giejay,
I discussed a similar issue with @dinchand here: ing-bank/cassandra-jdbc-wrapper#37 (reply in thread)
The NoNodeAvailableException can have various origins but one of most common is a missing or invalid localdatacenter property when the default load balancing policy is used.

@nicobte
Copy link

nicobte commented Nov 7, 2024

Hello folks, is there currently a way to disable the database changelog lock? I've been trying to use liquibase-nochangeloglock without success until now. @maximevw @giejay @dinchand

@giejay
Copy link

giejay commented Nov 7, 2024 via email

@nicobte
Copy link

nicobte commented Nov 7, 2024

It's not a error, what happens is that I'm running Liquibase updates every time the pod is starting, so when I have to scale many pods at the same time they all have to wait for the lock to be released and that increases the startup time a lot.

I was thinking of a couple of alternatives instead of always acquiring the lock:

  1. Acquire the lock only if there are pending changes to execute.
  2. Disable database changelog locks.

To achieve this I would have to implement another LockService, right? What do you think? I really appreciate any suggestions.

@maximevw
Copy link
Contributor

maximevw commented Nov 9, 2024

Hello @nicobte

Is it relevant to run Liquibase scripts for each pod if they all use the same database? Maybe the good solution should be to run Liquibase separately: execute the updates before deploying your pods. Typically, with K8s, initContainers could be used for that.

However, it's surprising the liquibase-nochangeloglock didn't work, do you have any clue why it fails? Is there any error?

@filipelautert
Copy link
Contributor

nochangeloglock extension should work for that.. Just notice that you need to set parameter databaseChangelogLockEnabled to true.

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

No branches or pull requests

6 participants