Skip to content

Commit d31449c

Browse files
jorisdralwenkokke
authored andcommitted
fix: make requested changes from PR review
In addition to minor changes, this commit makes the following changes: - Add classification of snapshot corruption exceptions in tests. - Fix snapshot corruption to be hardlink safe. - Clamp choice of bit-to-corrupt to avoid overflow. - Add more specific tagging in statemachine tests.
1 parent e2aa833 commit d31449c

File tree

7 files changed

+207
-96
lines changed

7 files changed

+207
-96
lines changed

src-control/Control/ActionRegistry.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Control.ActionRegistry (
2525
, CommitActionRegistryError (..)
2626
, AbortActionRegistryError (..)
2727
, AbortActionRegistryReason (..)
28+
, getReasonExitCaseException
2829
-- * Registering actions #registeringActions#
2930
-- $registering-actions
3031
, withRollback
@@ -372,6 +373,11 @@ data AbortActionRegistryReason =
372373
| ReasonExitCaseAbort
373374
deriving stock Show
374375

376+
getReasonExitCaseException :: AbortActionRegistryReason -> Maybe SomeException
377+
getReasonExitCaseException = \case
378+
ReasonExitCaseException e -> Just e
379+
ReasonExitCaseAbort -> Nothing
380+
375381
data AbortActionRegistryError =
376382
AbortActionRegistryError AbortActionRegistryReason (NonEmpty ActionError)
377383
deriving stock Show

test/Database/LSMTree/Class.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Database.LSMTree.Class.Common as Common
2828
import qualified Database.LSMTree.Internal as RI (SessionEnv (..), Table (..),
2929
Table' (..), withOpenSession)
3030
import qualified Database.LSMTree.Internal.Paths as RIP
31-
import Test.Util.FS (flipRandomBitInRandomFile)
31+
import Test.Util.FS (flipRandomBitInRandomFileHardlinkSafe)
3232
import Test.Util.QC (Choice)
3333

3434
-- | Class abstracting over table operations.
@@ -249,7 +249,7 @@ rCorruptSnapshot choice name (RI.Table' t) =
249249
let hfs = RI.sessionHasFS seshEnv
250250
root = RI.sessionRoot seshEnv
251251
namedSnapDir = RIP.getNamedSnapshotDir (RIP.namedSnapshotDir root name)
252-
in void $ flipRandomBitInRandomFile hfs choice namedSnapDir
252+
in void $ flipRandomBitInRandomFileHardlinkSafe hfs choice namedSnapDir
253253

254254
instance IsTable R.Table where
255255
type Session R.Table = R.Session

test/Database/LSMTree/Model/Session.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Database.LSMTree.Model.Session (
3232
, runModelM
3333
, runModelMWithInjectedErrors
3434
-- ** Errors
35-
, Err (.., DefaultErrDiskFault)
35+
, Err (.., DefaultErrDiskFault, DefaultErrSnapshotCorrupted)
3636
-- * Tables
3737
, Table
3838
, TableConfig (..)
@@ -241,19 +241,23 @@ runModelMWithInjectedErrors (Just _) _ onErrors st =
241241
pattern DefaultErrDiskFault :: Err
242242
pattern DefaultErrDiskFault = ErrDiskFault "default"
243243

244+
-- | The default 'ErrSnapshotCorrupted' that model operations will throw.
245+
pattern DefaultErrSnapshotCorrupted :: Err
246+
pattern DefaultErrSnapshotCorrupted = ErrSnapshotCorrupted "default"
247+
244248
--
245249
-- Errors
246250
--
247251

248252
data Err =
249253
ErrTableClosed
250-
| ErrSnapshotCorrupted
251254
| ErrSnapshotExists
252255
| ErrSnapshotDoesNotExist
253256
| ErrSnapshotWrongType
254257
| ErrBlobRefInvalidated
255258
| ErrCursorClosed
256259
-- | Something went wrong with the file system.
260+
| ErrSnapshotCorrupted String
257261
| ErrDiskFault String
258262
| ErrOther String
259263
deriving stock Eq
@@ -262,8 +266,6 @@ instance Show Err where
262266
showsPrec d = \case
263267
ErrTableClosed ->
264268
showString "ErrTableClosed"
265-
ErrSnapshotCorrupted ->
266-
showString "ErrSnapshotCorrupted"
267269
ErrSnapshotExists ->
268270
showString "ErrSnapshotExists"
269271
ErrSnapshotDoesNotExist ->
@@ -274,6 +276,10 @@ instance Show Err where
274276
showString "ErrBlobRefInvalidated"
275277
ErrCursorClosed ->
276278
showString "ErrCursorClosed"
279+
ErrSnapshotCorrupted s ->
280+
showParen (d > appPrec) $
281+
showString "ErrSnapshotCorrupted " .
282+
showParen True (showString s)
277283
ErrDiskFault s ->
278284
showParen (d > appPrec) $
279285
showString "ErrDiskFault " .
@@ -577,7 +583,7 @@ openSnapshot label name = do
577583
throwError ErrSnapshotDoesNotExist
578584
Just (Snapshot conf label' tbl corrupted) -> do
579585
when corrupted $
580-
throwError ErrSnapshotCorrupted
586+
throwError DefaultErrSnapshotCorrupted
581587
when (label /= label') $
582588
throwError ErrSnapshotWrongType
583589
case fromSomeTable tbl of
@@ -592,9 +598,9 @@ openSnapshot label name = do
592598
Just table' ->
593599
newTableWith conf table'
594600

595-
-- TODO: to match the implementation of the real table, this should not corrupt the
596-
-- snapshot if there are _no non-empty files_; however, since there are no such
597-
-- snapshots, this is probably fine
601+
-- To match the implementation of the real table, this should not corrupt the
602+
-- snapshot if there are _no non-empty files_; however, since there are no such
603+
-- snapshots, this is probably fine.
598604
corruptSnapshot ::
599605
(MonadState Model m, MonadError Err m)
600606
=> SnapshotName

test/Test/Database/LSMTree/Internal/Snapshot/FS.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ instance Arbitrary TestErrors where
161161
Snapshot corruption
162162
-------------------------------------------------------------------------------}
163163

164-
-- TODO: an alternative to generating doubles a priori is to run the monadic
164+
-- TODO: an alternative to generating a Choice a priori is to run the monadic
165165
-- code in @PropertyM (IOSim s)@, and then we can do quantification inside the
166166
-- monadic property using @pick@. This complicates matters, however, because
167167
-- functions like @withSimHasBlockIO@ and @withTable@ would have to run in

0 commit comments

Comments
 (0)