From 06eaf7232e9a920468c0f8d74dcf2fe8b555501c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:24:36 +0200 Subject: Adding upstream version 1:10.11.6. Signed-off-by: Daniel Baumann --- storage/rocksdb/unittest/CMakeLists.txt | 22 +++++++++ .../rocksdb/unittest/test_properties_collector.cc | 54 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 storage/rocksdb/unittest/CMakeLists.txt create mode 100644 storage/rocksdb/unittest/test_properties_collector.cc (limited to 'storage/rocksdb/unittest') diff --git a/storage/rocksdb/unittest/CMakeLists.txt b/storage/rocksdb/unittest/CMakeLists.txt new file mode 100644 index 00000000..de8d0d82 --- /dev/null +++ b/storage/rocksdb/unittest/CMakeLists.txt @@ -0,0 +1,22 @@ +IF (TARGET rocksdb) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/unittest/mytap + ${CMAKE_SOURCE_DIR}/rocksdb/third-party/gtest-1.7.0/fused-src + ) + LINK_LIBRARIES(mytap mysys dbug strings) + + ADD_DEFINITIONS(-DSTANDALONE_UNITTEST) + + MYSQL_ADD_EXECUTABLE(test_properties_collector + test_properties_collector.cc + ) + TARGET_LINK_LIBRARIES(test_properties_collector mysqlserver) + + # Necessary to make sure that we can use the jemalloc API calls. + GET_TARGET_PROPERTY(mysql_embedded LINK_FLAGS PREV_LINK_FLAGS) + IF(NOT PREV_LINK_FLAGS) + SET(PREV_LINK_FLAGS) + ENDIF() + SET_TARGET_PROPERTIES(test_properties_collector PROPERTIES LINK_FLAGS + "${PREV_LINK_FLAGS} ${WITH_MYSQLD_LDFLAGS}") +ENDIF() diff --git a/storage/rocksdb/unittest/test_properties_collector.cc b/storage/rocksdb/unittest/test_properties_collector.cc new file mode 100644 index 00000000..6870cd20 --- /dev/null +++ b/storage/rocksdb/unittest/test_properties_collector.cc @@ -0,0 +1,54 @@ +/* + Copyright (c) 2015, Facebook, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +/* MyRocks header files */ +#include "../ha_rocksdb.h" +#include "../rdb_datadic.h" + +void putKeys(myrocks::Rdb_tbl_prop_coll *coll, int num, bool is_delete, + uint64_t expected_deleted) { + std::string str("aaaaaaaaaaaaaa"); + rocksdb::Slice sl(str.data(), str.size()); + + for (int i = 0; i < num; i++) { + coll->AddUserKey( + sl, sl, is_delete ? rocksdb::kEntryDelete : rocksdb::kEntryPut, 0, 100); + } + DBUG_ASSERT(coll->GetMaxDeletedRows() == expected_deleted); +} + +int main(int argc, char **argv) { + // test the circular buffer for delete flags + myrocks::Rdb_compact_params params; + params.m_file_size = 333; + params.m_deletes = 333; // irrelevant + params.m_window = 10; + + myrocks::Rdb_tbl_prop_coll coll(nullptr, params, 0, + RDB_DEFAULT_TBL_STATS_SAMPLE_PCT); + + putKeys(&coll, 2, true, 2); // [xx] + putKeys(&coll, 3, false, 2); // [xxo] + putKeys(&coll, 1, true, 3); // [xxox] + putKeys(&coll, 6, false, 3); // [xxoxoooooo] + putKeys(&coll, 3, true, 4); // xxo[xooooooxxx] + putKeys(&coll, 1, false, 4); // xxox[ooooooxxxo] + putKeys(&coll, 100, false, 4); // ....[oooooooooo] + putKeys(&coll, 100, true, 10); // ....[xxxxxxxxxx] + putKeys(&coll, 100, true, 10); // ....[oooooooooo] + + return 0; +} -- cgit v1.2.3