I get some super annoying asserts when I try to delete the leveldb instance and I'm not sure why it's happening!
The assert is happening in the version_set.cc file:
void VersionSet::AppendVersion(Version* v) {
// Make "v" current
assert(v->refs_ == 0); // <---??? how do I avoid this assertion?
// the rest of the source code is available in the link to version_set.cc
}
Additionally, it asserts in another place in the same file:
Version::~Version() {
assert(refs_ == 0); // <-- Again... how do I avoid this one too?
// the rest of the source code is available in the link to version_set.cc
}
Here is more background details on the usage in my system, I have a:
- class
ExtStorage
(Extended Storage) which has aLevelDB::DB
instance. - class
EextStorageDotNet
, which is the C++/CLI wrapper around theExtStorage
. - class
AltStorage
, which holds a pointer to an ExtStorage class (passed through the constructor): - class
AltStorageDotNet
, which is the C++/CLI wrapper around theAltStorage
.
The alternate storage class looks like this:
class AltStorage{
ExtStorage* instance;
public:
AltStorage(ExtStorage* extStorage):instance(extStorage){}
~AltStorage(){
delete instance;
instance = NULL;
}
};
The ExtStorage
class looks like this:
class ExtStorage{
leveldb::DB* mydb;
public:
ExtStorage(/*some parameters*/){
mydb = new leveldb::DB(/*parameters*/);
}
// Destructor
~ExtStorage() {
Close();
}
// deletes the leveldb::DB instance
void Close() {
if(mydb == NULL) {
delete mydb; // <-- Asserts every time I get here when using with the AltStorageDotNet
mydb= NULL;
// Close the L1 and L2 caches
// only once (
}
}
}
The AltStorageDotNet
class looks like this:
public ref class AltStorageDotNet{
AltStorage* altInstance;
ExtStorageDotNet^ extInstance;
public:
AltStorageDotNet() {
ExtStorage extStorage = new ExtStorage(/*params*/);
altInstance = new AltStorage(extStorage);
extInstance = gcnew ExtStorageDotNet(extStorage);
}
~AltStorageDotNet(){
delete altInstance;
altInstance = NULL;
// no need to delete extInstance since it was created with gcnew
}
!AltStorageDotNet(){
delete altInstance;
altInstance = NULL;
// no need to delete extInstance since it was created with gcnew
}
inline ExtStorageDotNet^ GetExtInstance(){return extInstance;}
};
The DotNet wrappers look like this:
public ref class ExtStorageDotNet{
private:
ExtStorage* instance;
public:
ExtStorageDotNet(ExtStorage* extStorage){
instance = extStorage;
}
~ExtStorageDotNet(){
delete instance;
instance = NULL;
}
!ExtStorageDotNet(){
delete instance;
instance = NULL;
}
void Close(){instance->Close();}
};
Whenever I use the ExtStorageDotNet
wrapper in my C# application everything works good and there are no asserts. However, when I use the AltStorageDotNet
wrapper and I access the ExtStorageDotNet
wrapper, then I get the asserts when closing the database. This is all part of a test suite in which I initialize an instance for each test case and close it after each test case; the associated database files get deleted before a new test case begins. I don't see any reason why it should happen and the assertion is not helpful in tracking down the problem.