Skip to content
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

feat: Add a new cluster state "Unhealthy" #63

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

sbernauer
Copy link
Member

Part of #58
WIP, it still has commits from #62 until that is merged

@sbernauer sbernauer marked this pull request as draft February 24, 2025 13:41
@sbernauer sbernauer changed the title Feat/add unhealthy state feat: Add a new cluster state "Unhealthy" Feb 24, 2025
@sbernauer sbernauer marked this pull request as ready for review February 24, 2025 15:34
@Techassi Techassi self-requested a review February 24, 2025 15:36
Copy link
Member

@Techassi Techassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature overall lgtm, just a few questions and comments.

CHANGELOG.md Outdated
Comment on lines 15 to 16
`Unhealthy` clusters won't get any new queries, if all queries are unhealthy queries are queued.
<br>Note: Use the now configurable scaler reconcile interval to detect cluster changes quickly ([#63]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I don't quite understand the sentence in line 15. It is either wrong, or worded weirdly.

note: markdownlint complains about the <br /> tag. I think we should remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, there was a typo: a9726af

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL a backslash also works: 5e5b022

Comment on lines +151 to +152
#[instrument(skip(self, cluster), fields(cluster_name = cluster.name))]
async fn process_cluster(&self, cluster: &TrinoClusterConfig, state: ClusterState) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: You should add a small doc comment explaining what this method does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 373ab07

Comment on lines +162 to +165
if let Err(err) = self
.persistence
.set_cluster_query_count(&cluster.name, 0)
.await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why exactly do we set the number of queries to zero here? Can you add a developer comment here which shortly explains it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some rustdoc in 373ab07 explaining it. Is that sufficient in this case here?

ClusterState::Ready | ClusterState::Draining{ .. } => Some(cluster),
})
.map(|cluster| self.process_cluster(cluster)),
.map(|(cluster, state)| self.process_cluster(cluster, state))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: It seems like we are not actually mapping anything here. Does it maybe make more sense to use .for_each() here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, as we are using https://docs.rs/futures/latest/futures/future/fn.join_all.html here

    Checking trino-lb v0.3.2 (/home/sbernauer/stackable/trino-lb/trino-lb)
error[E0308]: mismatched types
   --> trino-lb/src/maintenance/query_count_fetcher.rs:139:54
    |
139 |                         .for_each(|(cluster, state)| self.process_cluster(cluster, state))
    |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found future
    |
note: calling an async function returns a future
   --> trino-lb/src/maintenance/query_count_fetcher.rs:139:54
    |
139 |                         .for_each(|(cluster, state)| self.process_cluster(cluster, state))
    |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider `await`ing on the `Future`
    |
139 |                         .for_each(|(cluster, state)| self.process_cluster(cluster, state).await)
    |                                                                                          ++++++
help: consider using a semicolon here
    |
139 |                         .for_each(|(cluster, state)| { self.process_cluster(cluster, state); })
    |                                                      +                                     +++

error[E0277]: `()` is not an iterator
   --> trino-lb/src/maintenance/query_count_fetcher.rs:135:30
    |
135 |                   let result = join_all(
    |  ______________________________^
136 | |                     self.clusters
137 | |                         .iter()
138 | |                         .zip(cluster_states)
139 | |                         .for_each(|(cluster, state)| self.process_cluster(cluster, state))
140 | |                 )
    | |_________________^ `()` is not an iterator
    |
    = help: the trait `Iterator` is not implemented for `()`
    = note: required for `()` to implement `IntoIterator`

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `trino-lb` (bin "trino-lb") due to 2 previous errors

We could do some things around futures::stream::iter(self.clusters.iter().zip(cluster_states)).for_each_concurrent(1000000, |(cluster, state)| self.process_cluster(cluster, state)).await, but
a.) that a different approach than we take everywhere else.
b.) The result.len() breaks, we need to do it differently

Not sure if that's worth it

@sbernauer sbernauer requested a review from Techassi February 25, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants