refactor(timezone): standardize checkTime initialization to local timezone offset across dnode and mnode#35057
refactor(timezone): standardize checkTime initialization to local timezone offset across dnode and mnode#35057
Conversation
… ms across dnode and mnode implementations
There was a problem hiding this comment.
Pull request overview
This PR refactors how checkTime is initialized in both mnode and dnode status/cluster-config paths, aiming to standardize the value (now set to 0) and updates inline documentation for the field.
Changes:
- Replace
taosParseTime("1970-01-01 00:00:00.00", ...)with directcheckTime = 0initialization in mnode open logic and dnode status request population. - Add/replace struct field comments describing
checkTimesemantics in internal mnode state and the cluster config message struct. - Minor cleanup from removing parsing/error-handling blocks (but introduces a duplicate assignment site in
dmSendStatusReq).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| source/dnode/mnode/impl/src/mndMain.c | Sets pMnode->checkTime directly to 0 during mndOpen() initialization. |
| source/dnode/mnode/impl/inc/mndInt.h | Adds a block comment documenting SMnode::checkTime. |
| source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | Sets req.clusterCfg.checkTime = 0 when building status request (now twice in the function). |
| include/common/tmsg.h | Updates SClusterCfg::checkTime comment to a block comment and removes the old “1970...” note. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| terrno = code; | ||
| return NULL; | ||
| } | ||
| pMnode->checkTime = 0; |
There was a problem hiding this comment.
Setting pMnode->checkTime to 0 makes the timezone consistency check in mndCheckClusterCfgPara ineffective: the check only errors when both timezone strings differ and checkTime differs. With both sides now using 0, a real timezone mismatch will not be detected. Consider keeping checkTime as a deterministic value derived from the node’s configured timezone (e.g., parse a fixed local datetime using the global/default timezone or store an explicit tz offset) or update the check logic accordingly.
| 0) { | ||
| dError("failed to parse time since %s", tstrerror(code)); | ||
| } | ||
| req.clusterCfg.checkTime = 0; |
There was a problem hiding this comment.
req.clusterCfg.checkTime is assigned twice in this function (earlier and again here). The second assignment is redundant and can mask future edits (e.g., if the first assignment is later changed to a computed value). Keep a single initialization for checkTime in one place.
| req.clusterCfg.checkTime = 0; |
| req.clusterCfg.checkTime = 0; | ||
| memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); |
There was a problem hiding this comment.
Changing checkTime to a constant 0 disables the intended semantic comparison used by mnode when validating dnode timezone (it checks timezone string mismatch but allows equivalent timezones when the derived checkTime matches). If the goal is to avoid environment-dependent parsing, compute a stable value that still reflects the configured timezone (e.g., derived offset) or adjust the validation logic to continue catching genuine mismatches.
include/common/tmsg.h
Outdated
| Unix epoch in ms (conventionally 0). | ||
| Dnode/mnode must agree; paired with timezone in cluster cfg check. |
There was a problem hiding this comment.
The new comment describes checkTime as “Unix epoch in ms (conventionally 0)”, but current usage in mndCheckClusterCfgPara treats checkTime as a derived value to help validate timezone equivalence. Please update this comment to reflect the actual purpose/meaning of checkTime (or, if semantics are intentionally changing to constant 0, update the validation logic and any other documentation accordingly).
| Unix epoch in ms (conventionally 0). | |
| Dnode/mnode must agree; paired with timezone in cluster cfg check. | |
| Reference timestamp in ms used together with timezone during cluster | |
| configuration checks to verify timezone equivalence across dnode/mnode. | |
| This is a derived comparison value, not a field that is conventionally 0. |
source/dnode/mnode/impl/inc/mndInt.h
Outdated
| Unix epoch in ms (conventionally 0). | ||
| Dnode/mnode must agree; paired with timezone in cluster cfg check. |
There was a problem hiding this comment.
The comment implies checkTime is always the Unix epoch (0), but the field is used in cluster cfg validation to disambiguate timezone equivalence. Please align this comment with the field’s real semantics (or change the validation logic if checkTime is meant to be constant).
| Unix epoch in ms (conventionally 0). | |
| Dnode/mnode must agree; paired with timezone in cluster cfg check. | |
| Reference timestamp in ms used together with timezone during | |
| cluster cfg validation to disambiguate timezone equivalence. | |
| Dnode/mnode must agree on this value. |
There was a problem hiding this comment.
Code Review
This pull request simplifies the initialization of checkTime by replacing the parsing of a hardcoded date string with a direct assignment of 0, representing the Unix epoch. It also adds descriptive comments to the checkTime field in several header files to clarify its purpose and synchronization requirements. Feedback suggests using a named constant instead of the literal 0 to enhance code readability and maintainability.
| 0) { | ||
| dError("failed to parse time since %s", tstrerror(code)); | ||
| } | ||
| req.clusterCfg.checkTime = 0; |
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
| terrno = code; | ||
| return NULL; | ||
| } | ||
| pMnode->checkTime = 0; |
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
… dmSendStatusReq and mndOpen
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pMnode->checkTime = (int64_t)taosGetLocalTimezoneOffset(&code); | ||
| if (code != 0) { | ||
| taosMemoryFree(pMnode); | ||
| mError("failed to get local timezone offset, since %s", tstrerror(code)); | ||
| terrno = code; | ||
| return NULL; |
There was a problem hiding this comment.
On failure, this path frees pMnode without destroying the rwlock initialized just above. The previous code called taosThreadRwlockDestroy(&pMnode->lock) on error; the new code should do the same before freeing to avoid leaking OS lock resources.
| /* | ||
| Local timezone UTC offset in seconds (east-positive, e.g. +28800 for | ||
| Asia/Shanghai). Derived from taosGetLocalTimezoneOffset() on each | ||
| status report. Paired with the timezone string in | ||
| mndCheckClusterCfgPara: a mismatch is reported only when both the | ||
| timezone string AND this offset differ. | ||
| */ | ||
| int64_t checkTime; | ||
| char timezone[TD_TIMEZONE_LEN]; // tsTimezone |
There was a problem hiding this comment.
The PR title/description says checkTime is standardized to initialization "0", but the code now sets it to the local timezone UTC offset (seconds) via taosGetLocalTimezoneOffset(). Please update the PR title/description (or rename the field) so reviewers/users aren’t misled about the semantics change.
… ms across dnode and mnode implementations
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.