Commit 445dce8b authored by Paal Kvamme's avatar Paal Kvamme
Browse files

User opt-in for the readonly kludge. This commit is just a preparation to make...

User opt-in for the readonly kludge. This commit is just a preparation to make the next one easier to diff.
parent 5ee7e541
......@@ -777,11 +777,25 @@ public:
return info_;
}
void close()
/**
* Close the underlying SDGenericDataset.
* If an exception occurs then the wrapper will still see
* the dataset as closed. And dataset() will return empty.
*
* Caveat: There was at one point a bug where SDGenericDataset::close()
* threw an appropriate exception (e.g. credentials timed out) then
* destructing the dataset could also throw. Exceptions from a
* destructor usually causes the program to terminate. Especially in
* C++11 and later. There are workarounds with multiple try/catch that
* *might* help but it should be a lot easier to fix the underlying bug.
*/
void wrapper_close()
{
auto victim = dataset_;
OpenMode disp = disposition_;
dataset_.reset();
switch (disposition_) {
disposition_ = OpenMode::Closed;
switch (disp) {
case OpenMode::Truncate:
case OpenMode::ReadWrite:
// TODO-Low: Maybe not if the file isn't finalized?
......@@ -790,7 +804,6 @@ public:
default:
break;
}
disposition_ = OpenMode::Closed;
victim->close();
victim.reset(); // Any throw from SDGenericDataset dtor happens here.
}
......@@ -1046,6 +1059,16 @@ public:
}
};
/**
* Automatically close the dataset when the last reference to it goes away.
* This is a fallback. Please do NOT rely on this behavior. Especially if
* the dataset is open for write. Instead, make sure xx_close() is called
* in a timely manner. If we get here with an open dataset then:
*
* - Exceptions will be logged and swallowed.
* - The C++ runtime might abort due to exception during unwind.
* - Cleanup such as making the dataset read-only might be skipped.
*/
SDGenericDatasetWrapper::~SDGenericDatasetWrapper()
{
info_.reset();
......@@ -1194,7 +1217,7 @@ SeismicStoreFile::~SeismicStoreFile()
// the application will crash.
if (_dataset && _dataset->dataset() && _dataset->disposition() != OpenMode::Closed) {
try {
_dataset->close();
_dataset->wrapper_close();
}
catch (const std::exception& ex) {
_logger(0, "EXCEPTION closing file: " + std::string(ex.what()));
......@@ -1682,7 +1705,7 @@ SeismicStoreFile::xx_close()
<< "Ignoring exception during close: "
<< ex.what());
}
victim->close();
victim->wrapper_close();
}
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment