-
Notifications
You must be signed in to change notification settings - Fork 987
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 limit handling on rpc configuration #4353
Changes from all commits
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 |
---|---|---|
|
@@ -34,15 +34,26 @@ pub struct FirehoseEndpoint { | |
pub token: Option<String>, | ||
pub filters_enabled: bool, | ||
pub compression_enabled: bool, | ||
pub subgraph_limit: usize, | ||
pub subgraph_limit: SubgraphLimit, | ||
channel: Channel, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
// TODO: Find a new home for this type. | ||
#[derive(Clone, Debug, PartialEq, Ord, Eq, PartialOrd)] | ||
pub enum SubgraphLimit { | ||
Unlimited, | ||
Disabled, | ||
Limit(usize), | ||
NoTraffic, | ||
Unlimited, | ||
} | ||
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. Do we really need this enum? I don't really think it buys us much above using a plain 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. It's mostly to improve readability since otherwise we'd need to set a value for 0 and some for "not set" in order to differentiate so there would be a few places with Option where we were not sure of the meaning. Also Unlimited will also get transformed in the different adapters, eg firehose uses 100 max so it gets set to the adapter-specific "maximum" |
||
|
||
impl SubgraphLimit { | ||
pub fn has_capacity(&self, current: usize) -> bool { | ||
match self { | ||
SubgraphLimit::Unlimited => true, | ||
SubgraphLimit::Limit(limit) => limit > ¤t, | ||
SubgraphLimit::Disabled => false, | ||
} | ||
} | ||
} | ||
|
||
impl Display for FirehoseEndpoint { | ||
|
@@ -93,10 +104,10 @@ impl FirehoseEndpoint { | |
|
||
let subgraph_limit = match subgraph_limit { | ||
// See the comment on the constant | ||
SubgraphLimit::Unlimited => SUBGRAPHS_PER_CONN, | ||
SubgraphLimit::Unlimited => SubgraphLimit::Limit(SUBGRAPHS_PER_CONN), | ||
// This is checked when parsing from config but doesn't hurt to be defensive. | ||
SubgraphLimit::Limit(limit) => limit.min(SUBGRAPHS_PER_CONN), | ||
SubgraphLimit::NoTraffic => 0, | ||
SubgraphLimit::Limit(limit) => SubgraphLimit::Limit(limit.min(SUBGRAPHS_PER_CONN)), | ||
l => l, | ||
}; | ||
|
||
FirehoseEndpoint { | ||
|
@@ -109,11 +120,11 @@ impl FirehoseEndpoint { | |
} | ||
} | ||
|
||
// The SUBGRAPHS_PER_CONN upper bound was already limited so we leave it the same | ||
// we need to use inclusive limits (<=) because there will always be a reference | ||
// we need to -1 because there will always be a reference | ||
// inside FirehoseEndpoints that is not used (is always cloned). | ||
pub fn has_subgraph_capacity(self: &Arc<Self>) -> bool { | ||
Arc::strong_count(&self) <= self.subgraph_limit | ||
self.subgraph_limit | ||
.has_capacity(Arc::strong_count(&self).checked_sub(1).unwrap_or(0)) | ||
} | ||
|
||
pub async fn get_block<M>( | ||
|
@@ -501,7 +512,7 @@ mod test { | |
None, | ||
false, | ||
false, | ||
SubgraphLimit::NoTraffic, | ||
SubgraphLimit::Disabled, | ||
))]; | ||
|
||
let mut endpoints = FirehoseEndpoints::from(endpoint); | ||
|
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.
I don't fully understand this comment, especially the 'or, this is fine' throws me off
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.
I initially had something else there :P I will fix this, good catch :)