diff --git a/hbs2-core/lib/HBS2/Storage/Operations/Class.hs b/hbs2-core/lib/HBS2/Storage/Operations/Class.hs index f69eeacb..0d0ddd57 100644 --- a/hbs2-core/lib/HBS2/Storage/Operations/Class.hs +++ b/hbs2-core/lib/HBS2/Storage/Operations/Class.hs @@ -15,6 +15,7 @@ data OperationError = | DecryptError | DecryptionError | MissedBlockError + | MissedBlockError2 String | UnsupportedFormat | IncompleteData | GroupKeyNotFound Int diff --git a/hbs2-git3/lib/HBS2/Git3/State/Internal/Index.hs b/hbs2-git3/lib/HBS2/Git3/State/Internal/Index.hs index da605988..0b452a57 100644 --- a/hbs2-git3/lib/HBS2/Git3/State/Internal/Index.hs +++ b/hbs2-git3/lib/HBS2/Git3/State/Internal/Index.hs @@ -9,6 +9,8 @@ import HBS2.Git3.State.Internal.Segment import HBS2.Git3.State.Internal.RefLog import HBS2.Git3.Git +import HBS2.Storage.Operations.Missed + import HBS2.Data.Log.Structured import Data.ByteString qualified as BS @@ -286,6 +288,7 @@ updateReflogIndex = do reflog <- getGitRemoteKey >>= orThrow Git3ReflogNotSet api <- getClientAPI @RefLogAPI @UNIX + peer <- getClientAPI @PeerAPI @UNIX sto <- getStorage @@ -313,9 +316,16 @@ updateReflogIndex = do debug $ "STATE" <+> pretty idxPath + missed <- findMissedBlocks sto what + + unless (L.null missed) do + for_ missed $ \h -> do + lift (callRpcWaitMay @RpcFetch (TimeoutSec 1) peer h) >>= orThrow RpcTimeout + throwIO RefLogNotReady + sink <- S.toList_ do walkMerkle (coerce what) (getBlock sto) $ \case - Left{} -> throwIO MissedBlockError + Left e -> throwIO $ MissedBlockError2 (show $ pretty e) Right (hs :: [HashRef]) -> do for_ [h | h <- hs, not (HS.member h written)] $ \h -> void $ runMaybeT do readTxMay sto (coerce h) >>= \case diff --git a/hbs2-git3/lib/HBS2/Git3/State/Internal/Types.hs b/hbs2-git3/lib/HBS2/Git3/State/Internal/Types.hs index 112eabbd..c3d1bcad 100644 --- a/hbs2-git3/lib/HBS2/Git3/State/Internal/Types.hs +++ b/hbs2-git3/lib/HBS2/Git3/State/Internal/Types.hs @@ -64,6 +64,7 @@ data HBS2GitExcepion = | GitRepoRefEmpty | GitRepoManifestMalformed | RefLogCredentialsNotMatched + | RefLogNotReady | RpcTimeout deriving stock (Show,Typeable)