leveldb-haskell 0.6 → 0.6.1
raw patch · 7 files changed
+74/−13 lines, 7 files
Files
- CHANGELOG +4/−0
- examples/features.hs +45/−9
- leveldb-haskell.cabal +1/−1
- src/Database/LevelDB/Base.hs +9/−0
- src/Database/LevelDB/C.hsc +6/−0
- src/Database/LevelDB/MonadResource.hs +7/−0
- test/Test/Streaming.hs +2/−3
CHANGELOG view
@@ -1,3 +1,7 @@+[0.6.1]:++* Expose `compactRange`+ [0.6.0]: * Slices include the end element (justifies version bump)
examples/features.hs view
@@ -9,6 +9,7 @@ import Control.Monad.Trans.Resource (release) import Data.ByteString.Char8 hiding (take) import Data.Default+import Data.Monoid import Database.LevelDB import qualified Database.LevelDB.Streaming as S import Prelude hiding (putStrLn)@@ -22,17 +23,29 @@ defaultOptions{ createIfMissing = True , cacheSize= 2048 }++ putStrLn' "Put value" put db def "foo" "bar" get db def "foo" >>= liftIO . print++ putStrLn' ""++ putStrLn' "Delete value" delete db def "foo" get db def "foo" >>= liftIO . print ++ putStrLn' ""+ (releaseSnap, snap) <- createSnapshot' db++ putStrLn' "Write batch" write db def{sync = True} [ Put "a" "one" , Put "b" "two" , Put "c" "three" ] + putStrLn' "Dump entries with old snapshot" withIterator db def{useSnapshot = Just snap} $ \iter -> dumpEntries iter -- early release snapshot@@ -42,18 +55,35 @@ -- Note that we don't explicitly release it (and thus don't keep the release -- key). The iterator will be released when runResourceT terminates. iter <- iterOpen db def+ putStrLn' "Dump entries with fresh iterator" dumpEntries iter - approximateSize db ("a", "z") >>= liftIO . print+ putStrLn' "" - getProperty db SSTables >>= printProperty "sstables"- getProperty db Stats >>= printProperty "stats"- getProperty db (NumFilesAtLevel 1) >>= printProperty "num files at level"+ printDbSize db+ putStrLn' "Trigger compaction"+ compactRange db ("a", "z")+ printDbSize db ++ putStrLn' ""++ putStrLn' " BEGIN dump properties"+ getProperty db SSTables >>= printProperty "SSTables:"+ getProperty db Stats >>= printProperty "Stats:"+ getProperty db (NumFilesAtLevel 1) >>= printProperty "Num files at level 1:"+ putStrLn' " END dump properties"+++ putStrLn' ""++ putStrLn' "Delete batch" write db def [ Del "a" , Del "b" , Del "c" ]++ putStrLn' "Dump entries" dumpEntries iter return ()@@ -63,17 +93,23 @@ S.toList (S.entrySlice iter S.AllKeys S.Asc) >>= print - printProperty l p = liftIO $ do- putStrLn l- maybe (putStrLn "n/a") putStrLn p+ printProperty l p = do+ putStrLn' l+ maybe (putStrLn' "n/a") putStrLn' p printVersion = do v <- versionBS- liftIO . putStrLn $ "LevelDB Version: " `append` v+ putStrLn' $ "LevelDB Version: " <> v + printDbSize db = do+ s <- approximateSize db ("a", "z")+ putStrLn' $ "Approximate DB size: " <> pack (show s)+ versionBS = do (major, minor) <- version- return $ intToBs major `append` "." `append` intToBs minor+ return $ intToBs major <> "." <> intToBs minor intToBs :: Int -> ByteString intToBs = pack . show++ putStrLn' = liftIO . putStrLn
leveldb-haskell.cabal view
@@ -1,5 +1,5 @@ name: leveldb-haskell-version: 0.6+version: 0.6.1 synopsis: Haskell bindings to LevelDB homepage: http://github.com/kim/leveldb-haskell bug-reports: http://github.com/kim/leveldb-haskell/issues
src/Database/LevelDB/Base.hs view
@@ -51,6 +51,7 @@ , destroy , repair , approximateSize+ , compactRange , version -- * Iteration@@ -182,6 +183,14 @@ where toInt64 = return . fromIntegral +-- | Compact the underlying storage for the given Range.+-- In particular this means discarding deleted and overwritten data as well as+-- rearranging the data to reduce the cost of operations accessing the data.+compactRange :: MonadIO m => DB -> Range -> m ()+compactRange (DB db_ptr _ _) (from, to) = liftIO $+ BU.unsafeUseAsCStringLen from $ \(from_ptr, flen) ->+ BU.unsafeUseAsCStringLen to $ \(to_ptr, tlen) ->+ c_leveldb_compact_range db_ptr from_ptr (intToCSize flen) to_ptr (intToCSize tlen) -- | Write a key/value pair. put :: MonadIO m => DB -> WriteOptions -> ByteString -> ByteString -> m ()
src/Database/LevelDB/C.hsc view
@@ -114,6 +114,12 @@ -> Ptr Word64 -- ^ array of approx. sizes of ranges -> IO () +foreign import ccall safe "leveldb/c.h leveldb_compact_range"+ c_leveldb_compact_range :: LevelDBPtr+ -> CString -> CSize -- ^ start key+ -> CString -> CSize -- ^ limit key+ -> IO ()+ foreign import ccall safe "leveldb/c.h leveldb_destroy_db" c_leveldb_destroy_db :: OptionsPtr -> DBName -> ErrPtr -> IO ()
src/Database/LevelDB/MonadResource.hs view
@@ -44,6 +44,7 @@ , destroy , repair , approximateSize+ , compactRange , version -- * Iteration@@ -143,6 +144,12 @@ -- | Inspect the approximate sizes of the different levels approximateSize :: MonadResource m => DB -> Range -> m Int64 approximateSize = Base.approximateSize++-- | Compact the underlying storage for the given Range.+-- In particular this means discarding deleted and overwritten data as well as+-- rearranging the data to reduce the cost of operations accessing the data.+compactRange :: MonadResource m => DB -> Range -> m ()+compactRange = Base.compactRange -- | Write a key/value pair put :: MonadResource m => DB -> WriteOptions -> ByteString -> ByteString -> m ()
test/Test/Streaming.hs view
@@ -200,9 +200,8 @@ -- prop_fromList :: [ByteString] -> Prop-prop_fromList xs = monadic runIdentity- . fmap (=== xs) . S.toList . S.fromList- $ xs+prop_fromList xs = monadic runIdentity $+ assert . (xs ==) =<< (S.toList . S.fromList $ xs) -- -- basic functions