提交 2fcc970d 编写于 作者: M Minghao Li

sync refactor

上级 d3b1d5d8
......@@ -103,6 +103,9 @@ typedef struct SVotesGranted SVotesGranted;
struct SVotesRespond;
typedef struct SVotesRespond SVotesRespond;
struct SSyncIndexMgr;
typedef struct SSyncIndexMgr SSyncIndexMgr;
typedef struct SRaftId {
SyncNodeId addr; // typedef uint64_t SyncNodeId;
SyncGroupId vgId; // typedef int32_t SyncGroupId;
......@@ -148,8 +151,8 @@ typedef struct SSyncNode {
SVotesRespond* pVotesRespond;
// tla+ leader vars
SHashObj* pNextIndex;
SHashObj* pMatchIndex;
SSyncIndexMgr* pNextIndex;
SSyncIndexMgr* pMatchIndex;
// tla+ log vars
SSyncLogStore* pLogStore;
......
......@@ -81,8 +81,9 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
arr[i] = pSyncIndexMgr->index[i];
}
cJSON *pIsRespond = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum);
cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum);
free(arr);
cJSON_AddItemToObject(pRoot, "index", pIndex);
snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode);
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
......@@ -93,7 +94,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) {
cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr);
char *serialized = cJSON_Print(pJson);
char * serialized = cJSON_Print(pJson);
cJSON_Delete(pJson);
return serialized;
}
\ No newline at end of file
#include <gtest/gtest.h>
#include "syncIndexMgr.h"
//#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
......@@ -97,60 +98,44 @@ int main(int argc, char** argv) {
initRaftId(pSyncNode);
SVotesGranted* pVotesGranted = voteGrantedCreate(pSyncNode);
assert(pVotesGranted != NULL);
SSyncIndexMgr* pSyncIndexMgr = syncIndexMgrCreate(pSyncNode);
assert(pSyncIndexMgr != NULL);
printf("---------------------------------------\n");
{
char* serialized = voteGranted2Str(pVotesGranted);
char* serialized = syncIndexMgr2Str(pSyncIndexMgr);
assert(serialized != NULL);
printf("%s\n", serialized);
free(serialized);
}
SyncTerm term = 1234;
syncIndexMgrSetIndex(pSyncIndexMgr, &ids[0], 100);
syncIndexMgrSetIndex(pSyncIndexMgr, &ids[1], 200);
syncIndexMgrSetIndex(pSyncIndexMgr, &ids[2], 300);
printf("---------------------------------------\n");
voteGrantedReset(pVotesGranted, term);
{
char* serialized = voteGranted2Str(pVotesGranted);
char* serialized = syncIndexMgr2Str(pSyncIndexMgr);
assert(serialized != NULL);
printf("%s\n", serialized);
free(serialized);
}
for (int i = 0; i < replicaNum; ++i) {
SyncRequestVoteReply* reply = SyncRequestVoteReplyBuild();
reply->destId = pSyncNode->myRaftId;
reply->srcId = ids[i];
reply->term = term;
reply->voteGranted = true;
voteGrantedVote(pVotesGranted, reply);
{
char* serialized = voteGranted2Str(pVotesGranted);
assert(serialized != NULL);
printf("%s\n", serialized);
free(serialized);
}
voteGrantedVote(pVotesGranted, reply);
{
char* serialized = voteGranted2Str(pVotesGranted);
assert(serialized != NULL);
printf("%s\n", serialized);
free(serialized);
}
printf("---------------------------------------\n");
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
SyncIndex idx = syncIndexMgrGetIndex(pSyncIndexMgr, &ids[i]);
printf("index %d : %lu \n", i, idx);
}
syncIndexMgrClear(pSyncIndexMgr);
printf("---------------------------------------\n");
voteGrantedReset(pVotesGranted, 123456789);
{
char* serialized = voteGranted2Str(pVotesGranted);
char* serialized = syncIndexMgr2Str(pSyncIndexMgr);
assert(serialized != NULL);
printf("%s\n", serialized);
free(serialized);
}
voteGrantedDestroy(pVotesGranted);
syncIndexMgrDestroy(pSyncIndexMgr);
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册