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

add sync store

上级 6cf9bb57
...@@ -27,6 +27,9 @@ extern "C" { ...@@ -27,6 +27,9 @@ extern "C" {
#include "syncRaft.h" #include "syncRaft.h"
#include "taosdef.h" #include "taosdef.h"
void testJson();
void testJson2();
int32_t currentTerm(SyncTerm *pCurrentTerm); int32_t currentTerm(SyncTerm *pCurrentTerm);
int32_t persistCurrentTerm(SyncTerm currentTerm); int32_t persistCurrentTerm(SyncTerm currentTerm);
......
...@@ -203,7 +203,7 @@ static int32_t syncIOPing(SSyncIO *io) { ...@@ -203,7 +203,7 @@ static int32_t syncIOPing(SSyncIO *io) {
rpcMsg.pCont = rpcMallocCont(10); rpcMsg.pCont = rpcMallocCont(10);
snprintf(rpcMsg.pCont, 10, "ping"); snprintf(rpcMsg.pCont, 10, "ping");
rpcMsg.contLen = 10; rpcMsg.contLen = 10;
rpcMsg.handle = io; rpcMsg.handle = NULL;
rpcMsg.msgType = 1; rpcMsg.msgType = 1;
rpcSendRequest(io->clientRpc, &io->epSet, &rpcMsg, NULL); rpcSendRequest(io->clientRpc, &io->epSet, &rpcMsg, NULL);
......
...@@ -14,8 +14,41 @@ ...@@ -14,8 +14,41 @@
*/ */
#include "syncRaftStore.h" #include "syncRaftStore.h"
#include "cJSON.h"
#include "sync.h" #include "sync.h"
char *serialized;
void testJson() {
FileFd raftStoreFd = taosOpenFileReadWrite("raft.store");
uint64_t currentTerm = 100;
uint64_t voteFor = 200;
cJSON *pRoot = cJSON_CreateObject();
cJSON_AddNumberToObject(pRoot, "current_term", currentTerm);
cJSON_AddNumberToObject(pRoot, "vote_for", voteFor);
serialized = cJSON_Print(pRoot);
int len = strlen(serialized);
printf("serialized: %s \n", serialized);
taosWriteFile(raftStoreFd, serialized, len);
taosCloseFile(raftStoreFd);
}
void testJson2() {
cJSON *pRoot = cJSON_Parse(serialized);
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
uint64_t currentTerm = pCurrentTerm->valueint;
cJSON *pVoteFor = cJSON_GetObjectItem(pRoot, "vote_for");
uint64_t voteFor = pVoteFor->valueint;
printf("read json: currentTerm:%lu, voteFor:%lu \n", currentTerm, voteFor);
}
int32_t currentTerm(SyncTerm *pCurrentTerm) { return 0; } int32_t currentTerm(SyncTerm *pCurrentTerm) { return 0; }
int32_t persistCurrentTerm(SyncTerm currentTerm) { return 0; } int32_t persistCurrentTerm(SyncTerm currentTerm) { return 0; }
......
#include <stdio.h> #include <stdio.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h"
void *pingFunc(void *param) { void *pingFunc(void *param) {
SSyncIO *io = (SSyncIO *)param; SSyncIO *io = (SSyncIO *)param;
...@@ -13,6 +14,10 @@ void *pingFunc(void *param) { ...@@ -13,6 +14,10 @@ void *pingFunc(void *param) {
} }
int main() { int main() {
testJson();
testJson2();
tsAsyncLog = 0; tsAsyncLog = 0;
taosInitLog((char *)"syncTest.log", 100000, 10); taosInitLog((char *)"syncTest.log", 100000, 10);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册