From b8018126601681cbfe7ac9d8a58a7be5b0943768 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Aug 2022 13:07:14 -0400 Subject: [PATCH] init: probe if sqlite works Help the user get annex.dbdir configured when their filesystem is not one that sqlite works on. The change in Database.Handle makes an error from sqlite not be ignored besides being displayed, which it was before. I can't see any reason git-annex would want to ignore these errors. I chose to use the fsck database rather than the keys database because opening the keys database populates it, and see commit b3c4579c7907147a496bdf2c73b42238d8b239d6. The placement of the call to checkSqliteWorks inside checkInitializeAllowed avoids annex.uuid getting set before it's called. Sponsored-by: Dartmouth College's Datalad project --- Annex/Init.hs | 22 +++++++++++++++++-- Database/Handle.hs | 2 +- ...stem__58___SQLite3_returned_ErrorBusy.mdwn | 2 ++ ..._baafac7f80ff4b7cc4cf078e4ab969c3._comment | 21 ++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy/comment_13_baafac7f80ff4b7cc4cf078e4ab969c3._comment diff --git a/Annex/Init.hs b/Annex/Init.hs index afe73954f2..1eb912b233 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -1,6 +1,6 @@ {- git-annex repository initialization - - - Copyright 2011-2021 Joey Hess + - Copyright 2011-2022 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -27,6 +27,7 @@ import qualified Git.Objects import Git.Types (fromConfigValue) import Git.ConfigTypes (SharedRepository(..)) import qualified Annex.Branch +import qualified Database.Fsck import Logs.UUID import Logs.Trust.Basic import Logs.Config @@ -69,7 +70,9 @@ import Control.Concurrent.Async checkInitializeAllowed :: Annex a -> Annex a checkInitializeAllowed a = guardSafeToUseRepo $ noAnnexFileContent' >>= \case - Nothing -> a + Nothing -> do + checkSqliteWorks + a Just noannexmsg -> do warning "Initialization prevented by .noannex file (remove the file to override)" unless (null noannexmsg) $ @@ -391,6 +394,21 @@ checkFifoSupport = unlessM probeFifoSupport $ do warning "Disabling ssh connection caching." setConfig (annexConfig "sshcaching") (Git.Config.boolConfig False) +{- Sqlite needs the filesystem to support range locking. Some like CIFS + - do not, which will cause sqlite to fail with ErrorBusy. -} +checkSqliteWorks :: Annex () +checkSqliteWorks = do + u <- getUUID + tryNonAsync (Database.Fsck.openDb u >>= Database.Fsck.closeDb) >>= \case + Right () -> return () + Left e -> do + showLongNote $ "Detected a filesystem where Sqlite does not work." + showLongNote $ "(" ++ show e ++ ")" + showLongNote $ "To work around this problem, you can set annex.dbdir " ++ + "to a directory on another filesystem." + showLongNote $ "For example: git config annex.dbdir $HOME/cache/git-annex" + giveup "Not initialized." + checkSharedClone :: Annex Bool checkSharedClone = inRepo Git.Objects.isSharedClone diff --git a/Database/Handle.hs b/Database/Handle.hs index 9c04f701b1..b0c9786974 100644 --- a/Database/Handle.hs +++ b/Database/Handle.hs @@ -123,7 +123,7 @@ workerThread db tablename jobs = newconn newconn = do v <- tryNonAsync (runSqliteRobustly tablename db loop) case v of - Left e -> hPutStrLn stderr $ + Left e -> giveup $ "sqlite worker thread crashed: " ++ show e Right cont -> cont diff --git a/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy.mdwn b/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy.mdwn index b22f15cb79..1a036f8a5d 100644 --- a/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy.mdwn +++ b/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy.mdwn @@ -86,3 +86,5 @@ add file1 ok When initializing the repo with v5 git-annex (git annex init --version=5 test), then the legacy direct mode is used and file addition works well. [[!tag projects/datalad]] + +> [[done]] --[[Joey]] diff --git a/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy/comment_13_baafac7f80ff4b7cc4cf078e4ab969c3._comment b/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy/comment_13_baafac7f80ff4b7cc4cf078e4ab969c3._comment new file mode 100644 index 0000000000..c3f92feb5b --- /dev/null +++ b/doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy/comment_13_baafac7f80ff4b7cc4cf078e4ab969c3._comment @@ -0,0 +1,21 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 13""" + date="2022-08-17T17:05:25Z" + content=""" +I've implemented probing by `git-annex init`, and it will display +this message to help the user get it configured: + + init + Detected a filesystem where Sqlite does not work. + + (sqlite worker thread crashed: user error (SQLite3 returned ErrorBusy while attempting to perform close(synthetic)(after successful open))) + + To work around this problem, you can set annex.dbdir to a directory on another filesystem. + + For example: git config annex.dbdir $HOME/cache/git-annex + + git-annex: Not initialized. + +Going to close the bug since I think this is the best that it can be handled. +"""]]