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

Update/delete record fails while using EXPECT_GEN_GT/EXPECT_GEN_EQUAL write generation policies #47

Closed
yevtsy opened this issue Nov 12, 2019 · 4 comments

Comments

@yevtsy
Copy link

yevtsy commented Nov 12, 2019

Write Generation Policy
EXPECT_GEN_EQUAL — Update/delete record if expected generation is equal to server generation. Otherwise, fail.
EXPECT_GEN_GT — Update/delete record if expected generation greater than the server generation. Otherwise, fail. This is useful for restore after backup.

Documentation tells us that Write Generation Policy can be used to handle update/delete requests.

Relative PR with tests cases which shows the issues:
#46

Expectations:
Let's say I use
policy.writePolicyDefault.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
and record with @Version property. I want to have the next cases:

  1. Create record -> update it with the same version -> check updates are applied
  2. Create record -> update it with different version -> update fails
  3. Create record -> delete it by id -> check record doesn't exist
  4. Create record -> delete it by object -> check record doesn't exist

Actual result:
All these requests are fail with generation-related error

org.springframework.dao.RecoverableDataAccessException: Error 3,1,30000,0,0,BB9030011AC4202 127.0.0.1 32879: Generation error; nested exception is com.aerospike.client.AerospikeException: Error 3,1,30000,0,0,BB9030011AC4202 127.0.0.1 32879: Generation error
	at org.springframework.data.aerospike.core.DefaultAerospikeExceptionTranslator.translateExceptionIfPossible(DefaultAerospikeExceptionTranslator.java:73)
	at org.springframework.data.aerospike.core.AerospikeTemplate.delete(AerospikeTemplate.java:227)
	at org.springframework.data.aerospike.core.AerospikeClientPolicyGenerationTest.shouldSuccessfullyDeleteRecordWithSameGeneration(AerospikeClientPolicyGenerationTest.java:104)

Caused by: com.aerospike.client.AerospikeException: Error 3,1,30000,0,0,BB9030011AC4202 127.0.0.1 32879: Generation error
	at com.aerospike.client.command.DeleteCommand.parseResult(DeleteCommand.java:77)
	at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:103)
	at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:50)
	at com.aerospike.client.AerospikeClient.delete(AerospikeClient.java:559)
	at org.springframework.data.aerospike.core.AerospikeTemplate.delete(AerospikeTemplate.java:225)```
@Aloren
Copy link

Aloren commented Nov 12, 2019

@yevtsy could you please prepare PR with the fix?

@yevtsy
Copy link
Author

yevtsy commented Nov 13, 2019

Yes, will do it

@Aloren
Copy link

Aloren commented Nov 26, 2019

We should not rely on the default generationPolicy provided by aerospikeClient as it may break operations provided in AerospikeTemplate.

Expectation
If document has version property (field annotated with @Version annotation), we expect document's version to be equal to the server one's.
If document does not have version property, we do not have any expectations regarding version.

Reality

  1. save operation meets expectation when version is present, when version is absent generationPolicy should be set to NONE.
  2. insert operation is expected to fail if document already exists regardless of version value, so we should override generationPolicy to NONE.
  3. update operation currently rewrites document content regardless of version value. Not sure whether it was intended or not. Right now we should override generationPolicy to NONE as with any other this operation will fail.
  4. delete operation theoretically is expected to fail if version you are trying to delete is not equal to server version, but currently it deletes document from server regardless of version. I would rather leave that behavior as is. We should override generationPolicy to NONE as with any other this operation will fail.

@Aloren
Copy link

Aloren commented Nov 26, 2019

fixed by #48

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