sync refactor

This commit is contained in:
Minghao Li 2022-03-09 18:56:39 +08:00
parent c462ef61e3
commit 3dfb9bb022
5 changed files with 16 additions and 8 deletions

View File

@ -24,8 +24,7 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "cJSON.h" #include "cJSON.h"
#include "sync.h" #include "syncInt.h"
#include "syncRaftEntry.h"
#include "taosdef.h" #include "taosdef.h"
// encode as uint32 // encode as uint32

View File

@ -24,19 +24,24 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syncInt.h" #include "syncInt.h"
#include "syncMessage.h"
#include "taosdef.h" #include "taosdef.h"
typedef struct SSyncRaftEntry { typedef struct SSyncRaftEntry {
uint32_t bytes; uint32_t bytes;
uint32_t msgType; uint32_t msgType;
uint32_t originalRpcType;
uint64_t seqNum;
bool isWeak;
SyncTerm term; SyncTerm term;
SyncIndex index; SyncIndex index;
int8_t flag;
uint32_t dataLen; uint32_t dataLen;
char data[]; char data[];
} SSyncRaftEntry; } SSyncRaftEntry;
SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index);
void syncEntryDestory(SSyncRaftEntry* pEntry);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -37,10 +37,10 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode);
void logStoreDestory(SSyncLogStore* pLogStore); void logStoreDestory(SSyncLogStore* pLogStore);
// append one log entry // append one log entry
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SRpcMsg* pEntry); int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
// get one log entry, user need to free pEntry->pCont // get one log entry, user need to free pEntry->pCont
int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry); int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry* pEntry);
// truncate log with index, entries after the given index (>=index) will be deleted // truncate log with index, entries after the given index (>=index) will be deleted
int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex); int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex);

View File

@ -14,3 +14,7 @@
*/ */
#include "syncRaftEntry.h" #include "syncRaftEntry.h"
SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) {}
void syncEntryDestory(SSyncRaftEntry* pEntry) {}

View File

@ -44,10 +44,10 @@ void logStoreDestory(SSyncLogStore* pLogStore) {
} }
// append one log entry // append one log entry
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SRpcMsg* pEntry) {} int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {}
// get one log entry, user need to free pEntry->pCont // get one log entry, user need to free pEntry->pCont
int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry) {} int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry* pEntry) {}
// truncate log with index, entries after the given index (>=index) will be deleted // truncate log with index, entries after the given index (>=index) will be deleted
int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {} int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {}