-
Notifications
You must be signed in to change notification settings - Fork 14
Multi-node client #52
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: main
Are you sure you want to change the base?
Conversation
fix: missing generic in impl block
… plain text (JSONL)
…and remove unused templates
First of all, thank you for fixing the return types of the auto-generated code. And I also have like a 100 questions to node_url
.strip_suffix('/')
.unwrap_or(node_url.as_str())
.to_string() You also can prebuild a let (nodes_len, mut index) = if self.has_nearest_node {
let last_node_index = self.nodes.len() - 1;
(last_node_index, last_node_index)
} else {
(self.nodes.len(), self.current_node_index.fetch_add(1, Ordering::Relaxed) % self.nodes.len())
};
for _ in 0..self.nodes.len() {
let node_arc = self.nodes[index];
let node = node_arc.lock().unwrap();
let is_due_for_check = Instant::now().duration_since(node.last_access_timestamp)
>= self.healthcheck_interval;
if node.is_healthy || is_due_for_check {
return Arc::clone(node_arc);
}
index = self.current_node_index.fetch_add(1, Ordering::Relaxed) % nodes_len;
}
... |
After this PR gets approved which means the |
Hey @RoDmitry, would you be open to collaborating on this PR with me? I have sent you an invitation to my repository, with that, you can directly push the changes to optimize the client/mod.rs |
It's not xtask but the openapi generator. I modified the template, specifically this line
Xtask is just a convenient way to run the open api generator |
I don't think they need the rust specific variables there. I thought you would preprocess it by xtask the way |
Adding a few of rust specific attributes won't hurt. Plus, there are some Go specific attributes in the openapi spec too
Preprocess it by xtask is possible but it's pretty tedious I think, but let's see if doing it through xtask is better... |
Also it's better to have Rust specific variables in this repository, because it is part of the code which can be changed. And it's just easier to modify and keep it synchronized when it's in a single repo. That's why I would prefer adding it through xtask. |
Just downloaded the project, no changes, and one test fails on my machine:
In code:
Each P.S. How does it not fail in github tests? They are very slow. |
Optimized |
Looks good. No more points to improve from me. |
e2b59aa
to
c2bb563
Compare
241576c
to
426efdc
Compare
While migrating my project to this version of typesense, caught myself on using the wrong |
0320f8b
to
dd9a723
Compare
dd9a723
to
9783c60
Compare
@haydenhoang do you approve |
So now we have three separate ways to access the single collection API: This looks good! But are there any useful usecases for I think we need to take Typesense's Sorry for the late reply, I'm currently not available for a while. |
Yes. Previously I have tried to use multiple collections of the same type with different names. I'm not sure if it's useful, and whether I will use it in the future or not. So I thought maybe Didn't understand about |
https://typesense.org/docs/29.0/api/search.html#results-parameters Like the name suggest, setting this param will exclude fields from search result. I think this would cause a parsing error if those fields aren't marked as optional in the struct. |
It's up to a user, which struct he chooses to use. He can create another struct, without those excluded fields, and pass it to |
We have some APIs implemented in this PR, but not all of them. So I think maybe we should expose |
ff169be
to
6e116b1
Compare
6e116b1
to
ab05dcf
Compare
I think it's best to not reexport those legacy APIs entirely to keep it minimal. We won't release this until we have implemented all the APIs. I have already had those lined up in the draft PR so this shouldn't take much time. This is a major version bump, so it is expected for users of old version to migrate.
Then this will be another breaking change. Other than that, all looks good! |
Then this re-export is temporal until the next PR with all of the APIs. I will need to check if all of the APIs are implemented, then it can be removed or marked as
but
It's ok then. Nothing to worry about. My opinion is: nobody knows how much time it may take. So |
@morenol it's ready for merge. We will continue in another PR |
What's in this PR
Added
/openapi-generator-template
We can freely modify this template which is used to generate
typesense_codegen
. This PR added some custom open-api attributes:x-rust-return-type
to specify the return type of a generated API methodx-rust-generic-parameter
to specify the generic params of a generated API method or a modelx-rust-type
to override the type of a generated model fieldx-supports-plain-text
: this is an existing attribute which indicates that the response will be text instead of JSONx-rust-body-is-raw-text
set this totrue
to avoid JSON serializing plain text request bodyx-rust-builder: true
will create builder for that model using bonExamples
typesense-rust/openapi.yml
Lines 425 to 433 in 4d4d38e
typesense-rust/openapi.yml
Lines 742 to 753 in 4b811e2
typesense-rust/openapi.yml
Lines 2446 to 2448 in 4b811e2
typesense-rust/openapi.yml
Lines 2476 to 2481 in 4b811e2
typesense-rust/openapi.yml
Lines 2163 to 2168 in 4d4d38e
Multi-node client
All the generated API methods are wrapped in
client.execute()
which will provide retry & load-balance across all nodes.For easier review, the client only has Collections, Documents, Keys and Multi search APIs, future PRs will add more APIs.
Please see the integration tests for more examples.
Removed httpmock in CI
The mock data is no longer relevant, it should be removed to avoid overhead. I replaced it with an actual Typesense v30.0.rc10 server.
PR Checklist