add sync code

This commit is contained in:
Minghao Li 2022-02-23 09:54:44 +08:00
parent dca01dda58
commit 3d9d5240a5
8 changed files with 141 additions and 3 deletions

View File

@ -153,6 +153,8 @@ int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak);
ESyncState syncGetMyRole(int64_t rid);
void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole);
int32_t syncStartEnv();
extern int32_t sDebugFlag;
#ifdef __cplusplus

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_LIBS_SYNC_ENV_H
#define _TD_LIBS_SYNC_ENV_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "taosdef.h"
#include "trpc.h"
#ifdef __cplusplus
}
#endif
#endif /*_TD_LIBS_SYNC_ENV_H*/

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_LIBS_IO_H
#define _TD_LIBS_IO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "taosdef.h"
#ifdef __cplusplus
}
#endif
#endif /*_TD_LIBS_IO_H*/

View File

@ -24,6 +24,15 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include "taosdef.h"
#include "sync.h"
#include "tlog.h"
extern int32_t sDebugFlag;
#define sLog(...) \
{ \
taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); \
}
#define sFatal(...) \
{ \

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_LIBS_TPL_H
#define _TD_LIBS_TPL_H
#ifndef _TD_LIBS_SYNC_RAFT_ENTRY_H
#define _TD_LIBS_SYNC_RAFT_ENTRY_H
#ifdef __cplusplus
extern "C" {
@ -37,4 +37,4 @@ typedef struct SSyncRaftEntry {
}
#endif
#endif /*_TD_LIBS_TPL_H*/
#endif /*_TD_LIBS_SYNC_RAFT_ENTRY_H*/

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "syncEnv.h"
#include "sync.h"
#include "syncInt.h"
int32_t syncStartEnv() {
sInfo("log: syncStartEnv \n");
if (rpcInit() != 0) {
return -1;
}
}

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "sync.h"

View File

@ -1,7 +1,26 @@
#include <stdio.h>
#include "syncInt.h"
int main() {
printf("test \n");
syncStartEnv();
char temp[100];
snprintf(temp, 100, "./debug.log");
taosInitLog(temp, 10000, 1);
tsAsyncLog = 0;
for (int i = 0; i < 100; i++) {
sDebug("log:%d -------- \n", i);
}
fflush(NULL);
//taosCloseLog();
while(1) {
sleep(3);
}
return 0;
}