Skip to content

Conversation

@yjh0502
Copy link
Collaborator

@yjh0502 yjh0502 commented Apr 21, 2018

  • I used error-chain for error handling because I'm familiar with it. It might better to change it to failure, as other sub-crates do.
  • I embedded fdb.options file into source. Please let me know if you have any preferred option.
  • FdbScope::ty and FdbOption::ty return String instead of taking Write (for maybe Formatter?) as a mutable argument. The code looks dirty but it works :(
  • fdb_network_set_options and similar APIs take length and pointer as arguments, so next step might be generating apply() function which call underlying C API for each enum types.

@bluejekyll
Copy link
Collaborator

This is awesome! I haven't even got a license up yet :)

I was planning an Apache 2.0/MIT if that's ok with you, I'll add that to repo then we can merge that into this PR so that we have all that squared away.


  • On error-chain: I just pushed an FdbError type last night, it's based on Failure which is going to replace error-chain in most use-cases in Rust. I think you're generator can skip generating errors and instead just use the hand-written type? https://github.com/bluejekyll/foundationdb-rs/blob/master/foundationdb/src/error.rs

  • fdb.options: I have no opinion at-the-moment, we can clean this up later... I don't think this is a bad option, but we probably want to track a version somehow.

  • "The code looks dirty but it works": All code starts out dirty, then we learn what we want and make it better ;) your decisions here seem fine to me.

  • fdb_network_set_options: I almost started working on the wrapper API for this last night. We'll have to see what happens with that.


Thanks, again for the PR. Let me get the LICENSE squared away, and then address the FdbError question and then let's go from there.

extern crate inflector;
extern crate xml;
#[macro_use]
extern crate error_chain;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Failure is quite nice and simple. For the generator, you can get away with just using format_err! and returning the failure::Error type. in the result type, example:

fn example() -> Result<Type, failure::Error> {
   Err(format_err!("my failure message: {}", extra_info)
}

Can we switch to that instead? I believe most of Rust is going to be going in this direction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to failure.

}
}

pub enum ErrorPredicate {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you look at error::FdbError in the foundationdb crate? We should maybe remove my hand-rolled version.

Copy link
Collaborator Author

@yjh0502 yjh0502 Apr 21, 2018

Choose a reason for hiding this comment

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

I replaced FdbErrorPredicate with options::ErrorPredicate. I'm not sure about name of fn code() -> fdb::FDBErrorPredicate. It's okay for other enum types which might have seperated value like String, but for ErrorPredicate case fn value() -> ... sounds better.

impl ErrorPredicate {
pub fn code(&self) -> fdb::FDBErrorPredicate {
match *self {
ErrorPredicate::Retryable => 50000,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically these values are fdb::FDBErrorPredicate_FDB_ERROR_PREDICATE_MAYBE_COMMITTED, rather than the raw value. Not sure if this is something the generator could write instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just tried to change those values to generated one, but there are some mismatches between names on fdb.options and names on fdb_c.h. Here's a list.

https://gist.github.com/yjh0502/cd19273e15464e5e2c377fc9f3ce3e03

  • Some of them are just singular/plural problem, for example WATCH/WATCHES, BYTE/BYTES. I can handle it with some brute-force replace rules.
  • It seems that options with hidden=true is not available on c header. I filtered those options.
  • There's one remaining non-regular case, FDBMutationType_FDB_MUTATION_TYPE_SET_VERSIONSTAMPED_KEY, which should not be converted to ..._KEYS. I just hard-coded the case :(

@yjh0502
Copy link
Collaborator Author

yjh0502 commented Apr 21, 2018

Thanks for the feedback!

  • I'm happy with Apache 2.0/MIT
  • For error types, I just error-chain mainly for ensure!/bail! macros which helps debugging during iteration. I'll replace it into hand-written error types.

For fdb_network_set_options things, I added a unsafe fn apply() which is a helper functions. You can use those functions for initial prototyping :)

@bluejekyll
Copy link
Collaborator

Thanks again for the PR, if this is ready I'll merge it in.

I'm working on travis scripts right now, so we should get some testing options.

@bluejekyll
Copy link
Collaborator

Thanks again for the PR, this is a massive help!

@bluejekyll bluejekyll merged commit 83f0dc4 into Clikengo:master Apr 21, 2018
pH14 pushed a commit to pH14/foundationdb-rs that referenced this pull request May 25, 2019
generate options types from fdb.options
Speedy37 pushed a commit that referenced this pull request Nov 19, 2019
Update to newest master
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