From 7960dbe1089dd389c3270af3734470d02aa0a7bb Mon Sep 17 00:00:00 2001 From: freemine Date: Mon, 25 Jan 2021 20:45:48 +0800 Subject: [PATCH] 1. sem_xxx -> tsem_xxx 2. SystemUid --- src/mnode/src/mnodeCluster.c | 8 -------- src/os/src/darwin/darwinSysInfo.c | 13 ++++++++++++- src/tsdb/inc/tsdbMain.h | 6 +----- src/tsdb/src/tsdbCommit.c | 6 +----- src/tsdb/src/tsdbMain.c | 23 +++-------------------- src/tsdb/src/tsdbMemTable.c | 15 +++------------ 6 files changed, 20 insertions(+), 51 deletions(-) diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index 94ec59b1b0..169d2ebd9d 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -138,14 +138,6 @@ void mnodeDecClusterRef(SClusterObj *pCluster) { sdbDecRef(tsClusterSdb, pCluster); } -#ifdef __APPLE__ -bool taosGetSystemUid(char *uid) { - fprintf(stderr, "%s[%d]%s(): not implemented yet!\n", basename(__FILE__), __LINE__, __func__); - abort(); - return false; -} -#endif // __APPLE__ - static int32_t mnodeCreateCluster() { int64_t numOfClusters = sdbGetNumOfRows(tsClusterSdb); if (numOfClusters != 0) return TSDB_CODE_SUCCESS; diff --git a/src/os/src/darwin/darwinSysInfo.c b/src/os/src/darwin/darwinSysInfo.c index ad3facdcee..cf799d7f55 100644 --- a/src/os/src/darwin/darwinSysInfo.c +++ b/src/os/src/darwin/darwinSysInfo.c @@ -103,4 +103,15 @@ int taosSystem(const char *cmd) { void taosSetCoreDump() {} -char *taosGetCmdlineByPID(int pid) { return ""; } \ No newline at end of file +char *taosGetCmdlineByPID(int pid) { + return "[not supported yet]"; +} + +bool taosGetSystemUid(char *uid) { + uuid_t uuid = {0}; + uuid_generate(uuid); + // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null + uuid_unparse(uuid, uid); + return true; +} + diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index f3e69d9210..05335b45d5 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -233,11 +233,7 @@ typedef struct { SMemTable* mem; SMemTable* imem; STsdbFileH* tsdbFileH; -#ifdef __APPLE__ - sem_t *readyToCommit; -#else // __APPLE__ - sem_t readyToCommit; -#endif // __APPLE__ + tsem_t readyToCommit; pthread_mutex_t mutex; bool repoLocked; int32_t code; // Commit code diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index b3f7f51327..cd8358e5e3 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -166,11 +166,7 @@ static void tsdbEndCommit(STsdbRepo *pRepo, int eno) { pRepo->imem = NULL; tsdbUnlockRepo(pRepo); tsdbUnRefMemTable(pRepo, pIMem); -#ifdef __APPLE__ - sem_post(pRepo->readyToCommit); -#else // __APPLE__ - sem_post(&(pRepo->readyToCommit)); -#endif // __APPLE__ + tsem_post(&(pRepo->readyToCommit)); } static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) { diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index adab932bb6..cadbfa91cf 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -146,11 +146,7 @@ int tsdbCloseRepo(TSDB_REPO_T *repo, int toCommit) { if (toCommit) { tsdbAsyncCommit(pRepo); -#ifdef __APPLE__ - sem_wait(pRepo->readyToCommit); -#else // __APPLE__ - sem_wait(&(pRepo->readyToCommit)); -#endif // __APPLE__ + tsem_wait(&(pRepo->readyToCommit)); terrno = pRepo->code; } tsdbUnRefMemTable(pRepo, pRepo->mem); @@ -647,21 +643,12 @@ static STsdbRepo *tsdbNewRepo(char *rootDir, STsdbAppH *pAppH, STsdbCfg *pCfg) { goto _err; } -#ifdef __APPLE__ - pRepo->readyToCommit = sem_open(NULL, O_CREAT, 0644, 1); - if (pRepo->readyToCommit==SEM_FAILED) { - code = errno; - terrno = TAOS_SYSTEM_ERROR(code); - goto _err; - } -#else // __APPLE__ - code = sem_init(&(pRepo->readyToCommit), 0, 1); + code = tsem_init(&(pRepo->readyToCommit), 0, 1); if (code != 0) { code = errno; terrno = TAOS_SYSTEM_ERROR(code); goto _err; } -#endif // __APPLE__ pRepo->repoLocked = false; @@ -707,11 +694,7 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) { // tsdbFreeMemTable(pRepo->mem); // tsdbFreeMemTable(pRepo->imem); tfree(pRepo->rootDir); -#ifdef __APPLE__ - sem_close(pRepo->readyToCommit); -#else // __APPLE__ - sem_destroy(&(pRepo->readyToCommit)); -#endif // __APPLE__ + tsem_destroy(&(pRepo->readyToCommit)); pthread_mutex_destroy(&pRepo->mutex); free(pRepo); } diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 206a3332d5..42bbebe5f7 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -207,11 +207,7 @@ void *tsdbAllocBytes(STsdbRepo *pRepo, int bytes) { int tsdbAsyncCommit(STsdbRepo *pRepo) { if (pRepo->mem == NULL) return 0; -#ifdef __APPLE__ - sem_wait(pRepo->readyToCommit); -#else // __APPLE__ - sem_wait(&(pRepo->readyToCommit)); -#endif // __APPLE__ + tsem_wait(&(pRepo->readyToCommit)); ASSERT(pRepo->imem == NULL); @@ -233,13 +229,8 @@ int tsdbSyncCommit(TSDB_REPO_T *repo) { STsdbRepo *pRepo = (STsdbRepo *)repo; tsdbAsyncCommit(pRepo); -#ifdef __APPLE__ - sem_wait(pRepo->readyToCommit); - sem_post(pRepo->readyToCommit); -#else // __APPLE__ - sem_wait(&(pRepo->readyToCommit)); - sem_post(&(pRepo->readyToCommit)); -#endif // __APPLE__ + tsem_wait(&(pRepo->readyToCommit)); + tsem_post(&(pRepo->readyToCommit)); if (pRepo->code != TSDB_CODE_SUCCESS) { terrno = pRepo->code; -- GitLab