@@ -47,7 +47,6 @@ pub struct TxContextItem {
4747 pub write_definition : TokenStream ,
4848 pub write_begin : TokenStream ,
4949 pub async_flush : Option < TokenStream > ,
50- pub deferred_flush : Option < TokenStream > ,
5150 pub write_shutdown : TokenStream ,
5251 pub read_definition : TokenStream ,
5352}
@@ -60,6 +59,7 @@ pub fn def_tx_context(entity_def: &EntityDef, tx_contexts: &[TxContextItem]) ->
6059 let write_entity_tx_context_ty = & entity_def. write_ctx_type ;
6160 let tx_context_name = format_ident ! ( "{}" , TX_CONTEXT ) ;
6261 quote ! {
62+ #[ derive( Debug ) ]
6363 pub struct #entity_tx_context_ty {
6464 #( #definitions) , *
6565 }
@@ -84,7 +84,6 @@ pub fn write_tx_context(entity_def: &EntityDef, tx_contexts: &[TxContextItem]) -
8484 let begins: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. write_begin . clone ( ) ) . collect ( ) ;
8585 let shutdowns: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. write_shutdown . clone ( ) ) . collect ( ) ;
8686 let async_flushes: Vec < TokenStream > = tx_contexts. iter ( ) . flat_map ( |item| item. async_flush . clone ( ) ) . collect ( ) ;
87- let deferred_flushes: Vec < TokenStream > = tx_contexts. iter ( ) . flat_map ( |item| item. deferred_flush . clone ( ) ) . collect ( ) ;
8887 let write_tx_context_name = tx_context_name ( TxType :: Write ) ;
8988 let write_tx_context_ty = & entity_def. write_ctx_type ;
9089 let entity_tx_context_ty = & entity_def. ctx_type ;
@@ -114,11 +113,6 @@ pub fn write_tx_context(entity_def: &EntityDef, tx_contexts: &[TxContextItem]) -
114113 #( futures. extend( #async_flushes) ; ) *
115114 Ok ( futures)
116115 }
117- fn commit_ctx_deferred( & self ) -> Result <Vec <FlushFuture >, AppError > {
118- let mut futures: Vec <FlushFuture > = Vec :: new( ) ;
119- #( futures. extend( #deferred_flushes) ; ) *
120- Ok ( futures)
121- }
122116 }
123117 }
124118}
@@ -164,7 +158,8 @@ pub fn tx_context_plain_item(def: &PlainTableDef) -> TxContextItem {
164158 let key_ty = & def. key_type ;
165159 let val_ty: Type = def. value_type . clone ( ) . unwrap_or_else ( || syn:: parse_str :: < Type > ( "()" ) . unwrap ( ) ) ;
166160 let table_def = & def. underlying . definition ;
167- let shards = def. column_props . shards ;
161+ let shards= def. column_props . shards ;
162+ let root_pk= def. root_pk ;
168163
169164 let definition =
170165 quote ! {
@@ -183,18 +178,13 @@ pub fn tx_context_plain_item(def: &PlainTableDef) -> TxContextItem {
183178
184179 let def_constructor = quote ! {
185180 #var_ident: RedbitTableDefinition :: new(
181+ #root_pk,
186182 Partitioning :: by_key( #shards) ,
187183 PlainFactory :: new( #name_lit, #table_def) ,
188184 )
189185 } ;
190186 let write_begin = quote ! { self . #var_ident. begin_async( durability) ? } ;
191- let async_flush =
192- if def. root_pk {
193- Some ( quote ! { self . #var_ident. flush_two_phased( ) ? } )
194- } else {
195- Some ( quote ! { self . #var_ident. flush_async( ) ? } )
196- } ;
197- let deferred_flush = Some ( quote ! { self . #var_ident. flush_deferred( ) ? } ) ;
187+ let async_flush = Some ( quote ! { self . #var_ident. flush_async( ) ? } ) ;
198188 let write_shutdown = quote ! { self . #var_ident. shutdown_async( ) ? } ;
199189
200190 TxContextItem {
@@ -204,7 +194,6 @@ pub fn tx_context_plain_item(def: &PlainTableDef) -> TxContextItem {
204194 write_definition,
205195 write_begin,
206196 async_flush,
207- deferred_flush,
208197 write_shutdown,
209198 read_definition,
210199 }
@@ -237,13 +226,13 @@ pub fn tx_context_index_item(defs: &IndexTableDefs) -> TxContextItem {
237226
238227 let def_constructor = quote ! {
239228 #var_ident: RedbitTableDefinition :: new(
229+ false ,
240230 Partitioning :: by_value( #shards) ,
241231 IndexFactory :: new( #name_lit, #lru_cache, #pk_by_index, #index_by_pk) ,
242232 )
243233 } ;
244234 let write_begin = quote ! { self . #var_ident. begin_async( durability) ? } ;
245235 let async_flush = Some ( quote ! { self . #var_ident. flush_async( ) ? } ) ;
246- let deferred_flush = Some ( quote ! { self . #var_ident. flush_deferred( ) ? } ) ;
247236 let write_shutdown = quote ! { self . #var_ident. shutdown_async( ) ? } ;
248237
249238 TxContextItem {
@@ -253,7 +242,6 @@ pub fn tx_context_index_item(defs: &IndexTableDefs) -> TxContextItem {
253242 write_definition,
254243 write_begin,
255244 async_flush,
256- deferred_flush,
257245 write_shutdown,
258246 read_definition,
259247 }
@@ -288,13 +276,13 @@ pub fn tx_context_dict_item(defs: &DictTableDefs) -> TxContextItem {
288276
289277 let def_constructor = quote ! {
290278 #var_ident: RedbitTableDefinition :: new(
279+ false ,
291280 Partitioning :: by_value( #shards) ,
292281 DictFactory :: new( #name_lit, #lru_cache, #dict_pk_to_ids, #value_by_dict, #value_to_dict, #dict_pk_by_pk) ,
293282 )
294283 } ;
295284 let write_begin = quote ! { self . #var_ident. begin_async( durability) ? } ;
296285 let async_flush = Some ( quote ! { self . #var_ident. flush_async( ) ? } ) ;
297- let deferred_flush = Some ( quote ! { self . #var_ident. flush_deferred( ) ? } ) ;
298286 let write_shutdown = quote ! { self . #var_ident. shutdown_async( ) ? } ;
299287
300288 TxContextItem {
@@ -304,7 +292,6 @@ pub fn tx_context_dict_item(defs: &DictTableDefs) -> TxContextItem {
304292 write_definition,
305293 write_begin,
306294 async_flush,
307- deferred_flush,
308295 write_shutdown,
309296 read_definition,
310297 }
@@ -329,6 +316,23 @@ pub fn begin_write_fn_def(entity_def: &EntityDef) -> FunctionDef {
329316
330317}
331318
319+ pub fn definition ( entity_def : & EntityDef ) -> FunctionDef {
320+ let tx_context_ty = & entity_def. ctx_type ;
321+ let fn_name = format_ident ! ( "definition" ) ;
322+ let fn_stream = quote ! {
323+ pub fn #fn_name( ) -> Result <#tx_context_ty, AppError > {
324+ #tx_context_ty:: definition( )
325+ }
326+ } ;
327+
328+ FunctionDef {
329+ fn_stream,
330+ endpoint : None ,
331+ test_stream : None ,
332+ bench_stream : None ,
333+ }
334+ }
335+
332336pub fn new_write_fn_def ( entity_def : & EntityDef ) -> FunctionDef {
333337 let tx_context_ty = & entity_def. ctx_type ;
334338 let write_tx_context_ty = & entity_def. write_ctx_type ;
0 commit comments