-
Notifications
You must be signed in to change notification settings - Fork 249
provider: adding provide and reprovide queue #1114
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
base: provider
Are you sure you want to change the base?
Conversation
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.
Some minor things, see comments
// Prefix is a prefix of (at least) an existing prefix in the queue. | ||
entriesToRemove := keyspace.AllEntries(subtrie, bit256.ZeroKey()) | ||
prefixesToRemove := make([]bitstr.Key, len(entriesToRemove)) | ||
for i, entry := range entriesToRemove { | ||
prefixesToRemove[i] = entry.Key | ||
} | ||
// Remove superstrings of `prefix` from the queue | ||
firstRemovedIndex := q.removePrefixesFromQueue(prefixesToRemove) |
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.
These lines are also present in Remove
. Maybe put them into a function.
digest := make([]byte, 32) | ||
if _, err := rand.Read(digest); err != nil { | ||
panic(err) | ||
} | ||
h, err := mh.Encode(digest, mh.SHA2_256) | ||
if err != nil { | ||
panic(err) | ||
} |
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.
Look at random.Multihashes
or even random.Bytes
digest := make([]byte, 32) | |
if _, err := rand.Read(digest); err != nil { | |
panic(err) | |
} | |
h, err := mh.Encode(digest, mh.SHA2_256) | |
if err != nil { | |
panic(err) | |
} | |
h := random.Multihashes(1)[0] |
panic(err) | ||
} | ||
k := keyspace.MhToBit256(h) | ||
if keyspace.IsPrefix(prefix, k) { |
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.
Instead of finding enough multihashes that have the prefix by chance, consider generating the requested number of random multihashes, and overwriting them to have the correct prefix.
// queue. It assumes the mutex is held already. | ||
func (q *ProvideQueue) sizeNoLock() int { | ||
return q.keys.Size() | ||
} |
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.
This seems like an unnecessary function. Would it be better to just call q.keys.Size()
?
Part of #1095
This PR adds 2 queues implementations:
Reprovide queue
This queue keeps track of the prefixes associated with the keyspace regions that should be reprovided as soon as possible. These regions end up in the queue if the provider failed to reprovide them on time.
Provide queue
This queue keeps track of all the keys that should be provided as soon as possible. The keys are grouped by common prefix to optimize batch providing.
Both queues make use of the
prefixQueue
.