From 98a97ba55fae91ebba55e7de3f83bf78a1ffab82 Mon Sep 17 00:00:00 2001 From: Dmitry Zuykov Date: Fri, 16 May 2025 10:45:21 +0300 Subject: [PATCH] wip, merge storage --- hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs | 22 ++++++++++++++++++++++ hbs2-tests/test/TCQ.hs | 20 -------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs index da5c4270..9c1cb61a 100644 --- a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs +++ b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs @@ -162,6 +162,28 @@ data NCQStorage = } +instance MonadUnliftIO m => Storage NCQStorage HbSync LBS.ByteString m where + putBlock ncq lbs = fmap coerce <$> ncqStoragePutBlock ncq lbs + enqueueBlock ncq lbs = fmap coerce <$> ncqStoragePutBlock ncq lbs + getBlock ncq h = ncqStorageGetBlock ncq (coerce h) + hasBlock ncq = hasBlock ncq . coerce + delBlock ncq = ncqStorageDel ncq . coerce + + updateRef ncq k v = do + ncqStorageSetRef ncq (HashRef $ hashObject k) (HashRef v) + + getRef ncq k = + ncqStorageGetRef ncq (HashRef $ hashObject k) <&> fmap coerce + + delRef ncq k = + ncqStorageDelRef ncq (HashRef $ hashObject k) + + getChunk ncq h off size = runMaybeT do + block <- lift (ncqStorageGetBlock ncq (coerce h)) >>= toMPlus + let chunk = LBS.take (fromIntegral size) $ LBS.drop (fromIntegral off) block + pure chunk + + data Location = InWriteQueue WQItem | InCurrent (Fd,Word64, Word64) diff --git a/hbs2-tests/test/TCQ.hs b/hbs2-tests/test/TCQ.hs index f2fcbb02..5666ba66 100644 --- a/hbs2-tests/test/TCQ.hs +++ b/hbs2-tests/test/TCQ.hs @@ -108,26 +108,6 @@ newtype TCQ = TCQ FilePath deriving newtype (Eq,Ord,Show,Typeable) -instance MonadUnliftIO m => Storage NCQStorage HbSync LBS.ByteString m where - putBlock ncq lbs = fmap coerce <$> ncqStoragePutBlock ncq lbs - enqueueBlock ncq lbs = fmap coerce <$> ncqStoragePutBlock ncq lbs - getBlock ncq h = ncqStorageGetBlock ncq (coerce h) - hasBlock ncq = hasBlock ncq . coerce - delBlock ncq = ncqStorageDel ncq . coerce - - updateRef ncq k v = do - ncqStorageSetRef ncq (HashRef $ hashObject k) (HashRef v) - - getRef ncq k = - ncqStorageGetRef ncq (HashRef $ hashObject k) <&> fmap coerce - - delRef ncq k = - ncqStorageDelRef ncq (HashRef $ hashObject k) - - getChunk ncq h off size = runMaybeT do - block <- lift (ncqStorageGetBlock ncq (coerce h)) >>= toMPlus - let chunk = LBS.take (fromIntegral size) $ LBS.drop (fromIntegral off) block - pure chunk main :: IO () main = do