Skip to content

Commit 5ba267d

Browse files
committed
Remove unnecessary CBOR encoded fields, update encoder/decoder documentation
1 parent 8ec484f commit 5ba267d

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

src/Database/LSMTree/Internal.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ instance NFData (MonoidalCursor m k v) where
165165
-------------------------------------------------------------------------------}
166166

167167
-- TODO: give this a nicer Show instance.
168-
--
169-
-- TODO: the snapshot-related errors could be put in a separate type, since each
170-
-- gets a SnapshotName.
171168
data LSMTreeError =
172169
SessionDirDoesNotExist FsErrorPath
173170
-- | The session directory is already locked

src/Database/LSMTree/Internal/Snapshot.hs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,16 @@ openLevels reg hfs hbio conf@TableConfig{..} uc sessionRoot resolve levels =
310310
class Encode a where
311311
encode :: a -> Encoding
312312

313+
-- | Decoder that is not parameterised by a 'SnapshotVersion'.
314+
--
315+
-- Used only for 'SnapshotVersion' and 'Versioned', which live outside the
316+
-- 'SnapshotMetaData' type hierachy.
313317
class Decode a where
314318
decode :: Decoder s a
315319

320+
-- | Decoder parameterised by a 'SnapshotVersion'.
321+
--
322+
-- Used for every type in the 'SnapshotMetaData' type hierarchy.
316323
class DecodeVersioned a where
317324
decodeVersioned :: SnapshotVersion -> Decoder s a
318325

@@ -331,6 +338,8 @@ instance Encode a => Encode (Versioned a) where
331338
<> encode currentSnapshotVersion
332339
<> encode x
333340

341+
-- | Decodes a 'SnapshotVersion' first, and then passes that into the versioned
342+
-- decoder for @a@.
334343
instance DecodeVersioned a => Decode (Versioned a) where
335344
decode = do
336345
_ <- decodeListLenOf 2
@@ -339,8 +348,8 @@ instance DecodeVersioned a => Decode (Versioned a) where
339348
Right () -> pure ()
340349
Left errMsg ->
341350
fail $
342-
printf "Incompatible version found. Version %s is not backwards \
343-
\compatible with version %s : %s"
351+
printf "Incompatible snapshot format version found. Version %s \
352+
\is not backwards compatible with version %s : %s"
344353
(prettySnapshotVersion currentSnapshotVersion)
345354
(prettySnapshotVersion version)
346355
errMsg
@@ -362,7 +371,7 @@ instance Decode SnapshotVersion where
362371
ver <- decodeWord
363372
case ver of
364373
0 -> pure V0
365-
_ -> fail ("Unknown version number: " <> show ver)
374+
_ -> fail ("Unknown snapshot format version number: " <> show ver)
366375

367376
{-------------------------------------------------------------------------------
368377
Encoding and decoding: SnapshotMetaData
@@ -396,12 +405,11 @@ instance DecodeVersioned SnapshotLabel where
396405
-- TableType
397406

398407
instance Encode SnapshotTableType where
399-
encode SnapNormalTable = encodeListLen 1 <> encodeWord 0
400-
encode SnapMonoidalTable = encodeListLen 1 <> encodeWord 1
408+
encode SnapNormalTable = encodeWord 0
409+
encode SnapMonoidalTable = encodeWord 1
401410

402411
instance DecodeVersioned SnapshotTableType where
403412
decodeVersioned V0 = do
404-
_ <- decodeListLenOf 1
405413
tag <- decodeWord
406414
case tag of
407415
0 -> pure SnapNormalTable
@@ -446,12 +454,10 @@ instance DecodeVersioned TableConfig where
446454
-- MergePolicy
447455

448456
instance Encode MergePolicy where
449-
encode MergePolicyLazyLevelling =
450-
encodeListLen 1 <> encodeWord 0
457+
encode MergePolicyLazyLevelling = encodeWord 0
451458

452459
instance DecodeVersioned MergePolicy where
453460
decodeVersioned V0 = do
454-
_ <- decodeListLenOf 1
455461
tag <- decodeWord
456462
case tag of
457463
0 -> pure MergePolicyLazyLevelling
@@ -460,7 +466,7 @@ instance DecodeVersioned MergePolicy where
460466
-- SizeRatio
461467

462468
instance Encode SizeRatio where
463-
encode Four = encodeWord64 4
469+
encode Four = encodeInt 4
464470

465471
instance DecodeVersioned SizeRatio where
466472
decodeVersioned V0 = do
@@ -523,12 +529,11 @@ instance DecodeVersioned BloomFilterAlloc where
523529
-- FencePointerIndex
524530

525531
instance Encode FencePointerIndex where
526-
encode CompactIndex = encodeListLen 1 <> encodeWord 0
527-
encode OrdinaryIndex = encodeListLen 1 <> encodeWord 1
532+
encode CompactIndex = encodeWord 0
533+
encode OrdinaryIndex = encodeWord 1
528534

529535
instance DecodeVersioned FencePointerIndex where
530536
decodeVersioned V0 = do
531-
_ <- decodeListLenOf 1
532537
tag <- decodeWord
533538
case tag of
534539
0 -> pure CompactIndex
@@ -562,12 +567,11 @@ instance DecodeVersioned DiskCachePolicy where
562567
-- MergeSchedule
563568

564569
instance Encode MergeSchedule where
565-
encode OneShot = encodeListLen 1 <> encodeWord 0
566-
encode Incremental = encodeListLen 1 <> encodeWord 1
570+
encode OneShot = encodeWord 0
571+
encode Incremental = encodeWord 1
567572

568573
instance DecodeVersioned MergeSchedule where
569574
decodeVersioned V0 = do
570-
_ <- decodeListLenOf 1
571575
tag <- decodeWord
572576
case tag of
573577
0 -> pure OneShot
@@ -659,12 +663,11 @@ instance DecodeVersioned NumRuns where
659663
-- MergePolicyForLevel
660664

661665
instance Encode MergePolicyForLevel where
662-
encode LevelTiering = encodeListLen 1 <> encodeWord 0
663-
encode LevelLevelling = encodeListLen 1 <> encodeWord 1
666+
encode LevelTiering = encodeWord 0
667+
encode LevelLevelling = encodeWord 1
664668

665669
instance DecodeVersioned MergePolicyForLevel where
666670
decodeVersioned V0 = do
667-
_ <- decodeListLenOf 1
668671
tag <- decodeWord
669672
case tag of
670673
0 -> pure LevelTiering
@@ -706,12 +709,11 @@ instance DecodeVersioned TotalCredits where
706709
-- Merge.Level
707710

708711
instance Encode Merge.Level where
709-
encode Merge.MidLevel = encodeListLen 1 <> encodeWord 0
710-
encode Merge.LastLevel = encodeListLen 1 <> encodeWord 1
712+
encode Merge.MidLevel = encodeWord 0
713+
encode Merge.LastLevel = encodeWord 1
711714

712715
instance DecodeVersioned Merge.Level where
713716
decodeVersioned V0 = do
714-
_ <- decodeListLenOf 1
715717
tag <- decodeWord
716718
case tag of
717719
0 -> pure Merge.MidLevel

0 commit comments

Comments
 (0)