-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTERNAL: Change tot_elem_cnt to subtree element count in set #817
base: develop
Are you sure you want to change the base?
Conversation
50d0a1d
to
dd999d1
Compare
dd999d1
to
6b2805e
Compare
8242e3a
to
2199b09
Compare
@@ -236,7 +236,7 @@ typedef struct _set_hash_node { | |||
uint16_t refcount; | |||
uint8_t slabs_clsid; /* which slab class we're in */ | |||
uint8_t hdepth; | |||
uint16_t tot_elem_cnt; | |||
uint32_t tot_elem_cnt; | |||
uint16_t tot_hash_cnt; | |||
int16_t hcnt[SET_HASHTAB_SIZE]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeesup0103
ํ์ node๋ฅผ ๊ฐ์ง๋ ๊ฒฝ์ฐ์ hcnt[i] = -1
์ค์ ์ ๊ทธ๋๋ก ์ ์งํ๊ณ ์๋ค์.
๊ฐ hash bucket์ ์๋ element ๊ฐ์๋ hcnt[i] ๊ฐ์ ํ์ธํ ์ ์๊ณ ,
-1์ด๋ผ๋ฉด child node ์ ๊ทผํ์ฌ tot_elem_cnt ํ์ธํ๋ค๋ ๊ฒ์ด์ฃ .
hcnt[i]์์ ํ์ node์ ์๋ element ๊ฐ์๋ฅผ ์ ์งํ๋ ๋ฐฉ์๋ ์๊ฐํด ๋ณผ ์ ์๋ ๋ฐ,
์ด ๋ฐฉ์์ ํํ์ง ์์ ์ด์ ๋ ๋ฌด์์ธ๊ฐ์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhpark816
hcnt[hidx]
๊ฐ์ ๋ณ๊ฒฝํ์ง ์์ ์ด์ ๋ ํด๋น ๋ฒํท์ ์ํ๋ฅผ ๋ฐ๋ก ํ์ธํ ์ ์๋๋ก ์ ์งํ๊ธฐ ์ํด์์
๋๋ค.
DFS ํ์ ๊ณผ์ ์์ hcnt[hidx]
๋ฅผ ํตํด ํด๋น ๋ฒํท์ด ์ถ๊ฐ ๋
ธ๋์ธ์ง ๋๋ element chain์ธ์ง ๋น ๋ฅด๊ฒ ํ๋จํ ์ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ , hcnt[hidx]
๊ฐ๋ ํ์ ๋
ธ๋์ element ๊ฐ์๋ก ๋ณ๊ฒฝํ๋ค๋ฉด, ์ด๋ tot_elem_cnt
์ ์ค๋ณต ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ํํ๊ฐ ๋ฉ๋๋ค.
๊ฒฐ๊ตญ, node->hcnt[hidx]
์ node->htab[hidx]->tot_elem_cnt
๋ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๊ฒ ๋๊ธฐ ๋๋ฌธ์ tot_elem_cnt
๋ง ๋ณ๊ฒฝํ๋ ๊ฒ์ด ๋ ํจ์จ์ ์ด๋ผ๊ณ ์๊ฐํ์ต๋๋ค.
@namsic ์ถ๊ฐ ๋ฆฌ๋ทฐ ์งํํด ์ฃผ์ธ์. |
node->tot_elem_cnt += 1; | ||
node = info->root; | ||
while (node != NULL) { | ||
node->tot_elem_cnt += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do_set_node_link()
, do_set_node_unlink()
, do_set_elem_link()
3๊ฐ ํจ์๋ ์์ ํ๋๋ฐ,
do_set_elem_unlink()
๋ ๊ธฐ์กด ๊ตฌํ์ ๊ทธ๋๋ก ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
do_set_elem_traverse_XXX()
์์ ์ฒ๋ฆฌํ๊ธฐ ๋๋ฌธ์ธ๊ฐ์?- ๊ธฐ์กด ๊ตฌํ์์๋
XXX_link()
์XXX_unlink()
์์tot_elem_cnt
๊ฐ์ ๋ณ๊ฒฝํ๊ณ ,
traverse
ํจ์์์๋ ๋น๊ต ์ฐ์ฐ๋ง ์ํํ์ต๋๋ค.
๊ธฐ์กด์ฒ๋ผ ๋ฐ๋ ์ด๋ฆ์ ๊ฐ๋ ํจ์์ ๋์์ด ์๋ก ์ง์ ์ด๋ฃจ๋๋ก ๊ตฌํํ๊ธฐ๋ ์ด๋ ค์ด๊ฐ์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ๋ค. ํด๋น ๋
ธ๋์ ๋ถ๋ชจ ๋
ธ๋๋ค์
tot_elem_cnt
๊ฐ์do_set_elem_traverse_XXX()
์์ ์ฒ๋ฆฌ ๋ฉ๋๋ค. - ์ด๋ ต์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค.
do_set_elem_unlink()
์์do_set_elem_link()
์ ๊ฐ์ด ํด์๊ฐ์ ๊ธฐ์ค์ผ๋ก while๋ฌธ์ ๋ฐ๋ณตํด์ ๋ถ๋ชจ ๋ ธ๋๋ค์tot_elem_cnt
๊ฐ์ ์ ๋ฐ์ดํธ ํ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ฉด ํ๋์ element๋ฅผ ์ญ์ ํ ๋๋ง๋ค ๋ถ๋ชจ ๋ ธ๋๋ค์ ์ ๋ฐ์ดํธ ํด์ผํ๋ ๋น์ฉ์ ๋ฐ์ํฉ๋๋ค. (ํ์ฌ PR์์๋ ๋ ธ๋๋น ํ๋ฒ ์ ๋ฐ์ดํธ)
while (node != NULL) {
node->tot_elem_cnt -= 1;
hidx = SET_GET_HASHIDX(elem->hval, node->hdepth);
if (node->hcnt[hidx] >= 0)
break;
node = node->htab[hidx];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
engines/default/item_base.h
Outdated
@@ -236,7 +236,7 @@ typedef struct _set_hash_node { | |||
uint16_t refcount; | |||
uint8_t slabs_clsid; /* which slab class we're in */ | |||
uint8_t hdepth; | |||
uint16_t tot_elem_cnt; | |||
uint32_t tot_elem_cnt; | |||
uint16_t tot_hash_cnt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit32_t tot_elem_cnt ๋ child node์ ์๋ elements ์๋ฅผ ํฌํจํ๋ ๊ฒ์ผ๋ก ๋ณ๊ฒฝํ๋ค๋ฉด,
uint16_t tot_hash_cnt ๋ ์ ๊ฑฐํ๋ ๊ฒ์ด ๋์ ๊ฒ ๊ฐ์ต๋๋ค. ๊ฒํ ํ ์กฐ์น ๋ฐ๋๋๋ค.
tot_hash_cnt๊ฐ ์ด์ฉ๋๋ 2๊ฐ์ง ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
์ฒซ์งธ, ์๋ ๊ฒฝ์ฐ์์ tot_elem_cnt == 0
์ด๋ฉด tot_hash_cnt == 0
์์ ์ ์ ์์ผ๋ฏ๋ก
tot_hash_cnt == 0
์กฐ๊ฑด์ ์ ๊ฑฐํด๋ ๋ฉ๋๋ค.
if (info->root->tot_hash_cnt == 0 && info->root->tot_elem_cnt == 0) {
do_set_node_unlink(info, NULL, 0);
}
๋์จฐ, ์๋ ๊ฒฝ์ฐ์์ tot_hash_cnt ํ๋๋ฅผ ์ ๊ฑฐํ๋ ๋์ ์
ํ์ํ๋ฉด get_child_node_count(node)
ํจ์๋ฅผ ๋์ด ๊ณ์ฐํ๊ฒ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.
if (child_node->tot_hash_cnt == 0 &&
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) {
do_set_node_unlink(info, node, hidx);
}
=>
if (child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)
&& get_child_node_count(node) == 0) {
do_set_node_unlink(info, node, hidx);
}
๊ทธ๋ฆฌ๊ณ tot_elem_cnt ํ๋๋ ๊ทธ ์๋ฏธ๊ฐ ๋ณ๊ฒฝ๋ ์ํ์ด๋ฏ๋ก,
ํ๋๋ช
์ ๋ค๋ฅด๊ฒ ๋ณ๊ฒฝํ ํ์๊ฐ ์๋์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ค tot_hash_cnt
์ ๊ฑฐํด๋ ๋ฌด๋ฐฉํด ๋ณด์
๋๋ค.
๋ค๋ง ๋๋ฒ์งธ ๊ฒฝ์ฐ์์ ์ค์ child_node์ ๊ฐ์๊ฐ ํ์ํ ๊ฒ์ด ์๋๊ธฐ ๋๋ฌธ์ is_leaf_node()
์ ๊ฐ์ ํจ์๋ ์ด๋จ๊น ์ถ์ต๋๋ค.
๊ตฌํ ์์
if (child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)
&& is_leaf_node(child_node)) {
do_set_node_unlink(info, node, hidx);
}
...
bool is_leaf_node(set_hash_node *node) {
for (int hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] == -1)
return false;
}
return true;
}
tot_elem_cnt
ํ๋๋ช
์ ๋ณ๊ฒฝํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. Map ์ tot_elem_cnt
๋ณ์์ ํท๊ฐ๋ฆด ์ฌ์ง๊ฐ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ณ๊ฒฝ ์์)
subtree_elem_cnt
subnode_elem_cnt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)
์ํ์ด๋ฉด, child node ๋ํ ์๋ค๋ ๊ฒ์ด ๋ณด์ฅ๋์ง ์๋ ์ง๋ฅผ ํ์ธํด ์ฃผ์ธ์.- tot_elem_cnt ํ๋๋ช ์ ์ผ๋จ ๊ทธ๋๋ก ์ฌ์ฉํฉ์๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2))
์กฐ๊ฑด๋ง ์์ด๋ ๊ฐ๋ฅํด ๋ณด์
๋๋ค.
parent_node->tot_elem_cnt
>=child_node->tot_elem_cnt
๊ฐ ๋ณด์ฅ๋ฉ๋๋ค.- delete, get delete ๋ช ๋ น์ด์์ DFS ์์์ child_node์์ ๋จผ์ node_unlink()๊ฐ ์ผ์ด๋ฉ๋๋ค.
๊ฒฐ๊ตญ ๋ถ๋ชจ ๋ ธ๋์ ์์ ๋ ธ๋๊ฐ ๋จ์ ์๋ค๋ ๊ฒ์ ํด๋น ์์ ๋ ธ๋๊ฐ ์ถฉ๋ถํ ํฐ ์ํ์ ๋๋ค. ๊ทธ๋ ์ง ์๋ค๋ฉด unlink().
engines/default/coll_set.c
Outdated
@@ -400,6 +404,7 @@ static ENGINE_ERROR_CODE do_set_elem_traverse_delete(set_meta_info *info, set_ha | |||
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) { | |||
do_set_node_unlink(info, node, hidx); | |||
} | |||
node->tot_elem_cnt--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ํํ๋ก ๋ณ๊ฒฝํ์์ฃ .
tot_elem_cnt ๋ณ๊ฒฝ ์คํ์ผ์ ๋์ผํ๊ฒ ๋ง์ถ๊ณ ์ ํฉ๋๋ค.
tot_elem_cnt -= 1;
@jeesup0103 |
ํ์ฌ ์ฃผ์ ์ฒ๋ฆฌ๋์ด ์๋ #ifdef SET_DELETE_NO_MERGE
static uint32_t do_set_elem_traverse_fast(set_meta_info *info,
set_hash_node *node, const uint32_t count)
{
int hidx;
int fcnt = 0;
/* node has child node */
if (node->tot_hash_cnt > 0) {
for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) { |
do_set_elem_xxxx_fast() ํจ์๋ค๋ ๊ฐ๋ฅํ๋ค๋ฉด, ์ ํํ๊ฒ ์์ ํด ๋๋ฉด ์ข๊ฒ ์ต๋๋ค. |
๋จผ์ hash table์ ์ฐพ์๊ฐ ๋ค์, ํด๋น hash table์ ๋ค์ด์๋ ๋ชจ๋ element๋ค์ ์ญ์ ํฉ๋๋ค.
๋ฌธ์ ์ํฉ์ DFS ์์๋ฅผ ์์ ์ธ๋ฑ์ค๋ถํฐ ์ฐพ์๊ฐ๋๋ก ๋ณ๊ฒฝํ๋ฉด hash table ๋จ์๋ก element๋ฅผ ์ญ์ ํ ์ ์์ต๋๋ค. (์์ ๋ณ๊ฒฝํ๋ฉด element chain ๋จ์๋ก ์ญ์ ๊ฐ๋ฅ) ๊ทธ๋์ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ค๋ง ๋ ์ด์ ์ฌ์ฉํ์ง ์๋ ๊ธฐ๋ฅ์ด๋ผ๋ฉด ์ง์ฐ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
2199b09
to
3782096
Compare
do_set_elem_XXX_fast() ์ด์ ์ ์ธํ๊ณ ๋จผ์ ์์ ํ์ต๋๋ค. |
@namsic ์ต๊ทผ์ ์์ ๋ ์ฌํญ์ด ์์ด ์ฌ๋ฆฌ๋ทฐ ์์ฒญํ์ต๋๋ค. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
@@ -219,8 +218,6 @@ static void do_set_node_link(set_meta_info *info, | |||
|
|||
par_node->htab[par_hidx] = node; | |||
par_node->hcnt[par_hidx] = -1; /* child hash node */ | |||
par_node->tot_elem_cnt -= num_found; | |||
par_node->tot_hash_cnt += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ ํ๋ ๊น์, num_found, num_elems ๋ณ์๋ฅผ ๋ชจ๋ ์ ๊ฑฐํด๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
while (par_node->htab[par_hidx] != NULL) {
set_elem_item *elem = par_node->htab[par_hidx];
par_node->htab[par_hidx] = elem->next;
int hidx = SET_GET_HASHIDX(elem->hval, node->hdepth);
elem->next = node->htab[hidx];
node->htab[hidx] = elem;
node->hcnt[hidx] += 1;
node->tot_elem_cnt += 1;
}
assert(node->tot_elem_cnt == par_node->hcnt[par_hidx]);
par_node->htab[par_hidx] = node;
par_node->hcnt[par_hidx] = -1; /* child hash node */
@@ -263,13 +258,10 @@ static void do_set_node_unlink(set_meta_info *info, | |||
assert(node->hcnt[hidx] == 0); | |||
} | |||
} | |||
assert(fcnt == node->tot_elem_cnt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฌ๊ธฐ assert ๋ฌธ์ ๊ทธ๋๋ก ๋ก์๋ค.
if (node->hcnt[hidx] >= 0) | ||
break; | ||
node = node->htab[hidx]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ์ฝ๋์ ๊ฐ์ด ํ์ฌ ๋
ธ๋์์ tot_elem_cnt ์ฆ๊ฐ์ํค๋ ์ฝ๋์
์ผ์ ๋
ธ๋๋ค์์ tot_elem_cnt ์ฆ๊ฐ์ํค๋ ์ฝ๋๊ฐ ๊ตฌ๋ถ๋๋ฉด ์ข๊ฒ ์ต๋๋ค.
do_set_elem_unlink()์์ ์ฐจ์ด๊ฐ ์ ๋๋ฌ๋๊ฒ ํ๋ ค๋ ์๋์
๋๋ค.
elem->next = node->htab[hidx];
node->htab[hidx] = elem;
node->hcnt[hidx] += 1;
node->tot_elem_cnt += 1;
set_hash_node *par_node = info->root;
while (par_node != node) {
par_node->tot_elem_cnt += 1;
hidx = SET_GET_HASHIDX(elem->hval, par_node->hdepth);
assert(par_node->hcnt[hidx] == -1);
par_node = par_node->htab[hidx];
}
info->ccnt++;
@@ -396,10 +395,10 @@ static ENGINE_ERROR_CODE do_set_elem_traverse_delete(set_meta_info *info, set_ha | |||
set_hash_node *child_node = node->htab[hidx]; | |||
ret = do_set_elem_traverse_delete(info, child_node, hval, val, vlen); | |||
if (ret == ENGINE_SUCCESS) { | |||
if (child_node->tot_hash_cnt == 0 && | |||
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) { | |||
if (child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)
์กฐ๊ฑด ๋ง์ผ๋ก
child_node๊ฐ leaf node์ธ์ง๋ฅผ 100% ๋ณด์ฅํ ์ ์๋ ์ง๊ฐ ์์ง ์๋ฌธ์ธ๋ฐ์.
์ด๋ค๊ฐ์?
์กฐ๊ธ์ด๋ผ๋ ํ์ ์ด ์์ง ์๋๋ค๋ฉด, ์๋์ ๊ฐ์ด is_leaf_node() ์ถ๊ฐํ๋ฉด ์ข๊ฒ ์ต๋๋ค.
if (child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)
&& is_leaf_node(child_node)) {
do_set_node_unlink(info, node, hidx);
}
๐ Related Issue
โจ๏ธ What I did
tot_elem_cnt
๋ฅผ ํด๋น ๋ ธ๋์ subtree์ ํฌํจ๋ ๋ชจ๋ element์ ์ด ๊ฐ์๋ก ๋ณ๊ฒฝ์ธ๋ถ ๊ตฌํ ๋ด์ฉ
tot_elem_cnt
ํฌ๊ธฐ ํ์ฅuint16_t
์์uint32_t
๋ก ๋ณ๊ฒฝtot_elem_cnt
๋ณ์ ๊ด๋ฆฌElement Insert (
do_set_elem_link()
)tot_elem_cnt
๋ฅผ 1 ์ฆ๊ฐElement Delete (
do_set_elem_traverse_dfs()
,do_set_elem_traverse_delete()
)tot_elem_cnt
๋ฅผ 1 ๊ฐ์Chain -> Hash table ๋ณ๊ฒฝ (
do_set_node_link()
)tot_elem_cnt
์ ์งtot_elem_cnt
= ๊ธฐ์กด Chain element ๊ฐ์ (num_found)Hash table -> Chain (
do_set_node_unlink()
)tot_elem_cnt
์ ์งtot_elem_cnt
= 0์ถํ PR ๋ด์ฉ