From b6324b5c4e842bedcb3ec4321578c38250c21901 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 30 Jul 2022 13:18:01 +0800 Subject: [PATCH] refactor: do some internal refactor. --- source/common/src/tmisce.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 source/common/src/tmisce.c diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c new file mode 100644 index 0000000000..2290c5d45f --- /dev/null +++ b/source/common/src/tmisce.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "tdatablock.h" +#include "tglobal.h" +#include "tlog.h" +#include "tname.h" + +int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) { + pEp->port = 0; + strcpy(pEp->fqdn, ep); + + char* temp = strchr(pEp->fqdn, ':'); + if (temp) { + *temp = 0; + pEp->port = atoi(temp + 1); + } + + if (pEp->port == 0) { + pEp->port = tsServerPort; + } + + return 0; +} + +void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port) { + if (pEpSet == NULL || fqdn == NULL || strlen(fqdn) == 0) { + return; + } + + int32_t index = pEpSet->numOfEps; + tstrncpy(pEpSet->eps[index].fqdn, fqdn, tListLen(pEpSet->eps[index].fqdn)); + pEpSet->eps[index].port = port; + pEpSet->numOfEps += 1; +} + +bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2) { + if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) { + return false; + } + + for (int32_t i = 0; i < s1->numOfEps; i++) { + if (s1->eps[i].port != s2->eps[i].port || strncmp(s1->eps[i].fqdn, s2->eps[i].fqdn, TSDB_FQDN_LEN) != 0) + return false; + } + return true; +} + +void updateEpSet_s(SCorEpSet* pEpSet, SEpSet* pNewEpSet) { + taosCorBeginWrite(&pEpSet->version); + pEpSet->epSet = *pNewEpSet; + taosCorEndWrite(&pEpSet->version); +} + +SEpSet getEpSet_s(SCorEpSet* pEpSet) { + SEpSet ep = {0}; + taosCorBeginRead(&pEpSet->version); + ep = pEpSet->epSet; + taosCorEndRead(&pEpSet->version); + + return ep; +} + + -- GitLab