提交 9007c77b 编写于 作者: N nroskill 提交者: LINGuanRen

disable construct of ObIAllocator

上级 17b0f303
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
ObDataBuffer(char* data, const int64_t capacity) : data_(data), capacity_(capacity), position_(0), limit_(0) 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) inline bool set_data(char* data, const int64_t capacity)
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
limit_ = 0; limit_ = 0;
} }
inline void* alloc(const int64_t sz) inline virtual void* alloc(const int64_t sz)
{ {
void* ret = NULL; void* ret = NULL;
if (OB_LIKELY(sz > 0 && capacity_ - position_ >= sz)) { if (OB_LIKELY(sz > 0 && capacity_ - position_ >= sz)) {
...@@ -64,13 +64,13 @@ public: ...@@ -64,13 +64,13 @@ public:
} }
return ret; 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); UNUSED(attr);
return alloc(sz); return alloc(sz);
} }
inline void free() inline virtual void free()
{ {
position_ = 0; position_ = 0;
} }
......
...@@ -66,6 +66,8 @@ public: ...@@ -66,6 +66,8 @@ public:
attr.tenant_id_ = tenant_id; attr.tenant_id_ = tenant_id;
attr.ctx_id_ = ctx_id; attr.ctx_id_ = ctx_id;
} }
virtual ~ObTenantCtxAllocator()
{}
int set_tenant_memory_mgr() int set_tenant_memory_mgr()
{ {
int ret = common::OB_SUCCESS; int ret = common::OB_SUCCESS;
......
...@@ -17,41 +17,23 @@ ...@@ -17,41 +17,23 @@
#include "lib/alloc/alloc_struct.h" #include "lib/alloc/alloc_struct.h"
namespace oceanbase { namespace oceanbase {
namespace lib {
struct ObMemAttr;
} // end of namespace lib
namespace common { namespace common {
using lib::ObMemAttr; using lib::ObMemAttr;
extern ObMemAttr default_memattr; extern ObMemAttr default_memattr;
class ObIAllocator { class ObIAllocator {
public:
virtual ~ObIAllocator(){};
public: public:
/************************************************************************/ /************************************************************************/
/* New Interface (Under construction) */ /* New Interface (Under construction) */
/************************************************************************/ /************************************************************************/
// Use attr passed in by set_attr(). // Use attr passed in by set_attr().
virtual void* alloc(const int64_t size) virtual void* alloc(const int64_t size) = 0;
{ virtual void* alloc(const int64_t size, const ObMemAttr& attr) = 0;
UNUSED(size);
return NULL;
}
virtual void* alloc(const int64_t size, const ObMemAttr& attr)
{
UNUSED(size);
UNUSED(attr);
return NULL;
}
virtual void* realloc(const void* ptr, const int64_t size, const ObMemAttr& attr) virtual void* realloc(const void* ptr, const int64_t size, const ObMemAttr& attr)
{ {
UNUSED(ptr); UNUSED(ptr);
UNUSED(size); UNUSED(size);
UNUSED(attr); UNUSED(attr);
return NULL; return nullptr;
} }
virtual void* realloc(void* ptr, const int64_t oldsz, const int64_t newsz) virtual void* realloc(void* ptr, const int64_t oldsz, const int64_t newsz)
...@@ -59,13 +41,10 @@ public: ...@@ -59,13 +41,10 @@ public:
UNUSED(ptr); UNUSED(ptr);
UNUSED(oldsz); UNUSED(oldsz);
UNUSED(newsz); UNUSED(newsz);
return NULL; return nullptr;
} }
virtual void free(void* ptr) virtual void free(void* ptr) = 0;
{
UNUSED(ptr);
}
virtual int64_t total() const virtual int64_t total() const
{ {
......
...@@ -38,12 +38,14 @@ class ObAllocator : public ObIAllocator { ...@@ -38,12 +38,14 @@ class ObAllocator : public ObIAllocator {
public: public:
ObAllocator(__MemoryContext__* mem_context, const ObMemAttr& attr = default_memattr, const bool use_pm = false, ObAllocator(__MemoryContext__* mem_context, const ObMemAttr& attr = default_memattr, const bool use_pm = false,
const uint32_t ablock_size = lib::INTACT_NORMAL_AOBJECT_SIZE); const uint32_t ablock_size = lib::INTACT_NORMAL_AOBJECT_SIZE);
virtual ~ObAllocator()
{}
void* alloc(const int64_t size) override void* alloc(const int64_t size) override
{ {
return alloc(size, attr_); return alloc(size, attr_);
} }
void* alloc(const int64_t size, const ObMemAttr& attr) override; virtual void* alloc(const int64_t size, const ObMemAttr& attr) override;
void free(void* ptr) override; virtual void free(void* ptr) override;
int64_t hold() const; int64_t hold() const;
int64_t total() const override int64_t total() const override
{ {
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
public: public:
explicit ObFIFOAllocator(const uint64_t tenant_id = OB_SERVER_TENANT_ID); 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, 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); const int64_t init_size = 0, const int64_t idle_size = 256L << 10, const int64_t max_size = INT64_MAX);
......
...@@ -156,7 +156,7 @@ public: ...@@ -156,7 +156,7 @@ public:
{} {}
public: public:
virtual void* alloc(int64_t sz) virtual void* alloc(int64_t sz) override
{ {
char* ptr = NULL; char* ptr = NULL;
if (OB_SUCCESS == mem_buf_.ensure_space(sz, label_)) { if (OB_SUCCESS == mem_buf_.ensure_space(sz, label_)) {
...@@ -164,12 +164,12 @@ public: ...@@ -164,12 +164,12 @@ public:
} }
return ptr; return ptr;
} }
virtual void* alloc(int64_t sz, const ObMemAttr& attr) virtual void* alloc(int64_t sz, const ObMemAttr& attr) override
{ {
UNUSEDx(attr); UNUSEDx(attr);
return alloc(sz); return alloc(sz);
} }
virtual void free(char* ptr) virtual void free(void* ptr) override
{ {
UNUSED(ptr); UNUSED(ptr);
} }
...@@ -185,7 +185,7 @@ public: ...@@ -185,7 +185,7 @@ public:
{} {}
public: public:
virtual void* alloc(int64_t sz) virtual void* alloc(int64_t sz) override
{ {
char* ptr = NULL; char* ptr = NULL;
if (mem_buf_len_ >= sz) { if (mem_buf_len_ >= sz) {
...@@ -193,12 +193,12 @@ public: ...@@ -193,12 +193,12 @@ public:
} }
return ptr; return ptr;
} }
virtual void* alloc(int64_t sz, const ObMemAttr& attr) virtual void* alloc(int64_t sz, const ObMemAttr& attr) override
{ {
UNUSEDx(attr); UNUSEDx(attr);
return alloc(sz); return alloc(sz);
} }
virtual void free(char* ptr) virtual void free(void* ptr) override
{ {
UNUSED(ptr); UNUSED(ptr);
} }
......
...@@ -49,6 +49,11 @@ public: ...@@ -49,6 +49,11 @@ public:
return nullptr; return nullptr;
} }
virtual void free(void *p) override
{
UNUSED(p);
}
virtual ~ObNullAllocator(){}; virtual ~ObNullAllocator(){};
}; };
...@@ -61,6 +66,13 @@ static inline void init_block_allocator(lib::MemoryContext& mem_entity, ModulePa ...@@ -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()); 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, // ObSEArrayImpl is a high performant array for OceanBase developers,
// to guarantee performance, it should be used in this way // 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 ...@@ -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; static const int64_t OB_DEFAULT_SE_ARRAY_COUNT = 64;
template <typename T, int64_t LOCAL_ARRAY_SIZE, typename BlockAllocatorT = ModulePageAllocator, bool auto_free = false> template <typename T, int64_t LOCAL_ARRAY_SIZE, typename BlockAllocatorT = ModulePageAllocator, bool auto_free = false>
class ObSEArrayImpl : public ObIArray<T> { class ObSEArrayImpl : public ObIArray<T> {
static_assert(std::is_constructible<BlockAllocatorT>::value || !auto_free, "BlockAllocatorT can not be constructed.");
public: public:
using ObIArray<T>::count; using ObIArray<T>::count;
using ObIArray<T>::at; using ObIArray<T>::at;
......
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
{ {
(void)set_data(buf_, MAX_MSGBUF_SIZE); (void)set_data(buf_, MAX_MSGBUF_SIZE);
} }
~ObElectionMsgBuffer() virtual ~ObElectionMsgBuffer()
{} {}
TO_STRING_KV(K_(capacity), K_(position), K_(limit)); TO_STRING_KV(K_(capacity), K_(position), K_(limit));
......
...@@ -57,12 +57,16 @@ public: ...@@ -57,12 +57,16 @@ public:
ObSmallArena(); ObSmallArena();
~ObSmallArena(); ~ObSmallArena();
void *alloc_aligned(const int64_t size, const int64_t align); 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); UNUSEDx(attr);
return alloc(size); 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(); void reset();
int64_t get_small_alloc_count() const; int64_t get_small_alloc_count() const;
int64_t get_large_alloc_count() const; int64_t get_large_alloc_count() const;
......
...@@ -2173,12 +2173,12 @@ public: ...@@ -2173,12 +2173,12 @@ public:
ObSchemaAllocator(common::ObIAllocator &allocator) : allocator_(&allocator) 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); 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; void *ret = NULL;
if (allocator_) { if (allocator_) {
...@@ -2187,6 +2187,10 @@ public: ...@@ -2187,6 +2187,10 @@ public:
return ret; return ret;
} }
virtual void free(void *p) override
{
allocator_->free(p);
}
virtual ~ObSchemaAllocator(){}; virtual ~ObSchemaAllocator(){};
private: private:
......
...@@ -344,6 +344,15 @@ public: ...@@ -344,6 +344,15 @@ public:
{} {}
void* alloc(const int64_t size) override; 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: private:
int64_t off_; int64_t off_;
......
...@@ -41,6 +41,15 @@ public: ...@@ -41,6 +41,15 @@ public:
} }
virtual void* alloc(const int64_t size) override; 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: private:
common::ObIAllocator* alloc_; common::ObIAllocator* alloc_;
......
...@@ -31,11 +31,16 @@ public: ...@@ -31,11 +31,16 @@ public:
int init(const int64_t obj_size, const char* label, uint64_t tenant_id_); 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); 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); free_(ptr);
} }
......
...@@ -168,7 +168,7 @@ public: ...@@ -168,7 +168,7 @@ public:
ATOMIC_STORE(&free_count_, 0); ATOMIC_STORE(&free_count_, 0);
ATOMIC_STORE(&alloc_size_, 0); ATOMIC_STORE(&alloc_size_, 0);
} }
void* alloc(const int64_t size) void* alloc(const int64_t size) override
{ {
void* ret = nullptr; void* ret = nullptr;
if (OB_ISNULL(ret = allocator_.alloc(size))) { if (OB_ISNULL(ret = allocator_.alloc(size))) {
...@@ -179,7 +179,12 @@ public: ...@@ -179,7 +179,12 @@ public:
} }
return ret; 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)) { if (OB_ISNULL(ptr)) {
// do nothing // do nothing
...@@ -244,7 +249,7 @@ public: ...@@ -244,7 +249,7 @@ public:
ATOMIC_STORE(&free_count_, 0); ATOMIC_STORE(&free_count_, 0);
ATOMIC_STORE(&alloc_size_, 0); ATOMIC_STORE(&alloc_size_, 0);
} }
void* alloc(const int64_t size) void* alloc(const int64_t size) override
{ {
void* ret = nullptr; void* ret = nullptr;
if (OB_ISNULL(ret = allocator_.alloc(size))) { if (OB_ISNULL(ret = allocator_.alloc(size))) {
...@@ -255,7 +260,12 @@ public: ...@@ -255,7 +260,12 @@ public:
} }
return ret; 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)) { if (OB_ISNULL(ptr)) {
// do nothing // do nothing
......
...@@ -76,6 +76,10 @@ class ObEmptyAlloc : public ObIAllocator { ...@@ -76,6 +76,10 @@ class ObEmptyAlloc : public ObIAllocator {
{ {
return NULL; return NULL;
} }
void free(void *ptr) override
{
UNUSED(ptr);
}
}; };
TEST(RARowStore, alloc_project_fail) TEST(RARowStore, alloc_project_fail)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册