From 828ab50af7553452401873e56f70e26486e09962 Mon Sep 17 00:00:00 2001 From: wuyichen <664334617@qq.com> Date: Mon, 28 Oct 2024 14:17:02 +0800 Subject: [PATCH] Refactor lock print function Signed-off-by: wuyichen <664334617@qq.com> --- src/sqlite3.c | 101 +++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c index 3ca7c7b..93fd40f 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -71040,10 +71040,13 @@ static int btreeInvokeBusyHandler(void *pArg){ BtShared *pBt = (BtShared*)pArg; assert( pBt->db ); assert( sqlite3_mutex_held(pBt->db->mutex) ); + int rc = sqlite3InvokeBusyHandler(&pBt->db->busyHandler); #if SQLITE_OS_UNIX - printLockInfoUsingPager( pBt->pPager ); + if( rc==0 ){ + printLockInfoUsingPager( pBt->pPager ); + } #endif /* SQLITE_OS_UNIX */ - return sqlite3InvokeBusyHandler(&pBt->db->busyHandler); + return rc; } /* @@ -246220,71 +246223,69 @@ export_finish: #if SQLITE_OS_UNIX #define DB_LOCK_NUM 3 +#define DB_SHARED_LOCK_OFFSET 2 #define WAL_LOCK_NUM 8 #define WAL_READ_LOCK_POS 3 +#define LOCK_NUM (DB_LOCK_NUM+WAL_LOCK_NUM) static void printLockInfo(unixFile *uFile_db, int walStat) { const char *lock_type[DB_LOCK_NUM] = {"F_RDLCK", "F_WRLCK", "F_UNLCK"}; - sqlite3_log(SQLITE_WARNING, "*** SQLITE_LOG DB Lock ***\n"); + sqlite3_log(SQLITE_WARNING, "*** SQLITE_LOG DB Lock ***"); if( uFile_db==NULL ){ - sqlite3_log(SQLITE_WARNING, "NO DB FILE !\n"); + sqlite3_log(SQLITE_WARNING, "NO DB FILE !"); + return; + } + unixInodeInfo *inode = uFile_db->pInode; + if( inode==NULL ){ + sqlite3_log(SQLITE_ERROR, "Inode is NULL !"); return; } + sqlite3_log(SQLITE_WARNING, "fileLock %d inodeRef %d inodeLockCnt %d inodeFileLock %d inodeProcessLock %d", + uFile_db->eFileLock, inode->nRef, inode->nLock, inode->eFileLock, inode->bProcessLock); /* File Lock Info */ int fd_db = uFile_db->h; - const off_t start_list[DB_LOCK_NUM] = {PENDING_BYTE, RESERVED_BYTE, SHARED_FIRST}; - const off_t len_list[DB_LOCK_NUM] = {1, 1, SHARED_SIZE}; - const char *lock_name_list[DB_LOCK_NUM] = {"pending lock ", "reserved lock", "shared lock "}; - - for(int i=0; ipShm==NULL ){ - sqlite3_log(SQLITE_ERROR, "DB Shm is NULL!\n"); - }else{ - for( int i=0; ipShm->pShmNode->aLock[i] ){ - sqlite3_log(SQLITE_WARNING, " thrad WAL Lock[%d] for DB file: %d\n", i, uFile_db->pShm->pShmNode->aLock[i]); - } + return; + } + for(int i=0; ipShm->pShmNode->aLock[i] ){ + sqlite3_log(SQLITE_WARNING, "Local WAL Lock[%d] for DB file: %d", i, uFile_db->pShm->pShmNode->aLock[i]); } } } @@ -246293,7 +246294,10 @@ static void printLockInfo(unixFile *uFile_db, int walStat) static void printLockInfoUsingWal(Wal *pWal) { if( pWal==NULL ){ - sqlite3_log(SQLITE_ERROR, "Wal ptr is NULL!\n"); + sqlite3_log(SQLITE_ERROR, "Wal ptr is NULL!"); + return; + } + if( pWal->pVfs==NULL || sqlite3_stricmp(pWal->pVfs->zName, "unix")!=0 ){ return; } printLockInfo((unixFile *)(pWal->pDbFd), 1); @@ -246303,7 +246307,10 @@ static void printLockInfoUsingWal(Wal *pWal) static void printLockInfoUsingPager(Pager *pPager) { if( pPager==NULL ){ - sqlite3_log(SQLITE_ERROR, "Pager ptr is NULL!\n"); + sqlite3_log(SQLITE_ERROR, "Pager ptr is NULL!"); + return; + } + if( pPager->pVfs==NULL || sqlite3_stricmp(pPager->pVfs->zName, "unix")!=0 ){ return; } #ifndef SQLITE_OMIT_WAL -- Gitee