apache / doris

Apache Doris is an easy-to-use, high performance and unified analytics database.
https://doris.apache.org
Apache License 2.0
12.74k stars 3.28k forks source link

[Bug] Be memory leak when insert data with bitmap type #8017

Open spaces-X opened 2 years ago

spaces-X commented 2 years ago

Search before asking

Version

tested in pre-0.15.0-5fc0a9f and trunk-a1d1bd8 (0.15)

What's Wrong?

DCHECK failed in Memtracker destructor: consumption() == 0

What You Expected?

DCHECK pass

How to Reproduce?

CREATE TABLE test_bitmap
(
    k1 int(11) NULL comment "date",
    k2 INT NULL comment "k2 int",
    v1 bitmap bitmap_union,
    v2 INT SUM
)
AGGREGATE KEY(k1, k2)
PARTITION BY RANGE (k1)
(
    PARTITION p1 VALUES [("20210101"), ("20210102")),
    PARTITION p2 VALUES [("20210102"), ("20210103"))
)
DISTRIBUTED BY HASH(k2) BUCKETS 3
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "V2"
);

 insert into test_bitmap values (20210101, 1, to_bitmap(10),50);

Anything Else?

be.INFO

I0211 05:40:56.943933   765 plan_fragment_executor.cpp:73] Prepare(): query_id=c6af8c191468438f-931edb9c29bd908b fragment_instance_id=c6af8c191468438f-931edb9c29bd908c backend_num=0
I0211 05:40:56.945101   607 plan_fragment_executor.cpp:226] Open(): fragment_instance_id=c6af8c191468438f-931edb9c29bd908c, Using query memory limit: 2.00 GB
I0211 05:40:56.946125   781 tablets_channel.cpp:59] open tablets channel: (id=c6af8c191468438f-931edb9c29bd908b,index_id=11006), tablets num: 6, timeout(s): 300
I0211 05:40:56.947970   727 tablets_channel.cpp:141] close tablets channel: (id=c6af8c191468438f-931edb9c29bd908b,index_id=11006), sender id: 0, backend id: 11001
I0211 05:40:56.948248   727 txn_manager.cpp:249] commit transaction to engine successfully. partition_id: 11003, transaction_id: 2, tablet: 11011.567419293.e943abe3443e910c-46cf0b9786bb0391, rowsetid: 0200000000000008244aa19c8d461b5c77370c69c7215fa3, version: 0
I0211 05:40:56.948499  1578 tablet_sink.cpp:1018] all node channels are stopped(maybe finished/offending/cancelled), consumer thread exit.
F0211 05:40:56.949322   504 mem_tracker.cpp:270] Check failed: consumption() == 0 Memory tracker limit: -1; consumption: 72; label: MemTable:c6af8c191468438f-931edb9c29bd908b; all tracker size: 6; limit trackers size: 2; parent is null: false;  has unreleased consumption 72

No response

Are you willing to submit PR?

Code of Conduct

spaces-X commented 2 years ago

DCHECK failure in memtracker destructor is caused by memtrack consumed the BitmapValue without releasing later in AggregateFuncTraits::init.

As follows:

template <>
struct AggregateFuncTraits<OLAP_FIELD_AGGREGATION_BITMAP_UNION, OLAP_FIELD_TYPE_OBJECT> {
    static void init(RowCursorCell* dst, const char* src, bool src_null, MemPool* mem_pool,
                     ObjectPool* agg_pool) {
        DCHECK_EQ(src_null, false);
        dst->set_not_null();
        auto* src_slice = reinterpret_cast<const Slice*>(src);
        auto* dst_slice = reinterpret_cast<Slice*>(dst->mutable_cell_ptr());

        // we use zero size represent this slice is a agg object
        dst_slice->size = 0;
        auto bitmap = new BitmapValue(src_slice->data);
        // here consumed size of (BitmapValue) without releasing later.
        mem_pool->mem_tracker()->Consume(sizeof(BitmapValue)); 
        dst_slice->data = (char*)bitmap;

        agg_pool->add(bitmap);
    }
 ...
}

Any suggestiones here or we can just ignore this DCHECK ? @morningman @liutang123