-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from ah-/change_logging
Implement basic state change logging to kafka topic
- Loading branch information
Showing
10 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
winton_kafka_streams/state/change_logging_key_value_store.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from .store_change_logger import StoreChangeLogger | ||
|
||
class ChangeLoggingKeyValueStore: | ||
def __init__(self, name, inner): | ||
self.inner = inner(name) | ||
|
||
|
||
def initialise(self, context, root): | ||
self.inner.initialise(context, root) | ||
self.change_logger = StoreChangeLogger(self.inner.name, context) | ||
|
||
|
||
def __setitem__(self, key, value): | ||
self.inner.__setitem__(key, value) | ||
self.change_logger.log_change(key, value) | ||
|
||
|
||
def __getitem__(self, key): | ||
return self.inner.__getitem__(key) | ||
|
||
|
||
def get(self, key, default=None): | ||
return self.inner.get(key, default) | ||
|
||
|
||
def __delitem__(self, key): | ||
v = self.inner.__delitem__(key) | ||
self.change_logger.log_change(key, None) | ||
return v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class StoreChangeLogger: | ||
def __init__(self, store_name, context): | ||
self.topic = f'{context.application_id}-{store_name}-changelog' | ||
self.context = context | ||
self.partition = context.task_id.partition; | ||
self.record_collector = context.recordCollector | ||
|
||
def log_change(self, key, value): | ||
if self.record_collector: | ||
self.record_collector.send(self.topic, key, value, | ||
self.context.timestamp, partition=self.partition) |