diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 00ba1120e713bf38ec371ecc380db394e92d6b96..0ec741ec3e2ab30f7079ae6c7b266b65406c714b 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -137,22 +137,21 @@ typedef struct { } SSyncInfo; -// will be defined in syncInt.h, here just for complie -typedef struct SSyncNode { -} SSyncNode; +struct SSyncNode; +typedef struct SSyncNode SSyncNode; int32_t syncInit(); void syncCleanUp(); -int64_t syncStart(const SSyncInfo*); +int64_t syncStart(const SSyncInfo* pSyncInfo); void syncStop(int64_t rid); -int32_t syncReconfig(int64_t rid, const SSyncCfg*); +int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); // int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak); int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak); ESyncState syncGetMyRole(int64_t rid); -void syncGetNodesRole(int64_t rid, SNodesRole*); +void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole); extern int32_t sDebugFlag; diff --git a/source/libs/sync/CMakeLists.txt b/source/libs/sync/CMakeLists.txt index 784a864451e16e19d325746add3173253998b545..37ee5194c81d337b68e92df096c42a4721ec93eb 100644 --- a/source/libs/sync/CMakeLists.txt +++ b/source/libs/sync/CMakeLists.txt @@ -1,4 +1,3 @@ - aux_source_directory(src SYNC_SRC) add_library(sync ${SYNC_SRC}) diff --git a/source/libs/sync/inc/syncAppendEntries.h b/source/libs/sync/inc/syncAppendEntries.h new file mode 100644 index 0000000000000000000000000000000000000000..9ca0de19c5fbecb6476d281658a4a5e2f5980451 --- /dev/null +++ b/source/libs/sync/inc/syncAppendEntries.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_APPEND_ENTRIES_H +#define _TD_LIBS_SYNC_APPEND_ENTRIES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "syncMessage.h" +#include "syncRaft.h" +#include "taosdef.h" + +void appendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg); + +void onAppendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_APPEND_ENTRIES_H*/ diff --git a/source/libs/sync/inc/syncAppendEntriesReply.h b/source/libs/sync/inc/syncAppendEntriesReply.h new file mode 100644 index 0000000000000000000000000000000000000000..8b5cbf1da53c9ff29e925eafe5ae912a9e28d396 --- /dev/null +++ b/source/libs/sync/inc/syncAppendEntriesReply.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_APPEND_ENTRIES_REPLY_H +#define _TD_LIBS_SYNC_APPEND_ENTRIES_REPLY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "syncMessage.h" +#include "syncRaft.h" +#include "taosdef.h" + +void onAppendEntriesReply(SRaft *pRaft, const SyncAppendEntriesReply *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_APPEND_ENTRIES_REPLY_H*/ diff --git a/source/libs/sync/inc/syncElection.h b/source/libs/sync/inc/syncElection.h new file mode 100644 index 0000000000000000000000000000000000000000..34dfdb3d0952f1e4ce996223393ade44f787f4a3 --- /dev/null +++ b/source/libs/sync/inc/syncElection.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_ELECTION_H +#define _TD_LIBS_SYNC_ELECTION_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "taosdef.h" + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_ELECTION_H*/ diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h new file mode 100644 index 0000000000000000000000000000000000000000..551ce83122c519190be0b494bc76d2fafe72b7e6 --- /dev/null +++ b/source/libs/sync/inc/syncInt.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_INT_H +#define _TD_LIBS_SYNC_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "taosdef.h" + +#define sFatal(...) \ + { \ + if (sDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); \ + } \ + } +#define sError(...) \ + { \ + if (sDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("SYN ERROR ", sDebugFlag, __VA_ARGS__); \ + } \ + } +#define sWarn(...) \ + { \ + if (sDebugFlag & DEBUG_WARN) { \ + taosPrintLog("SYN WARN ", sDebugFlag, __VA_ARGS__); \ + } \ + } +#define sInfo(...) \ + { \ + if (sDebugFlag & DEBUG_INFO) { \ + taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); \ + } \ + } +#define sDebug(...) \ + { \ + if (sDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); \ + } \ + } +#define sTrace(...) \ + { \ + if (sDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); \ + } \ + } + +typedef struct SSyncNode { + char path[TSDB_FILENAME_LEN]; + int8_t replica; + int8_t quorum; + int8_t selfIndex; + uint32_t vgId; + int32_t refCount; + int64_t rid; +} SSyncNode; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_INT_H*/ diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h new file mode 100644 index 0000000000000000000000000000000000000000..f410c8cf6ebf8f71b4585a72568afc88f80ac15d --- /dev/null +++ b/source/libs/sync/inc/syncMessage.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_MESSAGE_H +#define _TD_LIBS_SYNC_MESSAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "sync.h" +#include "syncRaftEntry.h" +#include "taosdef.h" + +typedef enum ESyncMessageType { + SYNC_PING = 0, + SYNC_PING_REPLY, + SYNC_CLIENT_REQUEST, + SYNC_CLIENT_REQUEST_REPLY, + SYNC_REQUEST_VOTE, + SYNC_REQUEST_VOTE_REPLY, + SYNC_APPEND_ENTRIES, + SYNC_APPEND_ENTRIES_REPLY, +} ESyncMessageType; + +typedef struct SyncPing { + ESyncMessageType msgType; + const SSyncBuffer *pData; +} SyncPing; + +typedef struct SyncPingReply { + ESyncMessageType msgType; + const SSyncBuffer *pData; +} SyncPingReply; + +typedef struct SyncClientRequest { + ESyncMessageType msgType; + const SSyncBuffer *pData; + int64_t seqNum; + bool isWeak; +} SyncClientRequest; + +typedef struct SyncClientRequestReply { + ESyncMessageType msgType; + int32_t errCode; + const SSyncBuffer *pErrMsg; + const SSyncBuffer *pLeaderHint; +} SyncClientRequestReply; + +typedef struct SyncRequestVote { + ESyncMessageType msgType; + SyncTerm currentTerm; + SyncNodeId nodeId; + SyncGroupId vgId; + SyncIndex lastLogIndex; + SyncTerm lastLogTerm; +} SyncRequestVote; + +typedef struct SyncRequestVoteReply { + ESyncMessageType msgType; + SyncTerm currentTerm; + SyncNodeId nodeId; + SyncGroupId vgId; + bool voteGranted; +} SyncRequestVoteReply; + +typedef struct SyncAppendEntries { + ESyncMessageType msgType; + SyncTerm currentTerm; + SyncNodeId nodeId; + SyncIndex prevLogIndex; + SyncTerm prevLogTerm; + int32_t entryCount; + SSyncRaftEntry * logEntries; + SyncIndex commitIndex; +} SyncAppendEntries; + +typedef struct SyncAppendEntriesReply { + ESyncMessageType msgType; + SyncTerm currentTerm; + SyncNodeId nodeId; + bool success; + SyncIndex matchIndex; +} SyncAppendEntriesReply; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_MESSAGE_H*/ diff --git a/source/libs/sync/inc/syncOnMessage.h b/source/libs/sync/inc/syncOnMessage.h new file mode 100644 index 0000000000000000000000000000000000000000..07c44b6199e6fb2e8feea98a9de789c4001a9c6d --- /dev/null +++ b/source/libs/sync/inc/syncOnMessage.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_ON_MESSAGE_H +#define _TD_LIBS_SYNC_ON_MESSAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "syncRaft.h" +#include "taosdef.h" + +void onMessage(SRaft *pRaft, void *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_ON_MESSAGE_H*/ diff --git a/source/libs/sync/inc/syncRaft.h b/source/libs/sync/inc/syncRaft.h new file mode 100644 index 0000000000000000000000000000000000000000..0c7e573572230e640094f734ca716886c26ac40c --- /dev/null +++ b/source/libs/sync/inc/syncRaft.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_RAFT_H +#define _TD_LIBS_SYNC_RAFT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "sync.h" +#include "syncMessage.h" +#include "taosdef.h" + +typedef struct SRaftId { + SyncNodeId nodeId; + SyncGroupId vgId; +} SRaftId; + +typedef struct SRaft { + SRaftId id; +} SRaft; + +int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak); + +static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_RAFT_H*/ diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h new file mode 100644 index 0000000000000000000000000000000000000000..adc82f2c5d9f2db8d7f1cd3f734b7bb129f6173a --- /dev/null +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_TPL_H +#define _TD_LIBS_TPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "sync.h" +#include "taosdef.h" + +typedef struct SSyncRaftEntry { + SyncTerm term; + SyncIndex index; + SSyncBuffer data; + int8_t flag; +} SSyncRaftEntry; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_TPL_H*/ diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h new file mode 100644 index 0000000000000000000000000000000000000000..8c4b5116ea17b2c1c57d0156a165d3bab845594e --- /dev/null +++ b/source/libs/sync/inc/syncRaftLog.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_RAFT_LOG_H +#define _TD_LIBS_SYNC_RAFT_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "sync.h" +#include "taosdef.h" + +int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf); + +// get one log entry, user need to free pBuf->data +int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncBuffer* pBuf); + +// update log store commit index with "index" +int32_t raftLogUpdateCommitIndex(struct SSyncLogStore* pLogStore, SyncIndex index); + +// truncate log with index, entries after the given index (>index) will be deleted +int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex index); + +// return commit index of log +SyncIndex raftLogGetCommitIndex(struct SSyncLogStore* pLogStore); + +// return index of last entry +SyncIndex raftLogGetLastIndex(struct SSyncLogStore* pLogStore); + +// return term of last entry +SyncTerm raftLogGetLastTerm(struct SSyncLogStore* pLogStore); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_RAFT_LOG_H*/ diff --git a/source/libs/sync/inc/syncRaftStore.h b/source/libs/sync/inc/syncRaftStore.h new file mode 100644 index 0000000000000000000000000000000000000000..4cb852f34a5d962824a91e8b7ca666bcb1f130c0 --- /dev/null +++ b/source/libs/sync/inc/syncRaftStore.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_RAFT_STORE_H +#define _TD_LIBS_SYNC_RAFT_STORE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "sync.h" +#include "syncRaft.h" +#include "taosdef.h" + +int32_t currentTerm(SyncTerm *pCurrentTerm); + +int32_t persistCurrentTerm(SyncTerm currentTerm); + +int32_t voteFor(SRaftId *pRaftId); + +int32_t persistVoteFor(SRaftId *pRaftId); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_RAFT_STORE_H*/ diff --git a/source/libs/sync/inc/syncReplication.h b/source/libs/sync/inc/syncReplication.h new file mode 100644 index 0000000000000000000000000000000000000000..40c5ff790b6c30ee141633cabd3d730275a026b8 --- /dev/null +++ b/source/libs/sync/inc/syncReplication.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_REPLICATION_H +#define _TD_LIBS_SYNC_REPLICATION_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "taosdef.h" + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_REPLICATION_H*/ diff --git a/source/libs/sync/inc/syncRequestVote.h b/source/libs/sync/inc/syncRequestVote.h new file mode 100644 index 0000000000000000000000000000000000000000..3ff96bbe8fad9f80db711e556ec841f7b6dd3082 --- /dev/null +++ b/source/libs/sync/inc/syncRequestVote.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_REQUEST_VOTE_H +#define _TD_LIBS_SYNC_REQUEST_VOTE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "syncMessage.h" +#include "syncRaft.h" +#include "taosdef.h" + +void requestVote(SRaft *pRaft, const SyncRequestVote *pMsg); + +void onRequestVote(SRaft *pRaft, const SyncRequestVote *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_REQUEST_VOTE_H*/ diff --git a/source/libs/sync/inc/syncRequestVoteReply.h b/source/libs/sync/inc/syncRequestVoteReply.h new file mode 100644 index 0000000000000000000000000000000000000000..033ac89bc2f4d0f74afd4a497e77a098b5934159 --- /dev/null +++ b/source/libs/sync/inc/syncRequestVoteReply.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_REQUEST_VOTE_REPLY_H +#define _TD_LIBS_SYNC_REQUEST_VOTE_REPLY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "syncMessage.h" +#include "syncRaft.h" +#include "taosdef.h" + +void onRequestVoteReply(SRaft *pRaft, const SyncRequestVoteReply *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_REQUEST_VOTE_REPLY_H*/ diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h new file mode 100644 index 0000000000000000000000000000000000000000..3b6121578ad99b55af5bc81bf9601a48b1391c68 --- /dev/null +++ b/source/libs/sync/inc/syncSnapshot.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_SNAPSHOT_H +#define _TD_LIBS_SYNC_SNAPSHOT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "sync.h" +#include "syncRaft.h" +#include "taosdef.h" + +int32_t takeSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot); + +int32_t restoreSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_SNAPSHOT_H*/ diff --git a/source/libs/sync/inc/syncTimeout.h b/source/libs/sync/inc/syncTimeout.h new file mode 100644 index 0000000000000000000000000000000000000000..8159d2566c740296ca58f6d1f8ba05d12d044a34 --- /dev/null +++ b/source/libs/sync/inc/syncTimeout.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_LIBS_SYNC_TIMEOUT_H +#define _TD_LIBS_SYNC_TIMEOUT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "syncMessage.h" +#include "syncRaft.h" +#include "taosdef.h" + +void onTimeout(SRaft *pRaft, void *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_TIMEOUT_H*/ diff --git a/source/libs/sync/src/sync.c b/source/libs/sync/src/sync.c deleted file mode 100644 index 7ded53b6e610e07b6b70c5022bce10c60899a9ac..0000000000000000000000000000000000000000 --- a/source/libs/sync/src/sync.c +++ /dev/null @@ -1 +0,0 @@ -#include "sync.h" \ No newline at end of file diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c new file mode 100644 index 0000000000000000000000000000000000000000..1286108664270b81a4b5ae70f6e592dc67a6a5ad --- /dev/null +++ b/source/libs/sync/src/syncAppendEntries.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncAppendEntries.h" +#include "sync.h" + +void appendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) { + +// TLA+ Spec +//AppendEntries(i, j) == +// /\ i /= j +// /\ state[i] = Leader +// /\ LET prevLogIndex == nextIndex[i][j] - 1 +// prevLogTerm == IF prevLogIndex > 0 THEN +// log[i][prevLogIndex].term +// ELSE +// 0 +// \* Send up to 1 entry, constrained by the end of the log. +// lastEntry == Min({Len(log[i]), nextIndex[i][j]}) +// entries == SubSeq(log[i], nextIndex[i][j], lastEntry) +// IN Send([mtype |-> AppendEntriesRequest, +// mterm |-> currentTerm[i], +// mprevLogIndex |-> prevLogIndex, +// mprevLogTerm |-> prevLogTerm, +// mentries |-> entries, +// \* mlog is used as a history variable for the proof. +// \* It would not exist in a real implementation. +// mlog |-> log[i], +// mcommitIndex |-> Min({commitIndex[i], lastEntry}), +// msource |-> i, +// mdest |-> j]) +// /\ UNCHANGED <> + +} + +void onAppendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) { + +// TLA+ Spec +//HandleAppendEntriesRequest(i, j, m) == +// LET logOk == \/ m.mprevLogIndex = 0 +// \/ /\ m.mprevLogIndex > 0 +// /\ m.mprevLogIndex <= Len(log[i]) +// /\ m.mprevLogTerm = log[i][m.mprevLogIndex].term +// IN /\ m.mterm <= currentTerm[i] +// /\ \/ /\ \* reject request +// \/ m.mterm < currentTerm[i] +// \/ /\ m.mterm = currentTerm[i] +// /\ state[i] = Follower +// /\ \lnot logOk +// /\ Reply([mtype |-> AppendEntriesResponse, +// mterm |-> currentTerm[i], +// msuccess |-> FALSE, +// mmatchIndex |-> 0, +// msource |-> i, +// mdest |-> j], +// m) +// /\ UNCHANGED <> +// \/ \* return to follower state +// /\ m.mterm = currentTerm[i] +// /\ state[i] = Candidate +// /\ state' = [state EXCEPT ![i] = Follower] +// /\ UNCHANGED <> +// \/ \* accept request +// /\ m.mterm = currentTerm[i] +// /\ state[i] = Follower +// /\ logOk +// /\ LET index == m.mprevLogIndex + 1 +// IN \/ \* already done with request +// /\ \/ m.mentries = << >> +// \/ /\ m.mentries /= << >> +// /\ Len(log[i]) >= index +// /\ log[i][index].term = m.mentries[1].term +// \* This could make our commitIndex decrease (for +// \* example if we process an old, duplicated request), +// \* but that doesn't really affect anything. +// /\ commitIndex' = [commitIndex EXCEPT ![i] = +// m.mcommitIndex] +// /\ Reply([mtype |-> AppendEntriesResponse, +// mterm |-> currentTerm[i], +// msuccess |-> TRUE, +// mmatchIndex |-> m.mprevLogIndex + +// Len(m.mentries), +// msource |-> i, +// mdest |-> j], +// m) +// /\ UNCHANGED <> +// \/ \* conflict: remove 1 entry +// /\ m.mentries /= << >> +// /\ Len(log[i]) >= index +// /\ log[i][index].term /= m.mentries[1].term +// /\ LET new == [index2 \in 1..(Len(log[i]) - 1) |-> +// log[i][index2]] +// IN log' = [log EXCEPT ![i] = new] +// /\ UNCHANGED <> +// \/ \* no conflict: append entry +// /\ m.mentries /= << >> +// /\ Len(log[i]) = m.mprevLogIndex +// /\ log' = [log EXCEPT ![i] = +// Append(log[i], m.mentries[1])] +// /\ UNCHANGED <> +// /\ UNCHANGED <> +// + + +} diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c new file mode 100644 index 0000000000000000000000000000000000000000..4a9055e172fce1aad4753410301c34f4c8823275 --- /dev/null +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncAppendEntriesReply.h" +#include "sync.h" + +void onAppendEntriesReply(SRaft *pRaft, const SyncAppendEntriesReply *pMsg) { + +// TLA+ Spec +//HandleAppendEntriesResponse(i, j, m) == +// /\ m.mterm = currentTerm[i] +// /\ \/ /\ m.msuccess \* successful +// /\ nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] +// /\ matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex] +// \/ /\ \lnot m.msuccess \* not successful +// /\ nextIndex' = [nextIndex EXCEPT ![i][j] = +// Max({nextIndex[i][j] - 1, 1})] +// /\ UNCHANGED <> +// /\ Discard(m) +// /\ UNCHANGED <> + +} diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c new file mode 100644 index 0000000000000000000000000000000000000000..738fc4c5e129562d368451c3f9d1eb3315060bb4 --- /dev/null +++ b/source/libs/sync/src/syncElection.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "sync.h" diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c new file mode 100644 index 0000000000000000000000000000000000000000..fbb969eb1c91b6d0641dd1ff8d02b49f4ebe428c --- /dev/null +++ b/source/libs/sync/src/syncMain.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include "sync.h" +#include "syncInt.h" + +int32_t syncInit() { return 0; } + +void syncCleanUp() {} + +int64_t syncStart(const SSyncInfo* pSyncInfo) { return 0; } + +void syncStop(int64_t rid) {} + +int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) { return 0; } + +int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak) { return 0; } + +ESyncState syncGetMyRole(int64_t rid) { return TAOS_SYNC_STATE_LEADER; } + +void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {} \ No newline at end of file diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c new file mode 100644 index 0000000000000000000000000000000000000000..dcfc940f76b37570f6052ef47bf15aa87dbb698f --- /dev/null +++ b/source/libs/sync/src/syncMessage.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncMessage.h" +#include "sync.h" +#include "syncRaft.h" + +void onMessage(SRaft *pRaft, void *pMsg) {} \ No newline at end of file diff --git a/source/libs/sync/src/syncOnMessage.c b/source/libs/sync/src/syncOnMessage.c new file mode 100644 index 0000000000000000000000000000000000000000..738fc4c5e129562d368451c3f9d1eb3315060bb4 --- /dev/null +++ b/source/libs/sync/src/syncOnMessage.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "sync.h" diff --git a/source/libs/sync/src/syncRaft.c b/source/libs/sync/src/syncRaft.c new file mode 100644 index 0000000000000000000000000000000000000000..85c2c6fe27ba70b4ecdac85c5d31aac165ce0a00 --- /dev/null +++ b/source/libs/sync/src/syncRaft.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncRaft.h" +#include "sync.h" + +int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak) { return 0; } + +static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft) { return 0; } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c new file mode 100644 index 0000000000000000000000000000000000000000..738fc4c5e129562d368451c3f9d1eb3315060bb4 --- /dev/null +++ b/source/libs/sync/src/syncRaftEntry.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "sync.h" diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c new file mode 100644 index 0000000000000000000000000000000000000000..4a5fc201b07c01cf537f809064ad10618115b4d6 --- /dev/null +++ b/source/libs/sync/src/syncRaftLog.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncRaftLog.h" +#include "sync.h" + +int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf) { return 0; } + +// get one log entry, user need to free pBuf->data +int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncBuffer* pBuf) { return 0; } + +// update log store commit index with "index" +int32_t raftLogupdateCommitIndex(struct SSyncLogStore* pLogStore, SyncIndex index) { return 0; } + +// truncate log with index, entries after the given index (>index) will be deleted +int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex index) { return 0; } + +// return commit index of log +SyncIndex raftLogGetCommitIndex(struct SSyncLogStore* pLogStore) { return 0; } + +// return index of last entry +SyncIndex raftLogGetLastIndex(struct SSyncLogStore* pLogStore) { return 0; } + +// return term of last entry +SyncTerm raftLogGetLastTerm(struct SSyncLogStore* pLogStore) { return 0; } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c new file mode 100644 index 0000000000000000000000000000000000000000..d45e53132cbc6d14f70f2c9d09948b9f09d283ce --- /dev/null +++ b/source/libs/sync/src/syncRaftStore.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncRaftStore.h" +#include "sync.h" + +int32_t currentTerm(SyncTerm *pCurrentTerm) { return 0; } + +int32_t persistCurrentTerm(SyncTerm currentTerm) { return 0; } + +int32_t voteFor(SRaftId *pRaftId) { return 0; } + +int32_t persistVoteFor(SRaftId *pRaftId) { return 0; } \ No newline at end of file diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c new file mode 100644 index 0000000000000000000000000000000000000000..738fc4c5e129562d368451c3f9d1eb3315060bb4 --- /dev/null +++ b/source/libs/sync/src/syncReplication.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "sync.h" diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c new file mode 100644 index 0000000000000000000000000000000000000000..c31ec0f34d521b214b7d45a3ce32c3890ebcabd5 --- /dev/null +++ b/source/libs/sync/src/syncRequestVote.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncRequestVote.h" +#include "sync.h" + +void requestVote(SRaft *pRaft, const SyncRequestVote *pMsg) { + +// TLA+ Spec +//RequestVote(i, j) == +// /\ state[i] = Candidate +// /\ j \notin votesResponded[i] +// /\ Send([mtype |-> RequestVoteRequest, +// mterm |-> currentTerm[i], +// mlastLogTerm |-> LastTerm(log[i]), +// mlastLogIndex |-> Len(log[i]), +// msource |-> i, +// mdest |-> j]) +// /\ UNCHANGED <> + +} + +void onRequestVote(SRaft *pRaft, const SyncRequestVote *pMsg) { + +// TLA+ Spec +//HandleRequestVoteRequest(i, j, m) == +// LET logOk == \/ m.mlastLogTerm > LastTerm(log[i]) +// \/ /\ m.mlastLogTerm = LastTerm(log[i]) +// /\ m.mlastLogIndex >= Len(log[i]) +// grant == /\ m.mterm = currentTerm[i] +// /\ logOk +// /\ votedFor[i] \in {Nil, j} +// IN /\ m.mterm <= currentTerm[i] +// /\ \/ grant /\ votedFor' = [votedFor EXCEPT ![i] = j] +// \/ ~grant /\ UNCHANGED votedFor +// /\ Reply([mtype |-> RequestVoteResponse, +// mterm |-> currentTerm[i], +// mvoteGranted |-> grant, +// \* mlog is used just for the `elections' history variable for +// \* the proof. It would not exist in a real implementation. +// mlog |-> log[i], +// msource |-> i, +// mdest |-> j], +// m) +// /\ UNCHANGED <> + +} diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c new file mode 100644 index 0000000000000000000000000000000000000000..ba9787f00c156a7b205a87108dd5670ff0f921b3 --- /dev/null +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncRequestVoteReply.h" +#include "sync.h" + +void onRequestVoteReply(SRaft *pRaft, const SyncRequestVoteReply *pMsg) { + +// TLA+ Spec +//HandleRequestVoteResponse(i, j, m) == +// \* This tallies votes even when the current state is not Candidate, but +// \* they won't be looked at, so it doesn't matter. +// /\ m.mterm = currentTerm[i] +// /\ votesResponded' = [votesResponded EXCEPT ![i] = +// votesResponded[i] \cup {j}] +// /\ \/ /\ m.mvoteGranted +// /\ votesGranted' = [votesGranted EXCEPT ![i] = +// votesGranted[i] \cup {j}] +// /\ voterLog' = [voterLog EXCEPT ![i] = +// voterLog[i] @@ (j :> m.mlog)] +// \/ /\ ~m.mvoteGranted +// /\ UNCHANGED <> +// /\ Discard(m) +// /\ UNCHANGED <> + +} diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c new file mode 100644 index 0000000000000000000000000000000000000000..8a27f097d1335a16d3033d091ba6e5221029a4b8 --- /dev/null +++ b/source/libs/sync/src/syncSnapshot.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncSnapshot.h" +#include "sync.h" +#include "syncRaft.h" + +int32_t takeSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { return 0; } + +int32_t restoreSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { return 0; } \ No newline at end of file diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c new file mode 100644 index 0000000000000000000000000000000000000000..206dd70046b07f5597b96e819d8fd10ceee59433 --- /dev/null +++ b/source/libs/sync/src/syncTimeout.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "syncTimeout.h" +#include "sync.h" + +void onTimeout(SRaft *pRaft, void *pMsg) {} \ No newline at end of file diff --git a/source/libs/sync/test/syncTest.cpp b/source/libs/sync/test/syncTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47566d537e74b4369806f11977220288aff2b00f --- /dev/null +++ b/source/libs/sync/test/syncTest.cpp @@ -0,0 +1,7 @@ +#include + +int main() { + printf("test \n"); + return 0; +} +