Skip to content

Commit b7142db

Browse files
committed
INTERNAL: Bundle nested fields of prefix_t with NESTED_PREFIX
1 parent 1970def commit b7142db

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

engines/default/prefix.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ static int _prefix_insert(prefix_t *pt, uint32_t hash)
266266
prefxp->total_prefix_items++;
267267
}
268268
#else
269-
assert(pt->parent_prefix != NULL);
270-
pt->parent_prefix->child_prefix_items++;
271269
prefxp->total_prefix_items++;
272270
#endif
273271
return 1;
@@ -294,8 +292,6 @@ static void _prefix_delete(const char *prefix, const int nprefix, uint32_t hash)
294292
prefxp->total_prefix_items--;
295293
}
296294
#else
297-
assert(pt->parent_prefix != NULL);
298-
pt->parent_prefix->child_prefix_items--;
299295
prefxp->total_prefix_items--;
300296
#endif
301297
/* unlink and free the prefix structure */
@@ -413,7 +409,6 @@ ENGINE_ERROR_CODE prefix_link(hash_item *it, const uint32_t item_size, bool *int
413409
if (PREFIX_IS_RSVD(key, pt->nprefix)) {
414410
pt->internal = 1; /* internal prefix */
415411
}
416-
pt->parent_prefix = (j == 0 ? null_pt : prefix_list[j-1].pt);
417412
#endif
418413
time(&pt->create_time);
419414

@@ -445,13 +440,22 @@ void prefix_unlink(hash_item *it, const uint32_t item_size, bool drop_if_empty)
445440

446441
if (drop_if_empty) {
447442
while (pt != NULL && pt != null_pt) {
448-
prefix_t *parent_pt = pt->parent_prefix;
449-
if (pt->child_prefix_items > 0 || pt->total_count_exclusive > 0)
443+
bool has_items = pt->total_count_exclusive > 0;
444+
bool has_children = false;
445+
prefix_t *next_pt = NULL;
446+
447+
#ifdef NESTED_PREFIX
448+
has_children = pt->child_prefix_items > 0;
449+
next_pt = pt->parent_prefix;
450+
#endif
451+
if (has_items || has_children) {
450452
break; /* NOT empty */
453+
}
454+
451455
assert(pt->total_bytes_exclusive == 0);
452456
_prefix_delete(_get_prefix(pt), pt->nprefix,
453457
svcore->hash(_get_prefix(pt), pt->nprefix, 0));
454-
pt = parent_pt;
458+
pt = next_pt;
455459
}
456460
}
457461
}
@@ -512,8 +516,12 @@ bool prefix_isvalid(hash_item *it, rel_time_t current_time)
512516
it->time <= pt->oldest_live)
513517
return false;
514518
/* traverse parent prefixes to validate them */
519+
#ifdef NESTED_PREFIX
515520
pt = pt->parent_prefix;
516-
} while(pt != NULL && pt != null_pt);
521+
#else
522+
pt = NULL;
523+
#endif
524+
} while (pt != NULL && pt != null_pt);
517525

518526
return true;
519527
}
@@ -528,8 +536,12 @@ static uint32_t do_count_invalid_prefix(void)
528536
for (i = 0; i < size; i++) {
529537
pt = prefxp->hashtable[i];
530538
while (pt) {
531-
if (pt->child_prefix_items == 0 && pt->total_count_exclusive == 0)
532-
invalid_prefix++;
539+
if (pt->total_count_exclusive == 0) {
540+
#ifdef NESTED_PREFIX
541+
if (pt->child_prefix_items == 0)
542+
#endif
543+
invalid_prefix++;
544+
}
533545
pt = pt->h_next;
534546
}
535547
}
@@ -593,7 +605,6 @@ static int _prefix_stats_write_buffer(char *buffer, const size_t buflen,
593605
pt->items_bytes_exclusive[ITEM_TYPE_MAP],
594606
pt->items_bytes_exclusive[ITEM_TYPE_BTREE],
595607
/* FUTURE: NESTED_PREFIX
596-
(uint64_t)pt->child_prefix_items,
597608
(uint64_t)0,
598609
(uint64_t)0,
599610
*/
@@ -665,7 +676,6 @@ char *prefix_dump_stats(token_t *tokens, const size_t ntokens, int *length)
665676
/* write prefix stats in the buffer */
666677
if (num_prefixes > prefxp->total_prefix_items) { /* include null prefix */
667678
pt = null_pt;
668-
assert(pt->child_prefix_items == 0);
669679
pos += _prefix_stats_write_buffer(buffer+pos, buflen-pos, format, pt, false);
670680
assert(pos < buflen);
671681
}
@@ -714,7 +724,11 @@ char *prefix_dump_stats(token_t *tokens, const size_t ntokens, int *length)
714724
#ifdef SCAN_COMMAND
715725
static bool _prefix_isempty(prefix_t *pt)
716726
{
717-
return pt->child_prefix_items == 0 && pt->total_count_exclusive == 0;
727+
#ifdef NESTED_PREFIX
728+
return pt->child_prefix_items == 0 && pt->total_count_exclusive == 0;
729+
#else
730+
return pt->total_count_exclusive == 0;
731+
#endif
718732
}
719733

720734
static int _prefix_scan_direct(const char *cursor, int req_count, void **item_array, int item_arrsz)

engines/default/prefix.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ typedef struct _prefix_t {
3636
time_t create_time;
3737

3838
struct _prefix_t *h_next; /* prefix hash chain */
39-
struct _prefix_t *parent_prefix;
40-
41-
/* Number of child prefix items */
42-
uint32_t child_prefix_items;
4339

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

5046
#ifdef NESTED_PREFIX
47+
struct _prefix_t *parent_prefix;
48+
/* Number of child prefix items */
49+
uint32_t child_prefix_items;
50+
5151
/* includes cache items that belong to child prefixes */
5252
uint64_t total_count_inclusive; /* NOT yet used */
5353
uint64_t total_bytes_inclusive; /* NOT yet used */

0 commit comments

Comments
 (0)