fix: commitid

Signed-off-by: xionglei6 <xionglei6@huawei.com>
This commit is contained in:
xionglei6 2022-03-28 20:04:02 +08:00
parent f665901862
commit be9d18660e
4 changed files with 8 additions and 1 deletions

View File

@ -97,6 +97,7 @@ int SystemWatchParameter(const char *keyprefix, ParameterChangePtr change, void
void SystemDumpParameters(int verbose);
int SysCheckParamExist(const char *name);
long long GetSystemCommitId();
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -85,6 +85,7 @@ typedef struct {
} ParamSecruityNode;
typedef struct {
atomic_llong commitId;
uint32_t trieNodeCount;
uint32_t paramNodeCount;
uint32_t securityNodeCount;

View File

@ -70,6 +70,8 @@ static int AddParam(WorkSpace *workSpace, const char *name, const char *value, u
uint32_t offset = AddParamNode(workSpace, name, strlen(name), value, strlen(value));
PARAM_CHECK(offset > 0, return PARAM_CODE_REACHED_MAX, "Failed to allocate name %s", name);
SaveIndex(&node->dataIndex, offset);
long long globalCommitId = atomic_load_explicit(&workSpace->area->commitId, memory_order_relaxed);
atomic_store_explicit(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
}
if (dataIndex != NULL) {
*dataIndex = node->dataIndex;
@ -86,6 +88,7 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch
uint32_t valueLen = strlen(value);
uint32_t commitId = atomic_load_explicit(&entry->commitId, memory_order_relaxed);
atomic_store_explicit(&entry->commitId, commitId | PARAM_FLAGS_MODIFY, memory_order_relaxed);
long long globalCommitId = atomic_load_explicit(&workSpace->area->commitId, memory_order_relaxed);
if (entry->valueLength < PARAM_VALUE_LEN_MAX && valueLen < PARAM_VALUE_LEN_MAX) {
int ret = memcpy_s(entry->data + entry->keyLength + 1, PARAM_VALUE_LEN_MAX, value, valueLen + 1);
@ -94,6 +97,7 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch
}
uint32_t flags = commitId & ~PARAM_FLAGS_COMMITID;
atomic_store_explicit(&entry->commitId, (++commitId) | flags, memory_order_release);
atomic_store_explicit(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
futex_wake(&entry->commitId, INT_MAX);
return 0;
}

View File

@ -83,7 +83,8 @@ static int32_t BShellParamCmdRead(BShellHandle shell, int32_t argc, char *argv[]
static void HandleParamChange(const char *key, const char *value, void *context)
{
PLUGIN_CHECK(key != NULL && value != NULL, return, "Invalid parameter");
printf("Receive parameter change %s %s \n", key, value);
long long commit = GetSystemCommitId();
printf("Receive parameter commit %lld change %s %s \n", commit, key, value);
}
static void *CmdWatcher(void *args)