Kouhei Sutou
null+****@clear*****
Tue Apr 4 17:18:29 JST 2017
Kouhei Sutou 2017-04-04 17:18:29 +0900 (Tue, 04 Apr 2017) New Revision: 27e4e0e1a8a8a788661984e17f56a38ce1718129 https://github.com/groonga/groonga/commit/27e4e0e1a8a8a788661984e17f56a38ce1718129 Message: cache: grn_cache_get_statistics() support persistent Modified files: lib/cache.c Modified: lib/cache.c (+34 -3) =================================================================== --- lib/cache.c 2017-04-04 16:57:59 +0900 (e5546aa) +++ lib/cache.c 2017-04-04 17:18:29 +0900 (a699756) @@ -247,9 +247,9 @@ grn_cache_get_max_n_entries(grn_ctx *ctx, grn_cache *cache) return cache->max_nentries; } -void -grn_cache_get_statistics(grn_ctx *ctx, grn_cache *cache, - grn_cache_statistics *statistics) +static void +grn_cache_get_statistics_memory(grn_ctx *ctx, grn_cache *cache, + grn_cache_statistics *statistics) { MUTEX_LOCK(cache->impl.memory.mutex); statistics->nentries = GRN_HASH_SIZE(cache->impl.memory.hash); @@ -260,6 +260,37 @@ grn_cache_get_statistics(grn_ctx *ctx, grn_cache *cache, } static void +grn_cache_get_statistics_persistent(grn_ctx *ctx, grn_cache *cache, + grn_cache_statistics *statistics) +{ + grn_rc rc = GRN_INVALID_ARGUMENT; + grn_hash *keys = cache->impl.persistent.keys; + + rc = grn_io_lock(ctx, keys->io, cache->impl.persistent.timeout); + if (rc != GRN_SUCCESS) { + return; + } + + statistics->nentries = GRN_HASH_SIZE(keys); + statistics->max_nentries = cache->max_nentries; + statistics->nfetches = cache->nfetches; + statistics->nhits = cache->nhits; + + grn_io_unlock(keys->io); +} + +void +grn_cache_get_statistics(grn_ctx *ctx, grn_cache *cache, + grn_cache_statistics *statistics) +{ + if (cache->is_memory) { + return grn_cache_get_statistics_memory(ctx, cache, statistics); + } else { + return grn_cache_get_statistics_persistent(ctx, cache, statistics); + } +} + +static void grn_cache_expire_entry_memory(grn_cache *cache, grn_cache_entry_memory *ce) { ce->prev->next = ce->next; -------------- next part -------------- HTML����������������������������...Download