Skip to content

Commit

Permalink
CLEANUP: Remove stats prefix command
Browse files Browse the repository at this point in the history
  • Loading branch information
namsic authored and jhpark816 committed Dec 16, 2024
1 parent 199dd9f commit b3bccb2
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 312 deletions.
14 changes: 0 additions & 14 deletions engines/default/default_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,19 +1217,6 @@ default_prefix_dump_stats(ENGINE_HANDLE* handle, const void* cookie,
return stats;
}

static ENGINE_ERROR_CODE
default_prefix_get_stats(ENGINE_HANDLE* handle, const void* cookie,
const void* prefix, const int nprefix, ADD_STAT add_stat)
{
struct default_engine* engine = get_handle(handle);
ENGINE_ERROR_CODE ret;

pthread_mutex_lock(&engine->cache_lock);
ret = prefix_get_stats(prefix, nprefix, add_stat, cookie);
pthread_mutex_unlock(&engine->cache_lock);
return ret;
}

/*
* Dump API
*/
Expand Down Expand Up @@ -2025,7 +2012,6 @@ create_instance(uint64_t interface, GET_SERVER_API get_server_api,
.get_stats = default_get_stats,
.reset_stats = default_reset_stats,
.prefix_dump_stats = default_prefix_dump_stats,
.prefix_get_stats = default_prefix_get_stats,
/* Dump API */
.cachedump = default_cachedump,
.dump = default_dump,
Expand Down
101 changes: 0 additions & 101 deletions engines/default/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,107 +701,6 @@ char *prefix_dump_stats(token_t *tokens, const size_t ntokens, int *length)
return buffer;
}

ENGINE_ERROR_CODE prefix_get_stats(const char *prefix, const int nprefix,
ADD_STAT add_stat, const void *cookie)
{
prefix_t *pt;
struct tm *t;
int len;
char val[64];

if (prefix != NULL) {
pt = _prefix_find(prefix, nprefix, svcore->hash(prefix,nprefix,0));
} else {
pt = (null_pt->total_count_exclusive > 0) ? null_pt : NULL;
}
if (pt == NULL) {
return ENGINE_PREFIX_ENOENT;
}

/* create time */
t = localtime(&pt->create_time);
len = sprintf(val, "%04d%02d%02d%02d%02d%02d",
t->tm_year+1900, t->tm_mon+1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec);
add_stat("create_time", 11, val, len, cookie);
#ifdef NESTED_PREFIX
if (pt->child_prefix_items > 0) {
/* item count */
len = sprintf(val, "%"PRIu64, pt->total_count_inclusive);
add_stat("item_count_total", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_inclusive[ITEM_TYPE_KV]);
add_stat("item_count_kv", 13, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_inclusive[ITEM_TYPE_LIST]);
add_stat("item_count_list", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_inclusive[ITEM_TYPE_SET]);
add_stat("item_count_set", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_inclusive[ITEM_TYPE_MAP]);
add_stat("item_count_map", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_inclusive[ITEM_TYPE_BTREE]);
add_stat("item_count_btree", 16, val, len, cookie);
/* item bytes */
len = sprintf(val, "%"PRIu64, pt->total_bytes_inclusive);
add_stat("item_bytes_total", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_inclusive[ITEM_TYPE_KV]);
add_stat("item_bytes_kv", 13, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_inclusive[ITEM_TYPE_LIST]);
add_stat("item_bytes_list", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_inclusive[ITEM_TYPE_SET]);
add_stat("item_bytes_set", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_inclusive[ITEM_TYPE_MAP]);
add_stat("item_bytes_map", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_inclusive[ITEM_TYPE_BTREE]);
add_stat("item_bytes_btree", 16, val, len, cookie);
#if 0 // FUTURE: NESTED_PREFIX
/* child prefixes */
len = sprintf(val, "%"PRIu64, (uint64_t)pt->child_prefix_items);
add_stat("child_prefixes", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->total_count_inclusive - pt->total_count_exclusive);
add_stat("child_item_count", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->total_bytes_inclusive - pt->total_bytes_exclusive);
add_stat("child_item_bytes", 16, val, len, cookie);
#endif
return ENGINE_SUCCESS;
}
#endif
/* item count */
len = sprintf(val, "%"PRIu64, pt->total_count_exclusive);
add_stat("item_count_total", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_exclusive[ITEM_TYPE_KV]);
add_stat("item_count_kv", 13, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_exclusive[ITEM_TYPE_LIST]);
add_stat("item_count_list", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_exclusive[ITEM_TYPE_SET]);
add_stat("item_count_set", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_exclusive[ITEM_TYPE_MAP]);
add_stat("item_count_map", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_count_exclusive[ITEM_TYPE_BTREE]);
add_stat("item_count_btree", 16, val, len, cookie);
/* item bytes */
len = sprintf(val, "%"PRIu64, pt->total_bytes_exclusive);
add_stat("item_bytes_total", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_exclusive[ITEM_TYPE_KV]);
add_stat("item_bytes_kv", 13, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_exclusive[ITEM_TYPE_LIST]);
add_stat("item_bytes_list", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_exclusive[ITEM_TYPE_SET]);
add_stat("item_bytes_set", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_exclusive[ITEM_TYPE_MAP]);
add_stat("item_bytes_map", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pt->items_bytes_exclusive[ITEM_TYPE_BTREE]);
add_stat("item_bytes_btree", 16, val, len, cookie);
#if 0 // FUTURE: NESTED_PREFIX
/* child prefixes */
len = sprintf(val, "%"PRIu64, (uint64_t)pt->child_prefix_items);
add_stat("child_prefixes", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, (uint64_t)0);
add_stat("child_item_count", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, (uint64_t)0);
add_stat("child_item_bytes", 16, val, len, cookie);
#endif
return ENGINE_SUCCESS;
}

#ifdef SCAN_COMMAND
static bool _prefix_isempty(prefix_t *pt)
{
Expand Down
2 changes: 0 additions & 2 deletions engines/default/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ void prefix_bytes_decr(prefix_t *pt, ENGINE_ITEM_TYPE item_type, co
bool prefix_isvalid(hash_item *it, rel_time_t current_time);
uint32_t prefix_count(void);
char * prefix_dump_stats(token_t *tokenes, const size_t ntokens, int *length);
ENGINE_ERROR_CODE prefix_get_stats(const char *prefix, const int nprefix,
ADD_STAT add_stat, const void *cookie);
#ifdef SCAN_COMMAND
int prefix_scan_direct(const char *cursor, int req_count,
void **item_array, int item_arrsz);
Expand Down
8 changes: 0 additions & 8 deletions engines/demo/demo_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,6 @@ Demo_prefix_dump_stats(ENGINE_HANDLE* handle, const void* cookie,
return NULL;
}

static ENGINE_ERROR_CODE
Demo_prefix_get_stats(ENGINE_HANDLE* handle, const void* cookie,
const void* prefix, const int nprefix, ADD_STAT add_stat)
{
return ENGINE_ENOTSUP;
}

/*
* Dump API
*/
Expand Down Expand Up @@ -860,7 +853,6 @@ create_instance(uint64_t interface, GET_SERVER_API get_server_api,
.get_stats = Demo_get_stats,
.reset_stats = Demo_reset_stats,
.prefix_dump_stats = Demo_prefix_dump_stats,
.prefix_get_stats = Demo_prefix_get_stats,
/* Dump API */
/* Config API */
.set_config = Demo_set_config,
Expand Down
4 changes: 0 additions & 4 deletions include/memcached/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,6 @@ extern "C" {
char *(*prefix_dump_stats)(ENGINE_HANDLE* handle, const void* cookie,
token_t *tokenes, const size_t ntokens, int *length);

ENGINE_ERROR_CODE (*prefix_get_stats)(ENGINE_HANDLE* handle, const void* cookie,
const void* prefix, const int nprefix,
ADD_STAT add_stat);

/**
* Set engine config.
*
Expand Down
21 changes: 0 additions & 21 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -8274,27 +8274,6 @@ static void process_stats_command(conn *c, token_t *tokens, const size_t ntokens
}
write_and_free(c, stats, len);
return; /* Output already generated */
} else if (strcmp(subcommand, "prefix") == 0) {
/* command: stats prefix <prefix>\r\n */
if (ntokens != 4) {
print_invalid_command(c, tokens, ntokens);
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
if (tokens[2].length > PREFIX_MAX_LENGTH) {
out_string(c, "CLIENT_ERROR too long prefix name");
return;
}
if (strcmp(tokens[2].value, "<null>") == 0) { /* reserved keyword */
(void)mc_engine.v1->prefix_get_stats(mc_engine.v0, c, NULL, 0,
append_ascii_stats);
stats_prefix_get(NULL, 0, append_ascii_stats, c);
} else {
(void)mc_engine.v1->prefix_get_stats(mc_engine.v0, c,
tokens[2].value, tokens[2].length,
append_ascii_stats);
stats_prefix_get(tokens[2].value, tokens[2].length, append_ascii_stats, c);
}
} else {
/* getting here means that the subcommand is either engine specific or
is invalid. query the engine and see. */
Expand Down
133 changes: 0 additions & 133 deletions stats_prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,139 +1299,6 @@ char *stats_prefix_dump(token_t *tokens, const size_t ntokens, int *length)
return buf;
}

void stats_prefix_get(const char *prefix, const size_t nprefix,
ADD_STAT add_stat, void *cookie)
{
PREFIX_STATS *pfs;
uint32_t hashval = mc_hash(prefix, nprefix, 0) % PREFIX_HASH_SIZE;
int len;
char val[64];

LOCK_STATS();
for (pfs = prefix_stats[hashval]; pfs != NULL; pfs = pfs->next) {
if ((pfs->prefix_len==nprefix) &&
(nprefix==0 || strncmp(pfs->prefix, prefix, nprefix)==0))
break;
}
if (pfs != NULL) {
/* KV */
len = sprintf(val, "%"PRIu64, pfs->num_gets);
add_stat("num_gets", 8, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_hits);
add_stat("num_hits", 8, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sets);
add_stat("num_sets", 8, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_deletes);
add_stat("num_deletes", 11, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_incrs);
add_stat("num_incrs", 9, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_decrs);
add_stat("num_decrs", 9, val, len, cookie);
/* LIST */
len = sprintf(val, "%"PRIu64, pfs->num_lop_creates);
add_stat("num_lop_creates", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_lop_inserts);
add_stat("num_lop_inserts", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_lop_insert_hits);
add_stat("num_lop_insert_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_lop_deletes);
add_stat("num_lop_deletes", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_lop_delete_hits);
add_stat("num_lop_delete_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_lop_gets);
add_stat("num_lop_gets", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_lop_get_hits);
add_stat("num_lop_get_hits", 16, val, len, cookie);
/* SET */
len = sprintf(val, "%"PRIu64, pfs->num_sop_creates);
add_stat("num_sop_creates", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_inserts);
add_stat("num_sop_inserts", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_insert_hits);
add_stat("num_sop_insert_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_deletes);
add_stat("num_sop_deletes", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_delete_hits);
add_stat("num_sop_delete_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_gets);
add_stat("num_sop_gets", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_get_hits);
add_stat("num_sop_get_hits", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_exists);
add_stat("num_sop_exists", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_sop_exist_hits);
add_stat("num_sop_exist_hits", 18, val, len, cookie);
/* MAP */
len = sprintf(val, "%"PRIu64, pfs->num_mop_creates);
add_stat("num_mop_creates", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_inserts);
add_stat("num_mop_inserts", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_insert_hits);
add_stat("num_mop_insert_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_updates);
add_stat("num_mop_updates", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_update_hits);
add_stat("num_mop_update_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_deletes);
add_stat("num_mop_deletes", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_delete_hits);
add_stat("num_mop_delete_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_gets);
add_stat("num_mop_gets", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_mop_get_hits);
add_stat("num_mop_get_hits", 16, val, len, cookie);
/* B+TREE */
len = sprintf(val, "%"PRIu64, pfs->num_bop_creates);
add_stat("num_bop_creates", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_inserts);
add_stat("num_bop_inserts", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_insert_hits);
add_stat("num_bop_insert_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_updates);
add_stat("num_bop_updates", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_update_hits);
add_stat("num_bop_update_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_deletes);
add_stat("num_bop_deletes", 15, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_delete_hits);
add_stat("num_bop_delete_hits", 19, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_incrs);
add_stat("num_bop_incrs", 13, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_incr_hits);
add_stat("num_bop_incr_hits", 17, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_decrs);
add_stat("num_bop_decrs", 13, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_decr_hits);
add_stat("num_bop_decr_hits", 17, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_gets);
add_stat("num_bop_gets", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_get_hits);
add_stat("num_bop_get_hits", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_counts);
add_stat("num_bop_counts", 14, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_count_hits);
add_stat("num_bop_count_hits", 18, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_positions);
add_stat("num_bop_positions", 17, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_position_hits);
add_stat("num_bop_position_hits", 21, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_pwgs);
add_stat("num_bop_pwgs", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_pwg_hits);
add_stat("num_bop_pwg_hits", 16, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_gbps);
add_stat("num_bop_gbps", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_bop_gbp_hits);
add_stat("num_bop_gbp_hits", 16, val, len, cookie);
/* ATTRS */
len = sprintf(val, "%"PRIu64, pfs->num_getattrs);
add_stat("num_getattrs", 12, val, len, cookie);
len = sprintf(val, "%"PRIu64, pfs->num_setattrs);
add_stat("num_setattrs", 12, val, len, cookie);
}
UNLOCK_STATS();
}

#ifdef UNIT_TEST
/****************************************************************************
To run unit tests, compile with $(CC) -DUNIT_TEST stats.c assoc.o
Expand Down
1 change: 0 additions & 1 deletion stats_prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ void stats_prefix_record_getattr(const char *key, const size_t nkey);
void stats_prefix_record_setattr(const char *key, const size_t nkey);
/*@null@*/
char *stats_prefix_dump(token_t *tokens, const size_t ntokens, int *length);
void stats_prefix_get(const char *prefix, const size_t nprefix, ADD_STAT add_stat, void *cookie);
29 changes: 1 addition & 28 deletions t/lib/MemcachedTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ my $builddir = getcwd;
mem_get_is mem_gets mem_gets_is mem_stats mem_cmd_val_is mem_cmd_is
getattr_is lop_get_is sop_get_is mop_get_is bop_get_is bop_gbp_is bop_pwg_is bop_smget_is
bop_ext_get_is bop_ext_smget_is bop_new_smget_is bop_old_smget_is
stats_prefixes_is stats_noprefix_is stats_prefix_is keyscan prefixscan
stats_prefixes_is stats_noprefix_is keyscan prefixscan
supports_sasl free_port);

sub sleep {
Expand Down Expand Up @@ -988,33 +988,6 @@ sub stats_noprefix_is {
Test::More::is($response, $expected, $msg);
}

# DELETE_BY_PREFIX
sub stats_prefix_is {
# works on single-line values only. no newlines in value.
my ($sock_opts, $prefix, $val, $msg) = @_;
my $opts = ref $sock_opts eq "HASH" ? $sock_opts : {};
my $sock = ref $sock_opts eq "HASH" ? $opts->{sock} : $sock_opts;

$msg ||= "stats prefix $prefix";

print $sock "stats prefix $prefix\r\n";
my $expected = $val;
my @res_array = ();
my $line = scalar <$sock>;

while ($line =~ /^PREFIX/) {
my $subline = substr $line, 7, length($line) - 9;

unless($subline =~ /^hash_items_bytes/ or $subline =~ /^name/ or $subline =~ /^tot_prefix_items/) {
push(@res_array, $subline);
}

$line = scalar <$sock>;
}
my $response = join(" ", @res_array);
Test::More::is($response, $expected, $msg);
}

#KEYSCAN
sub keyscan {
my ($sock_opts, $cursor, $count, $pattern, $type) = @_;
Expand Down

0 comments on commit b3bccb2

Please sign in to comment.