[CP] DecoderCtx optimizing memory fragmentation.
This commit is contained in:
@ -70,17 +70,18 @@ class ObDecoderCtxArray
|
||||
{
|
||||
public:
|
||||
typedef ObColumnDecoderCtx ObDecoderCtx;
|
||||
ObDecoderCtxArray() {};
|
||||
explicit ObDecoderCtxArray(ObIAllocator &allocator): ctxs_(), allocator_(&allocator) {};
|
||||
virtual ~ObDecoderCtxArray()
|
||||
{
|
||||
FOREACH(it, ctxs_) {
|
||||
ObDecoderCtx *c = *it;
|
||||
OB_DELETE(ObDecoderCtx, ObModIds::OB_SSTABLE_READER, c);
|
||||
c->~ObDecoderCtx();
|
||||
allocator_->free(c);
|
||||
}
|
||||
ctxs_.reset();
|
||||
}
|
||||
|
||||
TO_STRING_KV(K_(ctxs));
|
||||
TO_STRING_KV(K_(ctxs), KP_(allocator));
|
||||
|
||||
ObDecoderCtx **get_ctx_array(int64_t size)
|
||||
{
|
||||
@ -92,13 +93,14 @@ public:
|
||||
} else {
|
||||
if (ctxs_.size() < size) {
|
||||
for (int64_t i = ctxs_.size(); OB_SUCC(ret) && i < size; ++i) {
|
||||
ObDecoderCtx *ctx = OB_NEW(ObDecoderCtx, ObModIds::OB_SSTABLE_READER);
|
||||
if (NULL == ctx) {
|
||||
ObDecoderCtx *ctx = nullptr;
|
||||
if (OB_ISNULL(ctx = OB_NEWx(ObDecoderCtx, allocator_))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("alloc memory failed", K(ret));
|
||||
} else if (OB_FAIL(ctxs_.push_back(ctx))) {
|
||||
LOG_WARN("array push back failed", K(ret));
|
||||
OB_DELETE(ObDecoderCtx, ObModIds::OB_SSTABLE_READER, ctx);
|
||||
ctx->~ObDecoderCtx();
|
||||
allocator_->free(ctx);
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -113,6 +115,7 @@ public:
|
||||
|
||||
private:
|
||||
ObArray<ObDecoderCtx *> ctxs_;
|
||||
ObIAllocator *allocator_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ObDecoderCtxArray);
|
||||
};
|
||||
@ -123,14 +126,12 @@ ObColumnDecoderCtx ObMicroBlockDecoder::none_exist_column_decoder_ctx_;
|
||||
class ObTLDecoderCtxArray
|
||||
{
|
||||
public:
|
||||
ObTLDecoderCtxArray() {}
|
||||
ObTLDecoderCtxArray(): ctxs_array_(), allocator_("TLDecoderCtx") {}
|
||||
|
||||
virtual ~ObTLDecoderCtxArray()
|
||||
{
|
||||
FOREACH(it, ctxs_array_) {
|
||||
ObDecoderCtxArray *ctxs = *it;
|
||||
OB_DELETE(ObDecoderCtxArray, ObModIds::OB_SSTABLE_READER, ctxs);
|
||||
}
|
||||
ctxs_array_.reset();
|
||||
allocator_.reset();
|
||||
}
|
||||
|
||||
static ObDecoderCtxArray *alloc()
|
||||
@ -142,8 +143,7 @@ public:
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("NULL instance", K(ret));
|
||||
} else if (tl_array->ctxs_array_.empty()) {
|
||||
ctxs = OB_NEW(ObDecoderCtxArray, ObModIds::OB_SSTABLE_READER);
|
||||
if (NULL == ctxs) {
|
||||
if (OB_ISNULL(ctxs = OB_NEWx(ObDecoderCtxArray, (&tl_array->allocator_), tl_array->allocator_))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("alloc memory failed", K(ret));
|
||||
}
|
||||
@ -165,7 +165,8 @@ public:
|
||||
// do nothing
|
||||
} else if (OB_FAIL(tl_array->ctxs_array_.push_back(ctxs))) {
|
||||
LOG_WARN("array push back failed", K(ret));
|
||||
OB_DELETE(ObDecoderCtxArray, ObModIds::OB_SSTABLE_READER, ctxs);
|
||||
ctxs->~ObDecoderCtxArray();
|
||||
tl_array->allocator_.free(ctxs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,6 +175,7 @@ private:
|
||||
|
||||
private:
|
||||
ObArray<ObDecoderCtxArray *> ctxs_array_;
|
||||
ObArenaAllocator allocator_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ObTLDecoderCtxArray);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user