Fix crash saving an RDB

Former-commit-id: 51c35f03a84f7ada0f150a1c3992df574ab89b95
This commit is contained in:
John Sully 2021-03-05 00:54:11 +00:00
parent 902264efb7
commit 50060b4a13
2 changed files with 6 additions and 10 deletions

View File

@ -18,10 +18,11 @@ dictType dbStorageCacheType = {
NULL /* val destructor */ NULL /* val destructor */
}; };
StorageCache::StorageCache(IStorage *storage) StorageCache::StorageCache(IStorage *storage, bool fCache)
: m_spstorage(storage) : m_spstorage(storage)
{ {
m_pdict = dictCreate(&dbStorageCacheType, nullptr); if (fCache)
m_pdict = dictCreate(&dbStorageCacheType, nullptr);
} }
void StorageCache::clear() void StorageCache::clear()
@ -94,7 +95,7 @@ const StorageCache *StorageCache::clone()
{ {
std::unique_lock<fastlock> ul(m_lock); std::unique_lock<fastlock> ul(m_lock);
// Clones never clone the cache // Clones never clone the cache
StorageCache *cacheNew = new StorageCache(const_cast<IStorage*>(m_spstorage->clone())); StorageCache *cacheNew = new StorageCache(const_cast<IStorage*>(m_spstorage->clone()), false /*fCache*/);
return cacheNew; return cacheNew;
} }

View File

@ -8,7 +8,7 @@ class StorageCache
int m_collisionCount = 0; int m_collisionCount = 0;
mutable fastlock m_lock {"StorageCache"}; mutable fastlock m_lock {"StorageCache"};
StorageCache(IStorage *storage); StorageCache(IStorage *storage, bool fNoCache);
void cacheKey(sds key); void cacheKey(sds key);
void cacheKey(const char *rgchKey, size_t cchKey); void cacheKey(const char *rgchKey, size_t cchKey);
@ -29,12 +29,7 @@ class StorageCache
public: public:
static StorageCache *create(IStorageFactory *pfactory, int db, IStorageFactory::key_load_iterator fn, void *privdata) { static StorageCache *create(IStorageFactory *pfactory, int db, IStorageFactory::key_load_iterator fn, void *privdata) {
StorageCache *cache = new StorageCache(nullptr); StorageCache *cache = new StorageCache(nullptr, pfactory->FSlow() /*fCache*/);
if (!pfactory->FSlow())
{
dictRelease(cache->m_pdict);
cache->m_pdict = nullptr;
}
load_iter_data data = {cache, fn, privdata}; load_iter_data data = {cache, fn, privdata};
cache->m_spstorage = std::shared_ptr<IStorage>(pfactory->create(db, key_load_itr, (void*)&data)); cache->m_spstorage = std::shared_ptr<IStorage>(pfactory->create(db, key_load_itr, (void*)&data));
return cache; return cache;