-
Notifications
You must be signed in to change notification settings - Fork 5k
merge: from 3.3.6 to main branch #33474
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
Conversation
test: support multi vm run CI
Summary of ChangesHello @guanshengliang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates a new administrative feature that allows for the modification of the System Database (SDB) through a command-line utility. Users can now provide a JSON file to update vgroup configurations, streamlining the process of managing database metadata. The changes also include significant refactoring of SDB handling logic to improve modularity and maintainability. Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new feature to modify the SDB (state database) from a JSON file, exposed via the -mSdb command-line option. The changes include argument parsing, implementation of the modification logic, and refactoring of related SDB dump functions. While the new feature is a good addition, the review identified several critical issues. There are resource leaks in dmMain.c (file handle) and mndDump.c (JSON object) due to improper error handling. Additionally, a change in tests/parallel_test/run.sh effectively disables multi-host testing, which is likely an unintended side effect. There are also minor issues with missing newlines in console output and opportunities to improve code maintainability by reducing repetitive code. These issues should be addressed to ensure code quality and correctness.
| if (global.modifySdb) { | ||
| int32_t code = 0; | ||
| TdFilePtr pFile; | ||
| if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) { | ||
| printf("failed to modify sdb since taosd is running, please stop it first, reason:%s", tstrerror(code)); | ||
| return code; | ||
| } | ||
|
|
||
| TAOS_CHECK_RETURN(mndModifySdb(global.sdbJsonFile)); | ||
| taosCleanupCfg(); | ||
| taosCloseLog(); | ||
| taosCleanupArgs(); | ||
| taosConvDestroy(); | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a resource leak in this block. The file pointer pFile obtained from dmCheckRunning is not closed if mndModifySdb fails. The TAOS_CHECK_RETURN macro will cause an early return, leaking the file handle. The file should be closed in all execution paths. Additionally, the cleanup functions are not called on failure.
if (global.modifySdb) {
int32_t code = 0;
TdFilePtr pFile = NULL;
if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
printf("failed to modify sdb since taosd is running, please stop it first, reason:%s\n", tstrerror(code));
return code;
}
code = mndModifySdb(global.sdbJsonFile);
if (taosCloseFile(&pFile) != 0) {
dError("failed to close lock file, reason: %s", tstrerror(terrno));
}
taosCleanupCfg();
taosCloseLog();
taosCleanupArgs();
taosConvDestroy();
return code;
}| int32_t mndModifySdb(char *path) { | ||
| int32_t code = 0; | ||
| SJson *pJson = NULL; | ||
|
|
||
| mInfo("start to modify sdb info from sdb.json"); | ||
|
|
||
| SMnode *pMnode = mndPrepareMnode(); | ||
| if (pMnode == NULL) return terrno; | ||
|
|
||
| pJson = mndLoadSdbJson(path); | ||
| if (pJson == NULL) return terrno; | ||
|
|
||
| TAOS_CHECK_RETURN(mndGenerateVgroup(pMnode, pJson)); | ||
|
|
||
| mInfo("write back to sdb file"); | ||
| TAOS_CHECK_RETURN(sdbWriteFileForDump(pMnode->pSdb, -1)); | ||
|
|
||
| return 0; | ||
| _OVER: | ||
| if (pJson != NULL) cJSON_Delete(pJson); | ||
|
|
||
| if (code != 0) { | ||
| mError("failed to modify sdb, file:%s since %s", path, tstrerror(code)); | ||
| } | ||
|
|
||
| TAOS_RETURN(code); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a memory leak in mndModifySdb. If mndGenerateVgroup or sdbWriteFileForDump fails, the TAOS_CHECK_RETURN macro causes an early return, leaking the pJson object allocated by mndLoadSdbJson. The function should be refactored to use the goto _OVER pattern for cleanup, which is already present but unreachable. This ensures that pJson is always freed.
int32_t mndModifySdb(char *path) {
int32_t code = 0;
SJson *pJson = NULL;
SMnode *pMnode = NULL;
mInfo("start to modify sdb info from sdb.json");
pMnode = mndPrepareMnode();
if (pMnode == NULL) {
code = terrno;
goto _OVER;
}
pJson = mndLoadSdbJson(path);
if (pJson == NULL) {
code = terrno;
goto _OVER;
}
if ((code = mndGenerateVgroup(pMnode, pJson)) != 0) {
goto _OVER;
}
mInfo("write back to sdb file");
if ((code = sdbWriteFileForDump(pMnode->pSdb, -1)) != 0) {
goto _OVER;
}
_OVER:
if (pJson != NULL) cJSON_Delete(pJson);
if (code != 0) {
mError("failed to modify sdb, file:%s since %s", path, tstrerror(code));
}
TAOS_RETURN(code);
}|
|
||
| i=0 | ||
| while true; do | ||
| while [ $i -lt 1 ]; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The while loop condition has been changed from true to [ $i -lt 1 ]. This change limits the test execution to only the first host defined in the configuration file, effectively disabling multi-host parallel testing. This seems like a temporary debugging change that was accidentally committed and should be reverted.
| while [ $i -lt 1 ]; do | |
| while true; do |
| int32_t code = 0; | ||
| TdFilePtr pFile; | ||
| if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) { | ||
| printf("failed to modify sdb since taosd is running, please stop it first, reason:%s", tstrerror(code)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| tjsonGetNumberValue(pNodeVgroup, "vgId", group.vgId, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "createdTime", group.createdTime, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "updateTime", group.updateTime, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "version", group.version, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "hashBegin", group.hashBegin, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "hashEnd", group.hashEnd, code); | ||
| if (code) return code; | ||
| code = tjsonGetStringValue(pNodeVgroup, "db", group.dbName); | ||
| if (code) return code; | ||
| mInfo("group.dbname %s", group.dbName); | ||
| tjsonGetNumberValue(pNodeVgroup, "dbUid", group.dbUid, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "isTsma", group.isTsma, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "replica", group.replica, code); | ||
| if (code) return code; | ||
| tjsonGetNumberValue(pNodeVgroup, "syncConfChangeVer", group.syncConfChangeVer, code); | ||
| if (code) return code; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Please briefly describe the code changes in this pull request.
Checklist
Please check the items in the checklist if applicable.