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
b3c4579c79.

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
This commit is contained in:
Joey Hess 2022-08-17 13:07:14 -04:00
parent fc2d10d2cd
commit b801812660
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 44 additions and 3 deletions

View file

@ -1,6 +1,6 @@
{- git-annex repository initialization
-
- Copyright 2011-2021 Joey Hess <id@joeyh.name>
- Copyright 2011-2022 Joey Hess <id@joeyh.name>
-
- 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

View file

@ -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

View file

@ -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]]

View file

@ -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.
"""]]