@@ -18,10 +18,7 @@ use std::{
18
18
} ,
19
19
time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ,
20
20
} ;
21
- // use serde::Deserialize;
22
- // use serde_json::Value;
23
- // use simd_json::ValueAccess;
24
- // use tokio_postgres::{replication::LogicalReplicationStream, types::PgLsn, Client, SimpleQueryMessage, GenericClient};
21
+
25
22
use tokio_postgres:: { replication:: LogicalReplicationStream , types:: PgLsn , Client , SimpleQueryMessage } ;
26
23
mod serializer;
27
24
use serializer:: SerializedXLogDataBody ;
@@ -152,12 +149,12 @@ async fn produce_replication<'a>(
152
149
// println!("======== END OF the DELETE MESSAGE JSON ==========");
153
150
// }
154
151
//
155
- LogicalReplicationMessage :: Relation ( _relation) => {
152
+ // LogicalReplicationMessage::Relation(_relation) => {
156
153
// println!("======== RELATION ==========");
157
154
// let serialized_xlog = serde_json::to_string_pretty(&SerializedXLogDataBody(xlog_data)).unwrap();
158
155
// println!("{}", serialized_xlog);
159
156
// println!("======== END OF the RELATION MESSAGE JSON ==========");
160
- }
157
+ // }
161
158
_ => yield xlog_data,
162
159
}
163
160
}
@@ -364,6 +361,11 @@ struct SourceTable {
364
361
casts : Vec < MirScalarExpr > ,
365
362
}
366
363
364
+ #[ derive( Serialize , Deserialize ) ]
365
+ struct PublicationTables {
366
+ publication_tables : Vec < PostgresTableDesc > ,
367
+ }
368
+
367
369
pub ( crate ) async fn replication ( connection_config : MzConfig , tx : Sender < tremor_value:: Value < ' static > > ) -> Result < ( ) , anyhow:: Error > {
368
370
let publication = "gamespub" ;
369
371
let publication_tables =
@@ -372,10 +374,18 @@ pub(crate) async fn replication(connection_config:MzConfig, tx:Sender<tremor_val
372
374
let source_id = "source_id" ;
373
375
let mut _replication_lsn = PgLsn :: from ( 0 ) ;
374
376
375
- println ! ( "======== BEGIN SNAPSHOT ==========" ) ;
377
+ // println!("======== BEGIN SNAPSHOT ==========");
376
378
377
379
// Validate publication tables against the state snapshot
378
- dbg ! ( & publication_tables) ;
380
+ // dbg!(&publication_tables);
381
+ let mut postgres_tables = Vec :: new ( ) ;
382
+ for postgres_table_desc in & publication_tables {
383
+ postgres_tables. push ( postgres_table_desc. clone ( ) ) ;
384
+ }
385
+ let publication_tables_json = serde_json:: to_string ( & PublicationTables { publication_tables : postgres_tables} ) . unwrap ( ) ;
386
+ let json_obj : tremor_value:: Value = serde_json:: from_str ( & publication_tables_json) ?;
387
+ tx. send ( json_obj. into_static ( ) ) . await ?;
388
+
379
389
let source_tables: BTreeMap < u32 , SourceTable > = publication_tables
380
390
. into_iter ( )
381
391
. map ( |t| {
@@ -402,14 +412,14 @@ pub(crate) async fn replication(connection_config:MzConfig, tx:Sender<tremor_val
402
412
) )
403
413
. await ?;
404
414
405
- dbg ! ( & res) ;
415
+ // dbg!(&res);
406
416
let slot_lsn = parse_single_row ( & res, "confirmed_flush_lsn" ) ;
407
417
client
408
418
. simple_query ( "BEGIN READ ONLY ISOLATION LEVEL REPEATABLE READ;" )
409
419
. await ?;
410
420
let ( slot_lsn, snapshot_lsn, temp_slot) : ( PgLsn , PgLsn , _ ) = match slot_lsn {
411
421
Ok ( slot_lsn) => {
412
- dbg ! ( & slot_lsn) ;
422
+ // dbg!(&slot_lsn);
413
423
// The main slot already exists which means we can't use it for the snapshot. So
414
424
// we'll create a temporary replication slot in order to both set the transaction's
415
425
// snapshot to be a consistent point and also to find out the LSN that the snapshot
@@ -418,32 +428,32 @@ pub(crate) async fn replication(connection_config:MzConfig, tx:Sender<tremor_val
418
428
// When this happens we'll most likely be snapshotting at a later LSN than the slot
419
429
// which we will take care below by rewinding.
420
430
let temp_slot = uuid:: Uuid :: new_v4 ( ) . to_string ( ) . replace ( '-' , "" ) ;
421
- dbg ! ( & temp_slot) ;
431
+ // dbg!(&temp_slot);
422
432
let res = client
423
433
. simple_query ( & format ! (
424
434
r#"CREATE_REPLICATION_SLOT {:?} TEMPORARY LOGICAL "pgoutput" USE_SNAPSHOT"# ,
425
435
temp_slot
426
436
) )
427
437
. await ?;
428
- dbg ! ( & res) ;
438
+ // dbg!(&res);
429
439
let snapshot_lsn = parse_single_row ( & res, "consistent_point" ) ?;
430
440
( slot_lsn, snapshot_lsn, Some ( temp_slot) )
431
441
}
432
- Err ( e ) => {
433
- dbg ! ( e) ;
442
+ Err ( _e ) => {
443
+ // dbg!(e);
434
444
let res = client
435
445
. simple_query ( & format ! (
436
446
r#"CREATE_REPLICATION_SLOT {:?} LOGICAL "pgoutput" USE_SNAPSHOT"# ,
437
447
slot
438
448
) )
439
449
. await ?;
440
- dbg ! ( & res) ;
450
+ // dbg!(&res);
441
451
let slot_lsn: PgLsn = parse_single_row ( & res, "consistent_point" ) ?;
442
452
( slot_lsn, slot_lsn, None )
443
453
}
444
454
} ;
445
455
446
- dbg ! ( & slot_lsn, & snapshot_lsn, & temp_slot) ;
456
+ // dbg!(&slot_lsn, &snapshot_lsn, &temp_slot);
447
457
448
458
let mut stream = Box :: pin ( produce_snapshot ( & client, & source_tables) . enumerate ( ) ) ;
449
459
@@ -457,11 +467,11 @@ pub(crate) async fn replication(connection_config:MzConfig, tx:Sender<tremor_val
457
467
// ));
458
468
// // });
459
469
// }
460
- let ( output , row ) = event?;
470
+ let ( _output , _row ) = event?;
461
471
462
- dbg ! ( output, row, slot_lsn, 1 ) ;
472
+ // dbg!(output, row, slot_lsn, 1);
463
473
}
464
- println ! ( "======== END SNAPSHOT ==========" ) ;
474
+ // println!("======== END SNAPSHOT ==========");
465
475
466
476
if let Some ( temp_slot) = temp_slot {
467
477
let _ = client
@@ -491,7 +501,7 @@ pub(crate) async fn replication(connection_config:MzConfig, tx:Sender<tremor_val
491
501
)
492
502
. await ;
493
503
tokio:: pin!( replication_stream) ;
494
- println ! ( "======== STARTING WHILE LOOP ==========" ) ;
504
+ // println!("======== STARTING WHILE LOOP ==========");
495
505
while let Some ( event) = replication_stream. next ( ) . await {
496
506
// let event = event?;
497
507
let serialized_event = serde_json:: to_string_pretty ( & SerializedXLogDataBody ( event?) ) . unwrap ( ) ;
0 commit comments