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

New subcode for IOError to detect the ESTALE errno #1748

Closed
wants to merge 2 commits into from

Conversation

mdlugajczyk
Copy link
Contributor

I'd like to propose a patch to expose a new IOError type with subcode kStaleFile to allow to detect when ESTALE error is returned. This allows the rocksdb consumers to handle this error separately from other IOErrors.

I've also added a missing string representation for the kDeadlock subcode, I believe calling ToString() on Status object with that subcode would result in an out of band access in the msgs array,

Please let me know if you have any questions or would like me to make any changes to this pull request.

@facebook-github-bot
Copy link
Contributor

@IslamAbdelRahman has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@IslamAbdelRahman
Copy link
Contributor

Thanks @mdlugajczyk, Can you please explain why you need this

@mdlugajczyk
Copy link
Contributor Author

@IslamAbdelRahman - I'm storing rocksdbs on a distributed file system, if it becomes unavailable rocksdb receives ESTALE errno and returns IOError. I want to handle this situation, but don't want this code to be triggered by any other type of IOError.

I could try checking the error message of IOError and check for existence of "stale file" substring, but I don't like the idea of parsing error messages to determine what error has occurred, particularly since rocksdb had this information.

Does this explain the use case?

@IslamAbdelRahman
Copy link
Contributor

Thanks @mdlugajczyk for explaining.

Can you simply check status.subcode() in your application.
I am just asking because there are many possible errors that could happen and it does not make sense to put a special Status class for each one of them, so I think it would be better to check the subcode() outside RocksDB. What do you think ?

@mdlugajczyk
Copy link
Contributor Author

@IslamAbdelRahman - sure that makes sense. I'll modify my change to just add a new subcode. Thanks for reviewing the pull request and your feedback.

Calling ToString() function on an IOError with the kDeadlock
subcode would result in a crash as the array with the error messages
didn't have an entry for the subcode.
@facebook-github-bot
Copy link
Contributor

@mdlugajczyk updated the pull request - view changes - changes since last import

This change allows to differentiate between the ESTALE errno and other
IOErrors, making it possible to handle this error separately in user's
code.
@facebook-github-bot
Copy link
Contributor

@mdlugajczyk updated the pull request - view changes - changes since last import

@mdlugajczyk
Copy link
Contributor Author

@IslamAbdelRahman - apologies for the delay in getting back to you. I've updated the code to just add a new subcode and pass it to the IOError constructor when the errno is ESTALE. Does it look better now?

@mdlugajczyk
Copy link
Contributor Author

I've just realised that the current version of the code would lose the error message, would it be ok if I changed the IOError factory function to take subcode & optional error message? Something like

static Status IOError(Subcode subcode = kNone, const Slice& msg = Slice()) { return Status(kIOError, subcode, msg); }

and changing the private constructor for the Status class to:

Status::Status(Code _code, Subcode _subcode = kNone, const Slice& _msg = Slice())

@IslamAbdelRahman
Copy link
Contributor

@mdlugajczyk .. the current implementation have Status::subcode() function that will return the code to you, Should not that be good enough for your application ?

@mdlugajczyk
Copy link
Contributor Author

@IslamAbdelRahman - the subcode will be sufficient to handle this situation, however the Status::ToString() function will be a generic "stale file error". Currently the error message contains the file name for which the error happened, which is useful for logging and later analysis of the problem.

Currently one can get detailed error message if the ESTALE happens, but no easy way to detect it programmatically. My change makes the the detection possible but loses the error message.

Since all the information is available to rocksdb (errno & which file experienced the problem), I think it make sense to expose it to allow detailed logging & special handling of this error in the user code.

@facebook-github-bot
Copy link
Contributor

@IslamAbdelRahman has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants