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

Elasticsearch Lock Provider - Hardcoded Camel Case Field Names #2007

Open
VladMartyshevskyi opened this issue Jul 2, 2024 · 1 comment
Open

Comments

@VladMartyshevskyi
Copy link

VladMartyshevskyi commented Jul 2, 2024

I'm using ShedLock Provider Elasticsearch8 5.13.0.

The issue is that the Elasticsearch Lock Provider uses hardcoded field names such as 'lockUntil', 'lockedAt' and others. This causes errors when ElasticsearchClient is configured with JsonpMapper using SNAKE_CASE.

Successful Flow:

  1. The first attempt to acquire the lock leads to the creation of the ShedLock index and insertion of the record:
{
    "name": "MyLock",
    "locked_by": "my-service",
    "locked_at": 1719044530845,
    "lock_until": 1719045430845
}

Here, all fields are in snake_case because JsonpMapper is configured this way.

  1. When unlocking, the provider adds the lockUntil field (in camelCase) to the record with the current timestamp. The record then looks like:
{
    "name": "MyLock",
    "locked_by": "my-service",
    "locked_at": 1719044530845,
    "lock_until": 1719045430845,
    "lockUntil": 1719045420441
}
  1. When attempting to lock again, the provider checks the 'lockUntil' field using this script.

Error Scenario:

An error occurs when we skip step 2 (unlocking) and try to lock again. The query fails with the message: [es/update] failed: [illegal_argument_exception] failed to execute script. The issue is that the script checks for the 'lockUntil' field, which does not exist because only 'lock_until' is present.

This issue arises when using SNAKE_CASE with JsonpMapper.

Thank you.

@lukas-krecan
Copy link
Owner

Hi, thanks for reporting. Can you please send a PR with the fix? Either somehow taking the JsonpMapper settings into account or at least make the column names configurable similar to the JDBC lock provider. Thanks a lot

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

2 participants