From 9007c77b10db9be42bb1abfee89c46f9840098c0 Mon Sep 17 00:00:00 2001 From: nroskill Date: Thu, 10 Feb 2022 20:06:48 +0800 Subject: [PATCH] disable construct of ObIAllocator --- deps/oblib/src/common/data_buffer.h | 8 ++--- .../src/lib/alloc/ob_tenant_ctx_allocator.h | 2 ++ deps/oblib/src/lib/allocator/ob_allocator.h | 31 +++---------------- .../oblib/src/lib/allocator/ob_allocator_v2.h | 6 ++-- .../src/lib/allocator/ob_fifo_allocator.h | 2 +- deps/oblib/src/lib/allocator/ob_malloc.h | 12 +++---- deps/oblib/src/lib/container/ob_se_array.h | 14 +++++++++ src/election/ob_election_msg.h | 2 +- src/liboblog/src/ob_small_arena.h | 8 +++-- src/share/schema/ob_schema_struct.h | 8 +++-- src/sql/engine/expr/ob_expr.h | 9 ++++++ src/sql/engine/expr/ob_expr_regexp_context.h | 9 ++++++ src/sql/plan_cache/ob_id_manager_allocator.h | 9 ++++-- src/storage/memtable/ob_memtable_context.h | 18 ++++++++--- .../basic/test_ra_row_store_projector.cpp | 4 +++ 15 files changed, 92 insertions(+), 50 deletions(-) diff --git a/deps/oblib/src/common/data_buffer.h b/deps/oblib/src/common/data_buffer.h index 70592c0f0f..a1d898d3fa 100644 --- a/deps/oblib/src/common/data_buffer.h +++ b/deps/oblib/src/common/data_buffer.h @@ -28,7 +28,7 @@ public: ObDataBuffer(char* data, const int64_t capacity) : data_(data), capacity_(capacity), position_(0), limit_(0) {} - ~ObDataBuffer() + virtual ~ObDataBuffer() {} inline bool set_data(char* data, const int64_t capacity) @@ -55,7 +55,7 @@ public: limit_ = 0; } - inline void* alloc(const int64_t sz) + inline virtual void* alloc(const int64_t sz) { void* ret = NULL; if (OB_LIKELY(sz > 0 && capacity_ - position_ >= sz)) { @@ -64,13 +64,13 @@ public: } return ret; } - inline void* alloc(const int64_t sz, const lib::ObMemAttr& attr) + inline virtual void* alloc(const int64_t sz, const lib::ObMemAttr& attr) { UNUSED(attr); return alloc(sz); } - inline void free() + inline virtual void free() { position_ = 0; } diff --git a/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h b/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h index dfc8110cbe..015e862a07 100644 --- a/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h +++ b/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h @@ -66,6 +66,8 @@ public: attr.tenant_id_ = tenant_id; attr.ctx_id_ = ctx_id; } + virtual ~ObTenantCtxAllocator() + {} int set_tenant_memory_mgr() { int ret = common::OB_SUCCESS; diff --git a/deps/oblib/src/lib/allocator/ob_allocator.h b/deps/oblib/src/lib/allocator/ob_allocator.h index 795f85e6f6..6ab152131a 100644 --- a/deps/oblib/src/lib/allocator/ob_allocator.h +++ b/deps/oblib/src/lib/allocator/ob_allocator.h @@ -17,41 +17,23 @@ #include "lib/alloc/alloc_struct.h" namespace oceanbase { -namespace lib { -struct ObMemAttr; -} // end of namespace lib - namespace common { using lib::ObMemAttr; extern ObMemAttr default_memattr; class ObIAllocator { -public: - virtual ~ObIAllocator(){}; - public: /************************************************************************/ /* New Interface (Under construction) */ /************************************************************************/ // Use attr passed in by set_attr(). - virtual void* alloc(const int64_t size) - { - UNUSED(size); - return NULL; - } - - virtual void* alloc(const int64_t size, const ObMemAttr& attr) - { - UNUSED(size); - UNUSED(attr); - return NULL; - } - + virtual void* alloc(const int64_t size) = 0; + virtual void* alloc(const int64_t size, const ObMemAttr& attr) = 0; virtual void* realloc(const void* ptr, const int64_t size, const ObMemAttr& attr) { UNUSED(ptr); UNUSED(size); UNUSED(attr); - return NULL; + return nullptr; } virtual void* realloc(void* ptr, const int64_t oldsz, const int64_t newsz) @@ -59,13 +41,10 @@ public: UNUSED(ptr); UNUSED(oldsz); UNUSED(newsz); - return NULL; + return nullptr; } - virtual void free(void* ptr) - { - UNUSED(ptr); - } + virtual void free(void* ptr) = 0; virtual int64_t total() const { diff --git a/deps/oblib/src/lib/allocator/ob_allocator_v2.h b/deps/oblib/src/lib/allocator/ob_allocator_v2.h index 6d6888180c..07cf279f69 100644 --- a/deps/oblib/src/lib/allocator/ob_allocator_v2.h +++ b/deps/oblib/src/lib/allocator/ob_allocator_v2.h @@ -38,12 +38,14 @@ class ObAllocator : public ObIAllocator { public: ObAllocator(__MemoryContext__* mem_context, const ObMemAttr& attr = default_memattr, const bool use_pm = false, const uint32_t ablock_size = lib::INTACT_NORMAL_AOBJECT_SIZE); + virtual ~ObAllocator() + {} void* alloc(const int64_t size) override { return alloc(size, attr_); } - void* alloc(const int64_t size, const ObMemAttr& attr) override; - void free(void* ptr) override; + virtual void* alloc(const int64_t size, const ObMemAttr& attr) override; + virtual void free(void* ptr) override; int64_t hold() const; int64_t total() const override { diff --git a/deps/oblib/src/lib/allocator/ob_fifo_allocator.h b/deps/oblib/src/lib/allocator/ob_fifo_allocator.h index b6f43e768e..03747b662e 100644 --- a/deps/oblib/src/lib/allocator/ob_fifo_allocator.h +++ b/deps/oblib/src/lib/allocator/ob_fifo_allocator.h @@ -79,7 +79,7 @@ public: public: explicit ObFIFOAllocator(const uint64_t tenant_id = OB_SERVER_TENANT_ID); - ~ObFIFOAllocator(); + virtual ~ObFIFOAllocator(); int init(ObIAllocator* allocator, const int64_t page_size, const ObMemAttr& attr = default_memattr, const int64_t init_size = 0, const int64_t idle_size = 256L << 10, const int64_t max_size = INT64_MAX); diff --git a/deps/oblib/src/lib/allocator/ob_malloc.h b/deps/oblib/src/lib/allocator/ob_malloc.h index 2b4dcb71b0..7c33c35ab6 100644 --- a/deps/oblib/src/lib/allocator/ob_malloc.h +++ b/deps/oblib/src/lib/allocator/ob_malloc.h @@ -156,7 +156,7 @@ public: {} public: - virtual void* alloc(int64_t sz) + virtual void* alloc(int64_t sz) override { char* ptr = NULL; if (OB_SUCCESS == mem_buf_.ensure_space(sz, label_)) { @@ -164,12 +164,12 @@ public: } return ptr; } - virtual void* alloc(int64_t sz, const ObMemAttr& attr) + virtual void* alloc(int64_t sz, const ObMemAttr& attr) override { UNUSEDx(attr); return alloc(sz); } - virtual void free(char* ptr) + virtual void free(void* ptr) override { UNUSED(ptr); } @@ -185,7 +185,7 @@ public: {} public: - virtual void* alloc(int64_t sz) + virtual void* alloc(int64_t sz) override { char* ptr = NULL; if (mem_buf_len_ >= sz) { @@ -193,12 +193,12 @@ public: } return ptr; } - virtual void* alloc(int64_t sz, const ObMemAttr& attr) + virtual void* alloc(int64_t sz, const ObMemAttr& attr) override { UNUSEDx(attr); return alloc(sz); } - virtual void free(char* ptr) + virtual void free(void* ptr) override { UNUSED(ptr); } diff --git a/deps/oblib/src/lib/container/ob_se_array.h b/deps/oblib/src/lib/container/ob_se_array.h index 23649eb99b..a95542d5c8 100644 --- a/deps/oblib/src/lib/container/ob_se_array.h +++ b/deps/oblib/src/lib/container/ob_se_array.h @@ -49,6 +49,11 @@ public: return nullptr; } + virtual void free(void *p) override + { + UNUSED(p); + } + virtual ~ObNullAllocator(){}; }; @@ -61,6 +66,13 @@ static inline void init_block_allocator(lib::MemoryContext& mem_entity, ModulePa { block_allocator = ModulePageAllocator(mem_entity->get_allocator(), block_allocator.get_label()); } +static inline void init_block_allocator(lib::MemoryContext &mem_context, ObIAllocator &block_allocator) +{ + // this implement is invalid, just for compilation. + // protected by static_assert. + UNUSED(mem_context); + UNUSED(block_allocator); +} // ObSEArrayImpl is a high performant array for OceanBase developers, // to guarantee performance, it should be used in this way @@ -69,6 +81,8 @@ static inline void init_block_allocator(lib::MemoryContext& mem_entity, ModulePa static const int64_t OB_DEFAULT_SE_ARRAY_COUNT = 64; template class ObSEArrayImpl : public ObIArray { + static_assert(std::is_constructible::value || !auto_free, "BlockAllocatorT can not be constructed."); + public: using ObIArray::count; using ObIArray::at; diff --git a/src/election/ob_election_msg.h b/src/election/ob_election_msg.h index f6012b5847..952939bbfe 100644 --- a/src/election/ob_election_msg.h +++ b/src/election/ob_election_msg.h @@ -87,7 +87,7 @@ public: { (void)set_data(buf_, MAX_MSGBUF_SIZE); } - ~ObElectionMsgBuffer() + virtual ~ObElectionMsgBuffer() {} TO_STRING_KV(K_(capacity), K_(position), K_(limit)); diff --git a/src/liboblog/src/ob_small_arena.h b/src/liboblog/src/ob_small_arena.h index 529147efae..374b32ee3e 100644 --- a/src/liboblog/src/ob_small_arena.h +++ b/src/liboblog/src/ob_small_arena.h @@ -57,12 +57,16 @@ public: ObSmallArena(); ~ObSmallArena(); void *alloc_aligned(const int64_t size, const int64_t align); - void *alloc(const int64_t size, const common::ObMemAttr &attr) + virtual void *alloc(const int64_t size, const common::ObMemAttr &attr) override { UNUSEDx(attr); return alloc(size); } - void *alloc(const int64_t size); + virtual void *alloc(const int64_t size) override; + virtual void free(void *ptr) override + { + UNUSED(ptr); + } void reset(); int64_t get_small_alloc_count() const; int64_t get_large_alloc_count() const; diff --git a/src/share/schema/ob_schema_struct.h b/src/share/schema/ob_schema_struct.h index af576f26de..94c28549f4 100644 --- a/src/share/schema/ob_schema_struct.h +++ b/src/share/schema/ob_schema_struct.h @@ -2173,12 +2173,12 @@ public: ObSchemaAllocator(common::ObIAllocator &allocator) : allocator_(&allocator) {} - virtual void *alloc(const int64_t sz) + virtual void* alloc(const int64_t sz) override { return alloc(sz, common::default_memattr); } - virtual void *alloc(const int64_t sz, const common::ObMemAttr &attr) + virtual void* alloc(const int64_t sz, const common::ObMemAttr& attr) override { void *ret = NULL; if (allocator_) { @@ -2187,6 +2187,10 @@ public: return ret; } + virtual void free(void *p) override + { + allocator_->free(p); + } virtual ~ObSchemaAllocator(){}; private: diff --git a/src/sql/engine/expr/ob_expr.h b/src/sql/engine/expr/ob_expr.h index aebf9e7461..56badeb15c 100644 --- a/src/sql/engine/expr/ob_expr.h +++ b/src/sql/engine/expr/ob_expr.h @@ -344,6 +344,15 @@ public: {} void* alloc(const int64_t size) override; + void* alloc(const int64_t size, const common::ObMemAttr& attr) override + { + UNUSED(attr); + return alloc(size); + } + void free(void* ptr) override + { + UNUSED(ptr); + } private: int64_t off_; diff --git a/src/sql/engine/expr/ob_expr_regexp_context.h b/src/sql/engine/expr/ob_expr_regexp_context.h index 92b985d209..20215d1d10 100644 --- a/src/sql/engine/expr/ob_expr_regexp_context.h +++ b/src/sql/engine/expr/ob_expr_regexp_context.h @@ -41,6 +41,15 @@ public: } virtual void* alloc(const int64_t size) override; + virtual void* alloc(const int64_t size, const common::ObMemAttr& attr) override + { + UNUSED(attr); + return alloc(size); + } + virtual void free(void* ptr) override + { + UNUSED(ptr); + } private: common::ObIAllocator* alloc_; diff --git a/src/sql/plan_cache/ob_id_manager_allocator.h b/src/sql/plan_cache/ob_id_manager_allocator.h index fc1c1fa791..c0291e0d8f 100644 --- a/src/sql/plan_cache/ob_id_manager_allocator.h +++ b/src/sql/plan_cache/ob_id_manager_allocator.h @@ -31,11 +31,16 @@ public: int init(const int64_t obj_size, const char* label, uint64_t tenant_id_); - void* alloc(int64_t sz) + void* alloc(const int64_t sz) override { return alloc_(sz); } - void free(void* ptr) + void* alloc(const int64_t size, const common::ObMemAttr& attr) override + { + UNUSED(attr); + return alloc(size); + } + void free(void* ptr) override { free_(ptr); } diff --git a/src/storage/memtable/ob_memtable_context.h b/src/storage/memtable/ob_memtable_context.h index b9d13df2b7..ddf3ea4026 100644 --- a/src/storage/memtable/ob_memtable_context.h +++ b/src/storage/memtable/ob_memtable_context.h @@ -168,7 +168,7 @@ public: ATOMIC_STORE(&free_count_, 0); ATOMIC_STORE(&alloc_size_, 0); } - void* alloc(const int64_t size) + void* alloc(const int64_t size) override { void* ret = nullptr; if (OB_ISNULL(ret = allocator_.alloc(size))) { @@ -179,7 +179,12 @@ public: } return ret; } - void free(void* ptr) + void* alloc(const int64_t size, const ObMemAttr& attr) override + { + UNUSED(attr); + return alloc(size); + } + void free(void* ptr) override { if (OB_ISNULL(ptr)) { // do nothing @@ -244,7 +249,7 @@ public: ATOMIC_STORE(&free_count_, 0); ATOMIC_STORE(&alloc_size_, 0); } - void* alloc(const int64_t size) + void* alloc(const int64_t size) override { void* ret = nullptr; if (OB_ISNULL(ret = allocator_.alloc(size))) { @@ -255,7 +260,12 @@ public: } return ret; } - void free(void* ptr) + void* alloc(const int64_t size, const ObMemAttr& attr) override + { + UNUSED(attr); + return alloc(size); + } + void free(void* ptr) override { if (OB_ISNULL(ptr)) { // do nothing diff --git a/unittest/sql/engine/basic/test_ra_row_store_projector.cpp b/unittest/sql/engine/basic/test_ra_row_store_projector.cpp index d2deea9a31..44fe0460f0 100644 --- a/unittest/sql/engine/basic/test_ra_row_store_projector.cpp +++ b/unittest/sql/engine/basic/test_ra_row_store_projector.cpp @@ -76,6 +76,10 @@ class ObEmptyAlloc : public ObIAllocator { { return NULL; } + void free(void *ptr) override + { + UNUSED(ptr); + } }; TEST(RARowStore, alloc_project_fail) -- GitLab