|
5 | 5 | module Database.LSMTree.Internal.Config.Override ( |
6 | 6 | -- $override-policy |
7 | 7 |
|
8 | | - -- * Override disk cache policy |
9 | | - OverrideDiskCachePolicy (..) |
10 | | - , overrideDiskCachePolicy |
| 8 | + -- * Override table config |
| 9 | + TableConfigOverride (..) |
| 10 | + , noTableConfigOverride |
| 11 | + , overrideTableConfig |
11 | 12 | ) where |
12 | 13 |
|
13 | 14 | import qualified Data.Vector as V |
@@ -42,35 +43,75 @@ import Database.LSMTree.Internal.Snapshot |
42 | 43 | -- Another complicating factor is that we have thought about the possibility of |
43 | 44 | -- restoring sharing of ongoing merges between live tables and newly opened |
44 | 45 | -- snapshots. At that point, we run into the same challenges again... But for |
45 | | --- now, changing only the disk cache policy offline should work fine. |
| 46 | +-- now, changing only the disk cache policy and merge batch size offline should |
| 47 | +-- work fine. |
46 | 48 |
|
47 | 49 | {------------------------------------------------------------------------------- |
48 | | - Override disk cache policy |
| 50 | + Helper class |
| 51 | +-------------------------------------------------------------------------------} |
| 52 | + |
| 53 | +-- | This class is only here so that we can recursively call 'override' on all |
| 54 | +-- fields of a datatype, instead of having to invent a new name for each type |
| 55 | +-- that the function is called on such as @overrideTableConfig@, |
| 56 | +-- @overrideSnapshotRun@, etc. |
| 57 | +class Override o a where |
| 58 | + override :: o -> a -> a |
| 59 | + |
| 60 | +instance Override a c => Override (Maybe a) c where |
| 61 | + override = maybe id override |
| 62 | + |
| 63 | +{------------------------------------------------------------------------------- |
| 64 | + Override table config |
49 | 65 | -------------------------------------------------------------------------------} |
50 | 66 |
|
51 | 67 | {- | |
52 | | -The 'OverrideDiskCachePolicy' can be used to override the 'DiskCachePolicy' |
| 68 | +The 'TableConfigOverride' can be used to override the 'TableConfig' |
53 | 69 | when opening a table from a snapshot. |
54 | 70 | -} |
55 | | -data OverrideDiskCachePolicy = |
56 | | - NoOverrideDiskCachePolicy |
57 | | - | OverrideDiskCachePolicy DiskCachePolicy |
| 71 | +data TableConfigOverride = TableConfigOverride { |
| 72 | + overrideDiskCachePolicy :: Maybe DiskCachePolicy, |
| 73 | + overrideMergeBatchSize :: Maybe MergeBatchSize |
| 74 | + } |
58 | 75 | deriving stock (Show, Eq) |
59 | 76 |
|
60 | | --- | Override the disk cache policy that is stored in snapshot metadata. |
| 77 | +-- | No override of the 'TableConfig'. You can use this as a default value and |
| 78 | +-- record update to override some parameters, while being future-proof to new |
| 79 | +-- parameters, e.g. |
| 80 | +-- |
| 81 | +-- > noTableConfigOverride { overrideDiskCachePolicy = DiskCacheNone } |
| 82 | +-- |
| 83 | +noTableConfigOverride :: TableConfigOverride |
| 84 | +noTableConfigOverride = TableConfigOverride Nothing Nothing |
| 85 | + |
| 86 | +-- | Override the a subset of the table configuration parameters that are |
| 87 | +-- stored in snapshot metadata. |
61 | 88 | -- |
62 | 89 | -- Tables opened from the new 'SnapshotMetaData' will use the new value for the |
63 | | --- disk cache policy. |
64 | | -overrideDiskCachePolicy :: OverrideDiskCachePolicy -> SnapshotMetaData -> SnapshotMetaData |
65 | | -overrideDiskCachePolicy (OverrideDiskCachePolicy dcp) = override dcp |
66 | | -overrideDiskCachePolicy NoOverrideDiskCachePolicy = id |
| 90 | +-- table configuration. |
| 91 | +overrideTableConfig :: TableConfigOverride |
| 92 | + -> SnapshotMetaData -> SnapshotMetaData |
| 93 | +overrideTableConfig = override |
67 | 94 |
|
68 | | --- | This class is only here so that we can recursively call 'override' on all |
69 | | --- fields of a datatype, instead of having to invent a new name for each type |
70 | | --- that the function is called on such as 'overrideTableConfig', |
71 | | --- 'overrideSnapshotRun', etc. |
72 | | -class Override o a where |
73 | | - override :: o -> a -> a |
| 95 | +instance Override TableConfigOverride SnapshotMetaData where |
| 96 | + override TableConfigOverride {..} = |
| 97 | + override overrideMergeBatchSize |
| 98 | + . override overrideDiskCachePolicy |
| 99 | + |
| 100 | +{------------------------------------------------------------------------------- |
| 101 | + Override merge batch size |
| 102 | +-------------------------------------------------------------------------------} |
| 103 | + |
| 104 | +instance Override MergeBatchSize SnapshotMetaData where |
| 105 | + override mbs smd = |
| 106 | + smd { snapMetaConfig = override mbs (snapMetaConfig smd) } |
| 107 | + |
| 108 | +instance Override MergeBatchSize TableConfig where |
| 109 | + override confMergeBatchSize' tc = |
| 110 | + tc { confMergeBatchSize = confMergeBatchSize' } |
| 111 | + |
| 112 | +{------------------------------------------------------------------------------- |
| 113 | + Override disk cache policy |
| 114 | +-------------------------------------------------------------------------------} |
74 | 115 |
|
75 | 116 | -- NOTE: the instances below explicitly pattern match on the types of |
76 | 117 | -- constructor fields. This makes the code more verbose, but it also makes the |
|
0 commit comments