-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
db_stress: db_stress segmentation fault #9175
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ namespace ROCKSDB_NAMESPACE { | |
|
||
// TODO: consider using expected_values_dir instead, but this is more | ||
// convenient for now. | ||
UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name) | ||
UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name, Env* env) | ||
: path_(db_name + "/.unique_ids") { | ||
// We expect such a small number of files generated during this test | ||
// (thousands?), checking full 192-bit IDs for uniqueness is a very | ||
|
@@ -27,14 +27,14 @@ UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name) | |
// very good probability for the quantities in this test. | ||
offset_ = Random::GetTLSInstance()->Uniform(17); // 0 to 16 | ||
|
||
// Use default FileSystem to avoid fault injection, etc. | ||
FileSystem& fs = *FileSystem::Default(); | ||
// Use the FileSystem from the environment | ||
const std::shared_ptr<rocksdb::FileSystem>fs = env->GetFileSystem(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
IOOptions opts; | ||
|
||
{ | ||
std::unique_ptr<FSSequentialFile> reader; | ||
Status s = | ||
fs.NewSequentialFile(path_, FileOptions(), &reader, /*dbg*/ nullptr); | ||
fs->NewSequentialFile(path_, FileOptions(), &reader, /*dbg*/ nullptr); | ||
if (s.ok()) { | ||
// Load from file | ||
std::string id(24U, '\0'); | ||
|
@@ -54,7 +54,7 @@ UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name) | |
fprintf(stdout, "Warning: clearing corrupt unique id file\n"); | ||
id_set_.clear(); | ||
reader.reset(); | ||
s = fs.DeleteFile(path_, opts, /*dbg*/ nullptr); | ||
s = fs->DeleteFile(path_, opts, /*dbg*/ nullptr); | ||
assert(s.ok()); | ||
} | ||
break; | ||
|
@@ -65,16 +65,20 @@ UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name) | |
// Newly created is ok. | ||
// But FileSystem doesn't tell us whether non-existence was the cause of | ||
// the failure. (Issue #9021) | ||
Status s2 = fs.FileExists(path_, opts, /*dbg*/ nullptr); | ||
if (!s2.IsNotFound()) { | ||
fprintf(stderr, "Error opening unique id file: %s\n", | ||
s.ToString().c_str()); | ||
assert(false); | ||
Status s2 = fs->FileExists(path_, opts, /*dbg*/ nullptr); | ||
if (s2.IsNotFound()) { | ||
std::unique_ptr<FSWritableFile> wf; | ||
s = fs->NewWritableFile(path_, FileOptions(), &wf, /*dbg*/ nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary according to the API docs of ReopenWritableFile There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you pointed it out, I dug in a bit more into it and turns out the StressTest() constructor is deleting the "dbstress" directory under "/tmp/rocksdbtest-0/" directory because "--destroy_db_initially" option is by default on. So, below command seg faults on both debug and release builds So I added a change to create the db directory if it is missing, so that ReOpenWritableFile() can work as expected and there is no need of NewWritableFile(). |
||
if (!s.ok()) { | ||
fprintf(stderr, "Error creating unique id file: %s\n", | ||
s.ToString().c_str()); | ||
assert(false); | ||
} | ||
} | ||
} | ||
} | ||
fprintf(stdout, "(Re-)verified %zu unique IDs\n", id_set_.size()); | ||
Status s = fs.ReopenWritableFile(path_, FileOptions(), &data_file_writer_, | ||
Status s = fs->ReopenWritableFile(path_, FileOptions(), &data_file_writer_, | ||
/*dbg*/ nullptr); | ||
if (!s.ok()) { | ||
fprintf(stderr, "Error opening unique id file for append: %s\n", | ||
|
@@ -84,7 +88,8 @@ UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name) | |
} | ||
|
||
UniqueIdVerifier::~UniqueIdVerifier() { | ||
data_file_writer_->Close(IOOptions(), /*dbg*/ nullptr); | ||
if (data_file_writer_) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. data_file_writer_ is not intended to be nullable, because these checks are not intended to be optional. (If they were optional, Verify() would also need updating) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it is expected to be non-null, so will remove this check. |
||
data_file_writer_->Close(IOOptions(), /*dbg*/ nullptr); | ||
} | ||
|
||
void UniqueIdVerifier::VerifyNoWrite(const std::string& id) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described in the comment, for the listener, we use the default FS (a new instance) such that, the calls will not executed by fault_injection_fs. If we use the one from env_, then we may get IOError here, which is not expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better way might be, we create another wrapper for the customized FileSystem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion.
Could you please elaborate a bit more on the new wrapper that you are suggesting ? What would this wrapper include/exclude ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhichao-cao @aravind-wdc What is the goal here? You want to get the FileSystem from inside the FaultInjectionTestFS? Could you just use static_cast<FileSystem*>(env->GetFileSystem()->Inner())