[leap5] clear the DB dirty bit if pinnable_mapped_file fails to fully start#38
[leap5] clear the DB dirty bit if pinnable_mapped_file fails to fully start#38spoonincode merged 3 commits intoleap-5.0from
pinnable_mapped_file fails to fully start#38Conversation
|
|
||
| template<typename F> | ||
| struct scope_fail { | ||
| scope_fail(F&& f) : _f{static_cast<F&&>(f)}, _exception_count{std::uncaught_exceptions()} {} |
There was a problem hiding this comment.
I realize you just copied this here, but why does it use static_cast instead of std::move ? Also seems like we should delete the copy constructor and assignement operator.
|
I feel it would be much simpler to not set the dirty bit at all in the constructor except when we are in "mapped" mode. |
|
I don't think this implementation would work for |
I think that alone introduces a new defect for the other modes because currently dirty isn't set when writing out data. So you'd need to do it then. Regardless, I am not sure the upside of this since it doesn't do anything more helpful for the user anyways, for example, So the least complex approach is to just be consistent and blanket do it in a simple way: dirty in ctor, clean in dtor. Current complexity comes about more so due to the code structure and approach imo.
There are some unit tests added that show this working for the defect being resolved. It's not pretty but what seems to happen is that when in writable mapped_private mode, chainbase/src/pinnable_mapped_file.cpp Lines 185 to 187 in 7b8b830 and then, chainbase/src/pinnable_mapped_file.cpp Line 236 in 7b8b830 But it's on this line that the exception will be thrown so _file_mapped_region is left 'empty'. So when,chainbase/src/pinnable_mapped_file.cpp Lines 455 to 458 in 7b8b830 The mapping to the real disk file is recreated before setting the dirty bit. Of course, some other exception after line 236 and the end of the ctor would cause the problem you're describing, but I guess currently that isn't possible since |
|
Yes, I agree the issue I raised is not valid and the existing code is fine (discounting the complexity) I wonder why we remove the fork_db disk file after loading it (I would suggest to leave it except when chainbase is in |
Clear the DB dirty bit if
pinnable_mapped_filethrows during ctor after it has set the bit to dirty. Resolves AntelopeIO/leap#2086