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

Prepare client.c for use in the client library #458

Merged
merged 19 commits into from
Jan 31, 2023

Conversation

cole-miller
Copy link
Contributor

@cole-miller cole-miller commented Jan 17, 2023

  • src/client.{c,h} -> src/client/protocol.{c,h} in preparation for more client source files
  • Implement remaining request/response types (that are actually used by go-dqlite)
  • Use up-to-date protocol/schema versions for all requests
  • Improved error handling
  • Timeouts for reading from the underlying fd

This will be easiest to review commit-by-commit.

@codecov
Copy link

codecov bot commented Jan 17, 2023

Codecov Report

Merging #458 (f265305) into master (86ac733) will decrease coverage by 2.24%.
The diff coverage is 48.59%.

@@            Coverage Diff             @@
##           master     #458      +/-   ##
==========================================
- Coverage   74.32%   72.08%   -2.24%     
==========================================
  Files          32       33       +1     
  Lines        5382     5878     +496     
  Branches     1682     1871     +189     
==========================================
+ Hits         4000     4237     +237     
- Misses        823     1004     +181     
- Partials      559      637      +78     
Impacted Files Coverage Δ
src/transport.c 70.77% <ø> (+5.84%) ⬆️
src/client/protocol.c 48.42% <48.42%> (ø)
src/gateway.c 60.91% <66.66%> (+0.50%) ⬆️
src/request.c 100.00% <100.00%> (ø)
src/conn.c 71.92% <0.00%> (-1.45%) ⬇️
src/leader.c 69.31% <0.00%> (-0.77%) ⬇️
src/id.c 100.00% <0.00%> (ø)
src/fsm.c 75.04% <0.00%> (+0.04%) ⬆️
src/vfs.c 84.12% <0.00%> (+0.14%) ⬆️
src/server.c 68.60% <0.00%> (+0.41%) ⬆️
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cole-miller cole-miller changed the title Start setting up the C client Prepare client.c for use in the client library Jan 18, 2023
Signed-off-by: Cole Miller <cole.miller@canonical.com>
This information doesn't seem useful to me.

Signed-off-by: Cole Miller <cole.miller@canonical.com>
We probably want to save the generic name for a higher-level object.

Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
@cole-miller
Copy link
Contributor Author

@freeekanayaka, could you elucidate what DQLITE_REQUEST_CONNECT is for? It seems that it's not used at all by go-dqlite, so I didn't implement it here. There's still a codepath in dqlite to handle such requests -- perhaps it could be removed?

test/integration/test_cluster.c Outdated Show resolved Hide resolved
src/client/protocol.c Outdated Show resolved Hide resolved
src/client/protocol.c Outdated Show resolved Hide resolved
* On error, -1 is returned. Otherwise the return value is the count
* of bytes read. This may be less than n if either EOF happened or
* polling timed out. */
static ssize_t doRead(int fd, void *buf, size_t n, int timeout_millis)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can pass the client struct here instead and do some accounting on the timeout and save e.g. timeout_left in the client struct after measuring the time spent in poll?

Copy link
Contributor Author

@cole-miller cole-miller Jan 24, 2023

Choose a reason for hiding this comment

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

Yes, this makes sense to me, I'll try to implement it. (The alternative for setting a budget on the time spent in the loop as a whole would be arranging to get SIGALRM when a timer expires and setting up a handler, but that sounds terrible.)

@MathieuBordere
Copy link
Contributor

Did a first round of reading through the changes, think it already looks good.

@freeekanayaka
Copy link
Contributor

@freeekanayaka, could you elucidate what DQLITE_REQUEST_CONNECT is for? It seems that it's not used at all by go-dqlite, so I didn't implement it here. There's still a codepath in dqlite to handle such requests -- perhaps it could be removed?

It's basically used as glue between dqlite and raft. If you use dqlite without a custom transport, then when raft needs to establish a connection to another raft node it will use the default dqlite transport defined in transport.c which basically connects to the desired dqlite engine running the raft code and sends the DQLITE_REQUEST_CONNECT command to tell the dqlite engine to handover the connection to the raft code.

It's implicitly used by go-dqlite as well via dqlite_node_set_connect_func.

I hope my memory doesn't fail me and that everything is correct and clear :) Please let me know if something doesn't match.

@cole-miller
Copy link
Contributor Author

cole-miller commented Jan 25, 2023

@freeekanayaka Got it, thanks! I'll add this to the docs.

What's the motivation for proxying raft connections through dqlite, instead of having them flow independently? I guess it's convenient to have just one address that both dqlite and raft are listening on.

@freeekanayaka
Copy link
Contributor

@freeekanayaka Got it, thanks! I'll add this to the docs.

What's the motivation for proxying raft connections through dqlite, instead of having them flow independently? I guess it's convenient to have just one address that both dqlite and raft are listening on.

Sorry, I didn't see your follow up before. Yes, it's to have a single endpoint.

@cole-miller
Copy link
Contributor Author

I've pushed another (rather large, sorry) commit that implements a different strategy for timing out reads/writes. It also includes a rewrite of clientRecvRows to do proper cleanup if an error is encountered.

@cole-miller cole-miller marked this pull request as ready for review January 30, 2023 14:53
Copy link
Contributor

@MathieuBordere MathieuBordere left a comment

Choose a reason for hiding this comment

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

Mostly nits :-)

src/client/protocol.h Outdated Show resolved Hide resolved
{
switch (val.type) {
case SQLITE_TEXT:
free((char *)val.text);
Copy link
Contributor

Choose a reason for hiding this comment

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

Funny that you need to cast this :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I guess not being allow to free const T* is some kind of safeguard against calling it on static data.

src/client/protocol.c Show resolved Hide resolved
src/client/protocol.c Show resolved Hide resolved
src/client/protocol.c Outdated Show resolved Hide resolved
src/client/protocol.c Show resolved Hide resolved
src/client/protocol.c Show resolved Hide resolved
src/client/protocol.c Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
@MathieuBordere MathieuBordere merged commit d34e461 into canonical:master Jan 31, 2023
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.

3 participants