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

Projection isn't found in tx cache #31

Open
lavrukov opened this issue Feb 28, 2024 · 3 comments · May be fixed by #76
Open

Projection isn't found in tx cache #31

lavrukov opened this issue Feb 28, 2024 · 3 comments · May be fixed by #76
Labels
bug Something isn't working

Comments

@lavrukov
Copy link
Contributor

lavrukov commented Feb 28, 2024

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);
    }
@nvamelichev
Copy link
Collaborator

nvamelichev commented Feb 28, 2024

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).

@lavrukov
Copy link
Contributor Author

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.

@lavrukov lavrukov added the bug Something isn't working label Mar 6, 2024
@lavrukov lavrukov changed the title Projection isn't found in tx cache; Projection isn't found in tx cache Mar 6, 2024
@nvamelichev
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants