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

fix for reassign Table Keys faust-streaming#171 #174

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions faust/stores/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def apply_changelog_batch(
self._create_batch_iterator(to_delete.add, to_key, to_value, batch)
)
for key in to_delete:
delete_key(key, None)
# If the key was assigned a value again, it will not be deleted.
if not self.data[key]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an issue only for memory store? Rocksdb store does not have this issue AFAIK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is only for memory. When I look into the code for Rocksdb I don't recongnize that there can be the same error

delete_key(key, None)

def _create_batch_iterator(
self,
Expand All @@ -45,7 +47,6 @@ def _create_batch_iterator(
# to delete keys in the table we set the raw value to None
if event.message.value is None:
mark_as_delete(key)
continue
yield key, to_value(event.value)

def persisted_offset(self, tp: TP) -> Optional[int]:
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/stores/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def test_apply_changelog_batch__deletes_key_for_None_value(self, *, store):

assert to_key() not in store.data

def test_apply_changelog_batch__deletes_key_and_reassign_it(self, *, store):
self.test_apply_changelog_batch__deletes_key_for_None_value(store=store)

events = [self.mock_event(value=value) for value in ("v1", None, "v2")]
to_key, to_value = self.mock_to_key_value(events[0])

store.apply_changelog_batch(events, to_key=to_key, to_value=to_value)
assert to_key() in store.data

def mock_event_to_key_value(self, key=b"key", value=b"value"):
event = self.mock_event(key=key, value=value)
to_key, to_value = self.mock_to_key_value(event)
Expand Down