Skip to content

Commit 175d787

Browse files
authored
[MOD-8039] Reorganize stats files (#5329)
* new file : info/INFO_MODULES responsible to expose all aggregated shard stats to INFO command move RS_moduleInfoFunc from module-init to move all add to info functions to a dedicated file: from global_stats.c FieldsGlobalStats_AddToInfo TotalGlobalStats_Queries_AddToInfo DialectsGlobalStats_AddToInfo IndexesGlobalStats_AddToInfo from config.c: RSConfig_AddToInfo introduce FieldsGlobalStats_GetIndexError to expose fields errors move queries stats from TotalGlobalStats to seperate struct QueriesGlobalStats * rediSearchAPI::RediSearch_TotalInfo calls IndexesInfo_TotalInfo from indexes_info IndexesInfo_TotalInfo (orignally rediSearchAPI::RediSearch_TotalInfo) calls IndexSpec_TotalMemUsage instead of rediSearchAPI::RediSearch_TotalMemUsage introduce indexes_info rename TotalSpecsFieldInfo and TotalSpecsInfo: specs->indexes move TotalIndexesFieldsInfo and TotalIndexesInfo from info_command to indexes_info move global stats to info dir move info_command to info dir introduce util/units. A file for all macros handling shared units conversion remove CLOCKS_PER_MILLISEC from profile.h, include util/units.h instead add a cpp test for llapi indexes info * release index remove unused header from module-init * remove TODO * review fixes rename INFO_MODULES->info_redis rename MEMORY_HUMAN->MEMORY_MB
1 parent 98b342c commit 175d787

24 files changed

Lines changed: 537 additions & 390 deletions

src/aggregate/aggregate_exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "query_optimizer.h"
1919
#include "resp3.h"
2020
#include "query_error.h"
21-
#include "global_stats.h"
21+
#include "info/global_stats.h"
2222

2323
typedef enum { COMMAND_AGGREGATE, COMMAND_SEARCH, COMMAND_EXPLAIN } CommandType;
2424

src/config.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,31 +1099,6 @@ int RSConfig_SetOption(RSConfig *config, RSConfigOptions *options, const char *n
10991099
return rc;
11001100
}
11011101

1102-
void RSConfig_AddToInfo(RedisModuleInfoCtx *ctx) {
1103-
RedisModule_InfoAddSection(ctx, "runtime_configurations");
1104-
1105-
if (RSGlobalConfig.extLoad != NULL) {
1106-
RedisModule_InfoAddFieldCString(ctx, "extension_load", (char*)RSGlobalConfig.extLoad);
1107-
}
1108-
if (RSGlobalConfig.frisoIni != NULL) {
1109-
RedisModule_InfoAddFieldCString(ctx, "friso_ini", (char*)RSGlobalConfig.frisoIni);
1110-
}
1111-
RedisModule_InfoAddFieldCString(ctx, "enableGC", RSGlobalConfig.gcConfigParams.enableGC ? "ON" : "OFF");
1112-
RedisModule_InfoAddFieldLongLong(ctx, "minimal_term_prefix", RSGlobalConfig.iteratorsConfigParams.minTermPrefix);
1113-
RedisModule_InfoAddFieldLongLong(ctx, "minimal_stem_length", RSGlobalConfig.iteratorsConfigParams.minStemLength);
1114-
RedisModule_InfoAddFieldLongLong(ctx, "maximal_prefix_expansions", RSGlobalConfig.iteratorsConfigParams.maxPrefixExpansions);
1115-
RedisModule_InfoAddFieldLongLong(ctx, "query_timeout_ms", RSGlobalConfig.requestConfigParams.queryTimeoutMS);
1116-
RedisModule_InfoAddFieldCString(ctx, "timeout_policy", (char*)TimeoutPolicy_ToString(RSGlobalConfig.requestConfigParams.timeoutPolicy));
1117-
RedisModule_InfoAddFieldLongLong(ctx, "cursor_read_size", RSGlobalConfig.cursorReadSize);
1118-
RedisModule_InfoAddFieldLongLong(ctx, "cursor_max_idle_time", RSGlobalConfig.cursorMaxIdle);
1119-
1120-
RedisModule_InfoAddFieldLongLong(ctx, "max_doc_table_size", RSGlobalConfig.maxDocTableSize);
1121-
RedisModule_InfoAddFieldLongLong(ctx, "max_search_results", RSGlobalConfig.maxSearchResults);
1122-
RedisModule_InfoAddFieldLongLong(ctx, "max_aggregate_results", RSGlobalConfig.maxAggregateResults);
1123-
RedisModule_InfoAddFieldLongLong(ctx, "gc_scan_size", RSGlobalConfig.gcConfigParams.gcScanSize);
1124-
RedisModule_InfoAddFieldLongLong(ctx, "min_phonetic_term_length", RSGlobalConfig.minPhoneticTermLen);
1125-
}
1126-
11271102
const char *TimeoutPolicy_ToString(RSTimeoutPolicy policy) {
11281103
switch (policy) {
11291104
case TimeoutPolicy_Return:

src/field_spec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "rmalloc.h"
1010
#include "rmutil/rm_assert.h"
1111
#include "vector_index.h"
12-
#include "global_stats.h"
12+
#include "info/global_stats.h"
1313

1414
void FieldSpec_Cleanup(FieldSpec* fs) {
1515
// if `AS` was not used, name and path are pointing at the same string

src/fork_gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "rmutil/rm_assert.h"
2626
#include "suffix.h"
2727
#include "resp3.h"
28-
#include "global_stats.h"
28+
#include "info/global_stats.h"
2929

3030
#define GC_WRITERFD 1
3131
#define GC_READERFD 0

src/global_stats.c

Lines changed: 0 additions & 180 deletions
This file was deleted.

src/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "hybrid_reader.h"
2121
#include "metric_iterator.h"
2222
#include "optimizer_reader.h"
23+
#include "util/units.h"
2324

2425
static int UI_SkipTo(void *ctx, t_docId docId, RSIndexResult **hit);
2526
static int UI_SkipToHigh(void *ctx, t_docId docId, RSIndexResult **hit);
@@ -1064,7 +1065,7 @@ int NI_SkipTo_O(void *ctx, t_docId docId, RSIndexResult **hit) {
10641065
wcii_rc = nc->wcii->SkipTo(nc->wcii->ctx, docId, hit);
10651066
if (wcii_rc == INDEXREAD_EOF) {
10661067
IITER_SET_EOF(&nc->base);
1067-
}
1068+
}
10681069
// Note: If this is the last block in the child index and not in the wildcard
10691070
// index, we may have a docId in the child that does not exist in the
10701071
// wildcard index

src/info/global_stats.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright Redis Ltd. 2016 - present
3+
* Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or
4+
* the Server Side Public License v1 (SSPLv1).
5+
*/
6+
7+
#include "global_stats.h"
8+
#include "aggregate/aggregate.h"
9+
#include "util/units.h"
10+
11+
#define INCR_BY(x,y) __atomic_add_fetch(&(x), (y), __ATOMIC_RELAXED)
12+
#define INCR(x) INCR_BY(x, 1)
13+
#define READ(x) __atomic_load_n(&(x), __ATOMIC_RELAXED)
14+
15+
GlobalStats RSGlobalStats = {0};
16+
size_t FieldIndexErrorCounter[INDEXFLD_NUM_TYPES] = {0};
17+
18+
// Assuming that the GIL is already acquired
19+
void FieldsGlobalStats_UpdateStats(FieldSpec *fs, int toAdd) {
20+
if (fs->types & INDEXFLD_T_FULLTEXT) { // text field
21+
RSGlobalStats.fieldsStats.numTextFields += toAdd;
22+
} else if (fs->types & INDEXFLD_T_NUMERIC) { // numeric field
23+
RSGlobalStats.fieldsStats.numNumericFields += toAdd;
24+
} else if (fs->types & INDEXFLD_T_GEO) { // geo field
25+
RSGlobalStats.fieldsStats.numGeoFields += toAdd;
26+
} else if (fs->types & INDEXFLD_T_VECTOR) { // vector field
27+
RSGlobalStats.fieldsStats.numVectorFields += toAdd;
28+
if (fs->vectorOpts.vecSimParams.algo == VecSimAlgo_BF)
29+
RSGlobalStats.fieldsStats.numVectorFieldsFlat += toAdd;
30+
else if (fs->vectorOpts.vecSimParams.algo == VecSimAlgo_TIERED) {
31+
if (fs->vectorOpts.vecSimParams.algoParams.tieredParams.primaryIndexParams->algo == VecSimAlgo_HNSWLIB)
32+
RSGlobalStats.fieldsStats.numVectorFieldsHNSW += toAdd;
33+
}
34+
} else if (fs->types & INDEXFLD_T_TAG) { // tag field
35+
RSGlobalStats.fieldsStats.numTagFields += toAdd;
36+
if (fs->tagOpts.tagFlags & TagField_CaseSensitive) {
37+
RSGlobalStats.fieldsStats.numTagFieldsCaseSensitive += toAdd;
38+
}
39+
} else if (fs->types & INDEXFLD_T_GEOMETRY) { // geometry field
40+
RSGlobalStats.fieldsStats.numGeometryFields += toAdd;
41+
}
42+
43+
if (fs->options & FieldSpec_Sortable) {
44+
if (fs->types & INDEXFLD_T_FULLTEXT) RSGlobalStats.fieldsStats.numTextFieldsSortable += toAdd;
45+
else if (fs->types & INDEXFLD_T_NUMERIC) RSGlobalStats.fieldsStats.numNumericFieldsSortable += toAdd;
46+
else if (fs->types & INDEXFLD_T_GEO) RSGlobalStats.fieldsStats.numGeoFieldsSortable += toAdd;
47+
else if (fs->types & INDEXFLD_T_TAG) RSGlobalStats.fieldsStats.numTagFieldsSortable += toAdd;
48+
else if (fs->types & INDEXFLD_T_GEOMETRY) RSGlobalStats.fieldsStats.numGeometryFieldsSortable += toAdd;
49+
}
50+
if (fs->options & FieldSpec_NotIndexable) {
51+
if (fs->types & INDEXFLD_T_FULLTEXT) RSGlobalStats.fieldsStats.numTextFieldsNoIndex += toAdd;
52+
else if (fs->types & INDEXFLD_T_NUMERIC) RSGlobalStats.fieldsStats.numNumericFieldsNoIndex += toAdd;
53+
else if (fs->types & INDEXFLD_T_GEO) RSGlobalStats.fieldsStats.numGeoFieldsNoIndex += toAdd;
54+
else if (fs->types & INDEXFLD_T_TAG) RSGlobalStats.fieldsStats.numTagFieldsNoIndex += toAdd;
55+
else if (fs->types & INDEXFLD_T_GEOMETRY) RSGlobalStats.fieldsStats.numGeometryFieldsNoIndex += toAdd;
56+
}
57+
}
58+
59+
void FieldsGlobalStats_UpdateIndexError(FieldType field_type, int toAdd) {
60+
FieldIndexErrorCounter[INDEXTYPE_TO_POS(field_type)] += toAdd;
61+
}
62+
63+
size_t FieldsGlobalStats_GetIndexErrorCount(FieldType field_type) {
64+
return FieldIndexErrorCounter[INDEXTYPE_TO_POS(field_type)];
65+
}
66+
67+
void TotalGlobalStats_CountQuery(uint32_t reqflags, clock_t duration) {
68+
if (reqflags & QEXEC_F_INTERNAL) return; // internal queries are not counted
69+
70+
INCR(RSGlobalStats.totalStats.queries.total_query_commands);
71+
INCR_BY(RSGlobalStats.totalStats.queries.total_query_execution_time, duration);
72+
73+
if (!(QEXEC_F_IS_CURSOR & reqflags) || (QEXEC_F_IS_AGGREGATE & reqflags)) {
74+
// Count only unique queries, not iterations of a previous query (FT.CURSOR READ)
75+
INCR(RSGlobalStats.totalStats.queries.total_queries_processed);
76+
}
77+
}
78+
79+
QueriesGlobalStats TotalGlobalStats_GetQueryStats() {
80+
QueriesGlobalStats stats = {0};
81+
stats.total_queries_processed = READ(RSGlobalStats.totalStats.queries.total_queries_processed);
82+
stats.total_query_commands = READ(RSGlobalStats.totalStats.queries.total_query_commands);
83+
stats.total_query_execution_time = READ(RSGlobalStats.totalStats.queries.total_query_execution_time) / CLOCKS_PER_MILLISEC;
84+
return stats;
85+
}
86+
87+
void IndexsGlobalStats_UpdateLogicallyDeleted(int64_t toAdd) {
88+
INCR_BY(RSGlobalStats.totalStats.logically_deleted, toAdd);
89+
}
90+
91+
size_t IndexesGlobalStats_GetLogicallyDeletedDocs() {
92+
return READ(RSGlobalStats.totalStats.logically_deleted);
93+
}

0 commit comments

Comments
 (0)