-
Notifications
You must be signed in to change notification settings - Fork 33
Add getNodeRecordBuckets, addNodeRecord, and deleteNode to DiscoverySystem #188
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
Changes from 3 commits
b650809
aae881a
1a6c76a
367ab31
1fc4504
9065610
2c86e75
047214f
3c62cc1
a440285
eb31bb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import java.time.Clock; | ||
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Spliterator; | ||
|
|
@@ -143,4 +144,15 @@ public synchronized Optional<NodeRecord> getNode(final Bytes nodeId) { | |
| public synchronized boolean containsNode(final Bytes nodeId) { | ||
|
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. I don't understand why these methods are synchronized. E.g. containsNode is always just for a certain point in time. The node record could be deleted just after leaving the synchronized method. Or the node could be added just after we returned false.
Contributor
Author
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. I assume it's from an abundance of caution in a system intended to be used in a multi-threaded environment. Perhaps it would be good to overhaul it with ReentractReadWriteLock instead. It could increase performance if the discovery system is used frequently in multiple threads. |
||
| return getNode(nodeId).isPresent(); | ||
| } | ||
|
|
||
| public synchronized List<List<NodeRecord>> getNodeRecordBuckets() { | ||
|
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. Not sure I like this name. We are not returning the buckets, we are returning node records from all buckets. Maybe a simple name like
Contributor
Author
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. I included the words buckets because each sub list is a list of node records from a bucket. I'm not sure getNodeRecords conveys quite the same meaning. Personally, I don't understand why node records are organised like that, but it seems important. |
||
| return buckets.values().stream().map(KBucket::getAllNodes).toList(); | ||
| } | ||
|
|
||
| public synchronized void deleteNode(final Bytes nodeId) { | ||
| final int distance = Functions.logDistance(homeNodeId, nodeId); | ||
| if (distance <= MAXIMUM_BUCKET) { | ||
| getBucket(distance).ifPresent((bucket) -> bucket.deleteNode(nodeId)); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.