Cache: Pass argument as reference when it must be non-NULL
This commit is contained in:
@ -97,13 +97,13 @@ InMemoryStorage* InMemoryStorage::Create_instance(const char* zName,
|
||||
return sStorage.release();
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorage::Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey)
|
||||
cache_result_t InMemoryStorage::Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey)
|
||||
{
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(pQuery));
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(&query));
|
||||
|
||||
int n;
|
||||
bool fullnames = true;
|
||||
char** pzTables = qc_get_table_names(const_cast<GWBUF*>(pQuery), &n, fullnames);
|
||||
char** pzTables = qc_get_table_names(const_cast<GWBUF*>(&query), &n, fullnames);
|
||||
|
||||
set<string> dbs; // Elements in set are sorted.
|
||||
|
||||
@ -149,7 +149,7 @@ cache_result_t InMemoryStorage::Get_key(const char* zDefault_db, const GWBUF* pQ
|
||||
char *pSql;
|
||||
int length;
|
||||
|
||||
modutil_extract_SQL(const_cast<GWBUF*>(pQuery), &pSql, &length);
|
||||
modutil_extract_SQL(const_cast<GWBUF*>(&query), &pSql, &length);
|
||||
|
||||
// Then we store the query itself in the second half of the key.
|
||||
pData = reinterpret_cast<const unsigned char*>(pSql);
|
||||
@ -248,11 +248,11 @@ cache_result_t InMemoryStorage::do_get_value(const CACHE_KEY& key, uint32_t flag
|
||||
return result;
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
||||
cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF& value)
|
||||
{
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(pValue));
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(&value));
|
||||
|
||||
size_t size = GWBUF_LENGTH(pValue);
|
||||
size_t size = GWBUF_LENGTH(&value);
|
||||
|
||||
Entries::iterator i = m_entries.find(key);
|
||||
Entry* pEntry;
|
||||
@ -276,8 +276,8 @@ cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF*
|
||||
{
|
||||
// If the needed value is less than what is currently stored,
|
||||
// we shrink the buffer so as not to waste space.
|
||||
Value value(size);
|
||||
pEntry->value.swap(value);
|
||||
Value entry_value(size);
|
||||
pEntry->value.swap(entry_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -287,7 +287,7 @@ cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF*
|
||||
|
||||
m_stats.size += size;
|
||||
|
||||
const uint8_t* pData = GWBUF_DATA(pValue);
|
||||
const uint8_t* pData = GWBUF_DATA(&value);
|
||||
|
||||
copy(pData, pData + size, pEntry->value.begin());
|
||||
pEntry->time = time(NULL);
|
||||
|
@ -30,12 +30,12 @@ public:
|
||||
const CACHE_STORAGE_CONFIG& config,
|
||||
int argc, char* argv[]);
|
||||
|
||||
static cache_result_t Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey);
|
||||
static cache_result_t Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey);
|
||||
|
||||
void get_config(CACHE_STORAGE_CONFIG* pConfig);
|
||||
virtual cache_result_t get_info(uint32_t what, json_t** ppInfo) const = 0;
|
||||
virtual cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult) = 0;
|
||||
virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue) = 0;
|
||||
virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF& value) = 0;
|
||||
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
||||
|
||||
cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const;
|
||||
@ -49,7 +49,7 @@ protected:
|
||||
|
||||
cache_result_t do_get_info(uint32_t what, json_t** ppInfo) const;
|
||||
cache_result_t do_get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult);
|
||||
cache_result_t do_put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
||||
cache_result_t do_put_value(const CACHE_KEY& key, const GWBUF& value);
|
||||
cache_result_t do_del_value(const CACHE_KEY& key);
|
||||
|
||||
private:
|
||||
|
@ -49,11 +49,11 @@ cache_result_t InMemoryStorageMT::get_value(const CACHE_KEY& key, uint32_t flags
|
||||
return do_get_value(key, flags, ppResult);
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorageMT::put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
||||
cache_result_t InMemoryStorageMT::put_value(const CACHE_KEY& key, const GWBUF& value)
|
||||
{
|
||||
SpinLockGuard guard(lock_);
|
||||
|
||||
return do_put_value(key, pValue);
|
||||
return do_put_value(key, value);
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorageMT::del_value(const CACHE_KEY& key)
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
cache_result_t get_info(uint32_t what, json_t** ppInfo) const;
|
||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult);
|
||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF& value);
|
||||
cache_result_t del_value(const CACHE_KEY& key);
|
||||
|
||||
private:
|
||||
|
@ -43,9 +43,9 @@ cache_result_t InMemoryStorageST::get_value(const CACHE_KEY& key, uint32_t flags
|
||||
return do_get_value(key, flags, ppResult);
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorageST::put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
||||
cache_result_t InMemoryStorageST::put_value(const CACHE_KEY& key, const GWBUF& value)
|
||||
{
|
||||
return do_put_value(key, pValue);
|
||||
return do_put_value(key, value);
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorageST::del_value(const CACHE_KEY& key)
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
|
||||
cache_result_t get_info(uint32_t what, json_t** ppInfo) const;
|
||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult);
|
||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF& pValue);
|
||||
cache_result_t del_value(const CACHE_KEY& key);
|
||||
|
||||
private:
|
||||
|
@ -360,13 +360,13 @@ RocksDBStorage* RocksDBStorage::Create(const char* zName,
|
||||
return sStorage.release();
|
||||
}
|
||||
|
||||
cache_result_t RocksDBStorage::Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey)
|
||||
cache_result_t RocksDBStorage::Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey)
|
||||
{
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(pQuery));
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(&query));
|
||||
|
||||
int n;
|
||||
bool fullnames = true;
|
||||
char** pzTables = qc_get_table_names(const_cast<GWBUF*>(pQuery), &n, fullnames);
|
||||
char** pzTables = qc_get_table_names(const_cast<GWBUF*>(&query), &n, fullnames);
|
||||
|
||||
set<string> dbs; // Elements in set are sorted.
|
||||
|
||||
@ -409,7 +409,7 @@ cache_result_t RocksDBStorage::Get_key(const char* zDefault_db, const GWBUF* pQu
|
||||
char *pSql;
|
||||
int length;
|
||||
|
||||
modutil_extract_SQL(const_cast<GWBUF*>(pQuery), &pSql, &length);
|
||||
modutil_extract_SQL(const_cast<GWBUF*>(&query), &pSql, &length);
|
||||
|
||||
// Then we store the query itself in the second half of the key.
|
||||
pData = reinterpret_cast<const unsigned char*>(pSql);
|
||||
@ -510,14 +510,14 @@ cache_result_t RocksDBStorage::get_value(const CACHE_KEY& key, uint32_t flags, G
|
||||
return result;
|
||||
}
|
||||
|
||||
cache_result_t RocksDBStorage::put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
||||
cache_result_t RocksDBStorage::put_value(const CACHE_KEY& key, const GWBUF& value)
|
||||
{
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(pValue));
|
||||
ss_dassert(GWBUF_IS_CONTIGUOUS(&value));
|
||||
|
||||
rocksdb::Slice rocksdb_key(key.data, ROCKSDB_KEY_LENGTH);
|
||||
rocksdb::Slice value((char*)GWBUF_DATA(pValue), GWBUF_LENGTH(pValue));
|
||||
rocksdb::Slice rocksdb_value((char*)GWBUF_DATA(&value), GWBUF_LENGTH(&value));
|
||||
|
||||
rocksdb::Status status = m_sDb->Put(Write_options(), rocksdb_key, value);
|
||||
rocksdb::Status status = m_sDb->Put(Write_options(), rocksdb_key, rocksdb_value);
|
||||
|
||||
return status.ok() ? CACHE_RESULT_OK : CACHE_RESULT_ERROR;
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ public:
|
||||
int argc, char* argv[]);
|
||||
~RocksDBStorage();
|
||||
|
||||
static cache_result_t Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey);
|
||||
static cache_result_t Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey);
|
||||
|
||||
void get_config(CACHE_STORAGE_CONFIG* pConfig);
|
||||
cache_result_t get_info(uint32_t flags, json_t** ppInfo) const;
|
||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult);
|
||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF& value);
|
||||
cache_result_t del_value(const CACHE_KEY& key);
|
||||
|
||||
cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const;
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
|
||||
cache_result_t result = CACHE_RESULT_ERROR;
|
||||
|
||||
MXS_EXCEPTION_GUARD(result = StorageType::Get_key(zDefault_db, pQuery, pKey));
|
||||
MXS_EXCEPTION_GUARD(result = StorageType::Get_key(zDefault_db, *pQuery, pKey));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -113,7 +113,7 @@ public:
|
||||
|
||||
StorageType* pStorage = reinterpret_cast<StorageType*>(pCache_storage);
|
||||
|
||||
MXS_EXCEPTION_GUARD(result = pStorage->put_value(*pKey, pValue));
|
||||
MXS_EXCEPTION_GUARD(result = pStorage->put_value(*pKey, *pValue));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user