-
Notifications
You must be signed in to change notification settings - Fork 2
feat: support retrieval hints for efficient message retrieval from store nodes #18
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
Open
shash256
wants to merge
3
commits into
master
Choose a base branch
from
feat-retrieval-hint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,20 +1,31 @@ | ||
| import std/json | ||
| import ./json_base_event, ../../src/[message] | ||
| import ./json_base_event, ../../src/[message], std/base64 | ||
|
|
||
| type JsonMissingDependenciesEvent* = ref object of JsonEvent | ||
| messageId*: SdsMessageID | ||
| missingDeps: seq[SdsMessageID] | ||
| missingDeps*: seq[HistoryEntry] | ||
| channelId*: SdsChannelID | ||
|
|
||
| proc new*( | ||
| T: type JsonMissingDependenciesEvent, | ||
| messageId: SdsMessageID, | ||
| missingDeps: seq[SdsMessageID], | ||
| missingDeps: seq[HistoryEntry], | ||
| channelId: SdsChannelID, | ||
| ): T = | ||
| return JsonMissingDependenciesEvent( | ||
| eventType: "missing_dependencies", messageId: messageId, missingDeps: missingDeps, channelId: channelId | ||
| ) | ||
|
|
||
| method `$`*(jsonMissingDependencies: JsonMissingDependenciesEvent): string = | ||
| $(%*jsonMissingDependencies) | ||
| var node = newJObject() | ||
| node["eventType"] = %*jsonMissingDependencies.eventType | ||
| node["messageId"] = %*jsonMissingDependencies.messageId | ||
| node["channelId"] = %*jsonMissingDependencies.channelId | ||
| var missingDepsNode = newJArray() | ||
| for dep in jsonMissingDependencies.missingDeps: | ||
| var depNode = newJObject() | ||
| depNode["messageId"] = %*dep.messageId | ||
| depNode["retrievalHint"] = %*encode(dep.retrievalHint) | ||
| missingDepsNode.add(depNode) | ||
| node["missingDeps"] = missingDepsNode | ||
| $node |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,8 +9,13 @@ proc encode*(msg: SdsMessage): ProtoBuffer = | |||||
| pb.write(1, msg.messageId) | ||||||
| pb.write(2, uint64(msg.lamportTimestamp)) | ||||||
|
|
||||||
| for hist in msg.causalHistory: | ||||||
| pb.write(3, hist) | ||||||
| for entry in msg.causalHistory: | ||||||
| var entryPb = initProtoBuffer() | ||||||
| entryPb.write(1, entry.messageId) | ||||||
| if entry.retrievalHint.len > 0: | ||||||
| entryPb.write(2, entry.retrievalHint) | ||||||
| entryPb.finish() | ||||||
| pb.write(3, entryPb.buffer) | ||||||
|
|
||||||
| pb.write(4, msg.channelId) | ||||||
| pb.write(5, msg.content) | ||||||
|
|
@@ -31,10 +36,24 @@ proc decode*(T: type SdsMessage, buffer: seq[byte]): ProtobufResult[T] = | |||||
| return err(ProtobufError.missingRequiredField("lamportTimestamp")) | ||||||
| msg.lamportTimestamp = int64(timestamp) | ||||||
|
|
||||||
| var causalHistory: seq[SdsMessageID] | ||||||
| let histResult = pb.getRepeatedField(3, causalHistory) | ||||||
| if histResult.isOk: | ||||||
| msg.causalHistory = causalHistory | ||||||
| # Handle both old and new causal history formats | ||||||
| var historyBuffers: seq[seq[byte]] | ||||||
| if pb.getRepeatedField(3, historyBuffers).isOk: | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nitpick one. Verbs with parenthesis; nouns without
Suggested change
|
||||||
| # New format: repeated HistoryEntry | ||||||
| for histBuffer in historyBuffers: | ||||||
| let entryPb = initProtoBuffer(histBuffer) | ||||||
| var entry: HistoryEntry | ||||||
| if not ?entryPb.getField(1, entry.messageId): | ||||||
| return err(ProtobufError.missingRequiredField("HistoryEntry.messageId")) | ||||||
| # retrievalHint is optional | ||||||
| discard entryPb.getField(2, entry.retrievalHint) | ||||||
| msg.causalHistory.add(entry) | ||||||
| else: | ||||||
| # Try old format: repeated string | ||||||
| var causalHistory: seq[SdsMessageID] | ||||||
| let histResult = pb.getRepeatedField(3, causalHistory) | ||||||
| if histResult.isOk: | ||||||
| msg.causalHistory = toCausalHistory(causalHistory) | ||||||
|
|
||||||
| if not ?pb.getField(4, msg.channelId): | ||||||
| return err(ProtobufError.missingRequiredField("channelId")) | ||||||
|
|
||||||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always avoid the use of the implicit
result