spring-projects / spring-projects/spring-data-redis

save (update) operation on repository deletes the key and inserts it back [DATAREDIS-560]

Open
#1,135 8 comments 1 reaction 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Dec 30, 2020.

in: repository type: bug
Dominant language
Java
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

sumanth yamala opened DATAREDIS-560 and commented

When using the KeyValueRepository interface and enableRedisRepositories:

After the initial creation - repository.save() - everything is fine here.
When doing an update operation: calling repository.save() - correctly detects that this is an update and calls
SimpleKeyValueRepository().save() --> KeyValueTemplate.update(....) --> which calls the callback method:
doInRedis(RedisConnection connection ).. In this method I see an issue:

Issue: A call is being made to delete the key
boolean isNew = connection.del(objectKey) == 0;
and it is promptly added back in the same callback method.

During this period if another thread is looking up the key - it indicates the key is not there and shortly afterwards it reappears.

Two issues here:

  1. Integrity of redis is not maintained - a key is being deleted in the process of an update.
  2. In the event of a crash around this critical section I believe the integrity of the data is getting compromised.

How to reproduce this:
Do an update operation on the repository in a debugger and suspend the thread after the delete operation. Use another client to look up the key.

Should the connection.del(objectKey) be changed to connection.exisits(objectKey) to fix this.


Affects: 1.7.4 (Hopper SR4)

Issue Links:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.