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

After doc deletion the doc can still be fetched from another collection #3242

Closed
islamaliev opened this issue Nov 15, 2024 · 0 comments · Fixed by #3258
Closed

After doc deletion the doc can still be fetched from another collection #3242

islamaliev opened this issue Nov 15, 2024 · 0 comments · Fixed by #3258
Assignees
Labels
area/query Related to the query component bug Something isn't working priority/high
Milestone

Comments

@islamaliev
Copy link
Contributor

islamaliev commented Nov 15, 2024

This test does not pass:

func TestMutationDeletion_WithMultipleCollections_(t *testing.T) {
	test := testUtils.TestCase{
		Description: "Delete a document from one collection and check if the other collection is unaffected.",
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type User {
						name: String
					}
					type Pet {
						name: String
						breed: [String]
					}
				`,
			},
			testUtils.CreateDoc{
				Doc: `{
					"name": "Shahzad"
				}`,
			},
			testUtils.CreateDoc{
				Doc: `{
					"name": "John"
				}`,
			},
			testUtils.CreateDoc{
				CollectionID: 1,
				Doc: `{
					"name": "Scruffy",
					"breed": ["Yorkie"]
				}`,
			},
			testUtils.DeleteDoc{
				CollectionID: 1,
				DocID:        0,
			},
			testUtils.Request{
				Request: `query {
					Pet {
						_docID
					}
				}`,
				Results: map[string]any{
					"Pet": []map[string]any{},
				},
			},
			testUtils.Request{
				Request: `query {
					User {
						_docID
					}
				}`,
				Results: map[string]any{
					"User": []map[string]any{
						{
							"_docID": testUtils.NewDocIndex(0, 1),
						},
						{
							"_docID": testUtils.NewDocIndex(0, 0),
						},
					},
				},
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}

The last query returns 3 documents.

@islamaliev islamaliev added area/query Related to the query component bug Something isn't working labels Nov 15, 2024
@islamaliev islamaliev added this to the DefraDB v0.15 milestone Nov 15, 2024
@islamaliev islamaliev changed the title After doc deletion the doc can still be fetch from another collection After doc deletion the doc can still be fetched from another collection Nov 15, 2024
@fredcarle fredcarle mentioned this issue Nov 19, 2024
4 tasks
@fredcarle fredcarle self-assigned this Nov 19, 2024
fredcarle added a commit that referenced this issue Nov 20, 2024
## Relevant issue(s)

Resolves #3242 

## Description

This PR solves the situation where deleted documents in the immediate
next collection by ID were returned on a full collection query. The
reason for this behaviour was due to the fetcher start method redefining
the spans based on wanting deleted docs or not and was defining an end
key that might have been "prefix-ended" based on a shorter prefix (i.e.
collection instead of instance type). ~~The solution was to always
redefine the end key as the prefix end of the start key.~~

To fix this we removed the concept of spans and replaced it with a list
of prefixes. This results in the fetcher being asked, for example, for
all docs in collection 1 with a prefix of `/data/1` instead of a span
from `/data/1` to `/data/2`. Furthermore, when the fetcher checks if it
need to get deleted docs or non-deleted docs, the resulting prefix
becomes `/data/1/< v or d >` instead of the span from `/data/1/< v or d
>` to `/data/2/< v or d >` (the span is wrong).

The first commit documents the bug with an integration test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component bug Something isn't working priority/high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants