@@ -4786,8 +4786,8 @@ Size
4786
4786
EstimateTransactionStateSpace (void )
4787
4787
{
4788
4788
TransactionState s ;
4789
- Size nxids = 5 ;/* iso level, deferrable, top & current XID,
4790
- * XID count */
4789
+ Size nxids = 6 ;/* iso level, deferrable, top & current XID,
4790
+ *command counter, XID count */
4791
4791
4792
4792
for (s = CurrentTransactionState ;s != NULL ;s = s -> parent )
4793
4793
{
@@ -4807,27 +4807,30 @@ EstimateTransactionStateSpace(void)
4807
4807
*
4808
4808
* We need to save and restore XactDeferrable, XactIsoLevel, and the XIDs
4809
4809
* associated with this transaction. The first eight bytes of the result
4810
- * contain XactDeferrable and XactIsoLevel; the next eight bytes contain the
4811
- * XID of the top-level transaction and the XID of the current transaction
4812
- * (or, in each case, InvalidTransactionId if none). After that, the next 4
4813
- * bytes contain a count of how many additional XIDs follow; this is followed
4814
- * by all of those XIDs one after another. We emit the XIDs in sorted order
4815
- * for the convenience of the receiving process.
4810
+ * contain XactDeferrable and XactIsoLevel; the next twelve bytes contain the
4811
+ * XID of the top-level transaction, the XID of the current transaction
4812
+ * (or, in each case, InvalidTransactionId if none), and the current command
4813
+ * counter. After that, the next 4 bytes contain a count of how many
4814
+ * additional XIDs follow; this is followed by all of those XIDs one after
4815
+ * another. We emit the XIDs in sorted order for the convenience of the
4816
+ * receiving process.
4816
4817
*/
4817
4818
void
4818
4819
SerializeTransactionState (Size maxsize ,char * start_address )
4819
4820
{
4820
4821
TransactionState s ;
4821
4822
Size nxids = 0 ;
4822
4823
Size i = 0 ;
4824
+ Size c = 0 ;
4823
4825
TransactionId * workspace ;
4824
4826
TransactionId * result = (TransactionId * )start_address ;
4825
4827
4826
- Assert (maxsize >=5 * sizeof (TransactionId ));
4827
- result [0 ]= (TransactionId )XactIsoLevel ;
4828
- result [1 ]= (TransactionId )XactDeferrable ;
4829
- result [2 ]= XactTopTransactionId ;
4830
- result [3 ]= CurrentTransactionState -> transactionId ;
4828
+ result [c ++ ]= (TransactionId )XactIsoLevel ;
4829
+ result [c ++ ]= (TransactionId )XactDeferrable ;
4830
+ result [c ++ ]= XactTopTransactionId ;
4831
+ result [c ++ ]= CurrentTransactionState -> transactionId ;
4832
+ result [c ++ ]= (TransactionId )currentCommandId ;
4833
+ Assert (maxsize >=c * sizeof (TransactionId ));
4831
4834
4832
4835
/*
4833
4836
* If we're running in a parallel worker and launching a parallel worker
@@ -4836,9 +4839,9 @@ SerializeTransactionState(Size maxsize, char *start_address)
4836
4839
*/
4837
4840
if (nParallelCurrentXids > 0 )
4838
4841
{
4839
- Assert ( maxsize > ( nParallelCurrentXids + 4 ) * sizeof ( TransactionId )) ;
4840
- result [ 4 ] = nParallelCurrentXids ;
4841
- memcpy (& result [5 ],ParallelCurrentXids ,
4842
+ result [ c ++ ] = nParallelCurrentXids ;
4843
+ Assert ( maxsize >= ( nParallelCurrentXids + c ) * sizeof ( TransactionId )) ;
4844
+ memcpy (& result [c ],ParallelCurrentXids ,
4842
4845
nParallelCurrentXids * sizeof (TransactionId ));
4843
4846
return ;
4844
4847
}
@@ -4853,7 +4856,7 @@ SerializeTransactionState(Size maxsize, char *start_address)
4853
4856
nxids = add_size (nxids ,1 );
4854
4857
nxids = add_size (nxids ,s -> nChildXids );
4855
4858
}
4856
- Assert (nxids * sizeof (TransactionId )< maxsize );
4859
+ Assert (( c + 1 + nxids ) * sizeof (TransactionId ) <= maxsize );
4857
4860
4858
4861
/* Copy them to our scratch space. */
4859
4862
workspace = palloc (nxids * sizeof (TransactionId ));
@@ -4871,8 +4874,8 @@ SerializeTransactionState(Size maxsize, char *start_address)
4871
4874
qsort (workspace ,nxids ,sizeof (TransactionId ),xidComparator );
4872
4875
4873
4876
/* Copy data into output area. */
4874
- result [4 ]= (TransactionId )nxids ;
4875
- memcpy (& result [5 ],workspace ,nxids * sizeof (TransactionId ));
4877
+ result [c ++ ]= (TransactionId )nxids ;
4878
+ memcpy (& result [c ],workspace ,nxids * sizeof (TransactionId ));
4876
4879
}
4877
4880
4878
4881
/*
@@ -4892,8 +4895,9 @@ StartParallelWorkerTransaction(char *tstatespace)
4892
4895
XactDeferrable = (bool )tstate [1 ];
4893
4896
XactTopTransactionId = tstate [2 ];
4894
4897
CurrentTransactionState -> transactionId = tstate [3 ];
4895
- nParallelCurrentXids = (int )tstate [4 ];
4896
- ParallelCurrentXids = & tstate [5 ];
4898
+ currentCommandId = tstate [4 ];
4899
+ nParallelCurrentXids = (int )tstate [5 ];
4900
+ ParallelCurrentXids = & tstate [6 ];
4897
4901
4898
4902
CurrentTransactionState -> blockState = TBLOCK_PARALLEL_INPROGRESS ;
4899
4903
}