@@ -485,35 +485,37 @@ begin_remote_xact(ConnCacheEntry *entry)
485485 MemoryContextSwitchTo (oldcxt );
486486
487487
488- res = PQexec (entry -> conn , psprintf ("SELECT pg_global_snaphot_create('%s')" ,
489- two_phase_xact_gid ));
488+ // res = PQexec(entry->conn, psprintf("SELECT pg_global_snaphot_create('%s')",
489+ // two_phase_xact_gid));
490+
491+ // if (PQresultStatus(res) != PGRES_TUPLES_OK)
492+ // {
493+ // pgfdw_report_error(ERROR, res, entry->conn, true, sql);
494+ // }
495+ // resp = PQgetvalue(res, 0, 0);
496+ // if (resp == NULL || (*resp) == '\0' || sscanf(resp, "%ld", ¤t_global_cid) != 1)
497+ // {
498+ // pgfdw_report_error(ERROR, res, entry->conn, true, sql);
499+ // }
500+ // PQclear(res);
501+
502+
503+ current_global_cid = DtmLocalExtend (two_phase_xact_gid );
504+ }
505+ // else
506+ // {
507+ Assert (two_phase_xact_gid );
508+ /* join the new participant */
509+ res = PQexec (entry -> conn ,
510+ psprintf ("SELECT pg_global_snaphot_join(" UINT64_FORMAT ", '%s')" ,
511+ current_global_cid , two_phase_xact_gid ));
490512
491513 if (PQresultStatus (res ) != PGRES_TUPLES_OK )
492514 {
493515 pgfdw_report_error (ERROR , res , entry -> conn , true, sql );
494516 }
495- resp = PQgetvalue (res , 0 , 0 );
496- if (resp == NULL || (* resp ) == '\0' || sscanf (resp , "%ld" , & current_global_cid ) != 1 )
497- {
498- pgfdw_report_error (ERROR , res , entry -> conn , true, sql );
499- }
500517 PQclear (res );
501-
502-
503- // current_global_cid = DtmLocalExtend(two_phase_xact_gid);
504- }
505-
506- Assert (two_phase_xact_gid );
507- /* join the new participant */
508- res = PQexec (entry -> conn ,
509- psprintf ("SELECT pg_global_snaphot_join(" UINT64_FORMAT ", '%s')" ,
510- current_global_cid , two_phase_xact_gid ));
511-
512- if (PQresultStatus (res ) != PGRES_TUPLES_OK )
513- {
514- pgfdw_report_error (ERROR , res , entry -> conn , true, sql );
515- }
516- PQclear (res );
518+ // }
517519 }
518520
519521 /* A new potential participant for 2PC */
@@ -1045,22 +1047,22 @@ finalize_dtm(void)
10451047 {
10461048 char * gid = two_phase_xact_gid ; // != NULL? two_phase_xact_gid : "";
10471049 cid_t maxCSN = 0 ;
1048- // cid_t localCSN = 0;
1050+ cid_t localCSN = 0 ;
10491051
10501052 Assert (gid );
10511053
1052- // DtmLocalBeginPrepare(gid);
1054+ DtmLocalBeginPrepare (gid );
10531055 BroadcastFunc (psprintf ("SELECT pg_global_snaphot_begin_prepare('%s')" ,
10541056 gid ));
10551057
10561058 /* Collect CSNs and choose max */
1057- // localCSN = DtmLocalPrepare(gid, 0);
1059+ localCSN = DtmLocalPrepare (gid , 0 );
10581060 BroadcastStmt (psprintf ("SELECT pg_global_snaphot_prepare('%s', 0)" ,
10591061 gid ), PGRES_TUPLES_OK , DtmMaxCSN , & maxCSN );
1060- // if (localCSN > maxCSN)
1061- // maxCSN = localCSN;
1062+ if (localCSN > maxCSN )
1063+ maxCSN = localCSN ;
10621064
1063- // DtmLocalEndPrepare(gid, maxCSN);
1065+ DtmLocalEndPrepare (gid , maxCSN );
10641066 BroadcastFunc (psprintf ("SELECT pg_global_snaphot_end_prepare('%s'," UINT64_FORMAT ")" ,
10651067 gid , maxCSN ));
10661068
0 commit comments