提交 b6399528 编写于 作者: M Minghao Li

add raft store

上级 296d9abe
......@@ -34,23 +34,23 @@ typedef enum {
TAOS_SYNC_STATE_LEADER = 2,
} ESyncState;
typedef struct {
typedef struct SSyncBuffer {
void* data;
size_t len;
} SSyncBuffer;
typedef struct {
SyncNodeId nodeId;
uint16_t nodePort; // node sync Port
char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN
typedef struct SNodeInfo {
uint16_t nodePort; // node sync Port
char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN
} SNodeInfo;
typedef struct {
typedef struct SSyncCfg {
int32_t replicaNum;
int32_t myIndex;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
} SSyncCfg;
typedef struct {
typedef struct SNodesRole {
int32_t replicaNum;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
ESyncState role[TSDB_MAX_REPLICA];
......@@ -128,9 +128,9 @@ typedef struct SStateMgr {
} SStateMgr;
typedef struct {
SyncGroupId vgId;
SSyncCfg syncCfg;
typedef struct SSyncInfo {
SyncGroupId vgId;
SSyncCfg syncCfg;
} SSyncInfo;
struct SSyncNode;
......
......@@ -23,8 +23,8 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "taosdef.h"
#include "syncInt.h"
#include "taosdef.h"
#ifdef __cplusplus
}
......
......@@ -35,9 +35,9 @@ typedef struct SRaftId {
typedef struct SRaft {
SRaftId id;
SSyncLogStore *logStore;
SStateMgr *stateManager;
SSyncFSM *syncFsm;
SSyncLogStore* logStore;
SStateMgr* stateManager;
SSyncFSM* syncFsm;
} SRaft;
......
......@@ -23,8 +23,8 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "taosdef.h"
#include "syncInt.h"
#include "taosdef.h"
#ifdef __cplusplus
}
......
......@@ -23,10 +23,10 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaft.h"
#include "taosdef.h"
#include "syncInt.h"
void onTimeout(SRaft *pRaft, void *pMsg);
......
......@@ -20,12 +20,11 @@
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "taosdef.h"
#include "syncInt.h"
#include "taosdef.h"
#ifdef __cplusplus
}
......
add_executable(syncTest "")
add_executable(syncEnvTest "")
add_executable(syncPingTest "")
target_sources(syncTest
......@@ -10,6 +11,10 @@ target_sources(syncEnvTest
PRIVATE
"syncEnvTest.cpp"
)
target_sources(syncPingTest
PRIVATE
"syncPingTest.cpp"
)
target_include_directories(syncTest
......@@ -22,6 +27,11 @@ target_include_directories(syncEnvTest
"${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
......@@ -32,6 +42,10 @@ target_link_libraries(syncEnvTest
sync
gtest_main
)
target_link_libraries(syncPingTest
sync
gtest_main
)
enable_testing()
......
......@@ -13,6 +13,26 @@ void logTest() {
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 = syncNodeStart(&syncInfo);
assert(pSyncNode != NULL);
}
int main() {
taosInitLog((char*)"syncEnvTest.log", 100000, 10);
tsAsyncLog = 0;
......@@ -20,17 +40,13 @@ int main() {
logTest();
int32_t ret = syncEnvStart();
int32_t ret = syncIOStart();
assert(ret == 0);
ret = syncIOStart();
ret = syncEnvStart();
assert(ret == 0);
SSyncInfo syncInfo;
syncInfo.vgId = 1;
SSyncNode* pSyncNode = syncNodeStart(&syncInfo);
assert(pSyncNode != NULL);
doSync();
while (1) {
taosMsleep(1000);
......
#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() {
SSyncInfo syncInfo;
syncInfo.vgId = 1;
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 = syncNodeStart(&syncInfo);
assert(pSyncNode != NULL);
}
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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册