add sync store
This commit is contained in:
parent
6cf9bb57f5
commit
700287508a
|
@ -27,6 +27,9 @@ extern "C" {
|
|||
#include "syncRaft.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
void testJson();
|
||||
void testJson2();
|
||||
|
||||
int32_t currentTerm(SyncTerm *pCurrentTerm);
|
||||
|
||||
int32_t persistCurrentTerm(SyncTerm currentTerm);
|
||||
|
|
|
@ -203,7 +203,7 @@ static int32_t syncIOPing(SSyncIO *io) {
|
|||
rpcMsg.pCont = rpcMallocCont(10);
|
||||
snprintf(rpcMsg.pCont, 10, "ping");
|
||||
rpcMsg.contLen = 10;
|
||||
rpcMsg.handle = io;
|
||||
rpcMsg.handle = NULL;
|
||||
rpcMsg.msgType = 1;
|
||||
|
||||
rpcSendRequest(io->clientRpc, &io->epSet, &rpcMsg, NULL);
|
||||
|
|
|
@ -14,8 +14,41 @@
|
|||
*/
|
||||
|
||||
#include "syncRaftStore.h"
|
||||
#include "cJSON.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 persistCurrentTerm(SyncTerm currentTerm) { return 0; }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftStore.h"
|
||||
|
||||
void *pingFunc(void *param) {
|
||||
SSyncIO *io = (SSyncIO *)param;
|
||||
|
@ -13,6 +14,10 @@ void *pingFunc(void *param) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
|
||||
testJson();
|
||||
testJson2();
|
||||
|
||||
tsAsyncLog = 0;
|
||||
taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
|
||||
|
|
Loading…
Reference in New Issue