Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone PR for 6891 #54

Open
wants to merge 74 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
b9c7451
Update test cases for sentinel (#12)
hwware Aug 24, 2021
e19f170
Test sentinel tests (#24)
hwware Sep 13, 2021
11d95fe
Update 07-down-conditions.tcl
hwware Sep 13, 2021
4d97f51
Update 00-base.tcl
hwware Sep 14, 2021
e10eb9b
Update 02-slaves-reconf.tcl
hwware Sep 14, 2021
cd42e97
Update 00-base.tcl
hwware Sep 15, 2021
f219beb
fix merge errors for 00-base.tcl
hwware Sep 15, 2021
bcc3824
fix another error for 00-base.tcl
hwware Sep 15, 2021
76da6bd
update daily and ci config file
hwware Sep 15, 2021
e41d080
initial commit for sentinel info command change
hwware Feb 14, 2020
ffd5502
remove extra space
hwware Feb 14, 2020
6cff511
Update test cases for sentinel (#12)
hwware Aug 24, 2021
906ec0a
Test sentinel tests (#24)
hwware Sep 13, 2021
8de0a0c
Update 00-base.tcl
hwware Sep 14, 2021
015469a
Update 00-base.tcl
hwware Sep 15, 2021
1a11183
fix merge errors for 00-base.tcl
hwware Sep 15, 2021
6ebcde0
fix another error for 00-base.tcl
hwware Sep 15, 2021
7ac509b
Rebase and remove extra lines
hwware Oct 13, 2021
bc6e5c6
Revert "Rebase and remove extra lines"
hwware Oct 13, 2021
2a4ff0b
Rebase
hwware Oct 13, 2021
7e97df7
Update 02-slaves-reconf.tcl
hwware Oct 13, 2021
8de8406
Rebase
hwware Oct 13, 2021
422596f
Infoenhance new (#32)
hwware Nov 2, 2021
aa552fc
Formatting change
hwware Nov 2, 2021
ca187c9
Update test cases for sentinel (#12)
hwware Aug 24, 2021
ecf2425
Test sentinel tests (#24)
hwware Sep 13, 2021
740903b
Update 07-down-conditions.tcl
hwware Sep 13, 2021
f511561
Update 00-base.tcl
hwware Sep 14, 2021
dc91e67
Update 02-slaves-reconf.tcl
hwware Sep 14, 2021
86a5dc2
Update 00-base.tcl
hwware Sep 15, 2021
ee0aa3a
fix merge errors for 00-base.tcl
hwware Sep 15, 2021
da58dad
fix another error for 00-base.tcl
hwware Sep 15, 2021
73b12ee
update daily and ci config file
hwware Sep 15, 2021
7cd0f8a
initial commit for sentinel info command change
hwware Feb 14, 2020
9147ea3
remove extra space
hwware Feb 14, 2020
a32dc23
Update test cases for sentinel (#12)
hwware Aug 24, 2021
0b0b77a
Test sentinel tests (#24)
hwware Sep 13, 2021
a075689
Update 00-base.tcl
hwware Sep 14, 2021
47f8ac3
Update 00-base.tcl
hwware Sep 15, 2021
cdc5847
fix merge errors for 00-base.tcl
hwware Sep 15, 2021
6d3d2c6
fix another error for 00-base.tcl
hwware Sep 15, 2021
b696857
Rebase and remove extra lines
hwware Oct 13, 2021
ed9bef8
Revert "Rebase and remove extra lines"
hwware Oct 13, 2021
1a8dfe3
Rebase
hwware Oct 13, 2021
6b2030b
Update 02-slaves-reconf.tcl
hwware Oct 13, 2021
678c01b
Rebase
hwware Oct 13, 2021
a30f0f9
Infoenhance new (#32)
hwware Nov 2, 2021
f99bb3a
Formatting change
hwware Nov 2, 2021
5f5d8d3
update codes follow Oran comments
hwware Nov 19, 2021
751addb
Merge branch 'infoenhancement' of https://github.com/hwware/redis int…
hwware Nov 29, 2021
5325477
Update code according to comments (#47)
hwware Dec 3, 2021
a3bc141
Fixed module err
hwware Dec 3, 2021
6982d98
Remove extra space
hwware Dec 3, 2021
ccc4db8
Updated according to comments
hwware Dec 7, 2021
d34543f
add dectrelease
hwware Dec 7, 2021
b77a81c
free the dict in the right place
hwware Dec 7, 2021
076eb23
add modules variable condition
hwware Dec 16, 2021
b871ecd
update dict in module.c
hwware Dec 17, 2021
d581978
add code in the debug.c for passing the test
hwware Dec 17, 2021
a89ed62
fix memory leak
hwware Dec 17, 2021
1346a0f
fix memory lead version 2
hwware Dec 20, 2021
c7c55ab
fix memory lead version 3
hwware Dec 20, 2021
1134b7d
test it for memory leak
hwware Dec 20, 2021
ec77ec2
update line 7962
hwware Dec 20, 2021
e7d2a2d
adjust style
hwware Dec 29, 2021
2f84b91
minor style update
hwware Dec 29, 2021
0822f80
update genInfoSectionDict interface
hwware Dec 30, 2021
8514944
update function interface
hwware Jan 4, 2022
5a330b7
update server side dict
hwware Jan 5, 2022
bdeeea0
add dict check in modules part
hwware Jan 5, 2022
48c7e90
free memory
hwware Jan 5, 2022
15826b8
finish sentinel part
hwware Jan 5, 2022
6a38ac6
remove duplicate string in module.c
hwware Jan 5, 2022
01f8f3c
memory leak
hwware Jan 5, 2022
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
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ void logStackTrace(void *eip, int uplevel) {
void logServerInfo(void) {
sds infostring, clients;
serverLogRaw(LL_WARNING|LL_RAW, "\n------ INFO OUTPUT ------\n");
infostring = genRedisInfoString("all");
infostring = genRedisInfoString(NULL,1,0);
serverLogRaw(LL_WARNING|LL_RAW, infostring);
serverLogRaw(LL_WARNING|LL_RAW, "\n------ CLIENT LIST OUTPUT ------\n");
clients = getAllClientsInfoString(-1);
Expand Down
35 changes: 26 additions & 9 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

typedef struct RedisModuleInfoCtx {
struct RedisModule *module;
const char *requested_section;
dict * requested_sections;
sds info; /* info string we collected so far */
int sections; /* number of sections we collected so far */
int in_section; /* indication if we're in an active section or not */
Expand Down Expand Up @@ -7930,28 +7930,35 @@ int RM_InfoEndDictField(RedisModuleInfoCtx *ctx);
* NULL or empty string indicates the default section (only `<modulename>`) is used.
* When return value is REDISMODULE_ERR, the section should and will be skipped. */
int RM_InfoAddSection(RedisModuleInfoCtx *ctx, char *name) {

sds full_name = sdsdup(ctx->module->name);
if (name != NULL && strlen(name) > 0)
full_name = sdscatfmt(full_name, "_%s", name);

/* Implicitly end dicts, instead of returning an error which is likely un checked. */
if (ctx->in_dict_field)
RM_InfoEndDictField(ctx);

sdstolower(full_name);

/* proceed only if:
* 1) no section was requested (emit all)
* 2) the module name was requested (emit all)
* 3) this specific section was requested. */
if (ctx->requested_section) {
if (strcasecmp(ctx->requested_section, full_name) &&
strcasecmp(ctx->requested_section, ctx->module->name)) {
if (ctx->requested_sections) {
if ((dictFind(ctx->requested_sections,full_name) == NULL) &&
(dictFind(ctx->requested_sections,ctx->module->name) == NULL)) {
sdsfree(full_name);
ctx->in_section = 0;
return REDISMODULE_ERR;
}
}
if (ctx->sections++) ctx->info = sdscat(ctx->info,"\r\n");
ctx->info = sdscatfmt(ctx->info, "# %S\r\n", full_name);

if (name != NULL && strlen(name) > 0)
ctx->info = sdscatfmt(ctx->info, "# %S_%s\r\n", ctx->module->name, name);
else
ctx->info = sdscatfmt(ctx->info, "# %S\r\n", ctx->module->name);
ctx->in_section = 1;
sdsfree(full_name);
return REDISMODULE_OK;
Expand Down Expand Up @@ -8093,15 +8100,15 @@ int RM_RegisterInfoFunc(RedisModuleCtx *ctx, RedisModuleInfoFunc cb) {
return REDISMODULE_OK;
}

sds modulesCollectInfo(sds info, const char *section, int for_crash_report, int sections) {
sds modulesCollectInfo(sds info, dict *sections_dict, int for_crash_report, int sections) {
dictIterator *di = dictGetIterator(modules);
dictEntry *de;

while ((de = dictNext(di)) != NULL) {
struct RedisModule *module = dictGetVal(de);
if (!module->info_cb)
continue;
RedisModuleInfoCtx info_ctx = {module, section, info, sections, 0, 0};
RedisModuleInfoCtx info_ctx = {module, sections_dict, info, sections, 0, 0};
module->info_cb(&info_ctx, for_crash_report);
/* Implicitly end dicts (no way to handle errors, and we must add the newline). */
if (info_ctx.in_dict_field)
Expand All @@ -8123,7 +8130,12 @@ RedisModuleServerInfoData *RM_GetServerInfo(RedisModuleCtx *ctx, const char *sec
struct RedisModuleServerInfoData *d = zmalloc(sizeof(*d));
d->rax = raxNew();
if (ctx != NULL) autoMemoryAdd(ctx,REDISMODULE_AM_INFO,d);
sds info = genRedisInfoString(section);
int out_all = 0;
int out_everything = 0;
robj **argv = zmalloc(sizeof(robj*));
argv[0] = createStringObject(section, strlen(section));
dict *section_dict = genInfoSectionDict(argv, 1, &out_all, &out_everything);
sds info = genRedisInfoString(section_dict, out_all, out_everything);
int totlines, i;
sds *lines = sdssplitlen(info, sdslen(info), "\r\n", 2, &totlines);
for(i=0; i<totlines; i++) {
Expand All @@ -8139,6 +8151,11 @@ RedisModuleServerInfoData *RM_GetServerInfo(RedisModuleCtx *ctx, const char *sec
}
sdsfree(info);
sdsfreesplitres(lines,totlines);
dictRelease(section_dict);
for(i=0;i < 1;i++){
zfree(argv[0]);
}
zfree(argv);
return d;
}

Expand Down
40 changes: 8 additions & 32 deletions src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4058,46 +4058,22 @@ NULL
(char*)c->argv[1]->ptr);
}

#define info_section_from_redis(section_name) do { \
if (defsections || allsections || !strcasecmp(section,section_name)) { \
sds redissection; \
if (sections++) info = sdscat(info,"\r\n"); \
redissection = genRedisInfoString(section_name); \
info = sdscatlen(info,redissection,sdslen(redissection)); \
sdsfree(redissection); \
} \
} while(0)

/* SENTINEL INFO [section] */
void sentinelInfoCommand(client *c) {
if (c->argc > 2) {
addReplyErrorObject(c,shared.syntaxerr);
return;
}

int defsections = 0, allsections = 0;
char *section = c->argc == 2 ? c->argv[1]->ptr : NULL;
if (section) {
allsections = !strcasecmp(section,"all");
defsections = !strcasecmp(section,"default");
} else {
defsections = 1;
}
int out_all = 0;
int out_everything = 0;
dict *sections_dict = genInfoSectionDict(c->argv, c->argc, &out_all, &out_everything);

int sections = 0;
sds info = sdsempty();

info_section_from_redis("server");
info_section_from_redis("clients");
info_section_from_redis("cpu");
info_section_from_redis("stats");

if (defsections || allsections || !strcasecmp(section,"sentinel")) {
info = genRedisInfoString(sections_dict, out_all, out_everything);
if (c->argc == 1 || out_all || (dictFind(sections_dict,"sentinel") != NULL)) {
dictIterator *di;
dictEntry *de;
int master_id = 0;

if (sections++) info = sdscat(info,"\r\n");
if (sdslen(info) != 0)
info = sdscat(info,"\r\n");
info = sdscatprintf(info,
"# Sentinel\r\n"
"sentinel_masters:%lu\r\n"
Expand Down Expand Up @@ -4130,7 +4106,7 @@ void sentinelInfoCommand(client *c) {
}
dictReleaseIterator(di);
}

dictRelease(sections_dict);
addReplyBulkSds(c, info);
}

Expand Down
Loading