From 08ed99b0692cef6d791887dd2351f6bb8f1d1523 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 2 Apr 2022 02:56:09 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/btree/tdbBtreeBalance.c | 14 ------ source/libs/tdb/src/btree/tdbBtreeCommon.c | 14 ------ source/libs/tdb/src/btree/tdbBtreeDelete.c | 14 ------ source/libs/tdb/src/btree/tdbBtreeInsert.c | 14 ------ source/libs/tdb/src/btree/tdbBtreeInt.h | 27 ------------ source/libs/tdb/src/btree/tdbBtreeOpen.c | 14 ------ source/libs/tdb/src/db/tdbPCache.c | 47 ++++++++++++--------- source/libs/tdb/src/inc/tdbPCache.h | 1 + source/libs/tdb/src/inc/tdbTxn.h | 1 + 9 files changed, 29 insertions(+), 117 deletions(-) delete mode 100644 source/libs/tdb/src/btree/tdbBtreeBalance.c delete mode 100644 source/libs/tdb/src/btree/tdbBtreeCommon.c delete mode 100644 source/libs/tdb/src/btree/tdbBtreeDelete.c delete mode 100644 source/libs/tdb/src/btree/tdbBtreeInsert.c delete mode 100644 source/libs/tdb/src/btree/tdbBtreeInt.h delete mode 100644 source/libs/tdb/src/btree/tdbBtreeOpen.c diff --git a/source/libs/tdb/src/btree/tdbBtreeBalance.c b/source/libs/tdb/src/btree/tdbBtreeBalance.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/btree/tdbBtreeBalance.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 . - */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeCommon.c b/source/libs/tdb/src/btree/tdbBtreeCommon.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/btree/tdbBtreeCommon.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 . - */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeDelete.c b/source/libs/tdb/src/btree/tdbBtreeDelete.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/btree/tdbBtreeDelete.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 . - */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeInsert.c b/source/libs/tdb/src/btree/tdbBtreeInsert.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/btree/tdbBtreeInsert.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 . - */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeInt.h b/source/libs/tdb/src/btree/tdbBtreeInt.h deleted file mode 100644 index b8a935a614..0000000000 --- a/source/libs/tdb/src/btree/tdbBtreeInt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 _TDB_BTREE_INT_H_ -#define _TDB_BTREE_INT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TDB_BTREE_INT_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeOpen.c b/source/libs/tdb/src/btree/tdbBtreeOpen.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/btree/tdbBtreeOpen.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 . - */ \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index d886cfd889..024143c8b2 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -18,6 +18,7 @@ struct SPCache { int pageSize; int cacheSize; tdb_mutex_t mutex; + SPage *pList; int nFree; SPage *pFree; int nPage; @@ -35,16 +36,17 @@ struct SPCache { #define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL) static int tdbPCacheOpenImpl(SPCache *pCache); -static void tdbPCacheInitLock(SPCache *pCache); -static void tdbPCacheClearLock(SPCache *pCache); -static void tdbPCacheLock(SPCache *pCache); -static void tdbPCacheUnlock(SPCache *pCache); -static bool tdbPCacheLocked(SPCache *pCache); static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); static void tdbPCachePinPage(SPCache *pCache, SPage *pPage); static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage); static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage); static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage); +static int tdbPCacheCloseImpl(SPCache *pCache); + +static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); } +static void tdbPCacheDestroyLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } +static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } +static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); } int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { SPCache *pCache; @@ -69,7 +71,10 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { } int tdbPCacheClose(SPCache *pCache) { - /* TODO */ + if (pCache) { + tdbPCacheCloseImpl(pCache); + tdbOsFree(pCache); + } return 0; } @@ -99,19 +104,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { } } -static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); } - -static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } - -static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } - -static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); } - -static bool tdbPCacheLocked(SPCache *pCache) { - assert(0); - // TODO - return true; -} +int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; } static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) { SPage *pPage; @@ -268,4 +261,18 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { return 0; } -int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; } +static int tdbPCacheDestroyPage(SPage *pPage) { + // TODO + return 0; +} + +static int tdbPCacheCloseImpl(SPCache *pCache) { + SPage *pPage; + + for (pPage = pCache->pList; pPage; pPage = pCache->pList) { + pCache->pList = pPage->pCacheNext; + tdbPCacheDestroyPage(pPage); + } + + tdbPCacheDestroyLock(pCache); +} diff --git a/source/libs/tdb/src/inc/tdbPCache.h b/source/libs/tdb/src/inc/tdbPCache.h index f71d34ab53..eab5d7582a 100644 --- a/source/libs/tdb/src/inc/tdbPCache.h +++ b/source/libs/tdb/src/inc/tdbPCache.h @@ -25,6 +25,7 @@ extern "C" { u8 isLocalPage; \ u8 isDirty; \ i32 nRef; \ + SPage *pCacheNext; \ SPage *pFreeNext; \ SPage *pHashNext; \ SPage *pLruNext; \ diff --git a/source/libs/tdb/src/inc/tdbTxn.h b/source/libs/tdb/src/inc/tdbTxn.h index 0be2dad3c2..d979249f03 100644 --- a/source/libs/tdb/src/inc/tdbTxn.h +++ b/source/libs/tdb/src/inc/tdbTxn.h @@ -25,6 +25,7 @@ typedef struct STxn TXN; struct STxn { u64 txnId; void *(*xMalloc)(void *, int); + void (*xFree)(void *, void *); void *xArg; }; -- GitLab