Skip to content

INTERNAL: Separate htree and collection layer in map/set elem delete and get#982

Merged
jhpark816 merged 1 commit into
naver:developfrom
zhy2on:internal/map-set-delete-get
Jun 22, 2026
Merged

INTERNAL: Separate htree and collection layer in map/set elem delete and get#982
jhpark816 merged 1 commit into
naver:developfrom
zhy2on:internal/map-set-delete-get

Conversation

@zhy2on

@zhy2on zhy2on commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

🔗 Related Issue

⌨️ What I did

hash_tree 모듈 추출을 위한 사전 작업으로, map/set의 delete/get 경로에서 hash tree layer와 collection layer를 분리했습니다.

기존 do_map_elem_unlink는 chain unlink와 ccnt--, CLOG, space accounting, free(collection)를 한 함수에서 모두 처리하고 있었습니다.
이를 htree layer는 unlink만 담당하고, collection layer 후처리는 caller가 맡도록 나눴습니다.

기존 로직을 최대한 건드리지 않는 선에서 레이어 경계를 맞추는 것을 우선으로 했습니다.


delete 단건 — do_map_elem_delete_by_field / do_set_elem_delete_by_value

반환 타입을 bool → {map/set}_elem_item *으로 변경했습니다. caller가 반환된 elem을 받아 후처리할 수 있도록 했습니다.


delete bulk — do_{map/set}_elem_delete_by_count

unlink된 elem들을 linked list로 묶어 반환합니다. caller에서 리스트를 순회하며 후처리합니다.


get — do_map_elem_get_by_field, do_{map/set}_elem_get_all, do_set_elem_get_rand

어차피 elem_array로 반환하므로 별도 chain 연결은 불필요합니다. caller에서 elem_array를 순회하며 refcount++와 delete 후처리를 함께 처리하도록 했습니다.


공통 — do_{map/set}_delete_post

후처리 로직(CLOG, ccnt--, space accounting, free)이 여러 경로에서 반복되어 별도 함수로 추출했습니다.


비고

root node unlink

if (info->root->tot_elem_cnt == 0) {
    do_map_node_unlink(info, NULL, 0);
    space_decreased += slabs_space_size(sizeof(map_hash_node));
}

이 부분은 본래 hash tree layer로 이동해야 합니다. delete/get 함수들이 재귀 구조이므로, 현재는 내부로 이동하지 못 했고
추후 hash_tree 모듈 추출 시 public 함수 안에서 재귀 호출을 마친 뒤 root가 비었으면 unlink하는 형태로 옮길 예정입니다.

do_map_elem_get_all
hash tree로 추출 시 do_map_elem_get_by_count 형태로 변경할 예정입니다.

@zhy2on zhy2on assigned zhy2on and unassigned zhy2on Jun 18, 2026
@zhy2on zhy2on requested a review from jhpark816 June 18, 2026 10:27
@jhpark816

Copy link
Copy Markdown
Collaborator

coll_set 수정도 올려주면, 같이 리뷰할 수 있을 것 같습니다.

@zhy2on

zhy2on commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

추가해서 올리도록 하겠습니다.

@zhy2on zhy2on force-pushed the internal/map-set-delete-get branch from 1278238 to 72e2e84 Compare June 18, 2026 11:38
@zhy2on zhy2on changed the title INTERNAL: Separate htree and collection layer in map elem delete and get INTERNAL: Separate htree and collection layer in map/set elem delete and get Jun 18, 2026
@zhy2on

zhy2on commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

set의 변경사항도 함께 확인 부탁드립니다.

@jhpark816 jhpark816 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일부 리뷰

