@@ -13,11 +13,10 @@ use typed_store::{
13
13
DBMapUtils ,
14
14
metrics:: SamplingInterval ,
15
15
rocks:: {
16
- DBBatch , DBMap , DBOptions , MetricConf , ReadWriteOptions , default_db_options,
16
+ DBBatch , DBMap , DBMapTableConfigMap , DBOptions , MetricConf , default_db_options,
17
17
read_size_from_env,
18
18
util:: { empty_compaction_filter, reference_count_merge_operator} ,
19
19
} ,
20
- rocksdb:: Options ,
21
20
traits:: { Map , TableSummary , TypedStoreDebug } ,
22
21
} ;
23
22
@@ -37,6 +36,22 @@ const ENV_VAR_EFFECTS_BLOCK_CACHE_SIZE: &str = "EFFECTS_BLOCK_CACHE_MB";
37
36
const ENV_VAR_EVENTS_BLOCK_CACHE_SIZE : & str = "EVENTS_BLOCK_CACHE_MB" ;
38
37
const ENV_VAR_INDIRECT_OBJECTS_BLOCK_CACHE_SIZE : & str = "INDIRECT_OBJECTS_BLOCK_CACHE_MB" ;
39
38
39
+ /// Options to apply to every column family of the `perpetual` DB.
40
+ #[ derive( Default ) ]
41
+ pub struct AuthorityPerpetualTablesOptions {
42
+ /// Whether to enable write stalling on all column families.
43
+ pub enable_write_stall : bool ,
44
+ }
45
+
46
+ impl AuthorityPerpetualTablesOptions {
47
+ fn apply_to ( & self , mut db_options : DBOptions ) -> DBOptions {
48
+ if !self . enable_write_stall {
49
+ db_options = db_options. disable_write_throttling ( ) ;
50
+ }
51
+ db_options
52
+ }
53
+ }
54
+
40
55
/// AuthorityPerpetualTables contains data that must be preserved from one epoch
41
56
/// to the next.
42
57
#[ derive( DBMapUtils ) ]
@@ -56,21 +71,17 @@ pub struct AuthorityPerpetualTables {
56
71
/// executed transactions whose effects have not yet been written out,
57
72
/// and which must be retried. But, they cannot be retried unless their
58
73
/// input objects are still accessible!
59
- #[ default_options_override_fn = "objects_table_default_config" ]
60
74
pub ( crate ) objects : DBMap < ObjectKey , StoreObjectWrapper > ,
61
75
62
- #[ default_options_override_fn = "indirect_move_objects_table_default_config" ]
63
76
pub ( crate ) indirect_move_objects : DBMap < ObjectContentDigest , StoreMoveObjectWrapper > ,
64
77
65
78
/// Object references of currently active objects that can be mutated.
66
- #[ default_options_override_fn = "live_owned_object_markers_table_default_config" ]
67
79
pub ( crate ) live_owned_object_markers : DBMap < ObjectRef , ( ) > ,
68
80
69
81
/// This is a map between the transaction digest and the corresponding
70
82
/// transaction that's known to be executable. This means that it may
71
83
/// have been executed locally, or it may have been synced through
72
84
/// state-sync but hasn't been executed yet.
73
- #[ default_options_override_fn = "transactions_table_default_config" ]
74
85
pub ( crate ) transactions : DBMap < TransactionDigest , TrustedTransaction > ,
75
86
76
87
/// A map between the transaction digest of a certificate to the effects of
@@ -85,7 +96,6 @@ pub struct AuthorityPerpetualTables {
85
96
///
86
97
/// It's also possible for the effects to be reverted if the transaction
87
98
/// didn't make it into the epoch.
88
- #[ default_options_override_fn = "effects_table_default_config" ]
89
99
pub ( crate ) effects : DBMap < TransactionEffectsDigest , TransactionEffects > ,
90
100
91
101
/// Transactions that have been executed locally on this node. We need this
@@ -99,7 +109,6 @@ pub struct AuthorityPerpetualTables {
99
109
// We could potentially remove this if we decided not to provide events in the execution path.
100
110
// TODO: Figure out what to do with this table in the long run.
101
111
// Also we need a pruning policy for this table. We can prune this table along with tx/effects.
102
- #[ default_options_override_fn = "events_table_default_config" ]
103
112
pub ( crate ) events : DBMap < ( TransactionEventsDigest , usize ) , Event > ,
104
113
105
114
/// Epoch and checkpoint of transactions finalized by checkpoint
@@ -156,13 +165,45 @@ impl AuthorityPerpetualTables {
156
165
parent_path. join ( "perpetual" )
157
166
}
158
167
159
- pub fn open ( parent_path : & Path , db_options : Option < Options > ) -> Self {
168
+ pub fn open (
169
+ parent_path : & Path ,
170
+ db_options_override : Option < AuthorityPerpetualTablesOptions > ,
171
+ ) -> Self {
172
+ let db_options_override = db_options_override. unwrap_or_default ( ) ;
173
+ let db_options =
174
+ db_options_override. apply_to ( default_db_options ( ) . optimize_db_for_write_throughput ( 4 ) ) ;
175
+ let table_options = DBMapTableConfigMap :: new ( BTreeMap :: from ( [
176
+ (
177
+ "objects" . to_string ( ) ,
178
+ objects_table_config ( db_options. clone ( ) ) ,
179
+ ) ,
180
+ (
181
+ "indirect_move_objects" . to_string ( ) ,
182
+ indirect_move_objects_table_config ( db_options. clone ( ) ) ,
183
+ ) ,
184
+ (
185
+ "live_owned_object_markers" . to_string ( ) ,
186
+ live_owned_object_markers_table_config ( db_options. clone ( ) ) ,
187
+ ) ,
188
+ (
189
+ "transactions" . to_string ( ) ,
190
+ transactions_table_config ( db_options. clone ( ) ) ,
191
+ ) ,
192
+ (
193
+ "effects" . to_string ( ) ,
194
+ effects_table_config ( db_options. clone ( ) ) ,
195
+ ) ,
196
+ (
197
+ "events" . to_string ( ) ,
198
+ events_table_config ( db_options. clone ( ) ) ,
199
+ ) ,
200
+ ] ) ) ;
160
201
Self :: open_tables_read_write (
161
202
Self :: path ( parent_path) ,
162
203
MetricConf :: new ( "perpetual" )
163
204
. with_sampling ( SamplingInterval :: new ( Duration :: from_secs ( 60 ) , 0 ) ) ,
164
- db_options,
165
- None ,
205
+ Some ( db_options. options ) ,
206
+ Some ( table_options ) ,
166
207
)
167
208
}
168
209
@@ -605,57 +646,58 @@ impl Iterator for LiveSetIter<'_> {
605
646
}
606
647
607
648
// These functions are used to initialize the DB tables
608
- fn live_owned_object_markers_table_default_config ( ) -> DBOptions {
649
+ fn live_owned_object_markers_table_config ( db_options : DBOptions ) -> DBOptions {
609
650
DBOptions {
610
- options : default_db_options ( )
651
+ options : db_options
652
+ . clone ( )
611
653
. optimize_for_write_throughput ( )
612
654
. optimize_for_read ( read_size_from_env ( ENV_VAR_LOCKS_BLOCK_CACHE_SIZE ) . unwrap_or ( 1024 ) )
613
655
. options ,
614
- rw_options : ReadWriteOptions :: default ( ) . set_ignore_range_deletions ( false ) ,
656
+ rw_options : db_options . rw_options . set_ignore_range_deletions ( false ) ,
615
657
}
616
658
}
617
659
618
- fn objects_table_default_config ( ) -> DBOptions {
619
- default_db_options ( )
660
+ fn objects_table_config ( db_options : DBOptions ) -> DBOptions {
661
+ db_options
620
662
. optimize_for_write_throughput ( )
621
663
. optimize_for_read ( read_size_from_env ( ENV_VAR_OBJECTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 5 * 1024 ) )
622
664
}
623
665
624
- fn transactions_table_default_config ( ) -> DBOptions {
625
- default_db_options ( )
666
+ fn transactions_table_config ( db_options : DBOptions ) -> DBOptions {
667
+ db_options
626
668
. optimize_for_write_throughput ( )
627
669
. optimize_for_point_lookup (
628
670
read_size_from_env ( ENV_VAR_TRANSACTIONS_BLOCK_CACHE_SIZE ) . unwrap_or ( 512 ) ,
629
671
)
630
672
}
631
673
632
- fn effects_table_default_config ( ) -> DBOptions {
633
- default_db_options ( )
674
+ fn effects_table_config ( db_options : DBOptions ) -> DBOptions {
675
+ db_options
634
676
. optimize_for_write_throughput ( )
635
677
. optimize_for_point_lookup (
636
678
read_size_from_env ( ENV_VAR_EFFECTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 1024 ) ,
637
679
)
638
680
}
639
681
640
- fn events_table_default_config ( ) -> DBOptions {
641
- default_db_options ( )
682
+ fn events_table_config ( db_options : DBOptions ) -> DBOptions {
683
+ db_options
642
684
. optimize_for_write_throughput ( )
643
685
. optimize_for_read ( read_size_from_env ( ENV_VAR_EVENTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 1024 ) )
644
686
}
645
687
646
- fn indirect_move_objects_table_default_config ( ) -> DBOptions {
647
- let mut options = default_db_options ( )
688
+ fn indirect_move_objects_table_config ( mut db_options : DBOptions ) -> DBOptions {
689
+ db_options = db_options
648
690
. optimize_for_write_throughput ( )
649
691
. optimize_for_point_lookup (
650
692
read_size_from_env ( ENV_VAR_INDIRECT_OBJECTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 512 ) ,
651
693
) ;
652
- options . options . set_merge_operator (
694
+ db_options . options . set_merge_operator (
653
695
"refcount operator" ,
654
696
reference_count_merge_operator,
655
697
reference_count_merge_operator,
656
698
) ;
657
- options
699
+ db_options
658
700
. options
659
701
. set_compaction_filter ( "empty filter" , empty_compaction_filter) ;
660
- options
702
+ db_options
661
703
}
0 commit comments