提交 cda69861 编写于 作者: D dapan1121

Merge remote-tracking branch 'origin/3.0' into feature/qnode

...@@ -22,6 +22,7 @@ extern "C" { ...@@ -22,6 +22,7 @@ extern "C" {
#include "tcfg.h" #include "tcfg.h"
#include "tdef.h" #include "tdef.h"
#include "tarray.h"
// cluster // cluster
extern char tsFirst[]; extern char tsFirst[];
...@@ -94,8 +95,8 @@ extern SDiskCfg tsDiskCfg[]; ...@@ -94,8 +95,8 @@ extern SDiskCfg tsDiskCfg[];
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
const char *apolloUrl, bool tsc); const char *apolloUrl, SArray *pArgs, bool tsc);
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, bool tsc); int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc);
void taosCleanupCfg(); void taosCleanupCfg();
void taosCfgDynamicOptions(const char *option, const char *value); void taosCfgDynamicOptions(const char *option, const char *value);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define _TD_DNODE_H_ #define _TD_DNODE_H_
#include "tdef.h" #include "tdef.h"
#include "tcfg.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -47,6 +48,8 @@ typedef struct { ...@@ -47,6 +48,8 @@ typedef struct {
char localFqdn[TSDB_FQDN_LEN]; char localFqdn[TSDB_FQDN_LEN];
char firstEp[TSDB_EP_LEN]; char firstEp[TSDB_EP_LEN];
char secondEp[TSDB_EP_LEN]; char secondEp[TSDB_EP_LEN];
SDiskCfg *pDisks;
int32_t numOfDisks;
} SDnodeObjCfg; } SDnodeObjCfg;
/** /**
......
...@@ -63,7 +63,7 @@ typedef enum ENodeType { ...@@ -63,7 +63,7 @@ typedef enum ENodeType {
QUERY_NODE_FILL, QUERY_NODE_FILL,
QUERY_NODE_RAW_EXPR, // Only be used in parser module. QUERY_NODE_RAW_EXPR, // Only be used in parser module.
QUERY_NODE_TARGET, QUERY_NODE_TARGET,
QUERY_NODE_TUPLE_DESC, QUERY_NODE_DATABLOCK_DESC,
QUERY_NODE_SLOT_DESC, QUERY_NODE_SLOT_DESC,
// Statement nodes are used in parser and planner module. // Statement nodes are used in parser and planner module.
......
...@@ -71,17 +71,18 @@ typedef struct SSlotDescNode { ...@@ -71,17 +71,18 @@ typedef struct SSlotDescNode {
SDataType dataType; SDataType dataType;
bool reserve; bool reserve;
bool output; bool output;
bool tag;
} SSlotDescNode; } SSlotDescNode;
typedef struct STupleDescNode { typedef struct SDataBlockDescNode {
ENodeType type; ENodeType type;
int16_t tupleId; int16_t dataBlockId;
SNodeList* pSlots; SNodeList* pSlots;
} STupleDescNode; } SDataBlockDescNode;
typedef struct SPhysiNode { typedef struct SPhysiNode {
ENodeType type; ENodeType type;
STupleDescNode outputTuple; SDataBlockDescNode outputDataBlockDesc;
SNode* pConditions; SNode* pConditions;
SNodeList* pChildren; SNodeList* pChildren;
struct SPhysiNode* pParent; struct SPhysiNode* pParent;
...@@ -104,6 +105,7 @@ typedef struct STableScanPhysiNode { ...@@ -104,6 +105,7 @@ typedef struct STableScanPhysiNode {
SScanPhysiNode scan; SScanPhysiNode scan;
uint8_t scanFlag; // denotes reversed scan of data or not uint8_t scanFlag; // denotes reversed scan of data or not
STimeWindow scanRange; STimeWindow scanRange;
SNode* pScanConditions;
} STableScanPhysiNode; } STableScanPhysiNode;
typedef STableScanPhysiNode STableSeqScanPhysiNode; typedef STableScanPhysiNode STableSeqScanPhysiNode;
......
...@@ -58,21 +58,13 @@ typedef struct SColumnNode { ...@@ -58,21 +58,13 @@ typedef struct SColumnNode {
char tableAlias[TSDB_TABLE_NAME_LEN]; char tableAlias[TSDB_TABLE_NAME_LEN];
char colName[TSDB_COL_NAME_LEN]; char colName[TSDB_COL_NAME_LEN];
SNode* pProjectRef; SNode* pProjectRef;
int16_t tupleId; int16_t dataBlockId;
int16_t slotId; int16_t slotId;
} SColumnNode; } SColumnNode;
// typedef struct SColumnRefNode {
// ENodeType type;
// SDataType dataType;
// int16_t tupleId;
// int16_t slotId;
// int16_t columnId;
// } SColumnRefNode;
typedef struct STargetNode { typedef struct STargetNode {
ENodeType type; ENodeType type;
int16_t tupleId; int16_t dataBlockId;
int16_t slotId; int16_t slotId;
SNode* pExpr; SNode* pExpr;
} STargetNode; } STargetNode;
......
...@@ -21,7 +21,9 @@ extern "C" { ...@@ -21,7 +21,9 @@ extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
#include <tep.h>
#include "taosdef.h" #include "taosdef.h"
#include "trpc.h"
typedef uint64_t SyncNodeId; typedef uint64_t SyncNodeId;
typedef int32_t SyncGroupId; typedef int32_t SyncGroupId;
...@@ -34,23 +36,23 @@ typedef enum { ...@@ -34,23 +36,23 @@ typedef enum {
TAOS_SYNC_STATE_LEADER = 2, TAOS_SYNC_STATE_LEADER = 2,
} ESyncState; } ESyncState;
typedef struct { typedef struct SSyncBuffer {
void* data; void* data;
size_t len; size_t len;
} SSyncBuffer; } SSyncBuffer;
typedef struct { typedef struct SNodeInfo {
SyncNodeId nodeId;
uint16_t nodePort; // node sync Port uint16_t nodePort; // node sync Port
char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN
} SNodeInfo; } SNodeInfo;
typedef struct { typedef struct SSyncCfg {
int32_t replicaNum; int32_t replicaNum;
int32_t myIndex;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA]; SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
} SSyncCfg; } SSyncCfg;
typedef struct { typedef struct SNodesRole {
int32_t replicaNum; int32_t replicaNum;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA]; SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
ESyncState role[TSDB_MAX_REPLICA]; ESyncState role[TSDB_MAX_REPLICA];
...@@ -128,12 +130,12 @@ typedef struct SStateMgr { ...@@ -128,12 +130,12 @@ typedef struct SStateMgr {
} SStateMgr; } SStateMgr;
typedef struct { typedef struct SSyncInfo {
SyncGroupId vgId; SyncGroupId vgId;
SSyncCfg syncCfg; SSyncCfg syncCfg;
SSyncLogStore logStore; char path[TSDB_FILENAME_LEN];
SStateMgr stateManager; SSyncFSM* pFsm;
SSyncFSM syncFsm; int32_t (*FpSendMsg)(void* handle, const SEpSet* pEpSet, SRpcMsg* pMsg);
} SSyncInfo; } SSyncInfo;
......
...@@ -62,7 +62,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count); ...@@ -62,7 +62,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset); int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset);
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count); int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
void taosFprintfFile(TdFilePtr pFile, const char *format, ...); void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
size_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf); int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
int32_t taosEOFFile(TdFilePtr pFile); int32_t taosEOFFile(TdFilePtr pFile);
int64_t taosCloseFile(TdFilePtr *ppFile); int64_t taosCloseFile(TdFilePtr *ppFile);
......
...@@ -16,11 +16,12 @@ ...@@ -16,11 +16,12 @@
#ifndef _TD_UTIL_COMPARE_H_ #ifndef _TD_UTIL_COMPARE_H_
#define _TD_UTIL_COMPARE_H_ #define _TD_UTIL_COMPARE_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#define TSDB_PATTERN_MATCH 0 #define TSDB_PATTERN_MATCH 0
#define TSDB_PATTERN_NOMATCH 1 #define TSDB_PATTERN_NOMATCH 1
...@@ -62,7 +63,6 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight); ...@@ -62,7 +63,6 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight);
int32_t compareChkInString(const void *pLeft, const void *pRight); int32_t compareChkInString(const void *pLeft, const void *pRight);
int32_t compareChkNotInString(const void *pLeft, const void *pRight); int32_t compareChkNotInString(const void *pLeft, const void *pRight);
int32_t compareInt8Val(const void *pLeft, const void *pRight); int32_t compareInt8Val(const void *pLeft, const void *pRight);
int32_t compareInt16Val(const void *pLeft, const void *pRight); int32_t compareInt16Val(const void *pLeft, const void *pRight);
int32_t compareInt32Val(const void *pLeft, const void *pRight); int32_t compareInt32Val(const void *pLeft, const void *pRight);
...@@ -83,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight); ...@@ -83,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight);
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight);
int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight);
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight); int32_t compareInt8ValDesc(const void *pLeft, const void *pRight);
int32_t compareInt16ValDesc(const void *pLeft, const void *pRight); int32_t compareInt16ValDesc(const void *pLeft, const void *pRight);
int32_t compareInt32ValDesc(const void *pLeft, const void *pRight); int32_t compareInt32ValDesc(const void *pLeft, const void *pRight);
...@@ -102,7 +101,6 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight); ...@@ -102,7 +101,6 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
__compar_fn_t getComparFunc(int32_t type, int32_t optr); __compar_fn_t getComparFunc(int32_t type, int32_t optr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
此差异已折叠。
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define _TD_CONFIG_H_ #define _TD_CONFIG_H_
#include "os.h" #include "os.h"
#include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -32,7 +33,6 @@ typedef enum { ...@@ -32,7 +33,6 @@ typedef enum {
CFG_STYPE_ENV_VAR, CFG_STYPE_ENV_VAR,
CFG_STYPE_APOLLO_URL, CFG_STYPE_APOLLO_URL,
CFG_STYPE_ARG_LIST, CFG_STYPE_ARG_LIST,
CFG_STYPE_API_OPTION
} ECfgSrcType; } ECfgSrcType;
typedef enum { typedef enum {
...@@ -68,12 +68,19 @@ typedef struct SConfigItem { ...@@ -68,12 +68,19 @@ typedef struct SConfigItem {
int64_t imax; int64_t imax;
double fmax; double fmax;
}; };
SArray *array; // SDiskCfg
} SConfigItem; } SConfigItem;
typedef struct {
const char *name;
const char *value;
} SConfigPair;
typedef struct SConfig SConfig; typedef struct SConfig SConfig;
SConfig *cfgInit(); SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg); void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg);
......
...@@ -28,23 +28,42 @@ SJson* tjsonCreateObject(); ...@@ -28,23 +28,42 @@ SJson* tjsonCreateObject();
void tjsonDelete(SJson* pJson); void tjsonDelete(SJson* pJson);
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName); SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number); int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number);
int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number); int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number);
int32_t tjsonAddBoolToObject(SJson* pJson, const char* pName, const bool boolean);
int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal); int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal);
int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem); int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem); int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
int32_t tjsonGetIntValue(const SJson* pJson, const char* pName, int32_t* pVal);
int32_t tjsonGetSmallIntValue(const SJson* pJson, const char* pName, int16_t* pVal);
int32_t tjsonGetTinyIntValue(const SJson* pJson, const char* pName, int8_t* pVal);
int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pVal);
int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal);
int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal);
int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal);
int32_t tjsonGetArraySize(const SJson* pJson);
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index);
typedef int32_t (*FToJson)(const void* pObj, SJson* pJson); typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
int32_t tjsonAddObject(SJson* pJson, const char* pName, FToJson func, const void* pObj); int32_t tjsonAddObject(SJson* pJson, const char* pName, FToJson func, const void* pObj);
int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj); int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj);
typedef int32_t (*FFromJson)(const SJson* pJson, void* pObj); typedef int32_t (*FToObject)(const SJson* pJson, void* pObj);
int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, void* pObj);
char* tjsonToString(const SJson* pJson); char* tjsonToString(const SJson* pJson);
char* tjsonToUnformattedString(const SJson* pJson); char* tjsonToUnformattedString(const SJson* pJson);
SJson* tjsonParse(const char* pStr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
extern "C" { extern "C" {
#endif #endif
extern bool tsLogInited;
extern bool tsAsyncLog; extern bool tsAsyncLog;
extern int32_t tsNumOfLogLines; extern int32_t tsNumOfLogLines;
extern int32_t tsLogKeepDays; extern int32_t tsLogKeepDays;
...@@ -55,7 +54,7 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles); ...@@ -55,7 +54,7 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles);
void taosCloseLog(); void taosCloseLog();
void taosResetLog(); void taosResetLog();
void taosSetAllDebugFlag(int32_t flag); void taosSetAllDebugFlag(int32_t flag);
void taosDumpData(unsigned char *msg, int32_t len); void taosDumpData(uint8_t *msg, int32_t len);
void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...)
#ifdef __GNUC__ #ifdef __GNUC__
...@@ -69,6 +68,18 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . ...@@ -69,6 +68,18 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, .
#endif #endif
; ;
extern int8_t tscEmbeddedInUtil;
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -212,12 +212,12 @@ void taos_init_imp(void) { ...@@ -212,12 +212,12 @@ void taos_init_imp(void) {
deltaToUtcInitOnce(); deltaToUtcInitOnce();
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, 1) != 0) { if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) {
tscInitRes = -1; tscInitRes = -1;
return; return;
} }
if (taosInitCfg(configDir, NULL, NULL, 1) != 0) { if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) {
tscInitRes = -1; tscInitRes = -1;
return; return;
} }
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tdataformat.h" #include "tdataformat.h"
#include "ulog.h"
#include "talgo.h" #include "talgo.h"
#include "tcoding.h" #include "tcoding.h"
#include "wchar.h" #include "wchar.h"
#include "tarray.h" #include "tarray.h"
#include "tlog.h"
static void dataColSetNEleNull(SDataCol *pCol, int nEle); static void dataColSetNEleNull(SDataCol *pCol, int nEle);
#if 0 #if 0
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "tglobal.h" #include "tglobal.h"
#include "tlog.h" #include "tlog.h"
#include "tutil.h" #include "tutil.h"
#include "ulog.h"
SConfig *tsCfg = NULL; SConfig *tsCfg = NULL;
...@@ -154,19 +153,20 @@ static void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t prima ...@@ -154,19 +153,20 @@ static void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t prima
uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary); uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
} }
static void taosReadDataDirCfg(char *v1, char *v2, char *v3) { static void taosSetTfsCfg(SConfig *pCfg) {
if (tsDiskCfgNum == 1) { SConfigItem *pItem = cfgGetItem(pCfg, "dataDir");
SDiskCfg *cfg = &tsDiskCfg[0]; if (pItem == NULL) return;
uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1);
}
taosAddDataDir(0, v1, 0, 1);
tsDiskCfgNum = 1;
}
static void taosPrintDataDirCfg() { int32_t size = taosArrayGetSize(pItem->array);
for (int32_t i = 0; i < tsDiskCfgNum; ++i) { if (size <= 0) {
SDiskCfg *cfg = &tsDiskCfg[i]; tsDiskCfgNum = 1;
uInfo(" dataDir: %s", cfg->dir); taosAddDataDir(0, pItem->str, 0, 1);
} else {
tsDiskCfgNum = size < TFS_MAX_DISKS ? size : TFS_MAX_DISKS;
for (int32_t index = 0; index < tsDiskCfgNum; ++index) {
SDiskCfg *pCfg = taosArrayGet(pItem->array, index);
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
}
} }
} }
...@@ -206,113 +206,120 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e ...@@ -206,113 +206,120 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
return 0; return 0;
} }
static void taosAddClientLogCfg(SConfig *pCfg) { static int32_t taosAddClientLogCfg(SConfig *pCfg) {
cfgAddDir(pCfg, "logDir", tsLogDir, 1); if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1;
cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1); if (cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1) != 0) return -1;
cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1); if (cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1) != 0) return -1;
cfgAddBool(pCfg, "asyncLog", tsAsyncLog, 1); if (cfgAddBool(pCfg, "asyncLog", tsAsyncLog, 1) != 0) return -1;
cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000, 1); if (cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000, 1) != 0) return -1;
cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, 1); if (cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, 1) != 0) return -1;
cfgAddInt32(pCfg, "uDebugFlag", uDebugFlag, 0, 255, 1); if (cfgAddInt32(pCfg, "uDebugFlag", uDebugFlag, 0, 255, 1) != 0) return -1;
cfgAddInt32(pCfg, "rpcDebugFlag", rpcDebugFlag, 0, 255, 1); if (cfgAddInt32(pCfg, "rpcDebugFlag", rpcDebugFlag, 0, 255, 1) != 0) return -1;
cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1); if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1;
cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1); if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1;
cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1); if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1;
cfgAddDir(pCfg, "configDir", configDir, 1); if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1;
cfgAddDir(pCfg, "scriptDir", configDir, 1); if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1;
cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1); if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1;
return 0;
} }
static void taosAddServerLogCfg(SConfig *pCfg) { static int32_t taosAddServerLogCfg(SConfig *pCfg) {
cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "vDebugFlag", vDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "vDebugFlag", vDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "mDebugFlag", mDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "mDebugFlag", mDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "wDebugFlag", wDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "wDebugFlag", wDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "sDebugFlag", sDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "sDebugFlag", sDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "tsdbDebugFlag", tsdbDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "tsdbDebugFlag", tsdbDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "tqDebugFlag", tqDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "tqDebugFlag", tqDebugFlag, 0, 255, 0) != 0) return -1;
cfgAddInt32(pCfg, "fsDebugFlag", fsDebugFlag, 0, 255, 0); if (cfgAddInt32(pCfg, "fsDebugFlag", fsDebugFlag, 0, 255, 0) != 0) return -1;
return 0;
} }
static void taosAddClientCfg(SConfig *pCfg) { static int32_t taosAddClientCfg(SConfig *pCfg) {
char defaultFqdn[TSDB_FQDN_LEN] = {0}; char defaultFqdn[TSDB_FQDN_LEN] = {0};
int32_t defaultServerPort = 6030; int32_t defaultServerPort = 6030;
char defaultFirstEp[TSDB_EP_LEN] = {0}; char defaultFirstEp[TSDB_EP_LEN] = {0};
char defaultSecondEp[TSDB_EP_LEN] = {0}; char defaultSecondEp[TSDB_EP_LEN] = {0};
taosGetFqdn(defaultFqdn);
if (taosGetFqdn(defaultFqdn) != 0) return -1;
snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort); snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
snprintf(defaultSecondEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort); snprintf(defaultSecondEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
cfgAddString(pCfg, "firstEp", defaultFirstEp, 1); if (cfgAddString(pCfg, "firstEp", defaultFirstEp, 1) != 0) return -1;
cfgAddString(pCfg, "secondEp", defaultSecondEp, 1); if (cfgAddString(pCfg, "secondEp", defaultSecondEp, 1) != 0) return -1;
cfgAddString(pCfg, "fqdn", defaultFqdn, 1); if (cfgAddString(pCfg, "fqdn", defaultFqdn, 1) != 0) return -1;
cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056, 1); if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056, 1) != 0) return -1;
cfgAddDir(pCfg, "tempDir", tsTempDir, 1); if (cfgAddDir(pCfg, "tempDir", tsTempDir, 1) != 0) return -1;
cfgAddFloat(pCfg, "minimalTempDirGB", 1.0f, 0.001f, 10000000, 1); if (cfgAddFloat(pCfg, "minimalTempDirGB", 1.0f, 0.001f, 10000000, 1) != 0) return -1;
cfgAddFloat(pCfg, "numOfThreadsPerCore", tsNumOfThreadsPerCore, 0, 10, 1); if (cfgAddFloat(pCfg, "numOfThreadsPerCore", tsNumOfThreadsPerCore, 0, 10, 1) != 0) return -1;
cfgAddInt32(pCfg, "maxTmrCtrl", tsMaxTmrCtrl, 8, 2048, 1); if (cfgAddInt32(pCfg, "maxTmrCtrl", tsMaxTmrCtrl, 8, 2048, 1) != 0) return -1;
cfgAddInt32(pCfg, "rpcTimer", tsRpcTimer, 100, 3000, 1); if (cfgAddInt32(pCfg, "rpcTimer", tsRpcTimer, 100, 3000, 1) != 0) return -1;
cfgAddInt32(pCfg, "rpcMaxTime", tsRpcMaxTime, 100, 7200, 1); if (cfgAddInt32(pCfg, "rpcMaxTime", tsRpcMaxTime, 100, 7200, 1) != 0) return -1;
cfgAddBool(pCfg, "rpcForceTcp", tsRpcForceTcp, 1); if (cfgAddBool(pCfg, "rpcForceTcp", tsRpcForceTcp, 1) != 0) return -1;
cfgAddInt32(pCfg, "shellActivityTimer", tsShellActivityTimer, 1, 120, 1); if (cfgAddInt32(pCfg, "shellActivityTimer", tsShellActivityTimer, 1, 120, 1) != 0) return -1;
cfgAddInt32(pCfg, "compressMsgSize", tsCompressMsgSize, -1, 100000000, 1); if (cfgAddInt32(pCfg, "compressMsgSize", tsCompressMsgSize, -1, 100000000, 1) != 0) return -1;
cfgAddInt32(pCfg, "compressColData", tsCompressColData, -1, 100000000, 1); if (cfgAddInt32(pCfg, "compressColData", tsCompressColData, -1, 100000000, 1) != 0) return -1;
cfgAddInt32(pCfg, "maxWildCardsLength", tsMaxWildCardsLen, 0, TSDB_MAX_FIELD_LEN, 1); if (cfgAddInt32(pCfg, "maxWildCardsLength", tsMaxWildCardsLen, 0, TSDB_MAX_FIELD_LEN, 1) != 0) return -1;
cfgAddInt32(pCfg, "maxRegexStringLen", tsMaxRegexStringLen, 0, TSDB_MAX_FIELD_LEN, 1); if (cfgAddInt32(pCfg, "maxRegexStringLen", tsMaxRegexStringLen, 0, TSDB_MAX_FIELD_LEN, 1) != 0) return -1;
cfgAddInt32(pCfg, "maxNumOfOrderedRes", tsMaxNumOfOrderedResults, 128, TSDB_MAX_ALLOWED_SQL_LEN, 1); if (cfgAddInt32(pCfg, "maxNumOfOrderedRes", tsMaxNumOfOrderedResults, 128, TSDB_MAX_ALLOWED_SQL_LEN, 1) != 0)
cfgAddBool(pCfg, "keepColumnName", tsKeepOriginalColumnName, 1); return -1;
cfgAddInt32(pCfg, "maxBinaryDisplayWidth", tsMaxBinaryDisplayWidth, 1, 65536, 1); if (cfgAddBool(pCfg, "keepColumnName", tsKeepOriginalColumnName, 1) != 0) return -1;
if (cfgAddInt32(pCfg, "maxBinaryDisplayWidth", tsMaxBinaryDisplayWidth, 1, 65536, 1) != 0) return -1;
return 0;
} }
static void taosAddSystemInfo(SConfig *pCfg) { static int32_t taosAddSystemCfg(SConfig *pCfg) {
SysNameInfo info = taosGetSysNameInfo(); SysNameInfo info = taosGetSysNameInfo();
cfgAddTimezone(pCfg, "timezone", tsTimezone); if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
cfgAddLocale(pCfg, "locale", tsLocale); if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
cfgAddCharset(pCfg, "charset", tsCharset); if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
cfgAddBool(pCfg, "enableCoreFile", 0, 1); if (cfgAddBool(pCfg, "enableCoreFile", 0, 1) != 0) return -1;
cfgAddInt32(pCfg, "numOfCores", tsNumOfCores, 1, 100000, 1); if (cfgAddInt32(pCfg, "numOfCores", tsNumOfCores, 1, 100000, 1) != 0) return -1;
cfgAddInt32(pCfg, "pageSize(KB)", tsPageSize, 0, INT64_MAX, 1); if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSize, 0, INT64_MAX, 1) != 0) return -1;
cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1); if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1); if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
cfgAddInt32(pCfg, "totalMemory(MB)", tsTotalMemoryMB, 0, INT32_MAX, 1); if (cfgAddInt32(pCfg, "totalMemory(MB)", tsTotalMemoryMB, 0, INT32_MAX, 1) != 0) return -1;
cfgAddString(pCfg, "os sysname", info.sysname, 1); if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
cfgAddString(pCfg, "os nodename", info.nodename, 1); if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
cfgAddString(pCfg, "os release", info.release, 1); if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
cfgAddString(pCfg, "os version", info.version, 1); if (cfgAddString(pCfg, "os version", info.version, 1) != 0) return -1;
cfgAddString(pCfg, "os machine", info.machine, 1); if (cfgAddString(pCfg, "os machine", info.machine, 1) != 0) return -1;
cfgAddString(pCfg, "os sysname", info.sysname, 1); if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
cfgAddString(pCfg, "version", version, 1); if (cfgAddString(pCfg, "version", version, 1) != 0) return -1;
cfgAddString(pCfg, "compatible_version", compatible_version, 1); if (cfgAddString(pCfg, "compatible_version", compatible_version, 1) != 0) return -1;
cfgAddString(pCfg, "gitinfo", gitinfo, 1); if (cfgAddString(pCfg, "gitinfo", gitinfo, 1) != 0) return -1;
cfgAddString(pCfg, "gitinfoOfInternal", gitinfoOfInternal, 1); if (cfgAddString(pCfg, "gitinfoOfInternal", gitinfoOfInternal, 1) != 0) return -1;
cfgAddString(pCfg, "buildinfo", buildinfo, 1); if (cfgAddString(pCfg, "buildinfo", buildinfo, 1) != 0) return -1;
return 0;
} }
static void taosAddServerCfg(SConfig *pCfg) { static int32_t taosAddServerCfg(SConfig *pCfg) {
cfgAddInt32(pCfg, "supportVnodes", 256, 0, 65536, 0); if (cfgAddInt32(pCfg, "supportVnodes", 256, 0, 65536, 0) != 0) return -1;
cfgAddDir(pCfg, "dataDir", tsDataDir, 0); if (cfgAddDir(pCfg, "dataDir", tsDataDir, 0) != 0) return -1;
cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000, 0); if (cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000, 0) != 0) return -1;
cfgAddInt32(pCfg, "numOfCommitThreads", tsNumOfCommitThreads, 1, 100, 0); if (cfgAddInt32(pCfg, "numOfCommitThreads", tsNumOfCommitThreads, 1, 100, 0) != 0) return -1;
cfgAddFloat(pCfg, "ratioOfQueryCores", tsRatioOfQueryCores, 0, 2, 0); if (cfgAddFloat(pCfg, "ratioOfQueryCores", tsRatioOfQueryCores, 0, 2, 0) != 0) return -1;
cfgAddInt32(pCfg, "maxNumOfDistinctRes", tsMaxNumOfDistinctResults, 10 * 10000, 10000 * 10000, 0); if (cfgAddInt32(pCfg, "maxNumOfDistinctRes", tsMaxNumOfDistinctResults, 10 * 10000, 10000 * 10000, 0) != 0) return -1;
cfgAddBool(pCfg, "telemetryReporting", tsEnableTelemetryReporting, 0); if (cfgAddBool(pCfg, "telemetryReporting", tsEnableTelemetryReporting, 0) != 0) return -1;
cfgAddInt32(pCfg, "maxConnections", tsMaxConnections, 1, 100000, 0); if (cfgAddInt32(pCfg, "maxConnections", tsMaxConnections, 1, 100000, 0) != 0) return -1;
cfgAddInt32(pCfg, "maxShellConns", tsMaxShellConns, 10, 50000000, 0); if (cfgAddInt32(pCfg, "maxShellConns", tsMaxShellConns, 10, 50000000, 0) != 0) return -1;
cfgAddInt32(pCfg, "statusInterval", tsStatusInterval, 1, 30, 0); if (cfgAddInt32(pCfg, "statusInterval", tsStatusInterval, 1, 30, 0) != 0) return -1;
cfgAddInt32(pCfg, "minSlidingTime", tsMinSlidingTime, 10, 1000000, 0); if (cfgAddInt32(pCfg, "minSlidingTime", tsMinSlidingTime, 10, 1000000, 0) != 0) return -1;
cfgAddInt32(pCfg, "minIntervalTime", tsMinIntervalTime, 1, 1000000, 0); if (cfgAddInt32(pCfg, "minIntervalTime", tsMinIntervalTime, 1, 1000000, 0) != 0) return -1;
cfgAddInt32(pCfg, "maxStreamCompDelay", tsMaxStreamComputDelay, 10, 1000000000, 0); if (cfgAddInt32(pCfg, "maxStreamCompDelay", tsMaxStreamComputDelay, 10, 1000000000, 0) != 0) return -1;
cfgAddInt32(pCfg, "maxFirstStreamCompDelay", tsStreamCompStartDelay, 1000, 1000000000, 0); if (cfgAddInt32(pCfg, "maxFirstStreamCompDelay", tsStreamCompStartDelay, 1000, 1000000000, 0) != 0) return -1;
cfgAddInt32(pCfg, "retryStreamCompDelay", tsRetryStreamCompDelay, 10, 1000000000, 0); if (cfgAddInt32(pCfg, "retryStreamCompDelay", tsRetryStreamCompDelay, 10, 1000000000, 0) != 0) return -1;
cfgAddFloat(pCfg, "streamCompDelayRatio", tsStreamComputDelayRatio, 0.1, 0.9, 0); if (cfgAddFloat(pCfg, "streamCompDelayRatio", tsStreamComputDelayRatio, 0.1, 0.9, 0) != 0) return -1;
cfgAddInt32(pCfg, "queryBufferSize", tsQueryBufferSize, -1, 500000000000, 0); if (cfgAddInt32(pCfg, "queryBufferSize", tsQueryBufferSize, -1, 500000000000, 0) != 0) return -1;
cfgAddBool(pCfg, "retrieveBlockingModel", tsRetrieveBlockingModel, 0); if (cfgAddBool(pCfg, "retrieveBlockingModel", tsRetrieveBlockingModel, 0) != 0) return -1;
cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0); if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0); if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1;
cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0); if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
return 0;
} }
static void taosSetClientLogCfg(SConfig *pCfg) { static void taosSetClientLogCfg(SConfig *pCfg) {
...@@ -414,17 +421,17 @@ static void taosSetServerCfg(SConfig *pCfg) { ...@@ -414,17 +421,17 @@ static void taosSetServerCfg(SConfig *pCfg) {
} }
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
const char *apolloUrl, bool tsc) { const char *apolloUrl, SArray *pArgs, bool tsc) {
osInit(); osInit();
SConfig *pCfg = cfgInit(); SConfig *pCfg = cfgInit();
if (pCfg == NULL) return -1; if (pCfg == NULL) return -1;
if (tsc) { if (tsc) {
taosAddClientLogCfg(pCfg); if (taosAddClientLogCfg(pCfg) != 0) return -1;
} else { } else {
taosAddClientLogCfg(pCfg); if (taosAddClientLogCfg(pCfg) != 0) return -1;
taosAddServerLogCfg(pCfg); if (taosAddServerLogCfg(pCfg) != 0) return -1;
} }
if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) { if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
...@@ -433,15 +440,21 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -433,15 +440,21 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
return -1; return -1;
} }
if (cfgLoadArray(pCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(pCfg);
return -1;
}
if (tsc) { if (tsc) {
taosSetClientLogCfg(pCfg); taosSetClientLogCfg(pCfg);
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
} else { } else {
taosSetClientLogCfg(pCfg); taosSetClientLogCfg(pCfg);
taosSetServerLogCfg(pCfg); taosSetServerLogCfg(pCfg);
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
} }
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
if (taosInitLog(logname, logFileNum) != 0) { if (taosInitLog(logname, logFileNum) != 0) {
printf("failed to init log file since %s\n", terrstr()); printf("failed to init log file since %s\n", terrstr());
cfgCleanup(pCfg); cfgCleanup(pCfg);
...@@ -452,20 +465,20 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -452,20 +465,20 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
return 0; return 0;
} }
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, bool tsc) { int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) {
if (tsCfg != NULL) return 0; if (tsCfg != NULL) return 0;
tsCfg = cfgInit(); tsCfg = cfgInit();
if (tsc) { if (tsc) {
taosAddClientLogCfg(tsCfg); if (taosAddClientLogCfg(tsCfg) != 0) return -1;
taosAddClientCfg(tsCfg); if (taosAddClientCfg(tsCfg) != 0) return -1;
} else { } else {
taosAddClientLogCfg(tsCfg); if (taosAddClientLogCfg(tsCfg) != 0) return -1;
taosAddServerLogCfg(tsCfg); if (taosAddServerLogCfg(tsCfg) != 0) return -1;
taosAddClientCfg(tsCfg); if (taosAddClientCfg(tsCfg) != 0) return -1;
taosAddServerCfg(tsCfg); if (taosAddServerCfg(tsCfg) != 0) return -1;
} }
taosAddSystemInfo(tsCfg); taosAddSystemCfg(tsCfg);
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) { if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
uError("failed to load cfg since %s", terrstr()); uError("failed to load cfg since %s", terrstr());
...@@ -474,11 +487,18 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU ...@@ -474,11 +487,18 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
return -1; return -1;
} }
if (cfgLoadArray(tsCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(tsCfg);
return -1;
}
if (tsc) { if (tsc) {
taosSetClientCfg(tsCfg); taosSetClientCfg(tsCfg);
} else { } else {
taosSetClientCfg(tsCfg); taosSetClientCfg(tsCfg);
taosSetServerCfg(tsCfg); taosSetServerCfg(tsCfg);
taosSetTfsCfg(tsCfg);
} }
taosSetSystemCfg(tsCfg); taosSetSystemCfg(tsCfg);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "dnode.h" #include "dnode.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "ulog.h" #include "tlog.h"
#include "version.h" #include "version.h"
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -28,6 +28,8 @@ SDnodeObjCfg dmnGetObjCfg() { ...@@ -28,6 +28,8 @@ SDnodeObjCfg dmnGetObjCfg() {
objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn)); tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn));
snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort); snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort);
objCfg.pDisks = tsDiskCfg;
objCfg.numOfDisks = tsDiskCfgNum;
return objCfg; return objCfg;
} }
......
...@@ -111,12 +111,12 @@ int main(int argc, char const *argv[]) { ...@@ -111,12 +111,12 @@ int main(int argc, char const *argv[]) {
return 0; return 0;
} }
if (taosCreateLog("taosdlog", 1, configDir, dmn.envFile, dmn.apolloUrl, 0) != 0) { if (taosCreateLog("taosdlog", 1, configDir, dmn.envFile, dmn.apolloUrl, NULL, 0) != 0) {
uInfo("Failed to start TDengine since read config error"); uInfo("Failed to start TDengine since read config error");
return -1; return -1;
} }
if (taosInitCfg(configDir, dmn.envFile, dmn.apolloUrl, 0) != 0) { if (taosInitCfg(configDir, dmn.envFile, dmn.apolloUrl, NULL, 0) != 0) {
uInfo("Failed to start TDengine since read config error"); uInfo("Failed to start TDengine since read config error");
return -1; return -1;
} }
......
...@@ -81,7 +81,7 @@ static TdFilePtr dndCheckRunning(char *dataDir) { ...@@ -81,7 +81,7 @@ static TdFilePtr dndCheckRunning(char *dataDir) {
return pFile; return pFile;
} }
static int32_t dndCreateImp(SDnode *pDnode, SDnodeObjCfg *pCfg) { static int32_t dndInitDir(SDnode *pDnode, SDnodeObjCfg *pCfg) {
pDnode->pLockFile = dndCheckRunning(pCfg->dataDir); pDnode->pLockFile = dndCheckRunning(pCfg->dataDir);
if (pDnode->pLockFile == NULL) { if (pDnode->pLockFile == NULL) {
return -1; return -1;
...@@ -166,7 +166,7 @@ SDnode *dndCreate(SDnodeObjCfg *pCfg) { ...@@ -166,7 +166,7 @@ SDnode *dndCreate(SDnodeObjCfg *pCfg) {
dndSetStat(pDnode, DND_STAT_INIT); dndSetStat(pDnode, DND_STAT_INIT);
if (dndCreateImp(pDnode, pCfg) != 0) { if (dndInitDir(pDnode, pCfg) != 0) {
dError("failed to init dnode dir since %s", terrstr()); dError("failed to init dnode dir since %s", terrstr());
dndClose(pDnode); dndClose(pDnode);
return NULL; return NULL;
...@@ -176,7 +176,14 @@ SDnode *dndCreate(SDnodeObjCfg *pCfg) { ...@@ -176,7 +176,14 @@ SDnode *dndCreate(SDnodeObjCfg *pCfg) {
tstrncpy(dCfg.dir, pDnode->cfg.dataDir, TSDB_FILENAME_LEN); tstrncpy(dCfg.dir, pDnode->cfg.dataDir, TSDB_FILENAME_LEN);
dCfg.level = 0; dCfg.level = 0;
dCfg.primary = 1; dCfg.primary = 1;
pDnode->pTfs = tfsOpen(&dCfg, 1); SDiskCfg *pDisks = pDnode->cfg.pDisks;
int32_t numOfDisks = pDnode->cfg.numOfDisks;
if (numOfDisks <= 0 || pDisks == NULL) {
pDisks = &dCfg;
numOfDisks = 1;
}
pDnode->pTfs = tfsOpen(pDisks, numOfDisks);
if (pDnode->pTfs == NULL) { if (pDnode->pTfs == NULL) {
dError("failed to init tfs since %s", terrstr()); dError("failed to init tfs since %s", terrstr());
dndClose(pDnode); dndClose(pDnode);
......
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
#include "tmsg.h" #include "tmsg.h"
#include "trpc.h" #include "trpc.h"
#include "tthread.h" #include "tthread.h"
#include "ulog.h"
#include "client.h" #include "client.h"
#include "server.h" #include "server.h"
#include "tlog.h"
class Testbase { class Testbase {
public: public:
......
...@@ -631,13 +631,13 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp ...@@ -631,13 +631,13 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp
pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
tstrncpy(pSchema[cols].name, "name", sizeof(pSchema[cols].name)); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = pShow->bytes[cols]; pSchema[cols].bytes = pShow->bytes[cols];
cols++; cols++;
pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
tstrncpy(pSchema[cols].name, "value", sizeof(pSchema[cols].name)); strcpy(pSchema[cols].name, "value");
pSchema[cols].bytes = pShow->bytes[cols]; pSchema[cols].bytes = pShow->bytes[cols];
cols++; cols++;
...@@ -658,29 +658,30 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp ...@@ -658,29 +658,30 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp
static int32_t mndRetrieveConfigs(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { static int32_t mndRetrieveConfigs(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
int32_t totalRows = 0;
int32_t numOfRows = 0; int32_t numOfRows = 0;
char *cfgOpts[TSDB_CONFIG_NUMBER] = {0}; char *cfgOpts[TSDB_CONFIG_NUMBER] = {0};
char cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONIIG_VALUE_LEN + 1] = {0}; char cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONIIG_VALUE_LEN + 1] = {0};
char *pWrite; char *pWrite;
int32_t cols = 0; int32_t cols = 0;
cfgOpts[numOfRows] = "statusInterval"; cfgOpts[totalRows] = "statusInterval";
snprintf(cfgVals[numOfRows], TSDB_CONIIG_VALUE_LEN, "%d", tsStatusInterval); snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%d", tsStatusInterval);
numOfRows++; totalRows++;
cfgOpts[numOfRows] = "timezone"; cfgOpts[totalRows] = "timezone";
snprintf(cfgVals[numOfRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone); snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone);
numOfRows++; totalRows++;
cfgOpts[numOfRows] = "locale"; cfgOpts[totalRows] = "locale";
snprintf(cfgVals[numOfRows], TSDB_CONIIG_VALUE_LEN, "%s", tsLocale); snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsLocale);
numOfRows++; totalRows++;
cfgOpts[numOfRows] = "charset"; cfgOpts[totalRows] = "charset";
snprintf(cfgVals[numOfRows], TSDB_CONIIG_VALUE_LEN, "%s", tsCharset); snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsCharset);
numOfRows++; totalRows++;
for (int32_t i = 0; i < numOfRows; i++) { for (int32_t i = 0; i < totalRows; i++) {
cols = 0; cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -690,6 +691,8 @@ static int32_t mndRetrieveConfigs(SMnodeMsg *pReq, SShowObj *pShow, char *data, ...@@ -690,6 +691,8 @@ static int32_t mndRetrieveConfigs(SMnodeMsg *pReq, SShowObj *pShow, char *data,
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, cfgVals[i], TSDB_CONIIG_VALUE_LEN); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, cfgVals[i], TSDB_CONIIG_VALUE_LEN);
cols++; cols++;
numOfRows++;
} }
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
......
...@@ -356,7 +356,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader) { ...@@ -356,7 +356,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader) {
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC); ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pDFile->pFile < 0) { if (pDFile->pFile == NULL) {
if (errno == ENOENT) { if (errno == ENOENT) {
// Try to create directory recursively // Try to create directory recursively
char *s = strdup(TSDB_FILE_REL_NAME(pDFile)); char *s = strdup(TSDB_FILE_REL_NAME(pDFile));
...@@ -367,7 +367,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader) { ...@@ -367,7 +367,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader) {
tfree(s); tfree(s);
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pDFile->pFile < 0) { if (pDFile->pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
......
...@@ -29,6 +29,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -29,6 +29,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.processFunc = NULL, .processFunc = NULL,
.finalizeFunc = NULL .finalizeFunc = NULL
}, },
{
.name = "sum",
.type = FUNCTION_TYPE_SUM,
.classification = FUNC_MGT_AGG_FUNC,
.checkFunc = stubCheckAndGetResultType,
.getEnvFunc = NULL,
.initFunc = NULL,
.processFunc = NULL,
.finalizeFunc = NULL
},
{ {
.name = "concat", .name = "concat",
.type = FUNCTION_TYPE_CONCAT, .type = FUNCTION_TYPE_CONCAT,
......
...@@ -105,7 +105,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int ...@@ -105,7 +105,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
#endif #endif
} }
memcpy(ctx->file.buf, path, strlen(path)); memcpy(ctx->file.buf, path, strlen(path));
if (ctx->file.pFile < 0) { if (ctx->file.pFile == NULL) {
indexError("failed to open file, error %d", errno); indexError("failed to open file, error %d", errno);
goto END; goto END;
} }
......
...@@ -72,6 +72,11 @@ void iUnion(SArray *inters, SArray *final) { ...@@ -72,6 +72,11 @@ void iUnion(SArray *inters, SArray *final) {
if (sz <= 0) { if (sz <= 0) {
return; return;
} }
if (sz == 1) {
taosArrayAddAll(final, taosArrayGetP(inters, 0));
return;
}
MergeIndex *mi = calloc(sz, sizeof(MergeIndex)); MergeIndex *mi = calloc(sz, sizeof(MergeIndex));
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
SArray *t = taosArrayGetP(inters, i); SArray *t = taosArrayGetP(inters, i);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "tglobal.h" #include "tglobal.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tutil.h" #include "tutil.h"
#include "ulog.h" #include "tlog.h"
static std::string dir = "/tmp/index"; static std::string dir = "/tmp/index";
......
...@@ -192,7 +192,6 @@ TEST_F(UtilEnv, 03union) { ...@@ -192,7 +192,6 @@ TEST_F(UtilEnv, 03union) {
for (int i = 0; i < sizeof(arr2) / sizeof(arr2[0]); i++) { for (int i = 0; i < sizeof(arr2) / sizeof(arr2[0]); i++) {
taosArrayPush(f, &arr2[i]); taosArrayPush(f, &arr2[i]);
} }
uint64_t arr3[] = {1, 12, 13, 16, 17}; uint64_t arr3[] = {1, 12, 13, 16, 17};
f = (SArray *)taosArrayGetP(src, 2); f = (SArray *)taosArrayGetP(src, 2);
for (int i = 0; i < sizeof(arr3) / sizeof(arr3[0]); i++) { for (int i = 0; i < sizeof(arr3) / sizeof(arr3[0]); i++) {
...@@ -201,3 +200,27 @@ TEST_F(UtilEnv, 03union) { ...@@ -201,3 +200,27 @@ TEST_F(UtilEnv, 03union) {
iUnion(src, rslt); iUnion(src, rslt);
assert(taosArrayGetSize(rslt) == 9); assert(taosArrayGetSize(rslt) == 9);
} }
TEST_F(UtilEnv, 04union) {
clearSourceArray(src);
clearFinalArray(rslt);
uint64_t arr1[] = {1, 4, 5, 6};
SArray * f = (SArray *)taosArrayGetP(src, 0);
for (int i = 0; i < sizeof(arr1) / sizeof(arr1[0]); i++) {
taosArrayPush(f, &arr1[i]);
}
uint64_t arr2[] = {7, 8, 10};
f = (SArray *)taosArrayGetP(src, 1);
for (int i = 0; i < sizeof(arr2) / sizeof(arr2[0]); i++) {
taosArrayPush(f, &arr2[i]);
}
uint64_t arr3[] = {20, 21, 30, 100, 120};
f = (SArray *)taosArrayGetP(src, 2);
for (int i = 0; i < sizeof(arr3) / sizeof(arr3[0]); i++) {
taosArrayPush(f, &arr3[i]);
}
iUnion(src, rslt);
assert(taosArrayGetSize(rslt) == 12);
}
...@@ -72,6 +72,8 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { ...@@ -72,6 +72,8 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
COPY_CHAR_ARRAY_FIELD(tableAlias); COPY_CHAR_ARRAY_FIELD(tableAlias);
COPY_CHAR_ARRAY_FIELD(colName); COPY_CHAR_ARRAY_FIELD(colName);
// COPY_NODE_FIELD(pProjectRef); // COPY_NODE_FIELD(pProjectRef);
COPY_SCALAR_FIELD(dataBlockId);
COPY_SCALAR_FIELD(slotId);
return (SNode*)pDst; return (SNode*)pDst;
} }
...@@ -143,7 +145,7 @@ static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) { ...@@ -143,7 +145,7 @@ static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) {
} }
static SNode* targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) { static SNode* targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) {
COPY_SCALAR_FIELD(tupleId); COPY_SCALAR_FIELD(dataBlockId);
COPY_SCALAR_FIELD(slotId); COPY_SCALAR_FIELD(slotId);
COPY_NODE_FIELD(pExpr); COPY_NODE_FIELD(pExpr);
return (SNode*)pDst; return (SNode*)pDst;
......
...@@ -81,8 +81,8 @@ SNode* nodesMakeNode(ENodeType type) { ...@@ -81,8 +81,8 @@ SNode* nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SProjectLogicNode)); return makeNode(type, sizeof(SProjectLogicNode));
case QUERY_NODE_TARGET: case QUERY_NODE_TARGET:
return makeNode(type, sizeof(STargetNode)); return makeNode(type, sizeof(STargetNode));
case QUERY_NODE_TUPLE_DESC: case QUERY_NODE_DATABLOCK_DESC:
return makeNode(type, sizeof(STupleDescNode)); return makeNode(type, sizeof(SDataBlockDescNode));
case QUERY_NODE_SLOT_DESC: case QUERY_NODE_SLOT_DESC:
return makeNode(type, sizeof(SSlotDescNode)); return makeNode(type, sizeof(SSlotDescNode));
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
......
...@@ -29,9 +29,10 @@ ...@@ -29,9 +29,10 @@
namespace { namespace {
void generateTestT1(MockCatalogService* mcs) { void generateTestT1(MockCatalogService* mcs) {
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 4) ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
.setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) .setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT); .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT)
.addColumn("c4", TSDB_DATA_TYPE_DOUBLE).addColumn("c5", TSDB_DATA_TYPE_DOUBLE);
builder.done(); builder.done();
} }
......
...@@ -159,6 +159,10 @@ static SLogicNode* createScanLogicNode(SPlanContext* pCxt, SSelectStmt* pSelect, ...@@ -159,6 +159,10 @@ static SLogicNode* createScanLogicNode(SPlanContext* pCxt, SSelectStmt* pSelect,
CHECK_ALLOC(pScan->node.pTargets, (SLogicNode*)pScan); CHECK_ALLOC(pScan->node.pTargets, (SLogicNode*)pScan);
} }
pScan->scanType = SCAN_TYPE_TABLE;
pScan->scanFlag = MAIN_SCAN;
pScan->scanRange = TSWINDOW_INITIALIZER;
return (SLogicNode*)pScan; return (SLogicNode*)pScan;
} }
...@@ -397,14 +401,14 @@ int32_t splitLogicPlan(SSubLogicPlan* pLogicPlan) { ...@@ -397,14 +401,14 @@ int32_t splitLogicPlan(SSubLogicPlan* pLogicPlan) {
} }
typedef struct SSlotIndex { typedef struct SSlotIndex {
int16_t tupleId; int16_t dataBlockId;
int16_t slotId; int16_t slotId;
} SSlotIndex; } SSlotIndex;
typedef struct SPhysiPlanContext { typedef struct SPhysiPlanContext {
int32_t errCode; int32_t errCode;
int16_t nextTupleId; int16_t nextDataBlockId;
SArray* pTupleHelper; SArray* pLocationHelper;
} SPhysiPlanContext; } SPhysiPlanContext;
static int32_t getSlotKey(SNode* pNode, char* pKey) { static int32_t getSlotKey(SNode* pNode, char* pKey) {
...@@ -428,31 +432,31 @@ static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const SNode* pNode, int16_ ...@@ -428,31 +432,31 @@ static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const SNode* pNode, int16_
return (SNode*)pSlot; return (SNode*)pSlot;
} }
static SNode* createTarget(SNode* pNode, int16_t tupleId, int16_t slotId) { static SNode* createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId) {
STargetNode* pTarget = (STargetNode*)nodesMakeNode(QUERY_NODE_TARGET); STargetNode* pTarget = (STargetNode*)nodesMakeNode(QUERY_NODE_TARGET);
if (NULL == pTarget) { if (NULL == pTarget) {
return NULL; return NULL;
} }
pTarget->tupleId = tupleId; pTarget->dataBlockId = dataBlockId;
pTarget->slotId = slotId; pTarget->slotId = slotId;
pTarget->pExpr = pNode; pTarget->pExpr = pNode;
return (SNode*)pTarget; return (SNode*)pTarget;
} }
static int32_t addTupleDesc(SPhysiPlanContext* pCxt, SNodeList* pList, STupleDescNode* pTuple) { static int32_t addDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
SHashObj* pHash = NULL; SHashObj* pHash = NULL;
if (NULL == pTuple->pSlots) { if (NULL == pDataBlockDesc->pSlots) {
pTuple->pSlots = nodesMakeList(); pDataBlockDesc->pSlots = nodesMakeList();
CHECK_ALLOC(pTuple->pSlots, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(pDataBlockDesc->pSlots, TSDB_CODE_OUT_OF_MEMORY);
pHash = taosHashInit(LIST_LENGTH(pList), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pHash = taosHashInit(LIST_LENGTH(pList), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
CHECK_ALLOC(pHash, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(pHash, TSDB_CODE_OUT_OF_MEMORY);
if (NULL == taosArrayInsert(pCxt->pTupleHelper, pTuple->tupleId, &pHash)) { if (NULL == taosArrayInsert(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId, &pHash)) {
taosHashCleanup(pHash); taosHashCleanup(pHash);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
} else { } else {
pHash = taosArrayGetP(pCxt->pTupleHelper, pTuple->tupleId); pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
} }
SNode* pNode = NULL; SNode* pNode = NULL;
...@@ -460,17 +464,17 @@ static int32_t addTupleDesc(SPhysiPlanContext* pCxt, SNodeList* pList, STupleDes ...@@ -460,17 +464,17 @@ static int32_t addTupleDesc(SPhysiPlanContext* pCxt, SNodeList* pList, STupleDes
FOREACH(pNode, pList) { FOREACH(pNode, pList) {
SNode* pSlot = createSlotDesc(pCxt, pNode, slotId); SNode* pSlot = createSlotDesc(pCxt, pNode, slotId);
CHECK_ALLOC(pSlot, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(pSlot, TSDB_CODE_OUT_OF_MEMORY);
if (TSDB_CODE_SUCCESS != nodesListAppend(pTuple->pSlots, (SNode*)pSlot)) { if (TSDB_CODE_SUCCESS != nodesListAppend(pDataBlockDesc->pSlots, (SNode*)pSlot)) {
nodesDestroyNode(pSlot); nodesDestroyNode(pSlot);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SSlotIndex index = { .tupleId = pTuple->tupleId, .slotId = slotId }; SSlotIndex index = { .dataBlockId = pDataBlockDesc->dataBlockId, .slotId = slotId };
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
int32_t len = getSlotKey(pNode, name); int32_t len = getSlotKey(pNode, name);
CHECK_CODE(taosHashPut(pHash, name, len, &index, sizeof(SSlotIndex)), TSDB_CODE_OUT_OF_MEMORY); CHECK_CODE(taosHashPut(pHash, name, len, &index, sizeof(SSlotIndex)), TSDB_CODE_OUT_OF_MEMORY);
SNode* pTarget = createTarget(pNode, pTuple->tupleId, slotId); SNode* pTarget = createTarget(pNode, pDataBlockDesc->dataBlockId, slotId);
CHECK_ALLOC(pTarget, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(pTarget, TSDB_CODE_OUT_OF_MEMORY);
REPLACE_NODE(pTarget); REPLACE_NODE(pTarget);
...@@ -495,7 +499,7 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { ...@@ -495,7 +499,7 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
pIndex = taosHashGet(pCxt->pRightHash, name, len); pIndex = taosHashGet(pCxt->pRightHash, name, len);
} }
// pIndex is definitely not NULL, otherwise it is a bug // pIndex is definitely not NULL, otherwise it is a bug
((SColumnNode*)pNode)->tupleId = pIndex->tupleId; ((SColumnNode*)pNode)->dataBlockId = pIndex->dataBlockId;
((SColumnNode*)pNode)->slotId = pIndex->slotId; ((SColumnNode*)pNode)->slotId = pIndex->slotId;
CHECK_ALLOC(pNode, DEAL_RES_ERROR); CHECK_ALLOC(pNode, DEAL_RES_ERROR);
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
...@@ -503,11 +507,11 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { ...@@ -503,11 +507,11 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static SNode* setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftTupleId, int16_t rightTupleId, SNode* pNode) { static SNode* setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode) {
SNode* pRes = nodesCloneNode(pNode); SNode* pRes = nodesCloneNode(pNode);
CHECK_ALLOC(pRes, NULL); CHECK_ALLOC(pRes, NULL);
SSetSlotIdCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pLeftHash = taosArrayGetP(pCxt->pTupleHelper, leftTupleId), SSetSlotIdCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
.pRightHash = (rightTupleId < 0 ? NULL : taosArrayGetP(pCxt->pTupleHelper, rightTupleId)) }; .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)) };
nodesWalkNode(pRes, doSetSlotId, &cxt); nodesWalkNode(pRes, doSetSlotId, &cxt);
if (TSDB_CODE_SUCCESS != cxt.errCode) { if (TSDB_CODE_SUCCESS != cxt.errCode) {
nodesDestroyNode(pRes); nodesDestroyNode(pRes);
...@@ -516,11 +520,11 @@ static SNode* setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftTupleId, int16_ ...@@ -516,11 +520,11 @@ static SNode* setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftTupleId, int16_
return pRes; return pRes;
} }
static SNodeList* setListSlotId(SPhysiPlanContext* pCxt, int16_t leftTupleId, int16_t rightTupleId, SNodeList* pList) { static SNodeList* setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNodeList* pList) {
SNodeList* pRes = nodesCloneList(pList); SNodeList* pRes = nodesCloneList(pList);
CHECK_ALLOC(pRes, NULL); CHECK_ALLOC(pRes, NULL);
SSetSlotIdCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pLeftHash = taosArrayGetP(pCxt->pTupleHelper, leftTupleId), SSetSlotIdCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
.pRightHash = (rightTupleId < 0 ? NULL : taosArrayGetP(pCxt->pTupleHelper, rightTupleId)) }; .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)) };
nodesWalkList(pRes, doSetSlotId, &cxt); nodesWalkList(pRes, doSetSlotId, &cxt);
if (TSDB_CODE_SUCCESS != cxt.errCode) { if (TSDB_CODE_SUCCESS != cxt.errCode) {
nodesDestroyList(pRes); nodesDestroyList(pRes);
...@@ -534,27 +538,27 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, ENodeType type) { ...@@ -534,27 +538,27 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, ENodeType type) {
if (NULL == pPhysiNode) { if (NULL == pPhysiNode) {
return NULL; return NULL;
} }
pPhysiNode->outputTuple.tupleId = pCxt->nextTupleId++; pPhysiNode->outputDataBlockDesc.dataBlockId = pCxt->nextDataBlockId++;
pPhysiNode->outputTuple.type = QUERY_NODE_TUPLE_DESC; pPhysiNode->outputDataBlockDesc.type = QUERY_NODE_DATABLOCK_DESC;
return pPhysiNode; return pPhysiNode;
} }
static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) { static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) {
if (NULL != pLogicNode->pConditions) { if (NULL != pLogicNode->pConditions) {
pPhysiNode->pConditions = setNodeSlotId(pCxt, pPhysiNode->outputTuple.tupleId, -1, pLogicNode->pConditions); pPhysiNode->pConditions = setNodeSlotId(pCxt, pPhysiNode->outputDataBlockDesc.dataBlockId, -1, pLogicNode->pConditions);
CHECK_ALLOC(pPhysiNode->pConditions, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(pPhysiNode->pConditions, TSDB_CODE_OUT_OF_MEMORY);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t setSlotOutput(SPhysiPlanContext* pCxt, SNodeList* pTargets, STupleDescNode* pTuple) { static int32_t setSlotOutput(SPhysiPlanContext* pCxt, SNodeList* pTargets, SDataBlockDescNode* pDataBlockDesc) {
SHashObj* pHash = taosArrayGetP(pCxt->pTupleHelper, pTuple->tupleId); SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
SNode* pNode; SNode* pNode;
FOREACH(pNode, pTargets) { FOREACH(pNode, pTargets) {
int32_t len = getSlotKey(pNode, name); int32_t len = getSlotKey(pNode, name);
SSlotIndex* pIndex = taosHashGet(pHash, name, len); SSlotIndex* pIndex = taosHashGet(pHash, name, len);
((SSlotDescNode*)nodesListGetNode(pTuple->pSlots, pIndex->slotId))->output = true; ((SSlotDescNode*)nodesListGetNode(pDataBlockDesc->pSlots, pIndex->slotId))->output = true;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -565,12 +569,12 @@ static int32_t initScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanL ...@@ -565,12 +569,12 @@ static int32_t initScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanL
pScanPhysiNode->pScanCols = nodesCloneList(pScanLogicNode->pScanCols); pScanPhysiNode->pScanCols = nodesCloneList(pScanLogicNode->pScanCols);
CHECK_ALLOC(pScanPhysiNode->pScanCols, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(pScanPhysiNode->pScanCols, TSDB_CODE_OUT_OF_MEMORY);
} }
// Tuple describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t // Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t
CHECK_CODE(addTupleDesc(pCxt, pScanPhysiNode->pScanCols, &pScanPhysiNode->node.outputTuple), TSDB_CODE_OUT_OF_MEMORY); CHECK_CODE(addDataBlockDesc(pCxt, pScanPhysiNode->pScanCols, &pScanPhysiNode->node.outputDataBlockDesc), TSDB_CODE_OUT_OF_MEMORY);
CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pScanLogicNode, (SPhysiNode*)pScanPhysiNode), TSDB_CODE_OUT_OF_MEMORY); CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pScanLogicNode, (SPhysiNode*)pScanPhysiNode), TSDB_CODE_OUT_OF_MEMORY);
CHECK_CODE(setSlotOutput(pCxt, pScanLogicNode->node.pTargets, &pScanPhysiNode->node.outputTuple), TSDB_CODE_OUT_OF_MEMORY); CHECK_CODE(setSlotOutput(pCxt, pScanLogicNode->node.pTargets, &pScanPhysiNode->node.outputDataBlockDesc), TSDB_CODE_OUT_OF_MEMORY);
pScanPhysiNode->uid = pScanLogicNode->pMeta->uid; pScanPhysiNode->uid = pScanLogicNode->pMeta->uid;
pScanPhysiNode->tableType = pScanLogicNode->pMeta->tableType; pScanPhysiNode->tableType = pScanLogicNode->pMeta->tableType;
...@@ -612,32 +616,32 @@ static SPhysiNode* createScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* ...@@ -612,32 +616,32 @@ static SPhysiNode* createScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode*
return NULL; return NULL;
} }
static SNodeList* createJoinOutputCols(SPhysiPlanContext* pCxt, STupleDescNode* pLeftTuple, STupleDescNode* pRightTuple) { static SNodeList* createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode* pLeftDesc, SDataBlockDescNode* pRightDesc) {
SNodeList* pCols = nodesMakeList(); SNodeList* pCols = nodesMakeList();
CHECK_ALLOC(pCols, NULL); CHECK_ALLOC(pCols, NULL);
SNode* pNode; SNode* pNode;
FOREACH(pNode, pLeftTuple->pSlots) { FOREACH(pNode, pLeftDesc->pSlots) {
SSlotDescNode* pSlot = (SSlotDescNode*)pNode; SSlotDescNode* pSlot = (SSlotDescNode*)pNode;
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
if (NULL == pCol) { if (NULL == pCol) {
goto error; goto error;
} }
pCol->node.resType = pSlot->dataType; pCol->node.resType = pSlot->dataType;
pCol->tupleId = pLeftTuple->tupleId; pCol->dataBlockId = pLeftDesc->dataBlockId;
pCol->slotId = pSlot->slotId; pCol->slotId = pSlot->slotId;
pCol->colId = -1; pCol->colId = -1;
if (TSDB_CODE_SUCCESS != nodesListAppend(pCols, (SNode*)pCol)) { if (TSDB_CODE_SUCCESS != nodesListAppend(pCols, (SNode*)pCol)) {
goto error; goto error;
} }
} }
FOREACH(pNode, pRightTuple->pSlots) { FOREACH(pNode, pRightDesc->pSlots) {
SSlotDescNode* pSlot = (SSlotDescNode*)pNode; SSlotDescNode* pSlot = (SSlotDescNode*)pNode;
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
if (NULL == pCol) { if (NULL == pCol) {
goto error; goto error;
} }
pCol->node.resType = pSlot->dataType; pCol->node.resType = pSlot->dataType;
pCol->tupleId = pRightTuple->tupleId; pCol->dataBlockId = pRightDesc->dataBlockId;
pCol->slotId = pSlot->slotId; pCol->slotId = pSlot->slotId;
pCol->colId = -1; pCol->colId = -1;
if (TSDB_CODE_SUCCESS != nodesListAppend(pCols, (SNode*)pCol)) { if (TSDB_CODE_SUCCESS != nodesListAppend(pCols, (SNode*)pCol)) {
...@@ -654,18 +658,18 @@ static SPhysiNode* createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil ...@@ -654,18 +658,18 @@ static SPhysiNode* createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_JOIN); SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_JOIN);
CHECK_ALLOC(pJoin, NULL); CHECK_ALLOC(pJoin, NULL);
STupleDescNode* pLeftTuple = &((SPhysiNode*)nodesListGetNode(pChildren, 0))->outputTuple; SDataBlockDescNode* pLeftDesc = &((SPhysiNode*)nodesListGetNode(pChildren, 0))->outputDataBlockDesc;
STupleDescNode* pRightTuple = &((SPhysiNode*)nodesListGetNode(pChildren, 1))->outputTuple; SDataBlockDescNode* pRightDesc = &((SPhysiNode*)nodesListGetNode(pChildren, 1))->outputDataBlockDesc;
pJoin->pOnConditions = setNodeSlotId(pCxt, pLeftTuple->tupleId, pRightTuple->tupleId, pJoinLogicNode->pOnConditions); pJoin->pOnConditions = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions);
CHECK_ALLOC(pJoin->pOnConditions, (SPhysiNode*)pJoin); CHECK_ALLOC(pJoin->pOnConditions, (SPhysiNode*)pJoin);
pJoin->pTargets = createJoinOutputCols(pCxt, pLeftTuple, pRightTuple); pJoin->pTargets = createJoinOutputCols(pCxt, pLeftDesc, pRightDesc);
CHECK_ALLOC(pJoin->pTargets, (SPhysiNode*)pJoin); CHECK_ALLOC(pJoin->pTargets, (SPhysiNode*)pJoin);
CHECK_CODE(addTupleDesc(pCxt, pJoin->pTargets, &pJoin->node.outputTuple), (SPhysiNode*)pJoin); CHECK_CODE(addDataBlockDesc(pCxt, pJoin->pTargets, &pJoin->node.outputDataBlockDesc), (SPhysiNode*)pJoin);
CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin), (SPhysiNode*)pJoin); CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin), (SPhysiNode*)pJoin);
CHECK_CODE(setSlotOutput(pCxt, pJoinLogicNode->node.pTargets, &pJoin->node.outputTuple), (SPhysiNode*)pJoin); CHECK_CODE(setSlotOutput(pCxt, pJoinLogicNode->node.pTargets, &pJoin->node.outputDataBlockDesc), (SPhysiNode*)pJoin);
return (SPhysiNode*)pJoin; return (SPhysiNode*)pJoin;
} }
...@@ -689,9 +693,14 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) ...@@ -689,9 +693,14 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
nodesDestroyNode(pExpr); nodesDestroyNode(pExpr);
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode); SExprNode* pRewrittenExpr = (SExprNode*)pExpr;
pCol->node.resType = pToBeRewrittenExpr->resType; pCol->node.resType = pRewrittenExpr->resType;
strcpy(pCol->colName, pToBeRewrittenExpr->aliasName); if ('\0' != pRewrittenExpr->aliasName[0]) {
strcpy(pCol->colName, pRewrittenExpr->aliasName);
} else {
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, pCxt->rewriteId);
strcpy(pCol->colName, pRewrittenExpr->aliasName);
}
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)pCol; *pNode = (SNode*)pCol;
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
...@@ -758,29 +767,29 @@ static SPhysiNode* createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild ...@@ -758,29 +767,29 @@ static SPhysiNode* createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
CHECK_CODE(rewritePrecalcExprs(pCxt, pAggLogicNode->pGroupKeys, &pPrecalcExprs, &pGroupKeys), (SPhysiNode*)pAgg); CHECK_CODE(rewritePrecalcExprs(pCxt, pAggLogicNode->pGroupKeys, &pPrecalcExprs, &pGroupKeys), (SPhysiNode*)pAgg);
CHECK_CODE(rewritePrecalcExprs(pCxt, pAggLogicNode->pAggFuncs, &pPrecalcExprs, &pAggFuncs), (SPhysiNode*)pAgg); CHECK_CODE(rewritePrecalcExprs(pCxt, pAggLogicNode->pAggFuncs, &pPrecalcExprs, &pAggFuncs), (SPhysiNode*)pAgg);
STupleDescNode* pChildTupe = &(((SPhysiNode*)nodesListGetNode(pChildren, 0))->outputTuple); SDataBlockDescNode* pChildTupe = &(((SPhysiNode*)nodesListGetNode(pChildren, 0))->outputDataBlockDesc);
// push down expression to outputTuple of child node // push down expression to outputDataBlockDesc of child node
if (NULL != pPrecalcExprs) { if (NULL != pPrecalcExprs) {
pAgg->pExprs = setListSlotId(pCxt, pChildTupe->tupleId, -1, pPrecalcExprs); pAgg->pExprs = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs);
CHECK_ALLOC(pAgg->pExprs, (SPhysiNode*)pAgg); CHECK_ALLOC(pAgg->pExprs, (SPhysiNode*)pAgg);
CHECK_CODE(addTupleDesc(pCxt, pAgg->pExprs, pChildTupe), (SPhysiNode*)pAgg); CHECK_CODE(addDataBlockDesc(pCxt, pAgg->pExprs, pChildTupe), (SPhysiNode*)pAgg);
} }
if (NULL != pGroupKeys) { if (NULL != pGroupKeys) {
pAgg->pGroupKeys = setListSlotId(pCxt, pChildTupe->tupleId, -1, pGroupKeys); pAgg->pGroupKeys = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pGroupKeys);
CHECK_ALLOC(pAgg->pGroupKeys, (SPhysiNode*)pAgg); CHECK_ALLOC(pAgg->pGroupKeys, (SPhysiNode*)pAgg);
CHECK_CODE(addTupleDesc(pCxt, pAgg->pGroupKeys, &pAgg->node.outputTuple), (SPhysiNode*)pAgg); CHECK_CODE(addDataBlockDesc(pCxt, pAgg->pGroupKeys, &pAgg->node.outputDataBlockDesc), (SPhysiNode*)pAgg);
} }
if (NULL != pAggFuncs) { if (NULL != pAggFuncs) {
pAgg->pAggFuncs = setListSlotId(pCxt, pChildTupe->tupleId, -1, pAggFuncs); pAgg->pAggFuncs = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pAggFuncs);
CHECK_ALLOC(pAgg->pAggFuncs, (SPhysiNode*)pAgg); CHECK_ALLOC(pAgg->pAggFuncs, (SPhysiNode*)pAgg);
CHECK_CODE(addTupleDesc(pCxt, pAgg->pAggFuncs, &pAgg->node.outputTuple), (SPhysiNode*)pAgg); CHECK_CODE(addDataBlockDesc(pCxt, pAgg->pAggFuncs, &pAgg->node.outputDataBlockDesc), (SPhysiNode*)pAgg);
} }
CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pAggLogicNode, (SPhysiNode*)pAgg), (SPhysiNode*)pAgg); CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pAggLogicNode, (SPhysiNode*)pAgg), (SPhysiNode*)pAgg);
CHECK_CODE(setSlotOutput(pCxt, pAggLogicNode->node.pTargets, &pAgg->node.outputTuple), (SPhysiNode*)pAgg); CHECK_CODE(setSlotOutput(pCxt, pAggLogicNode->node.pTargets, &pAgg->node.outputDataBlockDesc), (SPhysiNode*)pAgg);
return (SPhysiNode*)pAgg; return (SPhysiNode*)pAgg;
} }
...@@ -789,9 +798,9 @@ static SPhysiNode* createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC ...@@ -789,9 +798,9 @@ static SPhysiNode* createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_PROJECT); SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
CHECK_ALLOC(pProject, NULL); CHECK_ALLOC(pProject, NULL);
pProject->pProjections = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->outputTuple.tupleId, -1, pProjectLogicNode->pProjections); pProject->pProjections = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->outputDataBlockDesc.dataBlockId, -1, pProjectLogicNode->pProjections);
CHECK_ALLOC(pProject->pProjections, (SPhysiNode*)pProject); CHECK_ALLOC(pProject->pProjections, (SPhysiNode*)pProject);
CHECK_CODE(addTupleDesc(pCxt, pProject->pProjections, &pProject->node.outputTuple), (SPhysiNode*)pProject); CHECK_CODE(addDataBlockDesc(pCxt, pProject->pProjections, &pProject->node.outputDataBlockDesc), (SPhysiNode*)pProject);
CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject), (SPhysiNode*)pProject); CHECK_CODE(setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject), (SPhysiNode*)pProject);
...@@ -840,8 +849,8 @@ static SPhysiNode* createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicPl ...@@ -840,8 +849,8 @@ static SPhysiNode* createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicPl
} }
int32_t createPhysiPlan(SLogicNode* pLogicNode, SPhysiNode** pPhyNode) { int32_t createPhysiPlan(SLogicNode* pLogicNode, SPhysiNode** pPhyNode) {
SPhysiPlanContext cxt = { .errCode = TSDB_CODE_SUCCESS, .nextTupleId = 0, .pTupleHelper = taosArrayInit(32, POINTER_BYTES) }; SPhysiPlanContext cxt = { .errCode = TSDB_CODE_SUCCESS, .nextDataBlockId = 0, .pLocationHelper = taosArrayInit(32, POINTER_BYTES) };
if (NULL == cxt.pTupleHelper) { if (NULL == cxt.pLocationHelper) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
*pPhyNode = createPhysiNode(&cxt, pLogicNode); *pPhyNode = createPhysiNode(&cxt, pLogicNode);
......
...@@ -62,7 +62,7 @@ protected: ...@@ -62,7 +62,7 @@ protected:
return false; return false;
} }
cout << "sql : [" << cxt_.pSql << "]" << endl; cout << "====================sql : [" << cxt_.pSql << "]" << endl;
cout << "syntax test : " << endl; cout << "syntax test : " << endl;
cout << syntaxTreeStr << endl; cout << syntaxTreeStr << endl;
cout << "unformatted logic plan : " << endl; cout << "unformatted logic plan : " << endl;
...@@ -123,8 +123,8 @@ TEST_F(NewPlannerTest, simple) { ...@@ -123,8 +123,8 @@ TEST_F(NewPlannerTest, simple) {
TEST_F(NewPlannerTest, groupBy) { TEST_F(NewPlannerTest, groupBy) {
setDatabase("root", "test"); setDatabase("root", "test");
// bind("SELECT count(*) FROM t1"); bind("SELECT count(*) FROM t1");
// ASSERT_TRUE(run()); ASSERT_TRUE(run());
bind("SELECT c1, count(*) FROM t1 GROUP BY c1"); bind("SELECT c1, count(*) FROM t1 GROUP BY c1");
ASSERT_TRUE(run()); ASSERT_TRUE(run());
...@@ -132,7 +132,7 @@ TEST_F(NewPlannerTest, groupBy) { ...@@ -132,7 +132,7 @@ TEST_F(NewPlannerTest, groupBy) {
bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3"); bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
ASSERT_TRUE(run()); ASSERT_TRUE(run());
bind("SELECT c1 + c3, count(*) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
ASSERT_TRUE(run()); ASSERT_TRUE(run());
} }
......
...@@ -1455,7 +1455,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1455,7 +1455,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) {
SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i];
SColumnNode *refNode = (SColumnNode *)field->desc; SColumnNode *refNode = (SColumnNode *)field->desc;
qDebug("COL%d => [%d][%d]", i, refNode->tupleId, refNode->slotId); qDebug("COL%d => [%d][%d]", i, refNode->dataBlockId, refNode->slotId);
} }
qDebug("VALUE Field Num:%u", info->fields[FLD_TYPE_VALUE].num); qDebug("VALUE Field Num:%u", info->fields[FLD_TYPE_VALUE].num);
...@@ -1485,7 +1485,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1485,7 +1485,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit);
SColumnNode *refNode = (SColumnNode *)left->desc; SColumnNode *refNode = (SColumnNode *)left->desc;
if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS){ if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS){
len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->tupleId, refNode->slotId, gOptrStr[unit->compare.optr].str); len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->dataBlockId, refNode->slotId, gOptrStr[unit->compare.optr].str);
} }
if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
...@@ -1504,7 +1504,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1504,7 +1504,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
if (unit->compare.optr2) { if (unit->compare.optr2) {
strcat(str, " && "); strcat(str, " && ");
if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS){ if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS){
sprintf(str + strlen(str), "[%d][%d] %s [", refNode->tupleId, refNode->slotId, gOptrStr[unit->compare.optr2].str); sprintf(str + strlen(str), "[%d][%d] %s [", refNode->dataBlockId, refNode->slotId, gOptrStr[unit->compare.optr2].str);
} }
if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
......
...@@ -80,7 +80,7 @@ void flttMakeColRefNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -80,7 +80,7 @@ void flttMakeColRefNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
SColumnNode *rnode = (SColumnNode *)node; SColumnNode *rnode = (SColumnNode *)node;
rnode->node.resType.type = dataType; rnode->node.resType.type = dataType;
rnode->node.resType.bytes = dataBytes; rnode->node.resType.bytes = dataBytes;
rnode->tupleId = 0; rnode->dataBlockId = 0;
if (NULL == block) { if (NULL == block) {
rnode->slotId = 2; rnode->slotId = 2;
......
...@@ -108,7 +108,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -108,7 +108,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
SColumnNode *rnode = (SColumnNode *)node; SColumnNode *rnode = (SColumnNode *)node;
rnode->node.resType.type = dataType; rnode->node.resType.type = dataType;
rnode->node.resType.bytes = dataBytes; rnode->node.resType.bytes = dataBytes;
rnode->tupleId = 0; rnode->dataBlockId = 0;
if (NULL == *block) { if (NULL == *block) {
SSDataBlock *res = (SSDataBlock *)calloc(1, sizeof(SSDataBlock)); SSDataBlock *res = (SSDataBlock *)calloc(1, sizeof(SSDataBlock));
......
...@@ -14,3 +14,7 @@ target_include_directories( ...@@ -14,3 +14,7 @@ target_include_directories(
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
if(${BUILD_TEST})
add_subdirectory(test)
endif(${BUILD_TEST})
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h" #include "syncMessage.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h" #include "syncMessage.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "taosdef.h" #include "taosdef.h"
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -13,31 +13,35 @@ ...@@ -13,31 +13,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_ULOG_H #ifndef _TD_LIBS_SYNC_ENV_H
#define _TD_UTIL_ULOG_H #define _TD_LIBS_SYNC_ENV_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h" #include <stdint.h>
#include "tlog.h" #include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "taosdef.h"
#include "trpc.h"
extern int32_t uDebugFlag; typedef struct SSyncEnv {
extern int8_t tscEmbeddedInUtil; void *pTimer;
void *pTimerManager;
} SSyncEnv;
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }} int32_t syncEnvStart();
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); } int32_t syncEnvStop();
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
static int32_t doSyncEnvStart(SSyncEnv *pSyncEnv);
static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_ULOG_H*/ #endif /*_TD_LIBS_SYNC_ENV_H*/
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_LIBS_IO_H
#define _TD_LIBS_IO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "os.h"
#include "syncInt.h"
#include "taosdef.h"
#include "tqueue.h"
#include "trpc.h"
typedef struct SSyncIO {
void * serverRpc;
void * clientRpc;
STaosQueue *pMsgQ;
STaosQset * pQset;
pthread_t tid;
int8_t isStart;
SEpSet epSet;
void *syncTimer;
void *syncTimerManager;
int32_t (*start)(struct SSyncIO *ths);
int32_t (*stop)(struct SSyncIO *ths);
int32_t (*ping)(struct SSyncIO *ths);
int32_t (*onMsg)(struct SSyncIO *ths, void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
int32_t (*destroy)(struct SSyncIO *ths);
void *pSyncNode;
int32_t (*FpOnPing)(struct SSyncNode *ths, SyncPing *pMsg);
} SSyncIO;
extern SSyncIO *gSyncIO;
int32_t syncIOStart();
int32_t syncIOStop();
int32_t syncIOSendMsg(void *handle, const SEpSet *pEpSet, SRpcMsg *pMsg);
SSyncIO *syncIOCreate();
static int32_t doSyncIOStart(SSyncIO *io);
static int32_t doSyncIOStop(SSyncIO *io);
static int32_t doSyncIOPing(SSyncIO *io);
static int32_t doSyncIOOnMsg(struct SSyncIO *io, void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
static int32_t doSyncIODestroy(SSyncIO *io);
#ifdef __cplusplus
}
#endif
#endif /*_TD_LIBS_IO_H*/
...@@ -23,7 +23,11 @@ extern "C" { ...@@ -23,7 +23,11 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "sync.h"
#include "taosdef.h" #include "taosdef.h"
#include "tlog.h"
extern int32_t sDebugFlag;
#define sFatal(...) \ #define sFatal(...) \
{ \ { \
...@@ -62,16 +66,81 @@ extern "C" { ...@@ -62,16 +66,81 @@ extern "C" {
} \ } \
} }
struct SRaft;
typedef struct SRaft SRaft;
struct SyncPing;
typedef struct SyncPing SyncPing;
struct SyncPingReply;
typedef struct SyncPingReply SyncPingReply;
struct SyncRequestVote;
typedef struct SyncRequestVote SyncRequestVote;
struct SyncRequestVoteReply;
typedef struct SyncRequestVoteReply SyncRequestVoteReply;
struct SyncAppendEntries;
typedef struct SyncAppendEntries SyncAppendEntries;
struct SyncAppendEntriesReply;
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
typedef struct SSyncNode { typedef struct SSyncNode {
char path[TSDB_FILENAME_LEN];
int8_t replica; int8_t replica;
int8_t quorum; int8_t quorum;
int8_t selfIndex;
uint32_t vgId; SyncGroupId vgId;
int32_t refCount; SSyncCfg syncCfg;
int64_t rid; char path[TSDB_FILENAME_LEN];
SRaft* pRaft;
int32_t (*FpPing)(struct SSyncNode* ths, const SyncPing* pMsg);
int32_t (*FpOnPing)(struct SSyncNode* ths, SyncPing* pMsg);
int32_t (*FpOnPingReply)(struct SSyncNode* ths, SyncPingReply* pMsg);
int32_t (*FpRequestVote)(struct SSyncNode* ths, const SyncRequestVote* pMsg);
int32_t (*FpOnRequestVote)(struct SSyncNode* ths, SyncRequestVote* pMsg);
int32_t (*FpOnRequestVoteReply)(struct SSyncNode* ths, SyncRequestVoteReply* pMsg);
int32_t (*FpAppendEntries)(struct SSyncNode* ths, const SyncAppendEntries* pMsg);
int32_t (*FpOnAppendEntries)(struct SSyncNode* ths, SyncAppendEntries* pMsg);
int32_t (*FpOnAppendEntriesReply)(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg);
int32_t (*FpSendMsg)(void* handle, const SEpSet* pEpSet, SRpcMsg* pMsg);
} SSyncNode; } SSyncNode;
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo);
void syncNodeClose(SSyncNode* pSyncNode);
static int32_t doSyncNodePing(struct SSyncNode* ths, const SyncPing* pMsg);
static int32_t onSyncNodePing(struct SSyncNode* ths, SyncPing* pMsg);
static int32_t onSyncNodePingReply(struct SSyncNode* ths, SyncPingReply* pMsg);
static int32_t doSyncNodeRequestVote(struct SSyncNode* ths, const SyncRequestVote* pMsg);
static int32_t onSyncNodeRequestVote(struct SSyncNode* ths, SyncRequestVote* pMsg);
static int32_t onSyncNodeRequestVoteReply(struct SSyncNode* ths, SyncRequestVoteReply* pMsg);
static int32_t doSyncNodeAppendEntries(struct SSyncNode* ths, const SyncAppendEntries* pMsg);
static int32_t onSyncNodeAppendEntries(struct SSyncNode* ths, SyncAppendEntries* pMsg);
static int32_t onSyncNodeAppendEntriesReply(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -41,26 +41,26 @@ typedef enum ESyncMessageType { ...@@ -41,26 +41,26 @@ typedef enum ESyncMessageType {
typedef struct SyncPing { typedef struct SyncPing {
ESyncMessageType msgType; ESyncMessageType msgType;
const SSyncBuffer *pData; const SSyncBuffer *pData;
} SyncPing; } SyncPing, RaftPing;
typedef struct SyncPingReply { typedef struct SyncPingReply {
ESyncMessageType msgType; ESyncMessageType msgType;
const SSyncBuffer *pData; const SSyncBuffer *pData;
} SyncPingReply; } SyncPingReply, RaftPingReply;
typedef struct SyncClientRequest { typedef struct SyncClientRequest {
ESyncMessageType msgType; ESyncMessageType msgType;
const SSyncBuffer *pData; const SSyncBuffer *pData;
int64_t seqNum; int64_t seqNum;
bool isWeak; bool isWeak;
} SyncClientRequest; } SyncClientRequest, RaftClientRequest;
typedef struct SyncClientRequestReply { typedef struct SyncClientRequestReply {
ESyncMessageType msgType; ESyncMessageType msgType;
int32_t errCode; int32_t errCode;
const SSyncBuffer *pErrMsg; const SSyncBuffer *pErrMsg;
const SSyncBuffer *pLeaderHint; const SSyncBuffer *pLeaderHint;
} SyncClientRequestReply; } SyncClientRequestReply, RaftClientRequestReply;
typedef struct SyncRequestVote { typedef struct SyncRequestVote {
ESyncMessageType msgType; ESyncMessageType msgType;
...@@ -69,7 +69,7 @@ typedef struct SyncRequestVote { ...@@ -69,7 +69,7 @@ typedef struct SyncRequestVote {
SyncGroupId vgId; SyncGroupId vgId;
SyncIndex lastLogIndex; SyncIndex lastLogIndex;
SyncTerm lastLogTerm; SyncTerm lastLogTerm;
} SyncRequestVote; } SyncRequestVote, RaftRequestVote;
typedef struct SyncRequestVoteReply { typedef struct SyncRequestVoteReply {
ESyncMessageType msgType; ESyncMessageType msgType;
...@@ -77,7 +77,7 @@ typedef struct SyncRequestVoteReply { ...@@ -77,7 +77,7 @@ typedef struct SyncRequestVoteReply {
SyncNodeId nodeId; SyncNodeId nodeId;
SyncGroupId vgId; SyncGroupId vgId;
bool voteGranted; bool voteGranted;
} SyncRequestVoteReply; } SyncRequestVoteReply, RaftRequestVoteReply;
typedef struct SyncAppendEntries { typedef struct SyncAppendEntries {
ESyncMessageType msgType; ESyncMessageType msgType;
...@@ -88,7 +88,7 @@ typedef struct SyncAppendEntries { ...@@ -88,7 +88,7 @@ typedef struct SyncAppendEntries {
int32_t entryCount; int32_t entryCount;
SSyncRaftEntry * logEntries; SSyncRaftEntry * logEntries;
SyncIndex commitIndex; SyncIndex commitIndex;
} SyncAppendEntries; } SyncAppendEntries, RaftAppendEntries;
typedef struct SyncAppendEntriesReply { typedef struct SyncAppendEntriesReply {
ESyncMessageType msgType; ESyncMessageType msgType;
...@@ -96,7 +96,7 @@ typedef struct SyncAppendEntriesReply { ...@@ -96,7 +96,7 @@ typedef struct SyncAppendEntriesReply {
SyncNodeId nodeId; SyncNodeId nodeId;
bool success; bool success;
SyncIndex matchIndex; SyncIndex matchIndex;
} SyncAppendEntriesReply; } SyncAppendEntriesReply, RaftAppendEntriesReply;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -28,14 +28,56 @@ extern "C" { ...@@ -28,14 +28,56 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
typedef struct SRaftId { typedef struct SRaftId {
SyncNodeId nodeId; SyncNodeId addr;
SyncGroupId vgId; SyncGroupId vgId;
} SRaftId; } SRaftId;
typedef struct SRaft { typedef struct SRaft {
SRaftId id; SRaftId id;
SSyncFSM* pFsm;
int32_t (*FpPing)(struct SRaft* ths, const RaftPing* pMsg);
int32_t (*FpOnPing)(struct SRaft* ths, RaftPing* pMsg);
int32_t (*FpOnPingReply)(struct SRaft* ths, RaftPingReply* pMsg);
int32_t (*FpRequestVote)(struct SRaft* ths, const RaftRequestVote* pMsg);
int32_t (*FpOnRequestVote)(struct SRaft* ths, RaftRequestVote* pMsg);
int32_t (*FpOnRequestVoteReply)(struct SRaft* ths, RaftRequestVoteReply* pMsg);
int32_t (*FpAppendEntries)(struct SRaft* ths, const RaftAppendEntries* pMsg);
int32_t (*FpOnAppendEntries)(struct SRaft* ths, RaftAppendEntries* pMsg);
int32_t (*FpOnAppendEntriesReply)(struct SRaft* ths, RaftAppendEntriesReply* pMsg);
} SRaft; } SRaft;
SRaft* raftOpen(SRaftId raftId, SSyncFSM* pFsm);
void raftClose(SRaft* pRaft);
static int32_t doRaftPing(struct SRaft* ths, const RaftPing* pMsg);
static int32_t onRaftPing(struct SRaft* ths, RaftPing* pMsg);
static int32_t onRaftPingReply(struct SRaft* ths, RaftPingReply* pMsg);
static int32_t doRaftRequestVote(struct SRaft* ths, const RaftRequestVote* pMsg);
static int32_t onRaftRequestVote(struct SRaft* ths, RaftRequestVote* pMsg);
static int32_t onRaftRequestVoteReply(struct SRaft* ths, RaftRequestVoteReply* pMsg);
static int32_t doRaftAppendEntries(struct SRaft* ths, const RaftAppendEntries* pMsg);
static int32_t onRaftAppendEntries(struct SRaft* ths, RaftAppendEntries* pMsg);
static int32_t onRaftAppendEntriesReply(struct SRaft* ths, RaftAppendEntriesReply* pMsg);
int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak); int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak);
static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft); static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft);
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_LIBS_TPL_H #ifndef _TD_LIBS_SYNC_RAFT_ENTRY_H
#define _TD_LIBS_TPL_H #define _TD_LIBS_SYNC_RAFT_ENTRY_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "sync.h" #include "syncInt.h"
#include "taosdef.h" #include "taosdef.h"
typedef struct SSyncRaftEntry { typedef struct SSyncRaftEntry {
...@@ -37,4 +37,4 @@ typedef struct SSyncRaftEntry { ...@@ -37,4 +37,4 @@ typedef struct SSyncRaftEntry {
} }
#endif #endif
#endif /*_TD_LIBS_TPL_H*/ #endif /*_TD_LIBS_SYNC_RAFT_ENTRY_H*/
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "sync.h" #include "syncInt.h"
#include "taosdef.h" #include "taosdef.h"
int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf); int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf);
......
...@@ -23,17 +23,36 @@ extern "C" { ...@@ -23,17 +23,36 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "sync.h" #include "cJSON.h"
#include "syncInt.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
int32_t currentTerm(SyncTerm *pCurrentTerm); #define RAFT_STORE_BLOCK_SIZE 512
#define RAFT_STORE_PATH_LEN 128
int32_t persistCurrentTerm(SyncTerm currentTerm); typedef struct SRaftStore {
SyncTerm currentTerm;
SRaftId voteFor;
//FileFd fd;
char path[RAFT_STORE_PATH_LEN];
} SRaftStore;
int32_t voteFor(SRaftId *pRaftId); SRaftStore *raftStoreOpen(const char *path);
int32_t persistVoteFor(SRaftId *pRaftId); static int32_t raftStoreInit(SRaftStore *pRaftStore);
int32_t raftStoreClose(SRaftStore *pRaftStore);
int32_t raftStorePersist(SRaftStore *pRaftStore);
static bool raftStoreFileExist(char *path);
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len);
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len);
void raftStorePrint(SRaftStore *pRaftStore);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "taosdef.h" #include "taosdef.h"
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h" #include "syncMessage.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h" #include "syncMessage.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
......
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "sync.h" #include "syncInt.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h" #include "syncMessage.h"
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_LIBS_SYNC_VOTG_MGR_H
#define _TD_LIBS_SYNC_VOTG_MGR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "taosdef.h"
#ifdef __cplusplus
}
#endif
#endif /*_TD_LIBS_SYNC_VOTG_MGR_H*/
...@@ -14,104 +14,98 @@ ...@@ -14,104 +14,98 @@
*/ */
#include "syncAppendEntries.h" #include "syncAppendEntries.h"
#include "sync.h"
void appendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) { void appendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) {
// TLA+ Spec
// TLA+ Spec // AppendEntries(i, j) ==
//AppendEntries(i, j) == // /\ i /= j
// /\ i /= j // /\ state[i] = Leader
// /\ state[i] = Leader // /\ LET prevLogIndex == nextIndex[i][j] - 1
// /\ LET prevLogIndex == nextIndex[i][j] - 1 // prevLogTerm == IF prevLogIndex > 0 THEN
// prevLogTerm == IF prevLogIndex > 0 THEN // log[i][prevLogIndex].term
// log[i][prevLogIndex].term // ELSE
// ELSE // 0
// 0 // \* Send up to 1 entry, constrained by the end of the log.
// \* Send up to 1 entry, constrained by the end of the log. // lastEntry == Min({Len(log[i]), nextIndex[i][j]})
// lastEntry == Min({Len(log[i]), nextIndex[i][j]}) // entries == SubSeq(log[i], nextIndex[i][j], lastEntry)
// entries == SubSeq(log[i], nextIndex[i][j], lastEntry) // IN Send([mtype |-> AppendEntriesRequest,
// IN Send([mtype |-> AppendEntriesRequest, // mterm |-> currentTerm[i],
// mterm |-> currentTerm[i], // mprevLogIndex |-> prevLogIndex,
// mprevLogIndex |-> prevLogIndex, // mprevLogTerm |-> prevLogTerm,
// mprevLogTerm |-> prevLogTerm, // mentries |-> entries,
// mentries |-> entries, // \* mlog is used as a history variable for the proof.
// \* mlog is used as a history variable for the proof. // \* It would not exist in a real implementation.
// \* It would not exist in a real implementation. // mlog |-> log[i],
// mlog |-> log[i], // mcommitIndex |-> Min({commitIndex[i], lastEntry}),
// mcommitIndex |-> Min({commitIndex[i], lastEntry}), // msource |-> i,
// msource |-> i, // mdest |-> j])
// mdest |-> j]) // /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
} }
void onAppendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) { void onAppendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) {
// TLA+ Spec
// TLA+ Spec // HandleAppendEntriesRequest(i, j, m) ==
//HandleAppendEntriesRequest(i, j, m) == // LET logOk == \/ m.mprevLogIndex = 0
// LET logOk == \/ m.mprevLogIndex = 0 // \/ /\ m.mprevLogIndex > 0
// \/ /\ m.mprevLogIndex > 0 // /\ m.mprevLogIndex <= Len(log[i])
// /\ m.mprevLogIndex <= Len(log[i]) // /\ m.mprevLogTerm = log[i][m.mprevLogIndex].term
// /\ m.mprevLogTerm = log[i][m.mprevLogIndex].term // IN /\ m.mterm <= currentTerm[i]
// IN /\ m.mterm <= currentTerm[i] // /\ \/ /\ \* reject request
// /\ \/ /\ \* reject request // \/ m.mterm < currentTerm[i]
// \/ m.mterm < currentTerm[i] // \/ /\ m.mterm = currentTerm[i]
// \/ /\ m.mterm = currentTerm[i] // /\ state[i] = Follower
// /\ state[i] = Follower // /\ \lnot logOk
// /\ \lnot logOk // /\ Reply([mtype |-> AppendEntriesResponse,
// /\ Reply([mtype |-> AppendEntriesResponse, // mterm |-> currentTerm[i],
// mterm |-> currentTerm[i], // msuccess |-> FALSE,
// msuccess |-> FALSE, // mmatchIndex |-> 0,
// mmatchIndex |-> 0, // msource |-> i,
// msource |-> i, // mdest |-> j],
// mdest |-> j], // m)
// m) // /\ UNCHANGED <<serverVars, logVars>>
// /\ UNCHANGED <<serverVars, logVars>> // \/ \* return to follower state
// \/ \* return to follower state // /\ m.mterm = currentTerm[i]
// /\ m.mterm = currentTerm[i] // /\ state[i] = Candidate
// /\ state[i] = Candidate // /\ state' = [state EXCEPT ![i] = Follower]
// /\ state' = [state EXCEPT ![i] = Follower] // /\ UNCHANGED <<currentTerm, votedFor, logVars, messages>>
// /\ UNCHANGED <<currentTerm, votedFor, logVars, messages>> // \/ \* accept request
// \/ \* accept request // /\ m.mterm = currentTerm[i]
// /\ m.mterm = currentTerm[i] // /\ state[i] = Follower
// /\ state[i] = Follower // /\ logOk
// /\ logOk // /\ LET index == m.mprevLogIndex + 1
// /\ LET index == m.mprevLogIndex + 1 // IN \/ \* already done with request
// IN \/ \* already done with request // /\ \/ m.mentries = << >>
// /\ \/ m.mentries = << >> // \/ /\ m.mentries /= << >>
// \/ /\ m.mentries /= << >> // /\ Len(log[i]) >= index
// /\ Len(log[i]) >= index // /\ log[i][index].term = m.mentries[1].term
// /\ log[i][index].term = m.mentries[1].term // \* This could make our commitIndex decrease (for
// \* This could make our commitIndex decrease (for // \* example if we process an old, duplicated request),
// \* example if we process an old, duplicated request), // \* but that doesn't really affect anything.
// \* but that doesn't really affect anything. // /\ commitIndex' = [commitIndex EXCEPT ![i] =
// /\ commitIndex' = [commitIndex EXCEPT ![i] = // m.mcommitIndex]
// m.mcommitIndex] // /\ Reply([mtype |-> AppendEntriesResponse,
// /\ Reply([mtype |-> AppendEntriesResponse, // mterm |-> currentTerm[i],
// mterm |-> currentTerm[i], // msuccess |-> TRUE,
// msuccess |-> TRUE, // mmatchIndex |-> m.mprevLogIndex +
// mmatchIndex |-> m.mprevLogIndex + // Len(m.mentries),
// Len(m.mentries), // msource |-> i,
// msource |-> i, // mdest |-> j],
// mdest |-> j], // m)
// m) // /\ UNCHANGED <<serverVars, log>>
// /\ UNCHANGED <<serverVars, log>> // \/ \* conflict: remove 1 entry
// \/ \* conflict: remove 1 entry // /\ m.mentries /= << >>
// /\ m.mentries /= << >> // /\ Len(log[i]) >= index
// /\ Len(log[i]) >= index // /\ log[i][index].term /= m.mentries[1].term
// /\ log[i][index].term /= m.mentries[1].term // /\ LET new == [index2 \in 1..(Len(log[i]) - 1) |->
// /\ LET new == [index2 \in 1..(Len(log[i]) - 1) |-> // log[i][index2]]
// log[i][index2]] // IN log' = [log EXCEPT ![i] = new]
// IN log' = [log EXCEPT ![i] = new] // /\ UNCHANGED <<serverVars, commitIndex, messages>>
// /\ UNCHANGED <<serverVars, commitIndex, messages>> // \/ \* no conflict: append entry
// \/ \* no conflict: append entry // /\ m.mentries /= << >>
// /\ m.mentries /= << >> // /\ Len(log[i]) = m.mprevLogIndex
// /\ Len(log[i]) = m.mprevLogIndex // /\ log' = [log EXCEPT ![i] =
// /\ log' = [log EXCEPT ![i] = // Append(log[i], m.mentries[1])]
// Append(log[i], m.mentries[1])] // /\ UNCHANGED <<serverVars, commitIndex, messages>>
// /\ UNCHANGED <<serverVars, commitIndex, messages>> // /\ UNCHANGED <<candidateVars, leaderVars>>
// /\ UNCHANGED <<candidateVars, leaderVars>> //
//
} }
...@@ -14,21 +14,18 @@ ...@@ -14,21 +14,18 @@
*/ */
#include "syncAppendEntriesReply.h" #include "syncAppendEntriesReply.h"
#include "sync.h"
void onAppendEntriesReply(SRaft *pRaft, const SyncAppendEntriesReply *pMsg) { void onAppendEntriesReply(SRaft *pRaft, const SyncAppendEntriesReply *pMsg) {
// TLA+ Spec
// TLA+ Spec // HandleAppendEntriesResponse(i, j, m) ==
//HandleAppendEntriesResponse(i, j, m) == // /\ m.mterm = currentTerm[i]
// /\ m.mterm = currentTerm[i] // /\ \/ /\ m.msuccess \* successful
// /\ \/ /\ m.msuccess \* successful // /\ nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
// /\ nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] // /\ matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
// /\ matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex] // \/ /\ \lnot m.msuccess \* not successful
// \/ /\ \lnot m.msuccess \* not successful // /\ nextIndex' = [nextIndex EXCEPT ![i][j] =
// /\ nextIndex' = [nextIndex EXCEPT ![i][j] = // Max({nextIndex[i][j] - 1, 1})]
// Max({nextIndex[i][j] - 1, 1})] // /\ UNCHANGED <<matchIndex>>
// /\ UNCHANGED <<matchIndex>> // /\ Discard(m)
// /\ Discard(m) // /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
} }
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "sync.h" #include "syncElection.h"
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "syncEnv.h"
#include <assert.h>
SSyncEnv *gSyncEnv = NULL;
int32_t syncEnvStart() {
int32_t ret;
gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
assert(gSyncEnv != NULL);
ret = doSyncEnvStart(gSyncEnv);
return ret;
}
int32_t syncEnvStop() {
int32_t ret = doSyncEnvStop(gSyncEnv);
return ret;
}
static int32_t doSyncEnvStart(SSyncEnv *pSyncEnv) { return 0; }
static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv) { return 0; }
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "syncIO.h"
#include <tep.h>
#include "syncOnMessage.h"
#include "tglobal.h"
#include "ttimer.h"
#include "tutil.h"
SSyncIO *gSyncIO = NULL;
int32_t syncIOSendMsg(void *handle, const SEpSet *pEpSet, SRpcMsg *pMsg) { return 0; }
int32_t syncIOStart() { return 0; }
int32_t syncIOStop() { return 0; }
static void syncTick(void *param, void *tmrId) {
SSyncIO *io = (SSyncIO *)param;
sDebug("syncTick ... ");
SRpcMsg rpcMsg;
rpcMsg.pCont = rpcMallocCont(10);
snprintf(rpcMsg.pCont, 10, "TICK");
rpcMsg.contLen = 10;
rpcMsg.handle = NULL;
rpcMsg.msgType = 2;
SRpcMsg *pTemp;
pTemp = taosAllocateQitem(sizeof(SRpcMsg));
memcpy(pTemp, &rpcMsg, sizeof(SRpcMsg));
taosWriteQitem(io->pMsgQ, pTemp);
io->syncTimer = taosTmrStart(syncTick, 1000, io, io->syncTimerManager);
}
void *syncConsumer(void *param) {
SSyncIO *io = param;
STaosQall *qall;
SRpcMsg * pRpcMsg, rpcMsg;
int type;
qall = taosAllocateQall();
while (1) {
int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, NULL, NULL);
sDebug("%d sync-io msgs are received", numOfMsgs);
if (numOfMsgs <= 0) break;
for (int i = 0; i < numOfMsgs; ++i) {
taosGetQitem(qall, (void **)&pRpcMsg);
sDebug("sync-io recv type:%d msg:%s", pRpcMsg->msgType, (char *)(pRpcMsg->pCont));
}
taosResetQitems(qall);
for (int i = 0; i < numOfMsgs; ++i) {
taosGetQitem(qall, (void **)&pRpcMsg);
rpcFreeCont(pRpcMsg->pCont);
if (pRpcMsg->handle != NULL) {
int msgSize = 128;
memset(&rpcMsg, 0, sizeof(rpcMsg));
rpcMsg.pCont = rpcMallocCont(msgSize);
rpcMsg.contLen = msgSize;
rpcMsg.handle = pRpcMsg->handle;
rpcMsg.code = 0;
rpcSendResponse(&rpcMsg);
}
taosFreeQitem(pRpcMsg);
}
}
taosFreeQall(qall);
return NULL;
}
static int retrieveAuthInfo(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey) {
// app shall retrieve the auth info based on meterID from DB or a data file
// demo code here only for simple demo
int ret = 0;
return ret;
}
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
sDebug("processResponse ... ");
rpcFreeCont(pMsg->pCont);
}
static void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
SSyncIO *io = pParent;
SRpcMsg *pTemp;
pTemp = taosAllocateQitem(sizeof(SRpcMsg));
memcpy(pTemp, pMsg, sizeof(SRpcMsg));
sDebug("request is received, type:%d, contLen:%d, item:%p", pMsg->msgType, pMsg->contLen, pTemp);
taosWriteQitem(io->pMsgQ, pTemp);
}
SSyncIO *syncIOCreate() {
SSyncIO *io = (SSyncIO *)malloc(sizeof(SSyncIO));
memset(io, 0, sizeof(*io));
io->pMsgQ = taosOpenQueue();
io->pQset = taosOpenQset();
taosAddIntoQset(io->pQset, io->pMsgQ, NULL);
io->start = doSyncIOStart;
io->stop = doSyncIOStop;
io->ping = doSyncIOPing;
io->onMsg = doSyncIOOnMsg;
io->destroy = doSyncIODestroy;
return io;
}
static int32_t doSyncIOStart(SSyncIO *io) {
taosBlockSIGPIPE();
tsRpcForceTcp = 1;
// cient rpc init
{
SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localPort = 0;
rpcInit.label = "SYNC-IO-CLIENT";
rpcInit.numOfThreads = 1;
rpcInit.cfp = processResponse;
rpcInit.sessions = 100;
rpcInit.idleTime = 100;
rpcInit.user = "sync-io";
rpcInit.secret = "sync-io";
rpcInit.ckey = "key";
rpcInit.spi = 0;
rpcInit.connType = TAOS_CONN_CLIENT;
io->clientRpc = rpcOpen(&rpcInit);
if (io->clientRpc == NULL) {
sError("failed to initialize RPC");
return -1;
}
}
// server rpc init
{
SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localPort = 38000;
rpcInit.label = "SYNC-IO-SERVER";
rpcInit.numOfThreads = 1;
rpcInit.cfp = processRequestMsg;
rpcInit.sessions = 1000;
rpcInit.idleTime = 2 * 1500;
rpcInit.afp = retrieveAuthInfo;
rpcInit.parent = io;
rpcInit.connType = TAOS_CONN_SERVER;
void *pRpc = rpcOpen(&rpcInit);
if (pRpc == NULL) {
sError("failed to start RPC server");
return -1;
}
}
io->epSet.inUse = 0;
addEpIntoEpSet(&io->epSet, "127.0.0.1", 38000);
// start consumer thread
{
if (pthread_create(&io->tid, NULL, syncConsumer, io) != 0) {
sError("failed to create sync consumer thread since %s", strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
}
// start tmr thread
io->syncTimerManager = taosTmrInit(1000, 50, 10000, "SYNC");
io->syncTimer = taosTmrStart(syncTick, 1000, io, io->syncTimerManager);
return 0;
}
static int32_t doSyncIOStop(SSyncIO *io) {
atomic_store_8(&io->isStart, 0);
pthread_join(io->tid, NULL);
return 0;
}
static int32_t doSyncIOPing(SSyncIO *io) {
SRpcMsg rpcMsg, rspMsg;
rpcMsg.pCont = rpcMallocCont(10);
snprintf(rpcMsg.pCont, 10, "ping");
rpcMsg.contLen = 10;
rpcMsg.handle = NULL;
rpcMsg.msgType = 1;
rpcSendRequest(io->clientRpc, &io->epSet, &rpcMsg, NULL);
return 0;
}
static int32_t doSyncIOOnMsg(struct SSyncIO *io, void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) { return 0; }
static int32_t doSyncIODestroy(SSyncIO *io) {
int8_t start = atomic_load_8(&io->isStart);
assert(start == 0);
if (io->serverRpc != NULL) {
free(io->serverRpc);
io->serverRpc = NULL;
}
if (io->clientRpc != NULL) {
free(io->clientRpc);
io->clientRpc = NULL;
}
if (io->pMsgQ != NULL) {
free(io->pMsgQ);
io->pMsgQ = NULL;
}
if (io->pQset != NULL) {
free(io->pQset);
io->pQset = NULL;
}
return 0;
}
...@@ -16,12 +16,17 @@ ...@@ -16,12 +16,17 @@
#include <stdint.h> #include <stdint.h>
#include "sync.h" #include "sync.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaft.h"
int32_t syncInit() { return 0; } int32_t syncInit() { return 0; }
void syncCleanUp() {} void syncCleanUp() {}
int64_t syncStart(const SSyncInfo* pSyncInfo) { return 0; } int64_t syncStart(const SSyncInfo* pSyncInfo) {
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
assert(pSyncNode != NULL);
return 0;
}
void syncStop(int64_t rid) {} void syncStop(int64_t rid) {}
...@@ -32,3 +37,73 @@ int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak) { r ...@@ -32,3 +37,73 @@ int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak) { r
ESyncState syncGetMyRole(int64_t rid) { return TAOS_SYNC_STATE_LEADER; } ESyncState syncGetMyRole(int64_t rid) { return TAOS_SYNC_STATE_LEADER; }
void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {} void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {}
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
SSyncNode* pSyncNode = (SSyncNode*)malloc(sizeof(SSyncNode));
assert(pSyncNode != NULL);
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
pSyncNode->FpPing = doSyncNodePing;
pSyncNode->FpOnPing = onSyncNodePing;
pSyncNode->FpOnPingReply = onSyncNodePingReply;
pSyncNode->FpRequestVote = doSyncNodeRequestVote;
pSyncNode->FpOnRequestVote = onSyncNodeRequestVote;
pSyncNode->FpOnRequestVoteReply = onSyncNodeRequestVoteReply;
pSyncNode->FpAppendEntries = doSyncNodeAppendEntries;
pSyncNode->FpOnAppendEntries = onSyncNodeAppendEntries;
pSyncNode->FpOnAppendEntriesReply = onSyncNodeAppendEntriesReply;
return pSyncNode;
}
void syncNodeClose(SSyncNode* pSyncNode) {
assert(pSyncNode != NULL);
raftClose(pSyncNode->pRaft);
free(pSyncNode);
}
static int32_t doSyncNodePing(struct SSyncNode* ths, const SyncPing* pMsg) {
int32_t ret = ths->pRaft->FpPing(ths->pRaft, pMsg);
return ret;
}
static int32_t onSyncNodePing(struct SSyncNode* ths, SyncPing* pMsg) {
int32_t ret = ths->pRaft->FpOnPing(ths->pRaft, pMsg);
return ret;
}
static int32_t onSyncNodePingReply(struct SSyncNode* ths, SyncPingReply* pMsg) {
int32_t ret = ths->pRaft->FpOnPingReply(ths->pRaft, pMsg);
return ret;
}
static int32_t doSyncNodeRequestVote(struct SSyncNode* ths, const SyncRequestVote* pMsg) {
int32_t ret = ths->pRaft->FpRequestVote(ths->pRaft, pMsg);
return ret;
}
static int32_t onSyncNodeRequestVote(struct SSyncNode* ths, SyncRequestVote* pMsg) {
int32_t ret = ths->pRaft->FpOnRequestVote(ths->pRaft, pMsg);
return ret;
}
static int32_t onSyncNodeRequestVoteReply(struct SSyncNode* ths, SyncRequestVoteReply* pMsg) {
int32_t ret = ths->pRaft->FpOnRequestVoteReply(ths->pRaft, pMsg);
return ret;
}
static int32_t doSyncNodeAppendEntries(struct SSyncNode* ths, const SyncAppendEntries* pMsg) {
int32_t ret = ths->pRaft->FpAppendEntries(ths->pRaft, pMsg);
return ret;
}
static int32_t onSyncNodeAppendEntries(struct SSyncNode* ths, SyncAppendEntries* pMsg) {
int32_t ret = ths->pRaft->FpOnAppendEntries(ths->pRaft, pMsg);
return ret;
}
static int32_t onSyncNodeAppendEntriesReply(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
int32_t ret = ths->pRaft->FpOnAppendEntriesReply(ths->pRaft, pMsg);
return ret;
}
\ No newline at end of file
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include "syncMessage.h" #include "syncMessage.h"
#include "sync.h"
#include "syncRaft.h" #include "syncRaft.h"
void onMessage(SRaft *pRaft, void *pMsg) {} void onMessage(SRaft *pRaft, void *pMsg) {}
\ No newline at end of file
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "sync.h" #include "syncOnMessage.h"
...@@ -16,6 +16,51 @@ ...@@ -16,6 +16,51 @@
#include "syncRaft.h" #include "syncRaft.h"
#include "sync.h" #include "sync.h"
SRaft* raftOpen(SRaftId raftId, SSyncFSM* pFsm) {
SRaft* pRaft = (SRaft*)malloc(sizeof(SRaft));
assert(pRaft != NULL);
pRaft->id = raftId;
pRaft->pFsm = pFsm;
pRaft->FpPing = doRaftPing;
pRaft->FpOnPing = onRaftPing;
pRaft->FpOnPingReply = onRaftPingReply;
pRaft->FpRequestVote = doRaftRequestVote;
pRaft->FpOnRequestVote = onRaftRequestVote;
pRaft->FpOnRequestVoteReply = onRaftRequestVoteReply;
pRaft->FpAppendEntries = doRaftAppendEntries;
pRaft->FpOnAppendEntries = onRaftAppendEntries;
pRaft->FpOnAppendEntriesReply = onRaftAppendEntriesReply;
return pRaft;
}
void raftClose(SRaft* pRaft) {
assert(pRaft != NULL);
free(pRaft);
}
static int32_t doRaftPing(struct SRaft* ths, const RaftPing* pMsg) { return 0; }
static int32_t onRaftPing(struct SRaft* ths, RaftPing* pMsg) { return 0; }
static int32_t onRaftPingReply(struct SRaft* ths, RaftPingReply* pMsg) { return 0; }
static int32_t doRaftRequestVote(struct SRaft* ths, const RaftRequestVote* pMsg) { return 0; }
static int32_t onRaftRequestVote(struct SRaft* ths, RaftRequestVote* pMsg) { return 0; }
static int32_t onRaftRequestVoteReply(struct SRaft* ths, RaftRequestVoteReply* pMsg) { return 0; }
static int32_t doRaftAppendEntries(struct SRaft* ths, const RaftAppendEntries* pMsg) { return 0; }
static int32_t onRaftAppendEntries(struct SRaft* ths, RaftAppendEntries* pMsg) { return 0; }
static int32_t onRaftAppendEntriesReply(struct SRaft* ths, RaftAppendEntriesReply* pMsg) { return 0; }
int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak) { return 0; } int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak) { return 0; }
static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft) { return 0; } static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft) { return 0; }
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "sync.h" #include "syncRaftEntry.h"
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include "syncRaftLog.h" #include "syncRaftLog.h"
#include "sync.h"
int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf) { return 0; } int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf) { return 0; }
......
...@@ -14,12 +14,142 @@ ...@@ -14,12 +14,142 @@
*/ */
#include "syncRaftStore.h" #include "syncRaftStore.h"
#include "sync.h" #include "cJSON.h"
int32_t currentTerm(SyncTerm *pCurrentTerm) { return 0; } // to complie success: FileIO interface is modified
int32_t persistCurrentTerm(SyncTerm currentTerm) { return 0; } SRaftStore *raftStoreOpen(const char *path) { return NULL;}
int32_t voteFor(SRaftId *pRaftId) { return 0; } static int32_t raftStoreInit(SRaftStore *pRaftStore) { return 0;}
int32_t persistVoteFor(SRaftId *pRaftId) { return 0; } int32_t raftStoreClose(SRaftStore *pRaftStore) { return 0;}
\ No newline at end of file
int32_t raftStorePersist(SRaftStore *pRaftStore) { return 0;}
static bool raftStoreFileExist(char *path) { return 0;}
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) { return 0;}
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) { return 0;}
void raftStorePrint(SRaftStore *pRaftStore) {}
#if 0
SRaftStore *raftStoreOpen(const char *path) {
int32_t ret;
SRaftStore *pRaftStore = malloc(sizeof(SRaftStore));
if (pRaftStore == NULL) {
sError("raftStoreOpen malloc error");
return NULL;
}
memset(pRaftStore, 0, sizeof(*pRaftStore));
snprintf(pRaftStore->path, sizeof(pRaftStore->path), "%s", path);
char storeBuf[RAFT_STORE_BLOCK_SIZE];
memset(storeBuf, 0, sizeof(storeBuf));
if (!raftStoreFileExist(pRaftStore->path)) {
ret = raftStoreInit(pRaftStore);
assert(ret == 0);
}
pRaftStore->fd = taosOpenFileReadWrite(pRaftStore->path);
if (pRaftStore->fd < 0) {
return NULL;
}
int len = taosReadFile(pRaftStore->fd, storeBuf, sizeof(storeBuf));
assert(len == RAFT_STORE_BLOCK_SIZE);
ret = raftStoreDeserialize(pRaftStore, storeBuf, len);
assert(ret == 0);
return pRaftStore;
}
static int32_t raftStoreInit(SRaftStore *pRaftStore) {
pRaftStore->fd = taosOpenFileCreateWrite(pRaftStore->path);
if (pRaftStore->fd < 0) {
return -1;
}
pRaftStore->currentTerm = 0;
pRaftStore->voteFor.addr = 0;
pRaftStore->voteFor.vgId = 0;
int32_t ret = raftStorePersist(pRaftStore);
assert(ret == 0);
taosCloseFile(pRaftStore->fd);
return 0;
}
int32_t raftStoreClose(SRaftStore *pRaftStore) {
taosCloseFile(pRaftStore->fd);
free(pRaftStore);
return 0;
}
int32_t raftStorePersist(SRaftStore *pRaftStore) {
int32_t ret;
char storeBuf[RAFT_STORE_BLOCK_SIZE];
ret = raftStoreSerialize(pRaftStore, storeBuf, sizeof(storeBuf));
assert(ret == 0);
taosLSeekFile(pRaftStore->fd, 0, SEEK_SET);
ret = taosWriteFile(pRaftStore->fd, storeBuf, sizeof(storeBuf));
assert(ret == RAFT_STORE_BLOCK_SIZE);
fsync(pRaftStore->fd);
return 0;
}
static bool raftStoreFileExist(char *path) { return taosStatFile(path, NULL, NULL) >= 0; }
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) {
cJSON *pRoot = cJSON_CreateObject();
cJSON_AddNumberToObject(pRoot, "current_term", pRaftStore->currentTerm);
cJSON_AddNumberToObject(pRoot, "vote_for_addr", pRaftStore->voteFor.addr);
cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId);
char *serialized = cJSON_Print(pRoot);
int len2 = strlen(serialized);
assert(len2 < len);
memset(buf, 0, len);
snprintf(buf, len, "%s", serialized);
free(serialized);
cJSON_Delete(pRoot);
return 0;
}
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
assert(len > 0 && len <= RAFT_STORE_BLOCK_SIZE);
cJSON *pRoot = cJSON_Parse(buf);
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
pRaftStore->currentTerm = pCurrentTerm->valueint;
cJSON *pVoteForAddr = cJSON_GetObjectItem(pRoot, "vote_for_addr");
pRaftStore->voteFor.addr = pVoteForAddr->valueint;
cJSON *pVoteForVgid = cJSON_GetObjectItem(pRoot, "vote_for_vgid");
pRaftStore->voteFor.vgId = pVoteForVgid->valueint;
cJSON_Delete(pRoot);
return 0;
}
void raftStorePrint(SRaftStore *pRaftStore) {
char storeBuf[RAFT_STORE_BLOCK_SIZE];
raftStoreSerialize(pRaftStore, storeBuf, sizeof(storeBuf));
printf("%s\n", storeBuf);
}
#endif
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "sync.h" #include "syncReplication.h"
...@@ -14,46 +14,41 @@ ...@@ -14,46 +14,41 @@
*/ */
#include "syncRequestVote.h" #include "syncRequestVote.h"
#include "sync.h"
void requestVote(SRaft *pRaft, const SyncRequestVote *pMsg) { void requestVote(SRaft *pRaft, const SyncRequestVote *pMsg) {
// TLA+ Spec
// TLA+ Spec // RequestVote(i, j) ==
//RequestVote(i, j) == // /\ state[i] = Candidate
// /\ state[i] = Candidate // /\ j \notin votesResponded[i]
// /\ j \notin votesResponded[i] // /\ Send([mtype |-> RequestVoteRequest,
// /\ Send([mtype |-> RequestVoteRequest, // mterm |-> currentTerm[i],
// mterm |-> currentTerm[i], // mlastLogTerm |-> LastTerm(log[i]),
// mlastLogTerm |-> LastTerm(log[i]), // mlastLogIndex |-> Len(log[i]),
// mlastLogIndex |-> Len(log[i]), // msource |-> i,
// msource |-> i, // mdest |-> j])
// mdest |-> j]) // /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
} }
void onRequestVote(SRaft *pRaft, const SyncRequestVote *pMsg) { void onRequestVote(SRaft *pRaft, const SyncRequestVote *pMsg) {
// TLA+ Spec
// TLA+ Spec // HandleRequestVoteRequest(i, j, m) ==
//HandleRequestVoteRequest(i, j, m) == // LET logOk == \/ m.mlastLogTerm > LastTerm(log[i])
// LET logOk == \/ m.mlastLogTerm > LastTerm(log[i]) // \/ /\ m.mlastLogTerm = LastTerm(log[i])
// \/ /\ m.mlastLogTerm = LastTerm(log[i]) // /\ m.mlastLogIndex >= Len(log[i])
// /\ m.mlastLogIndex >= Len(log[i]) // grant == /\ m.mterm = currentTerm[i]
// grant == /\ m.mterm = currentTerm[i] // /\ logOk
// /\ logOk // /\ votedFor[i] \in {Nil, j}
// /\ votedFor[i] \in {Nil, j} // IN /\ m.mterm <= currentTerm[i]
// IN /\ m.mterm <= currentTerm[i] // /\ \/ grant /\ votedFor' = [votedFor EXCEPT ![i] = j]
// /\ \/ grant /\ votedFor' = [votedFor EXCEPT ![i] = j] // \/ ~grant /\ UNCHANGED votedFor
// \/ ~grant /\ UNCHANGED votedFor // /\ Reply([mtype |-> RequestVoteResponse,
// /\ Reply([mtype |-> RequestVoteResponse, // mterm |-> currentTerm[i],
// mterm |-> currentTerm[i], // mvoteGranted |-> grant,
// mvoteGranted |-> grant, // \* mlog is used just for the `elections' history variable for
// \* mlog is used just for the `elections' history variable for // \* the proof. It would not exist in a real implementation.
// \* the proof. It would not exist in a real implementation. // mlog |-> log[i],
// mlog |-> log[i], // msource |-> i,
// msource |-> i, // mdest |-> j],
// mdest |-> j], // m)
// m) // /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
} }
...@@ -14,25 +14,22 @@ ...@@ -14,25 +14,22 @@
*/ */
#include "syncRequestVoteReply.h" #include "syncRequestVoteReply.h"
#include "sync.h"
void onRequestVoteReply(SRaft *pRaft, const SyncRequestVoteReply *pMsg) { void onRequestVoteReply(SRaft *pRaft, const SyncRequestVoteReply *pMsg) {
// TLA+ Spec
// TLA+ Spec // HandleRequestVoteResponse(i, j, m) ==
//HandleRequestVoteResponse(i, j, m) == // \* This tallies votes even when the current state is not Candidate, but
// \* This tallies votes even when the current state is not Candidate, but // \* they won't be looked at, so it doesn't matter.
// \* they won't be looked at, so it doesn't matter. // /\ m.mterm = currentTerm[i]
// /\ m.mterm = currentTerm[i] // /\ votesResponded' = [votesResponded EXCEPT ![i] =
// /\ votesResponded' = [votesResponded EXCEPT ![i] = // votesResponded[i] \cup {j}]
// votesResponded[i] \cup {j}] // /\ \/ /\ m.mvoteGranted
// /\ \/ /\ m.mvoteGranted // /\ votesGranted' = [votesGranted EXCEPT ![i] =
// /\ votesGranted' = [votesGranted EXCEPT ![i] = // votesGranted[i] \cup {j}]
// votesGranted[i] \cup {j}] // /\ voterLog' = [voterLog EXCEPT ![i] =
// /\ voterLog' = [voterLog EXCEPT ![i] = // voterLog[i] @@ (j :> m.mlog)]
// voterLog[i] @@ (j :> m.mlog)] // \/ /\ ~m.mvoteGranted
// \/ /\ ~m.mvoteGranted // /\ UNCHANGED <<votesGranted, voterLog>>
// /\ UNCHANGED <<votesGranted, voterLog>> // /\ Discard(m)
// /\ Discard(m) // /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
} }
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include "syncSnapshot.h" #include "syncSnapshot.h"
#include "sync.h"
#include "syncRaft.h" #include "syncRaft.h"
int32_t takeSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { return 0; } int32_t takeSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { return 0; }
......
...@@ -14,6 +14,5 @@ ...@@ -14,6 +14,5 @@
*/ */
#include "syncTimeout.h" #include "syncTimeout.h"
#include "sync.h"
void onTimeout(SRaft *pRaft, void *pMsg) {} void onTimeout(SRaft *pRaft, void *pMsg) {}
\ No newline at end of file
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "syncVoteMgr.h"
add_executable(syncTest "")
add_executable(syncEnvTest "")
add_executable(syncPingTest "")
target_sources(syncTest
PRIVATE
"syncTest.cpp"
)
target_sources(syncEnvTest
PRIVATE
"syncEnvTest.cpp"
)
target_sources(syncPingTest
PRIVATE
"syncPingTest.cpp"
)
target_include_directories(syncTest
PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
)
target_include_directories(syncEnvTest
PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
)
target_include_directories(syncPingTest
PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
)
target_link_libraries(syncTest
sync
gtest_main
)
target_link_libraries(syncEnvTest
sync
gtest_main
)
target_link_libraries(syncPingTest
sync
gtest_main
)
enable_testing()
add_test(
NAME sync_test
COMMAND syncTest
)
#include "syncEnv.h"
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
void logTest() {
sTrace("--- sync log test: trace");
sDebug("--- sync log test: debug");
sInfo("--- sync log test: info");
sWarn("--- sync log test: warn");
sError("--- sync log test: error");
sFatal("--- sync log test: fatal");
}
void doSync() {
SSyncInfo syncInfo;
syncInfo.vgId = 1;
SSyncCfg* pCfg = &syncInfo.syncCfg;
pCfg->replicaNum = 3;
pCfg->nodeInfo[0].nodePort = 7010;
taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
pCfg->nodeInfo[1].nodePort = 7110;
taosGetFqdn(pCfg->nodeInfo[1].nodeFqdn);
pCfg->nodeInfo[2].nodePort = 7210;
taosGetFqdn(pCfg->nodeInfo[2].nodeFqdn);
SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
assert(pSyncNode != NULL);
}
int main() {
//taosInitLog((char*)"syncEnvTest.log", 100000, 10);
tsAsyncLog = 0;
sDebugFlag = 143 + 64;
logTest();
int32_t ret = syncIOStart();
assert(ret == 0);
ret = syncEnvStart();
assert(ret == 0);
doSync();
while (1) {
taosMsleep(1000);
}
return 0;
}
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
void logTest() {
sTrace("--- sync log test: trace");
sDebug("--- sync log test: debug");
sInfo("--- sync log test: info");
sWarn("--- sync log test: warn");
sError("--- sync log test: error");
sFatal("--- sync log test: fatal");
}
void doSync() {
SSyncFSM* pFsm;
SSyncInfo syncInfo;
syncInfo.vgId = 1;
syncInfo.FpSendMsg = syncIOSendMsg;
syncInfo.pFsm = pFsm;
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_sync_ping");
SSyncCfg* pCfg = &syncInfo.syncCfg;
pCfg->myIndex = 0;
pCfg->replicaNum = 3;
pCfg->nodeInfo[0].nodePort = 7010;
taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
pCfg->nodeInfo[1].nodePort = 7110;
taosGetFqdn(pCfg->nodeInfo[1].nodeFqdn);
pCfg->nodeInfo[2].nodePort = 7210;
taosGetFqdn(pCfg->nodeInfo[2].nodeFqdn);
SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
assert(pSyncNode != NULL);
gSyncIO->FpOnPing = pSyncNode->FpOnPing;
gSyncIO->pSyncNode = pSyncNode;
}
int main() {
//taosInitLog((char*)"syncPingTest.log", 100000, 10);
tsAsyncLog = 0;
sDebugFlag = 143 + 64;
logTest();
int32_t ret = syncIOStart();
assert(ret == 0);
ret = syncEnvStart();
assert(ret == 0);
doSync();
while (1) {
taosMsleep(1000);
}
return 0;
}
#include <stdio.h> #include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
#include "gtest/gtest.h"
void *pingFunc(void *param) {
SSyncIO *io = (SSyncIO *)param;
while (1) {
sDebug("io->ping");
io->ping(io);
sleep(1);
}
return NULL;
}
int main() { int main() {
printf("test \n"); //taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog = 0;
sDebugFlag = 143 + 64;
sTrace("sync log test: trace");
sDebug("sync log test: debug");
sInfo("sync log test: info");
sWarn("sync log test: warn");
sError("sync log test: error");
sFatal("sync log test: fatal");
SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json");
// assert(pRaftStore != NULL);
// raftStorePrint(pRaftStore);
// pRaftStore->currentTerm = 100;
// pRaftStore->voteFor.addr = 200;
// pRaftStore->voteFor.vgId = 300;
// raftStorePrint(pRaftStore);
// raftStorePersist(pRaftStore);
// sDebug("sync test");
// SSyncIO *syncIO = syncIOCreate();
// assert(syncIO != NULL);
// syncIO->start(syncIO);
// sleep(2);
// pthread_t tid;
// pthread_create(&tid, NULL, pingFunc, syncIO);
// while (1) {
// sleep(1);
// }
return 0; return 0;
} }
...@@ -140,7 +140,7 @@ static int tdbEnvDestroy(TENV *pEnv) { ...@@ -140,7 +140,7 @@ static int tdbEnvDestroy(TENV *pEnv) {
int tdbEnvBeginTxn(TENV *pEnv) { int tdbEnvBeginTxn(TENV *pEnv) {
pEnv->jpFile = taosOpenFile(pEnv->jname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ); pEnv->jpFile = taosOpenFile(pEnv->jname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ);
if (pEnv->jpFile < 0) { if (pEnv->jpFile == NULL) {
return -1; return -1;
} }
......
...@@ -95,7 +95,7 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) { ...@@ -95,7 +95,7 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
int pgFileClose(SPgFile *pPgFile) { int pgFileClose(SPgFile *pPgFile) {
if (pPgFile) { if (pPgFile) {
if (pPgFile->pFile >= 0) { if (pPgFile->pFile != NULL) {
taosCloseFile(&pPgFile->pFile); taosCloseFile(&pPgFile->pFile);
} }
......
...@@ -25,7 +25,7 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pDir); ...@@ -25,7 +25,7 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pDir);
static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter); static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter);
STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) { STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) {
if (ndisk < 0 || ndisk > TFS_MAX_DISKS) { if (ndisk <= 0 || ndisk > TFS_MAX_DISKS) {
terrno = TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;
return NULL; return NULL;
} }
......
...@@ -43,7 +43,7 @@ void processShellMsg() { ...@@ -43,7 +43,7 @@ void processShellMsg() {
for (int i = 0; i < numOfMsgs; ++i) { for (int i = 0; i < numOfMsgs; ++i) {
taosGetQitem(qall, (void **)&pRpcMsg); taosGetQitem(qall, (void **)&pRpcMsg);
if (pDataFile >= 0) { if (pDataFile != NULL) {
if (taosWriteFile(pDataFile, pRpcMsg->pCont, pRpcMsg->contLen) < 0) { if (taosWriteFile(pDataFile, pRpcMsg->pCont, pRpcMsg->contLen) < 0) {
tInfo("failed to write data file, reason:%s", strerror(errno)); tInfo("failed to write data file, reason:%s", strerror(errno));
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "tep.h" #include "tep.h"
#include "tglobal.h" #include "tglobal.h"
#include "trpc.h" #include "trpc.h"
#include "ulog.h" #include "tlog.h"
using namespace std; using namespace std;
const char *label = "APP"; const char *label = "APP";
......
...@@ -58,13 +58,13 @@ int walSetWrite(SWal* pWal) { ...@@ -58,13 +58,13 @@ int walSetWrite(SWal* pWal) {
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildIdxName(pWal, fileFirstVer, fnameStr); walBuildIdxName(pWal, fileFirstVer, fnameStr);
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pIdxTFile < 0) { if (pIdxTFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
walBuildLogName(pWal, fileFirstVer, fnameStr); walBuildLogName(pWal, fileFirstVer, fnameStr);
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pLogTFile < 0) { if (pLogTFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
...@@ -104,14 +104,14 @@ int walChangeWrite(SWal* pWal, int64_t ver) { ...@@ -104,14 +104,14 @@ int walChangeWrite(SWal* pWal, int64_t ver) {
int64_t fileFirstVer = pFileInfo->firstVer; int64_t fileFirstVer = pFileInfo->firstVer;
walBuildIdxName(pWal, fileFirstVer, fnameStr); walBuildIdxName(pWal, fileFirstVer, fnameStr);
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pIdxTFile < 0) { if (pIdxTFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
pWal->pWriteIdxTFile = NULL; pWal->pWriteIdxTFile = NULL;
return -1; return -1;
} }
walBuildLogName(pWal, fileFirstVer, fnameStr); walBuildLogName(pWal, fileFirstVer, fnameStr);
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pLogTFile < 0) { if (pLogTFile == NULL) {
taosCloseFile(&pIdxTFile); taosCloseFile(&pIdxTFile);
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
pWal->pWriteLogTFile = NULL; pWal->pWriteLogTFile = NULL;
......
...@@ -89,7 +89,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ...@@ -89,7 +89,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr); walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ); TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ);
if (pLogTFile < 0) { if (pLogTFile == NULL) {
// TODO // TODO
pthread_mutex_unlock(&pWal->mutex); pthread_mutex_unlock(&pWal->mutex);
return -1; return -1;
...@@ -221,13 +221,13 @@ int walRoll(SWal *pWal) { ...@@ -221,13 +221,13 @@ int walRoll(SWal *pWal) {
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildIdxName(pWal, newFileFirstVersion, fnameStr); walBuildIdxName(pWal, newFileFirstVersion, fnameStr);
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pIdxTFile < 0) { if (pIdxTFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
walBuildLogName(pWal, newFileFirstVersion, fnameStr); walBuildLogName(pWal, newFileFirstVersion, fnameStr);
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pLogTFile < 0) { if (pLogTFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
......
...@@ -15,31 +15,33 @@ ...@@ -15,31 +15,33 @@
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#include "os.h" #include "os.h"
#define MAX_FPRINTFLINE_BUFFER_SIZE (1000)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <io.h> #include <io.h>
#if defined(_MSDOS) #if defined(_MSDOS)
#define open _open #define open _open
#endif #endif
#if defined(_WIN32) #if defined(_WIN32)
extern int openA(const char *, int, ...); /* MsvcLibX ANSI version of open */ extern int openA(const char *, int, ...); /* MsvcLibX ANSI version of open */
extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
#if defined(_UTF8_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) #if defined(_UTF8_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define open openU #define open openU
#else /* _ANSI_SOURCE */ #else /* _ANSI_SOURCE */
#define open openA #define open openA
#endif /* defined(_UTF8_SOURCE) */ #endif /* defined(_UTF8_SOURCE) */
#endif /* defined(_WIN32) */ #endif /* defined(_WIN32) */
#else #else
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#define LINUX_FILE_NO_TEXT_OPTION 0 #define LINUX_FILE_NO_TEXT_OPTION 0
#define O_TEXT LINUX_FILE_NO_TEXT_OPTION #define O_TEXT LINUX_FILE_NO_TEXT_OPTION
#endif #endif
typedef int32_t FileFd; typedef int32_t FileFd;
...@@ -48,11 +50,9 @@ typedef struct TdFile { ...@@ -48,11 +50,9 @@ typedef struct TdFile {
int refId; int refId;
FileFd fd; FileFd fd;
FILE *fp; FILE *fp;
}*TdFilePtr,TdFile; } * TdFilePtr, TdFile;
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) {
void taosGetTmpfilePath(const char * inputTmpDir, const char *fileNamePrefix, char *dstPath) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
const char *tdengineTmpFileNamePrefix = "tdengine-"; const char *tdengineTmpFileNamePrefix = "tdengine-";
char tmpPath[PATH_MAX]; char tmpPath[PATH_MAX];
...@@ -112,11 +112,11 @@ int64_t taosCopyFile(const char *from, const char *to) { ...@@ -112,11 +112,11 @@ int64_t taosCopyFile(const char *from, const char *to) {
int64_t bytes; int64_t bytes;
// fidfrom = open(from, O_RDONLY); // fidfrom = open(from, O_RDONLY);
TdFilePtr pFileFrom = taosOpenFile(from,TD_FILE_READ); TdFilePtr pFileFrom = taosOpenFile(from, TD_FILE_READ);
if (pFileFrom == NULL) goto _err; if (pFileFrom == NULL) goto _err;
// fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755); // fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755);
TdFilePtr pFileTo = taosOpenFile(to,TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_EXCL); TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_EXCL);
if (pFileTo == NULL) goto _err; if (pFileTo == NULL) goto _err;
while (true) { while (true) {
...@@ -148,14 +148,14 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { ...@@ -148,14 +148,14 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
if (code < 0) { if (code < 0) {
//printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); // printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
} }
return code; return code;
#else #else
int32_t code = rename(oldName, newName); int32_t code = rename(oldName, newName);
if (code < 0) { if (code < 0) {
//printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); // printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
} }
return code; return code;
...@@ -184,25 +184,22 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { ...@@ -184,25 +184,22 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#endif #endif
} }
void autoDelFileListAdd(const char *path) { void autoDelFileListAdd(const char *path) { return; }
return;
}
TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions) { TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return NULL; return NULL;
#else #else
int access = O_BINARY; int access = O_BINARY;
char *mode = NULL; char *mode = NULL;
access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0; access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0;
if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) {
{
access |= O_RDWR; access |= O_RDWR;
mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+"; mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+";
}else if(tdFileOptions & TD_FILE_WRITE) { } else if (tdFileOptions & TD_FILE_WRITE) {
access |= O_WRONLY; access |= O_WRONLY;
mode = (tdFileOptions & TD_FILE_TEXT) ? "wt" : "wb"; mode = (tdFileOptions & TD_FILE_TEXT) ? "wt" : "wb";
}else if(tdFileOptions & TD_FILE_READ) { } else if (tdFileOptions & TD_FILE_READ) {
access |= O_RDONLY; access |= O_RDONLY;
mode = (tdFileOptions & TD_FILE_TEXT) ? "rt" : "rb"; mode = (tdFileOptions & TD_FILE_TEXT) ? "rt" : "rb";
} }
...@@ -210,14 +207,14 @@ TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions) { ...@@ -210,14 +207,14 @@ TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions) {
access |= (tdFileOptions & TD_FILE_APPEND) ? O_APPEND : 0; access |= (tdFileOptions & TD_FILE_APPEND) ? O_APPEND : 0;
access |= (tdFileOptions & TD_FILE_TEXT) ? O_TEXT : 0; access |= (tdFileOptions & TD_FILE_TEXT) ? O_TEXT : 0;
access |= (tdFileOptions & TD_FILE_EXCL) ? O_EXCL : 0; access |= (tdFileOptions & TD_FILE_EXCL) ? O_EXCL : 0;
if(tdFileOptions & TD_FILE_AUTO_DEL) { if (tdFileOptions & TD_FILE_AUTO_DEL) {
autoDelFileListAdd(path); autoDelFileListAdd(path);
} }
int fd = open(path, access, S_IRWXU | S_IRWXG | S_IRWXO); int fd = open(path, access, S_IRWXU | S_IRWXG | S_IRWXO);
if(fd == -1) { if (fd == -1) {
return NULL; return NULL;
} }
FILE* fp = fdopen(fd, mode); FILE *fp = fdopen(fd, mode);
if (fp == NULL) { if (fp == NULL) {
close(fd); close(fd);
return NULL; return NULL;
...@@ -239,9 +236,10 @@ int64_t taosCloseFile(TdFilePtr *ppFile) { ...@@ -239,9 +236,10 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return 0; return 0;
#else #else
if(ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) { if (ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) {
return 0; return 0;
} }
fflush((*ppFile)->fp);
fsync((*ppFile)->fd); fsync((*ppFile)->fd);
close((*ppFile)->fd); close((*ppFile)->fd);
(*ppFile)->fd = -1; (*ppFile)->fd = -1;
...@@ -254,12 +252,12 @@ int64_t taosCloseFile(TdFilePtr *ppFile) { ...@@ -254,12 +252,12 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
} }
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
if(pFile == NULL) { if (pFile == NULL) {
return 0; return 0;
} }
int64_t leftbytes = count; int64_t leftbytes = count;
int64_t readbytes; int64_t readbytes;
char * tbuf = (char *)buf; char *tbuf = (char *)buf;
while (leftbytes > 0) { while (leftbytes > 0) {
readbytes = read(pFile->fd, (void *)tbuf, (uint32_t)leftbytes); readbytes = read(pFile->fd, (void *)tbuf, (uint32_t)leftbytes);
...@@ -281,7 +279,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { ...@@ -281,7 +279,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
} }
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) { int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) {
if(pFile == NULL) { if (pFile == NULL) {
return 0; return 0;
} }
return pread(pFile->fd, buf, count, offset); return pread(pFile->fd, buf, count, offset);
...@@ -290,7 +288,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) ...@@ -290,7 +288,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
int64_t nleft = count; int64_t nleft = count;
int64_t nwritten = 0; int64_t nwritten = 0;
char * tbuf = (char *)buf; char *tbuf = (char *)buf;
while (nleft > 0) { while (nleft > 0) {
nwritten = write(pFile->fd, (void *)tbuf, (uint32_t)nleft); nwritten = write(pFile->fd, (void *)tbuf, (uint32_t)nleft);
...@@ -298,12 +296,16 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { ...@@ -298,12 +296,16 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
if (errno == EINTR) { if (errno == EINTR) {
continue; continue;
} }
fflush(pFile->fp);
fsync(pFile->fd);
return -1; return -1;
} }
nleft -= nwritten; nleft -= nwritten;
tbuf += nwritten; tbuf += nwritten;
} }
fflush(pFile->fp);
fsync(pFile->fd);
return count; return count;
} }
...@@ -417,7 +419,7 @@ int32_t taosFsyncFile(TdFilePtr pFile) { ...@@ -417,7 +419,7 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
return FlushFileBuffers(h); return FlushFileBuffers(h);
#else #else
return fsync(pFile->fd); return fflush(pFile->fp);
#endif #endif
} }
...@@ -568,14 +570,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in ...@@ -568,14 +570,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
#endif #endif
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
void taosFprintfFile(TdFilePtr pFile, const char *format, ...) { void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
char buffer[MAX_FPRINTFLINE_BUFFER_SIZE] = {0};
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
fprintf(pFile->fp, format, ap); vfprintf(pFile->fp, format, ap);
va_end(ap); va_end(ap);
fflush(pFile->fp); fflush(pFile->fp);
} }
...@@ -587,9 +586,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { ...@@ -587,9 +586,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
return ptr; return ptr;
} }
bool taosValidFile(TdFilePtr pFile) { bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; }
return pFile != NULL;
}
int32_t taosUmaskFile(int32_t maskVal) { int32_t taosUmaskFile(int32_t maskVal) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...@@ -599,13 +596,9 @@ int32_t taosUmaskFile(int32_t maskVal) { ...@@ -599,13 +596,9 @@ int32_t taosUmaskFile(int32_t maskVal) {
#endif #endif
} }
int taosGetErrorFile(TdFilePtr pFile) { int32_t taosGetErrorFile(TdFilePtr pFile) { return errno; }
return errno; int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict__ ptrBuf) {
}
size_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf) {
size_t len = 0; size_t len = 0;
return getline(ptrBuf, &len, pFile->fp); return getline(ptrBuf, &len, pFile->fp);
} }
int32_t taosEOFFile(TdFilePtr pFile) { int32_t taosEOFFile(TdFilePtr pFile) { return feof(pFile->fp); }
return feof(pFile->fp); \ No newline at end of file
}
\ No newline at end of file
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "regex.h" #include "regex.h"
#include "thash.h" #include "thash.h"
#include "types.h" #include "types.h"
#include "ulog.h" #include "tlog.h"
#include "tdef.h" #include "tdef.h"
#include "taos.h" #include "taos.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "ulog.h" #include "tlog.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
#include "tcache.h" #include "tcache.h"
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#include "td_sz.h" #include "td_sz.h"
#endif #endif
#include "tcompression.h" #include "tcompression.h"
#include "ulog.h" #include "tlog.h"
static const int TEST_NUMBER = 1; static const int TEST_NUMBER = 1;
#define is_bigendian() ((*(char *)&TEST_NUMBER) == 0) #define is_bigendian() ((*(char *)&TEST_NUMBER) == 0)
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "tconfig.h" #include "tconfig.h"
#include "taoserror.h" #include "taoserror.h"
#include "tcfg.h"
#include "thash.h" #include "thash.h"
#include "tutil.h" #include "tutil.h"
#include "ulog.h" #include "tlog.h"
#define CFG_NAME_PRINT_LEN 24 #define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12 #define CFG_SRC_PRINT_LEN 12
...@@ -66,9 +67,37 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { ...@@ -66,9 +67,37 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
} }
} }
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs) {
int32_t size = taosArrayGetSize(pArgs);
for (int32_t i = 0; i < size; ++i) {
SConfigPair *pPair = taosArrayGet(pArgs, i);
if (cfgSetItem(pCfg, pPair->name, pPair->value, CFG_STYPE_ARG_LIST) != 0) {
return -1;
}
}
return 0;
}
static void cfgFreeItem(SConfigItem *pItem) {
if (pItem->dtype == CFG_DTYPE_STRING || pItem->dtype == CFG_DTYPE_DIR || pItem->dtype == CFG_DTYPE_LOCALE ||
pItem->dtype == CFG_DTYPE_CHARSET || pItem->dtype == CFG_DTYPE_TIMEZONE) {
tfree(pItem->str);
}
if (pItem->array) {
taosArrayDestroy(pItem->array);
pItem->array = NULL;
}
}
void cfgCleanup(SConfig *pCfg) { void cfgCleanup(SConfig *pCfg) {
if (pCfg != NULL) { if (pCfg != NULL) {
if (pCfg->hash != NULL) { if (pCfg->hash != NULL) {
SConfigItem *pItem = taosHashIterate(pCfg->hash, NULL);
while (pItem != NULL) {
cfgFreeItem(pItem);
pItem = taosHashIterate(pCfg->hash, pItem);
}
taosHashCleanup(pCfg->hash); taosHashCleanup(pCfg->hash);
pCfg->hash == NULL; pCfg->hash == NULL;
} }
...@@ -83,7 +112,7 @@ SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashIter ...@@ -83,7 +112,7 @@ SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashIter
void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashCancelIterate(pCfg->hash, pIter); } void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashCancelIterate(pCfg->hash, pIter); }
static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) { static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) {
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(timezone); pItem->str = strdup(timezone);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -94,7 +123,7 @@ static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) ...@@ -94,7 +123,7 @@ static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone)
} }
static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) { static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) {
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(charset); pItem->str = strdup(charset);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -105,7 +134,7 @@ static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) { ...@@ -105,7 +134,7 @@ static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) {
} }
static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) { static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) {
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(locale); pItem->str = strdup(locale);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -134,7 +163,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { ...@@ -134,7 +163,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
return -1; return -1;
} }
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(fullDir); pItem->str = strdup(fullDir);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -275,6 +304,33 @@ static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType ...@@ -275,6 +304,33 @@ static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType
return 0; return 0;
} }
static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, const char *level, const char *primary,
ECfgSrcType stype) {
SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) return -1;
if (pItem->array == NULL) {
pItem->array = taosArrayInit(16, sizeof(SDiskCfg));
if (pItem->array == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
}
SDiskCfg cfg = {0};
tstrncpy(cfg.dir, value, sizeof(cfg.dir));
cfg.level = atoi(level);
cfg.primary = atoi(primary);
void *ret = taosArrayPush(pItem->array, &cfg);
if (ret == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pItem->stype = stype;
return 0;
}
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) { int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) {
SConfigItem *pItem = cfgGetItem(pCfg, name); SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) { if (pItem == NULL) {
...@@ -441,8 +497,6 @@ const char *cfgStypeStr(ECfgSrcType type) { ...@@ -441,8 +497,6 @@ const char *cfgStypeStr(ECfgSrcType type) {
return "apollo_url"; return "apollo_url";
case CFG_STYPE_ARG_LIST: case CFG_STYPE_ARG_LIST:
return "arg_list"; return "arg_list";
case CFG_STYPE_API_OPTION:
return "api_option";
default: default:
return "invalid"; return "invalid";
} }
...@@ -583,7 +637,6 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -583,7 +637,6 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
while (!taosEOFFile(pFile)) { while (!taosEOFFile(pFile)) {
name = value = value2 = value3 = NULL; name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0; olen = vlen = vlen2 = vlen3 = 0;
...@@ -610,11 +663,13 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -610,11 +663,13 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE); cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE);
// taosReadConfigOption(name, value, value2, value3); if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0) {
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_CFG_FILE);
}
} }
taosCloseFile(&pFile); taosCloseFile(&pFile);
if(line != NULL) tfree(line); if (line != NULL) tfree(line);
uInfo("load from cfg file %s success", filepath); uInfo("load from cfg file %s success", filepath);
return 0; return 0;
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h"
#define TAOS_ERROR_C #define TAOS_ERROR_C
...@@ -22,16 +24,12 @@ typedef struct { ...@@ -22,16 +24,12 @@ typedef struct {
const char* str; const char* str;
} STaosError; } STaosError;
#include "os.h"
#include "taoserror.h"
static threadlocal int32_t tsErrno; static threadlocal int32_t tsErrno;
int32_t* taosGetErrno() {
return &tsErrno; int32_t* taosGetErrno() { return &tsErrno; }
}
#ifdef TAOS_ERROR_C #ifdef TAOS_ERROR_C
#define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str=(msg)}, #define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str = (msg)},
#else #else
#define TAOS_DEFINE_ERROR(name, mod, code, msg) static const int32_t name = TAOS_DEF_ERROR_CODE(mod, code); #define TAOS_DEFINE_ERROR(name, mod, code, msg) static const int32_t name = TAOS_DEF_ERROR_CODE(mod, code);
#endif #endif
...@@ -378,8 +376,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_MSG_ERROR, "Task message error") ...@@ -378,8 +376,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_MSG_ERROR, "Task message error")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JOB_FREED, "Job already freed") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JOB_FREED, "Job already freed")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_STATUS_ERROR, "Task status error") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_STATUS_ERROR, "Task status error")
// grant // grant
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, "License expired") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, "License expired")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, "DNode creation limited by licence") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, "DNode creation limited by licence")
...@@ -436,12 +432,11 @@ TAOS_DEFINE_ERROR(TSDB_CODE_CTG_OUT_OF_SERVICE, "catalog is out of ser ...@@ -436,12 +432,11 @@ TAOS_DEFINE_ERROR(TSDB_CODE_CTG_OUT_OF_SERVICE, "catalog is out of ser
TAOS_DEFINE_ERROR(TSDB_CODE_SCH_STATUS_ERROR, "scheduler status error") TAOS_DEFINE_ERROR(TSDB_CODE_SCH_STATUS_ERROR, "scheduler status error")
TAOS_DEFINE_ERROR(TSDB_CODE_SCH_INTERNAL_ERROR, "scheduler internal error") TAOS_DEFINE_ERROR(TSDB_CODE_SCH_INTERNAL_ERROR, "scheduler internal error")
#ifdef TAOS_ERROR_C #ifdef TAOS_ERROR_C
}; };
#endif #endif
static int tsCompareTaosError(const void* a, const void* b) { static int32_t taosCompareTaosError(const void* a, const void* b) {
const STaosError* x = (const STaosError*)a; const STaosError* x = (const STaosError*)a;
const STaosError* y = (const STaosError*)b; const STaosError* y = (const STaosError*)b;
if (x->val < y->val) { if (x->val < y->val) {
...@@ -454,11 +449,11 @@ static int tsCompareTaosError(const void* a, const void* b) { ...@@ -454,11 +449,11 @@ static int tsCompareTaosError(const void* a, const void* b) {
} }
static pthread_once_t tsErrorInit = PTHREAD_ONCE_INIT; static pthread_once_t tsErrorInit = PTHREAD_ONCE_INIT;
static void tsSortError(void) { static void tsSortError(void) {
qsort(errors, sizeof(errors)/sizeof(errors[0]), sizeof(errors[0]), tsCompareTaosError); qsort(errors, sizeof(errors) / sizeof(errors[0]), sizeof(errors[0]), taosCompareTaosError);
} }
const char* tstrerror(int32_t err) { const char* tstrerror(int32_t err) {
pthread_once(&tsErrorInit, tsSortError); pthread_once(&tsErrorInit, tsSortError);
...@@ -467,9 +462,11 @@ const char* tstrerror(int32_t err) { ...@@ -467,9 +462,11 @@ const char* tstrerror(int32_t err) {
return strerror(err & 0x0000ffff); return strerror(err & 0x0000ffff);
} }
size_t s = 0, e = sizeof(errors)/sizeof(errors[0]); int32_t s = 0;
int32_t e = sizeof(errors) / sizeof(errors[0]);
while (s < e) { while (s < e) {
size_t mid = (s + e) / 2; int32_t mid = (s + e) / 2;
int32_t val = errors[mid].val; int32_t val = errors[mid].val;
if (err > val) { if (err > val) {
s = mid + 1; s = mid + 1;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "taoserror.h" #include "taoserror.h"
#include "tref.h" #include "tref.h"
#include "tutil.h" #include "tutil.h"
#include "ulog.h" #include "tlog.h"
static int32_t tsFileRsetId = -1; static int32_t tsFileRsetId = -1;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "os.h" #include "os.h"
#include "thash.h" #include "thash.h"
#include "ulog.h" #include "tlog.h"
#include "taos.h" #include "taos.h"
#include "tdef.h" #include "tdef.h"
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h" #include "tlog.h"
#include "ulog.h"
typedef struct { typedef struct {
int maxId; int maxId;
......
此差异已折叠。
此差异已折叠。
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#include "os.h" #include "os.h"
#include "ulog.h" #include "tlog.h"
#include "tlosertree.h" #include "tlosertree.h"
#include "taoserror.h" #include "taoserror.h"
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h" #include "tlog.h"
#include "ulog.h"
#include "tmempool.h" #include "tmempool.h"
#include "tutil.h" #include "tutil.h"
......
#include "os.h" #include "tlog.h"
#include "ulog.h"
#include "tpagedbuf.h" #include "tpagedbuf.h"
#include "taoserror.h" #include "taoserror.h"
#include "tcompression.h" #include "tcompression.h"
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册