@@ -87,65 +87,42 @@ use crate::{
87
87
FunctionWrites ,
88
88
} ;
89
89
90
- /// Struct from which you can create a [Transaction].
91
- /// TODO: delete this in favor of using Transaction directly.
92
- pub struct TransactionIngredients < RT : Runtime > {
93
- pub ts : RepeatableTimestamp ,
94
- pub identity : Identity ,
95
- pub existing_writes : FunctionWrites ,
96
- pub rt : RT ,
97
- pub table_registry : TableRegistry ,
98
- pub index_registry : IndexRegistry ,
99
- pub table_count_snapshot : Arc < dyn TableCountSnapshot > ,
100
- pub database_index_snapshot : DatabaseIndexSnapshot ,
101
- pub text_index_snapshot : Arc < dyn TransactionTextSnapshot > ,
102
- pub retention_validator : Arc < dyn RetentionValidator > ,
103
- pub virtual_system_mapping : VirtualSystemMapping ,
104
- pub usage_tracker : FunctionUsageTracker ,
105
- }
106
-
107
- impl < RT : Runtime > TryFrom < TransactionIngredients < RT > > for Transaction < RT > {
108
- type Error = anyhow:: Error ;
109
-
110
- fn try_from (
111
- TransactionIngredients {
112
- ts,
113
- identity,
114
- existing_writes,
115
- rt,
116
- table_registry,
117
- index_registry,
118
- table_count_snapshot,
119
- database_index_snapshot,
120
- text_index_snapshot,
121
- retention_validator,
122
- virtual_system_mapping,
123
- usage_tracker,
124
- } : TransactionIngredients < RT > ,
125
- ) -> Result < Self , Self :: Error > {
126
- let id_generator = TransactionIdGenerator :: new ( & rt) ?;
127
- // The transaction timestamp might be few minutes behind if the backend
128
- // has been idle. Make sure creation time is always recent. Existing writes to
129
- // the transaction will advance next_creation_time in `merge_writes` below.
130
- let creation_time = CreationTime :: try_from ( cmp:: max ( * ts, rt. generate_timestamp ( ) ?) ) ?;
131
- let transaction_index =
132
- TransactionIndex :: new ( index_registry, database_index_snapshot, text_index_snapshot) ;
133
- let mut tx = Transaction :: new (
134
- identity,
135
- id_generator,
136
- creation_time,
137
- transaction_index,
138
- table_registry,
139
- table_count_snapshot,
140
- rt. clone ( ) ,
141
- usage_tracker,
142
- retention_validator,
143
- virtual_system_mapping,
144
- ) ;
145
- let updates = existing_writes. updates ;
146
- tx. merge_writes ( updates, existing_writes. generated_ids ) ?;
147
- Ok ( tx)
148
- }
90
+ fn make_transaction < RT : Runtime > (
91
+ ts : RepeatableTimestamp ,
92
+ identity : Identity ,
93
+ existing_writes : FunctionWrites ,
94
+ rt : RT ,
95
+ table_registry : TableRegistry ,
96
+ index_registry : IndexRegistry ,
97
+ table_count_snapshot : Arc < dyn TableCountSnapshot > ,
98
+ database_index_snapshot : DatabaseIndexSnapshot ,
99
+ text_index_snapshot : Arc < dyn TransactionTextSnapshot > ,
100
+ retention_validator : Arc < dyn RetentionValidator > ,
101
+ virtual_system_mapping : VirtualSystemMapping ,
102
+ usage_tracker : FunctionUsageTracker ,
103
+ ) -> anyhow:: Result < Transaction < RT > > {
104
+ let id_generator = TransactionIdGenerator :: new ( & rt) ?;
105
+ // The transaction timestamp might be few minutes behind if the backend
106
+ // has been idle. Make sure creation time is always recent. Existing writes to
107
+ // the transaction will advance next_creation_time in `merge_writes` below.
108
+ let creation_time = CreationTime :: try_from ( cmp:: max ( * ts, rt. generate_timestamp ( ) ?) ) ?;
109
+ let transaction_index =
110
+ TransactionIndex :: new ( index_registry, database_index_snapshot, text_index_snapshot) ;
111
+ let mut tx = Transaction :: new (
112
+ identity,
113
+ id_generator,
114
+ creation_time,
115
+ transaction_index,
116
+ table_registry,
117
+ table_count_snapshot,
118
+ rt. clone ( ) ,
119
+ usage_tracker,
120
+ retention_validator,
121
+ virtual_system_mapping,
122
+ ) ;
123
+ let updates = existing_writes. updates ;
124
+ tx. merge_writes ( updates, existing_writes. generated_ids ) ?;
125
+ Ok ( tx)
149
126
}
150
127
151
128
#[ derive( Hash , PartialEq , Eq , Clone , Debug ) ]
@@ -367,7 +344,7 @@ impl<RT: Runtime> InMemoryIndexCache<RT> {
367
344
text_index_snapshot : Arc < dyn TransactionTextSnapshot > ,
368
345
usage_tracker : FunctionUsageTracker ,
369
346
retention_validator : Arc < dyn RetentionValidator > ,
370
- ) -> anyhow:: Result < TransactionIngredients < RT > > {
347
+ ) -> anyhow:: Result < Transaction < RT > > {
371
348
let _timer = begin_tx_timer ( ) ;
372
349
for ( index_id, last_modified) in & in_memory_index_last_modified {
373
350
anyhow:: ensure!(
@@ -390,21 +367,20 @@ impl<RT: Runtime> InMemoryIndexCache<RT> {
390
367
bootstrap_metadata,
391
368
)
392
369
. await ?;
393
- let transaction_ingredients = TransactionIngredients {
370
+ make_transaction (
394
371
ts,
395
372
identity,
396
373
existing_writes,
397
- rt : self . rt . clone ( ) ,
374
+ self . rt . clone ( ) ,
398
375
table_registry,
399
376
index_registry,
400
377
table_count_snapshot,
401
378
database_index_snapshot,
402
379
text_index_snapshot,
403
380
retention_validator,
404
- virtual_system_mapping : virtual_system_mapping ( ) ,
381
+ virtual_system_mapping ( ) ,
405
382
usage_tracker,
406
- } ;
407
- Ok ( transaction_ingredients)
383
+ )
408
384
}
409
385
}
410
386
0 commit comments