Skip to content

Commit 737998c

Browse files
committed
doc: document table configuration
1 parent 170293f commit 737998c

File tree

12 files changed

+1139
-360
lines changed

12 files changed

+1139
-360
lines changed

README.md

Lines changed: 374 additions & 70 deletions
Large diffs are not rendered by default.

bench/macro/lsm-tree-bench-wp8.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ cmdP = O.subparser $ mconcat
227227

228228
setupOptsP :: O.Parser SetupOpts
229229
setupOptsP = pure SetupOpts
230-
<*> O.option O.auto (O.long "bloom-filter-alloc" <> O.value LSM.defaultBloomFilterAlloc <> O.showDefault <> O.help "Bloom filter allocation method [AllocFixed n | AllocRequestFPR d]")
230+
<*> O.option O.auto (O.long "bloom-filter-alloc" <> O.value (LSM.confBloomFilterAlloc LSM.defaultTableConfig) <> O.showDefault <> O.help "Bloom filter allocation method [AllocFixed n | AllocRequestFPR d]")
231231

232232
runOptsP :: O.Parser RunOpts
233233
runOptsP = pure RunOpts

lsm-tree.cabal

Lines changed: 298 additions & 53 deletions
Large diffs are not rendered by default.

src/Database/LSMTree.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,12 @@ module Database.LSMTree (
113113
),
114114
defaultTableConfig,
115115
MergePolicy (LazyLevelling),
116+
MergeSchedule (..),
116117
SizeRatio (Four),
117118
WriteBufferAlloc (AllocNumEntries),
118119
BloomFilterAlloc (AllocFixed, AllocRequestFPR),
119-
defaultBloomFilterAlloc,
120120
FencePointerIndexType (OrdinaryIndex, CompactIndex),
121121
DiskCachePolicy (..),
122-
MergeSchedule (..),
123122

124123
-- ** Table Configuration Overrides #table_configuration_overrides#
125124
OverrideDiskCachePolicy (..),
@@ -217,8 +216,7 @@ import Database.LSMTree.Internal.Config
217216
DiskCachePolicy (..), FencePointerIndexType (..),
218217
LevelNo (..), MergePolicy (..), MergeSchedule (..),
219218
SizeRatio (..), TableConfig (..), WriteBufferAlloc (..),
220-
defaultBloomFilterAlloc, defaultTableConfig,
221-
serialiseKeyMinimalSize)
219+
defaultTableConfig, serialiseKeyMinimalSize)
222220
import Database.LSMTree.Internal.Config.Override
223221
(OverrideDiskCachePolicy (..))
224222
import Database.LSMTree.Internal.Entry (NumEntries (..))

src/Database/LSMTree/Internal/Config.hs

Lines changed: 202 additions & 158 deletions
Large diffs are not rendered by default.

src/Database/LSMTree/Internal/Config/Override.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ import Database.LSMTree.Internal.Snapshot
4848
Override disk cache policy
4949
-------------------------------------------------------------------------------}
5050

51-
-- | Override the 'DiskCachePolicy'
51+
{- |
52+
The 'OverrideDiskCachePolicy' can be used to override the 'DiskCachePolicy'
53+
when opening a table from a snapshot.
54+
-}
5255
data OverrideDiskCachePolicy =
53-
OverrideDiskCachePolicy DiskCachePolicy
54-
| NoOverrideDiskCachePolicy
56+
NoOverrideDiskCachePolicy
57+
| OverrideDiskCachePolicy DiskCachePolicy
5558
deriving stock (Show, Eq)
5659

5760
-- | Override the disk cache policy that is stored in snapshot metadata.

src/Database/LSMTree/Internal/MergeSchedule.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ updatesWithInterleavedFlushes tr conf resolve hfs hbio root uc es reg tc = do
494494
(wb', es') <- addWriteBufferEntries hfs resolve wbblobs maxn wb es
495495
-- Supply credits before flushing, so that we complete merges in time. The
496496
-- number of supplied credits is based on the size increase of the write
497-
-- buffer, not the the number of processed entries @length es' - length es@.
497+
-- buffer, not the number of processed entries @length es' - length es@.
498498
let numAdded = unNumEntries (WB.numEntries wb') - unNumEntries (WB.numEntries wb)
499499
supplyCredits conf (NominalCredits numAdded) (tableLevels tc)
500500
let tc' = tc { tableWriteBuffer = wb' }

src/Database/LSMTree/Internal/Range.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ import Control.DeepSeq (NFData (..))
1313

1414
-- | A range of keys.
1515
data Range k =
16-
-- | Inclusive lower bound, exclusive upper bound
16+
{- |
17+
@'FromToExcluding' i j@ is the ranges from @i@ (inclusive) to @j@ (exclusive).
18+
-}
1719
FromToExcluding k k
18-
-- | Inclusive lower bound, inclusive upper bound
20+
{- |
21+
@'FromToIncluding' i j@ is the ranges from @i@ (inclusive) to @j@ (inclusive).
22+
-}
1923
| FromToIncluding k k
2024
deriving stock (Show, Eq, Functor)
2125

src/Database/LSMTree/Internal/RawBytes.hs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import Prelude hiding (drop, take)
6969
import GHC.Exts
7070
import GHC.Stack
7171
import GHC.Word
72+
import Text.Printf (printf)
7273

7374
{- Note: [Export structure]
7475
~~~~~~~~~~~~~~~~~~~~~~~
@@ -80,15 +81,30 @@ import GHC.Word
8081
Raw bytes
8182
-------------------------------------------------------------------------------}
8283

83-
-- | Raw bytes with no alignment constraint (i.e. byte aligned), and no
84-
-- guarantee of pinned or unpinned memory (i.e. could be either).
84+
{- |
85+
Raw bytes.
86+
87+
This type imposes no alignment constraint and provides no guarantee of whether the memory is pinned or unpinned.
88+
-}
8589
newtype RawBytes = RawBytes (VP.Vector Word8)
86-
deriving newtype (Show, NFData)
90+
deriving newtype (NFData)
91+
92+
-- TODO: Should we have a more well-behaved instance for 'Show'?
93+
-- For instance, an instance that prints the bytes as a hexadecimal string?
94+
deriving newtype instance Show RawBytes
95+
96+
_showBytesAsHex :: RawBytes -> ShowS
97+
_showBytesAsHex (RawBytes bytes) = VP.foldr ((.) . showByte) id bytes
98+
where
99+
showByte :: Word8 -> ShowS
100+
showByte = showString . printf "%02x"
87101

88102
instance Eq RawBytes where
89103
bs1 == bs2 = compareBytes bs1 bs2 == EQ
90104

91-
-- | Lexicographical 'Ord' instance.
105+
{- |
106+
This instance uses lexicographic ordering.
107+
-}
92108
instance Ord RawBytes where
93109
compare = compareBytes
94110

@@ -113,6 +129,11 @@ instance Hashable RawBytes where
113129
hash :: Word64 -> RawBytes -> Word64
114130
hash salt (RawBytes (VP.Vector off len ba)) = hashByteArray ba off len salt
115131

132+
{- |
133+
@'fromList'@: \(O(n)\).
134+
135+
@'toList'@: \(O(n)\).
136+
-}
116137
instance IsList RawBytes where
117138
type Item RawBytes = Word8
118139

@@ -122,9 +143,13 @@ instance IsList RawBytes where
122143
toList :: RawBytes -> [Item RawBytes]
123144
toList = unpack
124145

125-
-- | Mostly to make test cases shorter to write.
146+
{- |
147+
@'fromString'@: \(O(n)\).
148+
149+
__Warning:__ 'fromString' truncates multi-byte characters to octets. e.g. \"枯朶に烏のとまりけり秋の暮\" becomes \"�6k�nh~�Q��n�\".
150+
-}
126151
instance IsString RawBytes where
127-
fromString = pack . map (fromIntegral . fromEnum)
152+
fromString = fromByteString . fromString
128153

129154
{-------------------------------------------------------------------------------
130155
Accessors
@@ -171,9 +196,19 @@ toWord64 x# = byteSwap64 (W64# x#)
171196
Construction
172197
-------------------------------------------------------------------------------}
173198

199+
{- |
200+
@('<>')@: \(O(n)\).
201+
202+
@'Data.Semigroup.sconcat'@: \(O(n)\).
203+
-}
174204
instance Semigroup RawBytes where
175205
(<>) = coerce (VP.++)
176206

207+
{- |
208+
@'mempty'@: \(O(1)\).
209+
210+
@'mconcat'@: \(O(n)\).
211+
-}
177212
instance Monoid RawBytes where
178213
mempty = coerce VP.empty
179214
mconcat = coerce VP.concat

0 commit comments

Comments
 (0)