Files
openGauss-third_party/dependency/masstree/0003-masstree_code_cleanup.patch
Vinoth Veeraraghavan 26896745e0 Masstree code cleanup
2022-07-20 11:25:51 +08:00

450 lines
16 KiB
Diff

From 62fcebd4a8ac1a60acbf1f227a57be5b8d981c8e Mon Sep 17 00:00:00 2001
From: Vinoth Veeraraghavan <vinoth.veeraraghavan@hotmail.com>
Date: Thu, 14 Jul 2022 18:55:08 +0300
Subject: [PATCH] Clean masstree code
More detail: Clean masstree code
---
kvthread.hh | 27 +++--
masstree.hh | 15 +--
masstree_config.h | 118 +++++++++++----------
masstree_insert.hh | 4 +-
masstree_split.hh | 2 +-
masstree_tcursor.hh | 6 +-
mot_masstree_config.hpp | 99 -----------------
7 files changed, 83 insertions(+), 188 deletions(-)
delete mode 100644 mot_masstree_config.hpp
diff --git a/kvthread.hh b/kvthread.hh
index 364cd44..01d6919 100644
--- a/kvthread.hh
+++ b/kvthread.hh
@@ -69,11 +69,6 @@ enum {
class threadinfo;
class loginfo;
-namespace MOT
-{
- class MasstreePrimaryIndex;
- class GcManager;
-};
extern __thread threadinfo * mtSessionThreadInfo;
@@ -284,7 +279,7 @@ class alignas(64) threadinfo {
void* p = NULL;
int nl = (sz + memdebug_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
if (use_pool()) {
- masstree_invariant(false); // mot code should not reach here
+ masstree_invariant(false); // internal memory pool is currently disabled
assert(nl <= pool_max_nlines);
if (unlikely(!pool_[nl - 1]))
refill_pool(nl);
@@ -308,10 +303,11 @@ class alignas(64) threadinfo {
assert(p && nl <= pool_max_nlines);
p = memdebug::check_free(p, sz, memtag(tag + nl));
if (use_pool()) {
+ masstree_invariant(false); // internal memory pool is currently disabled
*reinterpret_cast<void **>(p) = pool_[nl - 1];
pool_[nl - 1] = p;
} else
- deallocate(p, sz, tag); // mot memory deallocation
+ deallocate(p, sz, tag); // external memory pool deallocation
mark(threadcounter(tc_alloc + (tag > memtag_value)),
-nl * CACHE_LINE_SIZE);
}
@@ -380,15 +376,16 @@ class alignas(64) threadinfo {
void set_rcu_free_count(int rcu_count) { rcu_free_count = rcu_count; }
int get_rcu_free_count() { return rcu_free_count; }
- void set_gc_session(MOT::GcManager* gc_session);
- MOT::GcManager * get_gc_session();
+ void set_gc_session(void * gc_session);
+ void * get_gc_session();
inline uint32_t get_occupied_elements() { return total_limbo_inuse_elements; }
- void set_working_index (MOT::MasstreePrimaryIndex * index) { cur_working_index = (MOT::MasstreePrimaryIndex *)index; }
- MOT::MasstreePrimaryIndex * get_working_index () { return cur_working_index; }
+ void set_working_index (void * index) { cur_working_index = index; }
+ void * get_working_index () { return cur_working_index; }
- // This function is now used to defer between Masstree internal pools (use_pool == true) vs MOT pools\slab allocators (use_pool == false)
+ // This function is now used to defer between Masstree internal memory pool (use_pool == true) vs external memory pool (use_pool == false)
+ // Masstree internal memory pool is currently disabled
static bool use_pool() {
#if ENABLE_ASSERTIONS
return !no_pool_value;
@@ -403,7 +400,7 @@ class alignas(64) threadinfo {
}
private:
- MOT::MasstreePrimaryIndex * cur_working_index;
+ void * cur_working_index;
int last_error = MT_MERR_OK;
std::vector<struct rcu_entry> dealloc_rcu;
union {
@@ -427,7 +424,7 @@ class alignas(64) threadinfo {
int rcu_free_count;
mt_limbo_group* limbo_head_;
mt_limbo_group* limbo_tail_;
- MOT::GcManager* gc_session_;
+ void * gc_session_;
uint32_t total_limbo_inuse_elements;
mutable kvtimestamp_t ts_;
@@ -458,7 +455,7 @@ class alignas(64) threadinfo {
void record_rcu(void* ptr, int size, memtag tag) {
if (unlikely(use_pool())) {
- masstree_invariant(false); // mot code should not reach here
+ masstree_invariant(false); // internal memory pool is currently disabled
if (limbo_tail_->tail_ + 2 > limbo_tail_->capacity)
refill_rcu();
uint64_t epoch = ng_getGlobalEpoch();
diff --git a/masstree.hh b/masstree.hh
index 89af0ee..955a5bc 100644
--- a/masstree.hh
+++ b/masstree.hh
@@ -20,12 +20,6 @@
#include "ksearch.hh"
#include "kvthread.hh"
-namespace MOT {
-class Key;
-}
-
-using namespace MOT;
-
namespace Masstree {
using lcdf::Str;
using lcdf::String;
@@ -62,8 +56,7 @@ template <typename P> class basic_table;
template <typename P> class unlocked_tcursor;
template <typename P> class tcursor;
-template<bool CONST_ITERATOR, bool FORWARD, typename P>
-class MasstreeIterator;
+template <bool CONST_ITERATOR, bool FORWARD, typename P> class MasstreeIterator;
template <typename P>
class basic_table {
@@ -78,12 +71,12 @@ class basic_table {
typedef MasstreeIterator<false, true, P> ForwardIterator;
typedef MasstreeIterator<false, false, P> ReverseIterator;
- void find(MOT::Key const* const& key, void*& output, bool& result, const uint32_t& pid) const;
+ void find(const uint8_t* key, const uint32_t key_len, void*& output, bool& result, const uint32_t& pid) const;
- void iteratorScan(const char * keybuf, uint32_t keylen, const bool& matchKey, Iterator* const& it, const bool& forwardDirection,
+ void iteratorScan(const char * keybuf, uint32_t keylen, const bool& matchKey, void* const& it, const bool& forwardDirection,
bool& result, const uint32_t& pid);
- void *insert(MOT::Key const* const& key, void* const& entry, bool& result, const uint32_t& pid);
+ void *insert(const uint8_t* key, const uint32_t key_len, void* const& entry, bool& result, const uint32_t& pid);
void *remove(uint8_t const *const &key, uint32_t length, bool &result, const uint32_t &pid);
bool init(const uint16_t keyLength, const std::string& name, destroy_value_cb_func destroyValue_CB = NULL);
int getMemtagMaxSize(enum memtag tag);
diff --git a/masstree_config.h b/masstree_config.h
index ecfaf2b..d5a3a17 100644
--- a/masstree_config.h
+++ b/masstree_config.h
@@ -1,62 +1,66 @@
-/*
- * Copyright (c) 2020 Huawei Technologies Co.,Ltd.
- *
- * openGauss is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
- * You may obtain a copy of Mulan PSL v2 at:
- *
- * http://license.coscl.org.cn/MulanPSL2
- *
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- * See the Mulan PSL v2 for more details.
- * -------------------------------------------------------------------------
- *
- * config.h
- * Masstree index configurations template.
- *
- * IDENTIFICATION
- * src/gausskernel/storage/mot/core/src/storage/index/masstree/config.h
- *
- * -------------------------------------------------------------------------
- */
-
-#include "mot_masstree_config.hpp"
-
#ifndef MASSTREE_CONFIG_H
#define MASSTREE_CONFIG_H
-#define HAVE_CXX_TEMPLATE_ALIAS MOT_HAVE_CXX_TEMPLATE_ALIAS
-#define HAVE_INT64_T_IS_LONG MOT_HAVE_INT64_T_IS_LONG
-#define HAVE_SIZE_T_IS_UNSIGNED_LONG MOT_HAVE_SIZE_T_IS_UNSIGNED_LONG
-#define HAVE_STD_HASH MOT_HAVE_STD_HASH
-#define HAVE_STD_IS_TRIVIALLY_COPYABLE MOT_HAVE_STD_IS_TRIVIALLY_COPYABLE
-#define HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE MOT_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
-#define HAVE_SUPERPAGE MOT_HAVE_SUPERPAGE
-#define HAVE_TYPE_TRAITS MOT_HAVE_TYPE_TRAITS
-#define HAVE_UNALIGNED_ACCESS MOT_HAVE_UNALIGNED_ACCESS
-#define HAVE___BUILTIN_CLZ MOT_HAVE___BUILTIN_CLZ
-#define HAVE___BUILTIN_CLZL MOT_HAVE___BUILTIN_CLZL
-#define HAVE___BUILTIN_CLZLL MOT_HAVE___BUILTIN_CLZLL
-#define HAVE___BUILTIN_CTZ MOT_HAVE___BUILTIN_CTZ
-#define HAVE___BUILTIN_CTZL MOT_HAVE___BUILTIN_CTZL
-#define HAVE___BUILTIN_CTZLL MOT_HAVE___BUILTIN_CTZLL
-#define HAVE___HAS_TRIVIAL_COPY MOT_HAVE___HAS_TRIVIAL_COPY
-#define HAVE___HAS_TRIVIAL_DESTRUCTOR MOT_HAVE___HAS_TRIVIAL_DESTRUCTOR
-#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP
-#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8 MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8
-#define HAVE___SYNC_FETCH_AND_ADD MOT_HAVE___SYNC_FETCH_AND_ADD
-#define HAVE___SYNC_FETCH_AND_ADD_8 MOT_HAVE___SYNC_FETCH_AND_ADD_8
-#define HAVE___SYNC_FETCH_AND_OR MOT_HAVE___SYNC_FETCH_AND_OR
-#define HAVE___SYNC_FETCH_AND_OR_8 MOT_HAVE___SYNC_FETCH_AND_OR_8
-#define HAVE___SYNC_VAL_COMPARE_AND_SWAP MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP
-#define HAVE___SYNC_VAL_COMPARE_AND_SWAP_8 MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP_8
-#define MASSTREE_MAXKEYLEN MOT_MASSTREE_MAXKEYLEN
-#define SIZEOF_INT MOT_SIZEOF_INT
-#define SIZEOF_LONG MOT_SIZEOF_LONG
-#define SIZEOF_LONG_LONG MOT_SIZEOF_LONG_LONG
-#define SIZEOF_SHORT MOT_SIZEOF_SHORT
-#define WORDS_BIGENDIAN_SET MOT_WORDS_BIGENDIAN_SET
+#define HAVE_CXX_TEMPLATE_ALIAS 1
+#define HAVE_INT64_T_IS_LONG 1
+#define HAVE_SIZE_T_IS_UNSIGNED_LONG 1
+#define HAVE_STD_HASH 1
+#define HAVE_STD_IS_TRIVIALLY_COPYABLE 1
+#define HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
+#define HAVE_SUPERPAGE 1
+#define HAVE_TYPE_TRAITS 1
+#define HAVE_UNALIGNED_ACCESS 0
+#define HAVE___BUILTIN_CLZ 1
+#define HAVE___BUILTIN_CLZL 1
+#define HAVE___BUILTIN_CLZLL 1
+#define HAVE___BUILTIN_CTZ 1
+#define HAVE___BUILTIN_CTZL 1
+#define HAVE___BUILTIN_CTZLL 1
+#define HAVE___HAS_TRIVIAL_COPY 1
+#define HAVE___HAS_TRIVIAL_DESTRUCTOR 1
+#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP 1
+#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8 1
+#define HAVE___SYNC_FETCH_AND_ADD 1
+#define HAVE___SYNC_FETCH_AND_ADD_8 1
+#define HAVE___SYNC_FETCH_AND_OR 1
+#define HAVE___SYNC_FETCH_AND_OR_8 1
+#define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1
+#define HAVE___SYNC_VAL_COMPARE_AND_SWAP_8 1
+
+/* Maximum key length */
+#define MASSTREE_MAXKEYLEN 256U
+
+#define SIZEOF_INT 4
+#define SIZEOF_LONG 8
+#define SIZEOF_LONG_LONG 8
+#define SIZEOF_SHORT 2
+#define WORDS_BIGENDIAN_SET 1
+
+#define MASSTREE_OBSOLETE_CODE 1
+#define masstree_invariant(x, ...) assert(x)
+#define masstree_precondition(x, ...) assert(x)
+
+
+
+#ifndef invariant
+#define invariant masstree_invariant
+#endif
+#ifndef precondition
+#define precondition masstree_precondition
#endif
+
+#ifndef CACHE_LINE_SIZE
+#define CACHE_LINE_SIZE 64
+#endif
+
+#ifndef PRIu64
+#if HAVE_SIZE_T_IS_UNSIGNED_LONG_LONG
+#define PRIu64 "llu"
+#else
+#define PRIu64 "lu"
+#endif
+#endif
+
+
+#endif // MASSTREE_CONFIG_H
diff --git a/masstree_insert.hh b/masstree_insert.hh
index e641f03..9f21bca 100644
--- a/masstree_insert.hh
+++ b/masstree_insert.hh
@@ -98,7 +98,7 @@ bool tcursor<P>::make_new_layer(threadinfo& ti) {
twig_head = nl;
nl->permutation_ = permuter_type::make_sorted(1);
twig_tail = nl;
-#ifndef MOT_OBSOLETE_CODE
+#ifndef MASSTREE_OBSOLETE_CODE
new_nodes_.emplace_back(nl, nl->full_unlocked_version_value());
#endif
oka.shift();
@@ -213,7 +213,7 @@ inline void tcursor<P>::finish(int state, threadinfo& ti)
// we finally know this!
if (n_ == original_n_)
updated_v_ = n_->full_unlocked_version_value();
-#ifndef MOT_OBSOLETE_CODE
+#ifndef MASSTREE_OBSOLETE_CODE
else
new_nodes_.emplace_back(n_, n_->full_unlocked_version_value());
#endif
diff --git a/masstree_split.hh b/masstree_split.hh
index 42b012b..2d53de6 100644
--- a/masstree_split.hh
+++ b/masstree_split.hh
@@ -363,7 +363,7 @@ bool tcursor<P>::make_split(threadinfo& ti)
ti.set_last_error(MT_MERR_MAKE_SPLIT_ASSIGN_SUFFIX);
rc = false;
}
-#ifndef MOT_OBSOLETE_CODE
+#ifndef MASSTREE_OBSOLETE_CODE
new_nodes_.emplace_back(nr, nr->full_unlocked_version_value());
#endif
} else {
diff --git a/masstree_tcursor.hh b/masstree_tcursor.hh
index 755588d..73231b8 100644
--- a/masstree_tcursor.hh
+++ b/masstree_tcursor.hh
@@ -106,7 +106,7 @@ class tcursor {
static constexpr int new_nodes_size = 1; // unless we make a new trie newnodes will have at most 1 item
typedef small_vector<std::pair<leaf_type*, nodeversion_value_type>, new_nodes_size> new_nodes_type;
-#ifndef MOT_OBSOLETE_CODE
+#ifndef MASSTREE_OBSOLETE_CODE
tcursor(basic_table<P>& table, Str str)
: ka_(str), root_(table.fix_root()) {
}
@@ -149,7 +149,7 @@ class tcursor {
inline nodeversion_value_type updated_version_value() const {
return updated_v_;
}
-#ifndef MOT_OBSOLETE_CODE
+#ifndef MASSTREE_OBSOLETE_CODE
inline const new_nodes_type &new_nodes() const {
return new_nodes_;
}
@@ -174,7 +174,7 @@ class tcursor {
nodeversion_value_type original_v_;
nodeversion_value_type updated_v_;
-#ifndef MOT_OBSOLETE_CODE
+#ifndef MASSTREE_OBSOLETE_CODE
new_nodes_type new_nodes_;
#endif
inline node_type* reset_retry() {
diff --git a/mot_masstree_config.hpp b/mot_masstree_config.hpp
deleted file mode 100644
index fe3930b..0000000
--- a/mot_masstree_config.hpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2020 Huawei Technologies Co.,Ltd.
- *
- * openGauss is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
- * You may obtain a copy of Mulan PSL v2 at:
- *
- * http://license.coscl.org.cn/MulanPSL2
- *
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- * See the Mulan PSL v2 for more details.
- * -------------------------------------------------------------------------
- *
- * mot_masstree_config.hpp
- * MOT configurations for Masstree index.
- *
- * IDENTIFICATION
- * src/gausskernel/storage/mot/core/src/storage/index/masstree/mot_masstree_config.hpp
- *
- * -------------------------------------------------------------------------
- */
-
-#ifndef MOT_MASSTREE_CONFIG_HPP
-#define MOT_MASSTREE_CONFIG_HPP
-
-// Ignore masstree code which is obsolete in MOT
-#define MOT_OBSOLETE_CODE 1
-
-#define MOT_HAVE_CXX_TEMPLATE_ALIAS 1
-#define MOT_HAVE_INT64_T_IS_LONG 1
-#define MOT_HAVE_SIZE_T_IS_UNSIGNED_LONG 1
-#define MOT_HAVE_STD_HASH 1
-#define MOT_HAVE_STD_IS_TRIVIALLY_COPYABLE 1
-#define MOT_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
-#define MOT_HAVE_SUPERPAGE 1
-#define MOT_HAVE_TYPE_TRAITS 1
-#define MOT_HAVE_UNALIGNED_ACCESS 0
-#define MOT_HAVE___BUILTIN_CLZ 1
-#define MOT_HAVE___BUILTIN_CLZL 1
-#define MOT_HAVE___BUILTIN_CLZLL 1
-#define MOT_HAVE___BUILTIN_CTZ 1
-#define MOT_HAVE___BUILTIN_CTZL 1
-#define MOT_HAVE___BUILTIN_CTZLL 1
-#define MOT_HAVE___HAS_TRIVIAL_COPY 1
-#define MOT_HAVE___HAS_TRIVIAL_DESTRUCTOR 1
-#define MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP 1
-#define MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8 1
-#define MOT_HAVE___SYNC_FETCH_AND_ADD 1
-#define MOT_HAVE___SYNC_FETCH_AND_ADD_8 1
-#define MOT_HAVE___SYNC_FETCH_AND_OR 1
-#define MOT_HAVE___SYNC_FETCH_AND_OR_8 1
-#define MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP 1
-#define MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP_8 1
-
-/* Maximum key length */
-#define MOT_MASSTREE_MAXKEYLEN MAX_KEY_SIZE
-#define MOT_SIZEOF_INT 4
-#define MOT_SIZEOF_LONG 8
-#define MOT_SIZEOF_LONG_LONG 8
-#define MOT_SIZEOF_SHORT 2
-#define MOT_WORDS_BIGENDIAN_SET 1
-/*
-#define masstree_invariant(x, ...) \
- do { \
- } while (0)
-
-#define masstree_precondition(x, ...) \
- do { \
- } while (0)
-*/
-
-#define masstree_invariant(x, ...) assert(x)
-#define masstree_precondition(x, ...) assert(x)
-
-
-
-#ifndef invariant
-#define invariant masstree_invariant
-#endif
-#ifndef precondition
-#define precondition masstree_precondition
-#endif
-
-#ifndef CACHE_LINE_SIZE
-#define CACHE_LINE_SIZE 64
-#endif
-
-#ifndef PRIu64
-#if HAVE_SIZE_T_IS_UNSIGNED_LONG_LONG
-#define PRIu64 "llu"
-#else
-#define PRIu64 "lu"
-#endif
-#endif
-
-
-#endif // MOT_MASSTREE_CONFIG_HPP
--
1.8.3.1