From 3d9d5240a520b0fdc206eb361a08323c49f0e333 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 23 Feb 2022 09:54:44 +0800 Subject: [PATCH] add sync code --- include/libs/sync/sync.h | 2 ++ source/libs/sync/inc/syncEnv.h | 33 ++++++++++++++++++++++++++++ source/libs/sync/inc/syncIO.h | 33 ++++++++++++++++++++++++++++ source/libs/sync/inc/syncInt.h | 9 ++++++++ source/libs/sync/inc/syncRaftEntry.h | 6 ++--- source/libs/sync/src/syncEnv.c | 26 ++++++++++++++++++++++ source/libs/sync/src/syncIO.c | 16 ++++++++++++++ source/libs/sync/test/syncTest.cpp | 19 ++++++++++++++++ 8 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 source/libs/sync/inc/syncEnv.h create mode 100644 source/libs/sync/inc/syncIO.h create mode 100644 source/libs/sync/src/syncEnv.c create mode 100644 source/libs/sync/src/syncIO.c diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 0ec741ec3e..3d875a4be8 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -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 diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h new file mode 100644 index 0000000000..a6ab03e1ee --- /dev/null +++ b/source/libs/sync/inc/syncEnv.h @@ -0,0 +1,33 @@ +/* + * 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_ENV_H +#define _TD_LIBS_SYNC_ENV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "taosdef.h" +#include "trpc.h" + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_ENV_H*/ diff --git a/source/libs/sync/inc/syncIO.h b/source/libs/sync/inc/syncIO.h new file mode 100644 index 0000000000..ebe9fb32d1 --- /dev/null +++ b/source/libs/sync/inc/syncIO.h @@ -0,0 +1,33 @@ +/* + * 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_IO_H +#define _TD_LIBS_IO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "taosdef.h" + + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_IO_H*/ diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 551ce83122..c1aba0518c 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -24,6 +24,15 @@ extern "C" { #include #include #include "taosdef.h" +#include "sync.h" +#include "tlog.h" + +extern int32_t sDebugFlag; + +#define sLog(...) \ + { \ + taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); \ + } #define sFatal(...) \ { \ diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index adc82f2c5d..65f77f3759 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#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*/ diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c new file mode 100644 index 0000000000..a11ed86dc0 --- /dev/null +++ b/source/libs/sync/src/syncEnv.c @@ -0,0 +1,26 @@ +/* + * 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 "syncEnv.h" +#include "sync.h" +#include "syncInt.h" + +int32_t syncStartEnv() { + sInfo("log: syncStartEnv \n"); + + if (rpcInit() != 0) { + return -1; + } +} \ No newline at end of file diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c new file mode 100644 index 0000000000..738fc4c5e1 --- /dev/null +++ b/source/libs/sync/src/syncIO.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/test/syncTest.cpp b/source/libs/sync/test/syncTest.cpp index 47566d537e..e069091ad8 100644 --- a/source/libs/sync/test/syncTest.cpp +++ b/source/libs/sync/test/syncTest.cpp @@ -1,7 +1,26 @@ #include +#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; } -- GitLab