ydb-platform / yoj-project

YDB ORM for Java (YOJ) is a lightweight ORM for immutable entities. It has native support for YDB and is battle-tested.
Apache License 2.0
13 stars 12 forks source link

Check that read happend before save. #66

Open lavrukov opened 7 months ago

lavrukov commented 7 months ago

In our service, we predominantly do not use blind writes. We encountered a bug in the user code where we read an object in one transaction and saved it in another without a preliminary read. As a result, we ended up with an incorrect value in the database.

It's difficult to protect against such issues, however, an optional check can be added in the InMemoryRepository before saving: if the object is present in the database, we check the cache, and if the required object is not there, we fail. There are several problems here: