@@ -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,41 @@ 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
+ "transactions" . to_string ( ) ,
186
+ transactions_table_config ( db_options. clone ( ) ) ,
187
+ ) ,
188
+ (
189
+ "effects" . to_string ( ) ,
190
+ effects_table_config ( db_options. clone ( ) ) ,
191
+ ) ,
192
+ (
193
+ "events" . to_string ( ) ,
194
+ events_table_config ( db_options. clone ( ) ) ,
195
+ ) ,
196
+ ] ) ) ;
160
197
Self :: open_tables_read_write (
161
198
Self :: path ( parent_path) ,
162
199
MetricConf :: new ( "perpetual" )
163
200
. with_sampling ( SamplingInterval :: new ( Duration :: from_secs ( 60 ) , 0 ) ) ,
164
- db_options,
165
- None ,
201
+ Some ( db_options. options ) ,
202
+ Some ( table_options ) ,
166
203
)
167
204
}
168
205
@@ -605,57 +642,58 @@ impl Iterator for LiveSetIter<'_> {
605
642
}
606
643
607
644
// These functions are used to initialize the DB tables
608
- fn live_owned_object_markers_table_default_config ( ) -> DBOptions {
645
+ fn live_owned_object_markers_table_config ( db_options : DBOptions ) -> DBOptions {
609
646
DBOptions {
610
- options : default_db_options ( )
647
+ options : db_options
648
+ . clone ( )
611
649
. optimize_for_write_throughput ( )
612
650
. optimize_for_read ( read_size_from_env ( ENV_VAR_LOCKS_BLOCK_CACHE_SIZE ) . unwrap_or ( 1024 ) )
613
651
. options ,
614
- rw_options : ReadWriteOptions :: default ( ) . set_ignore_range_deletions ( false ) ,
652
+ rw_options : db_options . rw_options . set_ignore_range_deletions ( false ) ,
615
653
}
616
654
}
617
655
618
- fn objects_table_default_config ( ) -> DBOptions {
619
- default_db_options ( )
656
+ fn objects_table_config ( db_options : DBOptions ) -> DBOptions {
657
+ db_options
620
658
. optimize_for_write_throughput ( )
621
659
. optimize_for_read ( read_size_from_env ( ENV_VAR_OBJECTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 5 * 1024 ) )
622
660
}
623
661
624
- fn transactions_table_default_config ( ) -> DBOptions {
625
- default_db_options ( )
662
+ fn transactions_table_config ( db_options : DBOptions ) -> DBOptions {
663
+ db_options
626
664
. optimize_for_write_throughput ( )
627
665
. optimize_for_point_lookup (
628
666
read_size_from_env ( ENV_VAR_TRANSACTIONS_BLOCK_CACHE_SIZE ) . unwrap_or ( 512 ) ,
629
667
)
630
668
}
631
669
632
- fn effects_table_default_config ( ) -> DBOptions {
633
- default_db_options ( )
670
+ fn effects_table_config ( db_options : DBOptions ) -> DBOptions {
671
+ db_options
634
672
. optimize_for_write_throughput ( )
635
673
. optimize_for_point_lookup (
636
674
read_size_from_env ( ENV_VAR_EFFECTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 1024 ) ,
637
675
)
638
676
}
639
677
640
- fn events_table_default_config ( ) -> DBOptions {
641
- default_db_options ( )
678
+ fn events_table_config ( db_options : DBOptions ) -> DBOptions {
679
+ db_options
642
680
. optimize_for_write_throughput ( )
643
681
. optimize_for_read ( read_size_from_env ( ENV_VAR_EVENTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 1024 ) )
644
682
}
645
683
646
- fn indirect_move_objects_table_default_config ( ) -> DBOptions {
647
- let mut options = default_db_options ( )
684
+ fn indirect_move_objects_table_config ( mut db_options : DBOptions ) -> DBOptions {
685
+ db_options = db_options
648
686
. optimize_for_write_throughput ( )
649
687
. optimize_for_point_lookup (
650
688
read_size_from_env ( ENV_VAR_INDIRECT_OBJECTS_BLOCK_CACHE_SIZE ) . unwrap_or ( 512 ) ,
651
689
) ;
652
- options . options . set_merge_operator (
690
+ db_options . options . set_merge_operator (
653
691
"refcount operator" ,
654
692
reference_count_merge_operator,
655
693
reference_count_merge_operator,
656
694
) ;
657
- options
695
+ db_options
658
696
. options
659
697
. set_compaction_filter ( "empty filter" , empty_compaction_filter) ;
660
- options
698
+ db_options
661
699
}
0 commit comments