Projection isn't found in tx cache
lavrukov opened this issue · 3 comments
let's imagine Entity(id, value) with projection ValueIndex(id_value, entity_id). If we save in tx some entity and after it try to find projections - they will be unchanged
For example: this test is green
@Test
public void savedIndexIsNotInCache() {
Book.Id bookId = new Book.Id("1");
Book.ByAuthor index1 = db.tx(() -> {
db.table(Book.class).save(new Book(bookId, 1, "title1", List.of("author1")));
return db.table(Book.ByAuthor.class).find(new Book.ByAuthor.Id("author1", bookId));
});
Book.ByAuthor index2 = db.tx(() -> {
return db.table(Book.ByAuthor.class).find(new Book.ByAuthor.Id("author1", bookId));
});
assertNull(index1);
assertNotNull(index2);
}
Does db.table(Book.class).saveOrUpdate(...)
work?
Table.save()
is marked "unsafe" because it does not work well with projections.
I'd like to mark "projections" as a deprecated feature, because in new code you almost always should use YDB indexes (@GlobalIndex
).
No, it doesn't. Because we make actions with projections only in RwProjectionCache::applyProjectionChanges which calls on commit.
Overall projections is useful feature, but unsafe in current design. It looks impossible to remove it from current projects which are using YOJ. Anyway GlobalIndex can't close all case of projections. For example GlobalIndex can't be computable.
You can enable immediate writes, then projection changes will be applied immediately, not on commit, and should end up in the first-level cache of the transaction.