Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions engines/default/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ static int _prefix_insert(prefix_t *pt, uint32_t hash)
prefxp->total_prefix_items++;
}
#else
assert(pt->parent_prefix != NULL);
pt->parent_prefix->child_prefix_items++;
prefxp->total_prefix_items++;
#endif
return 1;
Expand All @@ -294,8 +292,6 @@ static void _prefix_delete(const char *prefix, const int nprefix, uint32_t hash)
prefxp->total_prefix_items--;
}
#else
assert(pt->parent_prefix != NULL);
pt->parent_prefix->child_prefix_items--;
prefxp->total_prefix_items--;
#endif
/* unlink and free the prefix structure */
Expand Down Expand Up @@ -351,6 +347,9 @@ ENGINE_ERROR_CODE prefix_link(hash_item *it, const uint32_t item_size, bool *int
if (prefix_depth >= DEFAULT_PREFIX_MAX_DEPTH) {
break;
}
#ifndef NESTED_PREFIX
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ν˜„μž¬λ‘œμ„œλŠ” Non-Nested Prefix λ‘œμ§μ—μ„œ prefix_list, prefix_depth, DEFAULT_PREFIX_MAX_DEPTHλ₯Ό μ‚¬μš©ν•˜κ³  μžˆλŠ” 뢀뢄이 쑰금 λΆ€μžμ—°μŠ€λŸ¬μ›Œ λ³΄μž…λ‹ˆλ‹€. 이 뢀뢄을 Non Nested Prefix와 Nested Prefixλ₯Ό ν™œμš©ν•  λ•Œλ₯Ό 뢄리할 수 μžˆλ‚˜μš”?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ν˜„μž¬ NESTED_PREFIXλ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” κ²½μš°μ—λ„ prefix_list[0]을 μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. 이 λ³€μˆ˜λ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€λ©΄ prefix_link()μ—μ„œ 두 경우의 둜직 자체λ₯Ό 뢄리해야 할텐데, 가독성이 λ–¨μ–΄μ§€μ§€ μ•Šμ„κΉŒμš”?

#endif
}

if (prefix_depth == 0) {
Expand Down Expand Up @@ -413,7 +412,6 @@ ENGINE_ERROR_CODE prefix_link(hash_item *it, const uint32_t item_size, bool *int
if (PREFIX_IS_RSVD(key, pt->nprefix)) {
pt->internal = 1; /* internal prefix */
}
pt->parent_prefix = (j == 0 ? null_pt : prefix_list[j-1].pt);
#endif
time(&pt->create_time);

Expand Down Expand Up @@ -445,13 +443,22 @@ void prefix_unlink(hash_item *it, const uint32_t item_size, bool drop_if_empty)

if (drop_if_empty) {
while (pt != NULL && pt != null_pt) {
prefix_t *parent_pt = pt->parent_prefix;
if (pt->child_prefix_items > 0 || pt->total_count_exclusive > 0)
bool has_items = pt->total_count_exclusive > 0;
bool has_children = false;
prefix_t *next_pt = NULL;

#ifdef NESTED_PREFIX
has_children = pt->child_prefix_items > 0;
next_pt = pt->parent_prefix;
#endif
if (has_items || has_children) {
break; /* NOT empty */
}

assert(pt->total_bytes_exclusive == 0);
_prefix_delete(_get_prefix(pt), pt->nprefix,
svcore->hash(_get_prefix(pt), pt->nprefix, 0));
pt = parent_pt;
pt = next_pt;
}
}
}
Expand Down Expand Up @@ -512,8 +519,12 @@ bool prefix_isvalid(hash_item *it, rel_time_t current_time)
it->time <= pt->oldest_live)
return false;
/* traverse parent prefixes to validate them */
#ifdef NESTED_PREFIX
pt = pt->parent_prefix;
} while(pt != NULL && pt != null_pt);
#else
pt = NULL;
#endif
} while (pt != NULL && pt != null_pt);

return true;
}
Expand All @@ -528,8 +539,12 @@ static uint32_t do_count_invalid_prefix(void)
for (i = 0; i < size; i++) {
pt = prefxp->hashtable[i];
while (pt) {
if (pt->child_prefix_items == 0 && pt->total_count_exclusive == 0)
invalid_prefix++;
if (pt->total_count_exclusive == 0) {
#ifdef NESTED_PREFIX
if (pt->child_prefix_items == 0)
#endif
invalid_prefix++;
}
pt = pt->h_next;
}
}
Expand Down Expand Up @@ -593,7 +608,6 @@ static int _prefix_stats_write_buffer(char *buffer, const size_t buflen,
pt->items_bytes_exclusive[ITEM_TYPE_MAP],
pt->items_bytes_exclusive[ITEM_TYPE_BTREE],
/* FUTURE: NESTED_PREFIX
(uint64_t)pt->child_prefix_items,
(uint64_t)0,
(uint64_t)0,
*/
Expand Down Expand Up @@ -665,7 +679,6 @@ char *prefix_dump_stats(token_t *tokens, const size_t ntokens, int *length)
/* write prefix stats in the buffer */
if (num_prefixes > prefxp->total_prefix_items) { /* include null prefix */
pt = null_pt;
assert(pt->child_prefix_items == 0);
pos += _prefix_stats_write_buffer(buffer+pos, buflen-pos, format, pt, false);
assert(pos < buflen);
}
Expand Down Expand Up @@ -714,7 +727,11 @@ char *prefix_dump_stats(token_t *tokens, const size_t ntokens, int *length)
#ifdef SCAN_COMMAND
static bool _prefix_isempty(prefix_t *pt)
{
return pt->child_prefix_items == 0 && pt->total_count_exclusive == 0;
#ifdef NESTED_PREFIX
return pt->child_prefix_items == 0 && pt->total_count_exclusive == 0;
#else
return pt->total_count_exclusive == 0;
#endif
}

static int _prefix_scan_direct(const char *cursor, int req_count, void **item_array, int item_arrsz)
Expand Down
8 changes: 4 additions & 4 deletions engines/default/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ typedef struct _prefix_t {
time_t create_time;

struct _prefix_t *h_next; /* prefix hash chain */
struct _prefix_t *parent_prefix;

/* Number of child prefix items */
uint32_t child_prefix_items;

/* count and bytes of cache items per item type */
uint64_t total_count_exclusive;
Expand All @@ -48,6 +44,10 @@ typedef struct _prefix_t {
uint64_t items_bytes_exclusive[ITEM_TYPE_MAX];

#ifdef NESTED_PREFIX
struct _prefix_t *parent_prefix;
/* Number of child prefix items */
uint32_t child_prefix_items;

/* includes cache items that belong to child prefixes */
uint64_t total_count_inclusive; /* NOT yet used */
uint64_t total_bytes_inclusive; /* NOT yet used */
Expand Down