Comment thread engines/default/coll_set.c
Comment thread engines/default/coll_set.c Outdated
if (info->root != NULL) {
fcnt = do_set_elem_delete_by_count(info, info->root, count, ELEM_DELETE_COLL);
set_elem_item *deleted_head = NULL;
fcnt = do_set_elem_delete_by_count(info, info->root, count, ELEM_DELETE_COLL, &deleted_head, &space_decreased);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ELEM_DELETE_COLL 넘겨야 하나요?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넘기지 않아도 됩니다. 제거했습니다.

@zhy2on zhy2on force-pushed the internal/map-set-delete-get branch from 72e2e84 to 31a55f0 Compare June 18, 2026 15:23
@zhy2on zhy2on requested a review from jhpark816 June 19, 2026 00:52

@jhpark816 jhpark816 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일부 리뷰

Comment thread engines/default/coll_set.c Outdated
fcnt = do_set_elem_get_rand(info, count, delete, elem_array, &space_decreased);
}
for (int ii = 0; ii < fcnt; ii++) {
if (delete) do_set_elem_delete_post(info, elem_array[ii], cause);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 형태가 좋겠습니다.

if (delete) {
   for 문
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다.

Comment thread engines/default/coll_set.c Outdated
if (hash_insert(&offset_ht, rand_offset)) {
set_elem_item *found = do_set_elem_get_by_offset(info, info->root,
rand_offset, delete);
rand_offset, delete, space_decreased);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete = false, space_decreased = NULL 값을 넘기는 것이 어떤지 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그게 맞는 것 같습니다. 반영했습니다.

Comment thread engines/default/coll_map.c
@zhy2on zhy2on force-pushed the internal/map-set-delete-get branch from 31a55f0 to 7d49a44 Compare June 19, 2026 05:00
@zhy2on zhy2on requested a review from jhpark816 June 19, 2026 08:18
Comment thread engines/default/coll_set.c
Comment thread engines/default/coll_set.c Outdated
}
if (info->stotal > 0) {
do_coll_space_decr((coll_meta_info *)info, ITEM_TYPE_SET, space_decreased);
}

@jhpark816 jhpark816 Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위의 코드를 보니, do_set_elem_delete_post()에 space_decreased 넘기기 힘드군요.
그러면, 아래와 같이 구현해야 할 것 같습니다.

    if (delete) {
        if (info->root->tot_elem_cnt == 0) {
            do_set_node_unlink(info, NULL, 0);
            space_decreased += slabs_space_size(sizeof(set_hash_node));
        }
        if (space_decreased > 0) {
            do_coll_space_decr((coll_meta_info *)info, ITEM_TYPE_SET, space_decreased);
        }
        for (int ii = 0; ii < fcnt; ii++) {
            do_set_elem_delete_post(info, elem_array[ii], cause);
        }
        CLOG_ELEM_DELETE_END((coll_meta_info*)info, cause);
    }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//static void do_item_unlink(hash_item *it, enum item_unlink_cause cause)
void do_item_unlink(hash_item *it, enum item_unlink_cause cause)
{
....
        if (IS_COLL_ITEM(it)) {
            /* IMPORTANT NOTE)
             * The element space statistics has already been decreased.
             * So, we must not decrease the space statistics any more
             * even if the elements are freed later.
             * For that purpose, we set info->stotal to 0 like below.
             */
            coll_meta_info *info = (coll_meta_info *)item_get_meta(it);
            info->stotal = 0;
        }

확인해 보니 item_unlink를 할 때 collection의 경우 info->stotal = 0;으로 먼저 초기화를 하고 elem들을 unlink 하는 것이었습니다.

do_coll_space_decrif (info->stotal > 0) 가드로 item unlink 중 발생하는 elem unlink에 대해선 space decr을 하지 않도록 한 것이었습니다.

따라서 if (info->stotal > 0) 은 빼지 않는 것으로 하였습니다.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따라서 if (info->stotal > 0) 은 빼지 않는 것으로 하였습니다.

예전 코드가 기억이 납니다.
OK. 위와 같이 처리해야 하네요.

@zhy2on zhy2on requested a review from jhpark816 June 22, 2026 00:56

@jhpark816 jhpark816 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료

Comment thread engines/default/coll_set.c Outdated
}
for (int ii = 0; ii < fcnt; ii++) {
do_set_elem_delete_post(info, elem_array[ii], cause);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다른 코드와 일관되게 여기 코드 순서를 변경하시죠.
do_set_elem_delete_post() 호출하는 코드를 가장 위로 둡시다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정 후 커밋을 하나로 합쳤습니다.

@zhy2on zhy2on force-pushed the internal/map-set-delete-get branch from fee38ad to ad659fe Compare June 22, 2026 03:50
@zhy2on zhy2on requested a review from jhpark816 June 22, 2026 03:55
@jhpark816 jhpark816 merged commit 2f00dfd into naver:develop Jun 22, 2026
1 check passed
@zhy2on zhy2on deleted the internal/map-set-delete-get branch June 22, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants