@@ -39,7 +39,7 @@ module Database.LSMTree.Internal (
3939 , listSnapshots
4040 -- * Mutiple writable table handles
4141 , duplicate
42- -- * configuration
42+ -- * Configuration
4343 , TableConfig (.. )
4444 , defaultTableConfig
4545 , MergePolicy (.. )
@@ -48,6 +48,7 @@ module Database.LSMTree.Internal (
4848 , NumEntries (.. )
4949 , BloomFilterAlloc (.. )
5050 , defaultBloomFilterAlloc
51+ , FencePointerIndex (.. )
5152 , DiskCachePolicy (.. )
5253 -- * Exported for cabal-docspec
5354 , MergePolicyForLevel (.. )
@@ -1277,22 +1278,24 @@ duplicate th = withOpenTable th $ \thEnv -> do
12771278--
12781279-- * Size ratio: 4
12791280data TableConfig = TableConfig {
1280- confMergePolicy :: ! MergePolicy
1281+ confMergePolicy :: ! MergePolicy
12811282 -- Size ratio between the capacities of adjacent levels.
1282- , confSizeRatio :: ! SizeRatio
1283+ , confSizeRatio :: ! SizeRatio
12831284 -- | Total number of bytes that the write buffer can use.
12841285 --
12851286 -- The maximum is 4GiB, which should be more than enough for realistic
12861287 -- applications.
1287- , confWriteBufferAlloc :: ! WriteBufferAlloc
1288- , confBloomFilterAlloc :: ! BloomFilterAlloc
1288+ , confWriteBufferAlloc :: ! WriteBufferAlloc
1289+ , confBloomFilterAlloc :: ! BloomFilterAlloc
1290+ , confFencePointerIndex :: ! FencePointerIndex
12891291 -- | The policy for caching key\/value data from disk in memory.
1290- , confDiskCachePolicy :: ! DiskCachePolicy
1292+ , confDiskCachePolicy :: ! DiskCachePolicy
12911293 }
1292- deriving stock Show
1294+ deriving stock ( Show , Eq )
12931295
12941296instance NFData TableConfig where
1295- rnf (TableConfig a b c d e) = rnf a `seq` rnf b `seq` rnf c `seq` rnf d `seq` rnf e
1297+ rnf (TableConfig a b c d e f) =
1298+ rnf a `seq` rnf b `seq` rnf c `seq` rnf d `seq` rnf e `seq` rnf f
12961299
12971300-- | TODO: this should be removed once we have proper snapshotting with proper
12981301-- persistence of the config to disk.
@@ -1310,6 +1313,7 @@ defaultTableConfig =
13101313 , confSizeRatio = Four
13111314 , confWriteBufferAlloc = AllocNumEntries (NumEntries 20_000 )
13121315 , confBloomFilterAlloc = defaultBloomFilterAlloc
1316+ , confFencePointerIndex = CompactIndex
13131317 , confDiskCachePolicy = DiskCacheAll
13141318 }
13151319
@@ -1451,6 +1455,39 @@ bloomFilterAllocForLevel conf (LevelNo l) =
14511455 0 -> Just x
14521456 _ -> r (k- 1 )) (const Nothing ) xs n
14531457
1458+ -- | Configure the type of fence pointer index.
1459+ --
1460+ -- TODO: this configuration option currently has no effect: 'CompactIndex' is
1461+ -- always used.
1462+ data FencePointerIndex =
1463+ -- | Use a compact fence pointer index.
1464+ --
1465+ -- The compact index type is designed to work with keys that are large
1466+ -- cryptographic hashes, e.g. 32 bytes.
1467+ --
1468+ -- When using the 'IndexCompact', additional constraints apply to the
1469+ -- 'Database.LSMTree.Internal.Serialise.Class.serialiseKey' function. The
1470+ -- __Minimal size__ law should be satisfied:
1471+ --
1472+ -- [Minimal size] @'Database.LSMTree.Internal.RawBytes.size'
1473+ -- ('Database.LSMTree.Internal.Serialise.Class.serialiseKey' x) >= 8@
1474+ --
1475+ -- Use 'Database.LSMTree.Internal.Serialise.Class.serialiseKeyMinimalSize'
1476+ -- to test this law.
1477+ CompactIndex
1478+ -- | Use an ordinary fence pointer index, without any constraints on
1479+ -- serialised keys.
1480+ | OrdinaryIndex
1481+ deriving stock (Show , Eq )
1482+
1483+ instance NFData FencePointerIndex where
1484+ rnf CompactIndex = ()
1485+ rnf OrdinaryIndex = ()
1486+
1487+ -- | TODO: this should be removed once we have proper snapshotting with proper
1488+ -- persistence of the config to disk.
1489+ deriving stock instance Read FencePointerIndex
1490+
14541491-- | The policy for caching data from disk in memory (using the OS page cache).
14551492--
14561493-- Caching data in memory can improve performance if the access pattern has
0 commit comments