-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor Run modules to use modern record extensions #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mwihoti
wants to merge
6
commits into
IntersectMBO:main
Choose a base branch
from
mwihoti:feature/811-modern-record-extensions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e608bd
Refactor Run modules to use modern record extensions
mwihoti 5823d35
addressed review feedback: remove redundant parens and fix
mwihoti 0f52a91
Fix build errors after review feedback changes
mwihoti 6ccaf2d
Apply stylish-haskell formatting
mwihoti 2b0d319
apply haskell formatting
mwihoti 6568b11
Remove redundant blobFile let-binding shadowed by dupRef in RunReader
mwihoti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||||||||||||||
| {-# LANGUAGE OverloadedRecordDot #-} | ||||||||||||||
|
|
||||||||||||||
| module Bench.Database.LSMTree.Internal.Lookup (benchmarks) where | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -91,9 +92,9 @@ benchSalt = 4 | |||||||||||||
| benchLookups :: Config -> Benchmark | ||||||||||||||
| benchLookups conf@Config{name} = | ||||||||||||||
| withEnv $ \ ~(_dir, arenaManager, _hasFS, hasBlockIO, _refCtx, wbblobs, rs, ks) -> | ||||||||||||||
| env ( pure ( V.map (\(DeRef r) -> Run.runFilter r) rs | ||||||||||||||
| , V.map (\(DeRef r) -> Run.runIndex r) rs | ||||||||||||||
| , V.map (\(DeRef r) -> Run.runKOpsFile r) rs | ||||||||||||||
| env ( pure ( V.map (\(DeRef r) -> r.bloomFilter ) rs | ||||||||||||||
| , V.map (\(DeRef r) -> r.index ) rs | ||||||||||||||
| , V.map (\(DeRef r) -> r.kOpsFile ) rs | ||||||||||||||
|
Comment on lines
+95
to
+97
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| ) | ||||||||||||||
| ) $ \ ~(blooms, indexes, kopsFiles) -> | ||||||||||||||
| bgroup name [ | ||||||||||||||
|
|
||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,18 @@ | ||||||||||||||
| {-# LANGUAGE DataKinds #-} | ||||||||||||||
| {-# LANGUAGE DeriveAnyClass #-} | ||||||||||||||
| {-# LANGUAGE DerivingStrategies #-} | ||||||||||||||
| {-# LANGUAGE DerivingVia #-} | ||||||||||||||
| {-# LANGUAGE RecordWildCards #-} | ||||||||||||||
| {-# LANGUAGE DataKinds #-} | ||||||||||||||
| {-# LANGUAGE DeriveAnyClass #-} | ||||||||||||||
| {-# LANGUAGE DerivingStrategies #-} | ||||||||||||||
| {-# LANGUAGE DerivingVia #-} | ||||||||||||||
| {-# LANGUAGE DuplicateRecordFields #-} | ||||||||||||||
| {-# LANGUAGE NoFieldSelectors #-} | ||||||||||||||
| {-# LANGUAGE OverloadedRecordDot #-} | ||||||||||||||
|
|
||||||||||||||
| {-# OPTIONS_HADDOCK not-home #-} | ||||||||||||||
|
|
||||||||||||||
| -- | Runs of sorted key\/value data. | ||||||||||||||
| module Database.LSMTree.Internal.Run ( | ||||||||||||||
| -- * Run | ||||||||||||||
| Run (Run, runIndex, runHasFS, runHasBlockIO, runRunDataCaching, | ||||||||||||||
| runBlobFile, runFilter, runKOpsFile) | ||||||||||||||
| Run (Run, index, hasFS, hasBlockIO, dataCaching, | ||||||||||||||
| blobFile, bloomFilter, kOpsFile) | ||||||||||||||
| , RunFsPaths | ||||||||||||||
| , size | ||||||||||||||
| , sizeInPages | ||||||||||||||
|
|
@@ -68,75 +71,77 @@ import System.FS.BlockIO.API (HasBlockIO) | |||||||||||||
| -- | The in-memory representation of a completed LSM run. | ||||||||||||||
| -- | ||||||||||||||
| data Run m h = Run { | ||||||||||||||
| runNumEntries :: !NumEntries | ||||||||||||||
| numEntries :: !NumEntries | ||||||||||||||
| -- | The reference count for the LSM run. This counts the | ||||||||||||||
| -- number of references from LSM handles to this run. When | ||||||||||||||
| -- this drops to zero the open files will be closed. | ||||||||||||||
| , runRefCounter :: !(RefCounter m) | ||||||||||||||
| , refCounter :: !(RefCounter m) | ||||||||||||||
| -- | The file system paths for all the files used by the run. | ||||||||||||||
| , runRunFsPaths :: !RunFsPaths | ||||||||||||||
| , fsPaths :: !RunFsPaths | ||||||||||||||
| -- | The bloom filter for the set of keys in this run. | ||||||||||||||
| , runFilter :: !(Bloom SerialisedKey) | ||||||||||||||
| , bloomFilter :: !(Bloom SerialisedKey) | ||||||||||||||
| -- | The in-memory index mapping keys to page numbers in the | ||||||||||||||
| -- Key\/Ops file. In future we may support alternative index | ||||||||||||||
| -- representations. | ||||||||||||||
| , runIndex :: !Index | ||||||||||||||
| , index :: !Index | ||||||||||||||
| -- | The file handle for the Key\/Ops file. This file is opened | ||||||||||||||
| -- read-only and is accessed in a page-oriented way, i.e. only | ||||||||||||||
| -- reading whole pages, at page offsets. It will be opened with | ||||||||||||||
| -- 'O_DIRECT' on supported platforms. | ||||||||||||||
| , runKOpsFile :: !(FS.Handle h) | ||||||||||||||
| , kOpsFile :: !(FS.Handle h) | ||||||||||||||
| -- | The file handle for the BLOBs file. This file is opened | ||||||||||||||
| -- read-only and is accessed in a normal style using buffered | ||||||||||||||
| -- I\/O, reading arbitrary file offset and length spans. | ||||||||||||||
| , runBlobFile :: !(Ref (BlobFile m h)) | ||||||||||||||
| , runRunDataCaching :: !RunDataCaching | ||||||||||||||
| , runHasFS :: !(HasFS m h) | ||||||||||||||
| , runHasBlockIO :: !(HasBlockIO m h) | ||||||||||||||
| , blobFile :: !(Ref (BlobFile m h)) | ||||||||||||||
| , dataCaching :: !RunDataCaching | ||||||||||||||
| , hasFS :: !(HasFS m h) | ||||||||||||||
| , hasBlockIO :: !(HasBlockIO m h) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| -- | Shows only the 'runRunFsPaths' field. | ||||||||||||||
| instance Show (Run m h) where | ||||||||||||||
| showsPrec _ run = showString "Run { runRunFsPaths = " . showsPrec 0 (runRunFsPaths run) . showString " }" | ||||||||||||||
| showsPrec _ run = showString "Run { fsPaths = " . showsPrec 0 run.fsPaths . showString " }" | ||||||||||||||
|
|
||||||||||||||
| instance NFData h => NFData (Run m h) where | ||||||||||||||
| rnf (Run a b c d e f g h i j) = | ||||||||||||||
| rnf a `seq` rwhnf b `seq` rnf c `seq` rnf d `seq` rnf e `seq` | ||||||||||||||
| rnf f `seq` rnf g `seq` rnf h `seq` rwhnf i `seq` rwhnf j | ||||||||||||||
| rnf (Run numEntries refCounter fsPaths bloomFilter index kOpsFile blobFile dataCaching hasFS hasBlockIO) = | ||||||||||||||
| rnf numEntries `seq` rwhnf refCounter `seq` rnf fsPaths `seq` | ||||||||||||||
| rnf bloomFilter `seq` rnf index `seq` rnf kOpsFile `seq` | ||||||||||||||
| rnf blobFile `seq` rnf dataCaching `seq` rwhnf hasFS `seq` rwhnf hasBlockIO | ||||||||||||||
|
|
||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| instance RefCounted m (Run m h) where | ||||||||||||||
| getRefCounter = runRefCounter | ||||||||||||||
| getRefCounter r = r.refCounter | ||||||||||||||
|
|
||||||||||||||
| size :: Ref (Run m h) -> NumEntries | ||||||||||||||
| size (DeRef run) = runNumEntries run | ||||||||||||||
| size (DeRef run) = run.numEntries | ||||||||||||||
|
|
||||||||||||||
| sizeInPages :: Ref (Run m h) -> NumPages | ||||||||||||||
| sizeInPages (DeRef run) = Index.sizeInPages (runIndex run) | ||||||||||||||
| sizeInPages (DeRef run) = Index.sizeInPages run.index | ||||||||||||||
|
|
||||||||||||||
| runFsPaths :: Ref (Run m h) -> RunFsPaths | ||||||||||||||
| runFsPaths (DeRef r) = runRunFsPaths r | ||||||||||||||
| runFsPaths (DeRef r) = r.fsPaths | ||||||||||||||
|
|
||||||||||||||
| runFsPathsNumber :: Ref (Run m h) -> RunNumber | ||||||||||||||
| runFsPathsNumber = Paths.runNumber . runFsPaths | ||||||||||||||
|
|
||||||||||||||
| -- | See 'openFromDisk' | ||||||||||||||
| runIndexType :: Ref (Run m h) -> IndexType | ||||||||||||||
| runIndexType (DeRef r) = Index.indexToIndexType (runIndex r) | ||||||||||||||
| runIndexType (DeRef r) = Index.indexToIndexType r.index | ||||||||||||||
|
|
||||||||||||||
| -- | See 'openFromDisk' | ||||||||||||||
| runDataCaching :: Ref (Run m h) -> RunDataCaching | ||||||||||||||
| runDataCaching (DeRef r) = runRunDataCaching r | ||||||||||||||
| runDataCaching (DeRef r) = r.dataCaching | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| -- | Helper function to make a 'WeakBlobRef' that points into a 'Run'. | ||||||||||||||
| mkRawBlobRef :: Run m h -> BlobSpan -> RawBlobRef m h | ||||||||||||||
| mkRawBlobRef Run{runBlobFile} blobspan = | ||||||||||||||
| BlobRef.mkRawBlobRef runBlobFile blobspan | ||||||||||||||
| mkRawBlobRef run = | ||||||||||||||
| BlobRef.mkRawBlobRef run.blobFile | ||||||||||||||
|
|
||||||||||||||
| -- | Helper function to make a 'WeakBlobRef' that points into a 'Run'. | ||||||||||||||
| mkWeakBlobRef :: Ref (Run m h) -> BlobSpan -> WeakBlobRef m h | ||||||||||||||
| mkWeakBlobRef (DeRef Run{runBlobFile}) blobspan = | ||||||||||||||
| BlobRef.mkWeakBlobRef runBlobFile blobspan | ||||||||||||||
| mkWeakBlobRef (DeRef run) blobspan = | ||||||||||||||
| BlobRef.mkWeakBlobRef run.blobFile blobspan | ||||||||||||||
|
|
||||||||||||||
| {-# SPECIALISE finaliser :: | ||||||||||||||
| HasFS IO h | ||||||||||||||
|
|
@@ -227,7 +232,18 @@ fromBuilder refCtx builder = do | |||||||||||||
| setRunDataCaching runHasBlockIO runKOpsFile runRunDataCaching | ||||||||||||||
| newRef refCtx | ||||||||||||||
| (finaliser runHasFS runKOpsFile runBlobFile runRunFsPaths) | ||||||||||||||
| (\runRefCounter -> Run { .. }) | ||||||||||||||
| (\refCounter -> Run { | ||||||||||||||
| numEntries = runNumEntries | ||||||||||||||
| , refCounter = refCounter | ||||||||||||||
| , fsPaths = runRunFsPaths | ||||||||||||||
|
Comment on lines
+236
to
+238
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| , bloomFilter = runFilter | ||||||||||||||
| , index = runIndex | ||||||||||||||
| , kOpsFile = runKOpsFile | ||||||||||||||
| , blobFile = runBlobFile | ||||||||||||||
| , dataCaching = runRunDataCaching | ||||||||||||||
| , hasFS = runHasFS | ||||||||||||||
| , hasBlockIO = runHasBlockIO | ||||||||||||||
| }) | ||||||||||||||
|
jorisdral marked this conversation as resolved.
|
||||||||||||||
|
|
||||||||||||||
| {-# SPECIALISE fromWriteBuffer :: | ||||||||||||||
| HasFS IO h | ||||||||||||||
|
|
@@ -336,9 +352,16 @@ openFromDisk fs hbio refCtx runRunDataCaching indexType expectedSalt runRunFsPat | |||||||||||||
| setRunDataCaching hbio runKOpsFile runRunDataCaching | ||||||||||||||
| newRef refCtx (finaliser fs runKOpsFile runBlobFile runRunFsPaths) $ \runRefCounter -> | ||||||||||||||
| Run { | ||||||||||||||
| runHasFS = fs | ||||||||||||||
| , runHasBlockIO = hbio | ||||||||||||||
| , .. | ||||||||||||||
| numEntries = runNumEntries | ||||||||||||||
| , refCounter = runRefCounter | ||||||||||||||
| , fsPaths = runRunFsPaths | ||||||||||||||
| , bloomFilter = runFilter | ||||||||||||||
| , index = runIndex | ||||||||||||||
| , kOpsFile = runKOpsFile | ||||||||||||||
| , blobFile = runBlobFile | ||||||||||||||
| , dataCaching = runRunDataCaching | ||||||||||||||
| , hasFS = fs | ||||||||||||||
| , hasBlockIO = hbio | ||||||||||||||
| } | ||||||||||||||
| where | ||||||||||||||
| -- Note: all file data for this path is evicted from the page cache /if/ the | ||||||||||||||
|
|
||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.