]> dgit.raspbian.org Git - git-annex.git/commitdiff
init: probe if sqlite works
authorJoey Hess <joeyh@joeyh.name>
Wed, 17 Aug 2022 17:07:14 +0000 (13:07 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 17 Aug 2022 17:12:26 +0000 (13:12 -0400)
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
Database/Handle.hs
doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy.mdwn
doc/bugs/crippled_filesystem__58___SQLite3_returned_ErrorBusy/comment_13_baafac7f80ff4b7cc4cf078e4ab969c3._comment [new file with mode: 0644]

index afe73954f29680f1f9947f406f89d2cbc1855b33..1eb912b2336d7ceb7b158ea24f6c2299676d011d 100644 (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
 
index 9c04f701b123d9c1c8df7e187d9f595f54bd1ad0..b0c9786974f6a79b82480a58204af984ad7638a9 100644 (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
        
index b22f15cb799ed8451f354420b0eaad3680287053..1a036f8a5d10a1b3c1220071d4bbc305eaa1eb25 100644 (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]]
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 (file)
index 0000000..c3f92fe
--- /dev/null
@@ -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.
+"""]]