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();
|
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;
|
int n;
|
||||||
bool fullnames = true;
|
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.
|
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;
|
char *pSql;
|
||||||
int length;
|
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.
|
// Then we store the query itself in the second half of the key.
|
||||||
pData = reinterpret_cast<const unsigned char*>(pSql);
|
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;
|
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);
|
Entries::iterator i = m_entries.find(key);
|
||||||
Entry* pEntry;
|
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,
|
// If the needed value is less than what is currently stored,
|
||||||
// we shrink the buffer so as not to waste space.
|
// we shrink the buffer so as not to waste space.
|
||||||
Value value(size);
|
Value entry_value(size);
|
||||||
pEntry->value.swap(value);
|
pEntry->value.swap(entry_value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -287,7 +287,7 @@ cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF*
|
|||||||
|
|
||||||
m_stats.size += size;
|
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());
|
copy(pData, pData + size, pEntry->value.begin());
|
||||||
pEntry->time = time(NULL);
|
pEntry->time = time(NULL);
|
||||||
|
@ -30,12 +30,12 @@ public:
|
|||||||
const CACHE_STORAGE_CONFIG& config,
|
const CACHE_STORAGE_CONFIG& config,
|
||||||
int argc, char* argv[]);
|
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);
|
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_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 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;
|
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
||||||
|
|
||||||
cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const;
|
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_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_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);
|
cache_result_t do_del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
private:
|
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);
|
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_);
|
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)
|
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_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 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 del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
private:
|
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);
|
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)
|
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_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 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);
|
cache_result_t del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -360,13 +360,13 @@ RocksDBStorage* RocksDBStorage::Create(const char* zName,
|
|||||||
return sStorage.release();
|
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;
|
int n;
|
||||||
bool fullnames = true;
|
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.
|
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;
|
char *pSql;
|
||||||
int length;
|
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.
|
// Then we store the query itself in the second half of the key.
|
||||||
pData = reinterpret_cast<const unsigned char*>(pSql);
|
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;
|
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 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;
|
return status.ok() ? CACHE_RESULT_OK : CACHE_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,12 @@ public:
|
|||||||
int argc, char* argv[]);
|
int argc, char* argv[]);
|
||||||
~RocksDBStorage();
|
~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);
|
void get_config(CACHE_STORAGE_CONFIG* pConfig);
|
||||||
cache_result_t get_info(uint32_t flags, json_t** ppInfo) const;
|
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 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 del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const;
|
cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const;
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
|
|
||||||
cache_result_t result = CACHE_RESULT_ERROR;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ public:
|
|||||||
|
|
||||||
StorageType* pStorage = reinterpret_cast<StorageType*>(pCache_storage);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user