add raft store
This commit is contained in:
parent
296d9abe2a
commit
b63995287d
|
@ -34,23 +34,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,9 +128,9 @@ typedef struct SStateMgr {
|
||||||
|
|
||||||
} SStateMgr;
|
} SStateMgr;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct SSyncInfo {
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
SSyncCfg syncCfg;
|
SSyncCfg syncCfg;
|
||||||
} SSyncInfo;
|
} SSyncInfo;
|
||||||
|
|
||||||
struct SSyncNode;
|
struct SSyncNode;
|
||||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "taosdef.h"
|
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
|
#include "taosdef.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,9 @@ typedef struct SRaftId {
|
||||||
typedef struct SRaft {
|
typedef struct SRaft {
|
||||||
SRaftId id;
|
SRaftId id;
|
||||||
|
|
||||||
SSyncLogStore *logStore;
|
SSyncLogStore* logStore;
|
||||||
SStateMgr *stateManager;
|
SStateMgr* stateManager;
|
||||||
SSyncFSM *syncFsm;
|
SSyncFSM* syncFsm;
|
||||||
|
|
||||||
} SRaft;
|
} SRaft;
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "taosdef.h"
|
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
|
#include "taosdef.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ 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"
|
||||||
#include "syncInt.h"
|
|
||||||
|
|
||||||
void onTimeout(SRaft *pRaft, void *pMsg);
|
void onTimeout(SRaft *pRaft, void *pMsg);
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include "taosdef.h"
|
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
|
#include "taosdef.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
add_executable(syncTest "")
|
add_executable(syncTest "")
|
||||||
add_executable(syncEnvTest "")
|
add_executable(syncEnvTest "")
|
||||||
|
add_executable(syncPingTest "")
|
||||||
|
|
||||||
|
|
||||||
target_sources(syncTest
|
target_sources(syncTest
|
||||||
|
@ -10,6 +11,10 @@ target_sources(syncEnvTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncEnvTest.cpp"
|
"syncEnvTest.cpp"
|
||||||
)
|
)
|
||||||
|
target_sources(syncPingTest
|
||||||
|
PRIVATE
|
||||||
|
"syncPingTest.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_include_directories(syncTest
|
target_include_directories(syncTest
|
||||||
|
@ -22,6 +27,11 @@ target_include_directories(syncEnvTest
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${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
|
target_link_libraries(syncTest
|
||||||
|
@ -32,6 +42,10 @@ target_link_libraries(syncEnvTest
|
||||||
sync
|
sync
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
|
target_link_libraries(syncPingTest
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
|
@ -13,6 +13,26 @@ void logTest() {
|
||||||
sFatal("--- sync log test: fatal");
|
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() {
|
int main() {
|
||||||
taosInitLog((char*)"syncEnvTest.log", 100000, 10);
|
taosInitLog((char*)"syncEnvTest.log", 100000, 10);
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
|
@ -20,17 +40,13 @@ int main() {
|
||||||
|
|
||||||
logTest();
|
logTest();
|
||||||
|
|
||||||
int32_t ret = syncEnvStart();
|
int32_t ret = syncIOStart();
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
|
|
||||||
ret = syncIOStart();
|
ret = syncEnvStart();
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
|
|
||||||
SSyncInfo syncInfo;
|
doSync();
|
||||||
syncInfo.vgId = 1;
|
|
||||||
|
|
||||||
SSyncNode* pSyncNode = syncNodeStart(&syncInfo);
|
|
||||||
assert(pSyncNode != NULL);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue