MXS-2727 Add test that reveals problem
This commit is contained in:
@ -46,6 +46,11 @@ target_link_libraries(test_cacheoptions maxscale-common)
|
|||||||
add_executable(cache_stress cache_stress.cc)
|
add_executable(cache_stress cache_stress.cc)
|
||||||
target_link_libraries(cache_stress ${MARIADB_CONNECTOR_LIBRARIES} ssl crypt crypto dl pthread)
|
target_link_libraries(cache_stress ${MARIADB_CONNECTOR_LIBRARIES} ssl crypt crypto dl pthread)
|
||||||
|
|
||||||
|
add_executable(cache_bugs cache_bugs.cc)
|
||||||
|
target_link_libraries(cache_bugs cache maxscale-common mysqlcommon)
|
||||||
|
|
||||||
|
add_test(test_cache_bugs cache_bugs)
|
||||||
|
|
||||||
add_test(test_cache_rules testrules)
|
add_test(test_cache_rules testrules)
|
||||||
|
|
||||||
add_test(test_cache_inmemory_keygeneration testkeygeneration storage_inmemory ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
add_test(test_cache_inmemory_keygeneration testkeygeneration storage_inmemory ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
||||||
|
|||||||
113
server/modules/filter/cache/test/cache_bugs.cc
vendored
Normal file
113
server/modules/filter/cache/test/cache_bugs.cc
vendored
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2023-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <maxscale/ccdefs.hh>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <maxbase/log.hh>
|
||||||
|
#include <maxscale/modinfo.h>
|
||||||
|
#include "../cachemt.hh"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
GWBUF* create_gwbuf(const string& s)
|
||||||
|
{
|
||||||
|
size_t len = s.length();
|
||||||
|
size_t payload_len = len + 1;
|
||||||
|
size_t gwbuf_len = MYSQL_HEADER_LEN + payload_len;
|
||||||
|
|
||||||
|
GWBUF* pBuf = gwbuf_alloc(gwbuf_len);
|
||||||
|
|
||||||
|
*((unsigned char*)((char*)GWBUF_DATA(pBuf))) = payload_len;
|
||||||
|
*((unsigned char*)((char*)GWBUF_DATA(pBuf) + 1)) = (payload_len >> 8);
|
||||||
|
*((unsigned char*)((char*)GWBUF_DATA(pBuf) + 2)) = (payload_len >> 16);
|
||||||
|
*((unsigned char*)((char*)GWBUF_DATA(pBuf) + 3)) = 0x00;
|
||||||
|
*((unsigned char*)((char*)GWBUF_DATA(pBuf) + 4)) = 0x03;
|
||||||
|
memcpy((char*)GWBUF_DATA(pBuf) + 5, s.c_str(), len);
|
||||||
|
|
||||||
|
return pBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mxs_2727()
|
||||||
|
{
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
const size_t MAX_SIZE = 10;
|
||||||
|
|
||||||
|
CacheConfig config("MXS-2727");
|
||||||
|
config.storage = std::string("storage_inmemory");
|
||||||
|
config.soft_ttl = std::chrono::seconds(1);
|
||||||
|
config.hard_ttl = std::chrono::seconds(10);
|
||||||
|
config.max_size = MAX_SIZE;
|
||||||
|
config.thread_model = CACHE_THREAD_MODEL_MT;
|
||||||
|
config.enabled = true;
|
||||||
|
|
||||||
|
auto* pCache = CacheMT::Create("MXS-2727", &config);
|
||||||
|
|
||||||
|
CACHE_KEY key;
|
||||||
|
GWBUF* pSelect = create_gwbuf("SELECT * FROM t");
|
||||||
|
|
||||||
|
cache_result_t result = pCache->get_key("test", pSelect, &key);
|
||||||
|
|
||||||
|
if (!CACHE_RESULT_IS_OK(result))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<uint8_t> value(MAX_SIZE - 1); // Less than max size.
|
||||||
|
std::generate(value.begin(), value.end(), random);
|
||||||
|
|
||||||
|
GWBUF* pValue = gwbuf_alloc_and_load(value.size(), &value.front());
|
||||||
|
|
||||||
|
result = pCache->put_value(key, pValue);
|
||||||
|
gwbuf_free(pValue);
|
||||||
|
|
||||||
|
if (!CACHE_RESULT_IS_OK(result))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
value.push_back(4);
|
||||||
|
value.push_back(2);
|
||||||
|
// Now, larger than max size.
|
||||||
|
|
||||||
|
pValue = gwbuf_alloc_and_load(value.size(), &value.front());
|
||||||
|
|
||||||
|
// This will crash without the MXS-2727 fix.
|
||||||
|
result = pCache->put_value(key, pValue);
|
||||||
|
gwbuf_free(pValue);
|
||||||
|
|
||||||
|
if (!CACHE_RESULT_IS_OK(result))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
mxb::Log log;
|
||||||
|
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
rv += mxs_2727();
|
||||||
|
|
||||||
|
return rv == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user