Commit 205f4662 authored by Amit Kapila's avatar Amit Kapila

Fix the computation of slot stats for 'total_bytes'.

Previously, we were using the size of all the changes present in
ReorderBuffer to compute total_bytes after decoding a transaction and that
can lead to counting some of the transactions' changes more than once. Fix
it by using the size of the changes decoded for a transaction to compute
'total_bytes'.

Author: Sawada Masahiko
Reviewed-by: Vignesh C, Amit Kapila
Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de
parent eb086056
...@@ -1366,10 +1366,11 @@ ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state) ...@@ -1366,10 +1366,11 @@ ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state)
dlist_push_tail(&state->old_change, &change->node); dlist_push_tail(&state->old_change, &change->node);
/* /*
* Update the total bytes processed before releasing the current set * Update the total bytes processed by the txn for which we are
* of changes and restoring the new set of changes. * releasing the current set of changes and restoring the new set of
* changes.
*/ */
rb->totalBytes += rb->size; rb->totalBytes += entry->txn->size;
if (ReorderBufferRestoreChanges(rb, entry->txn, &entry->file, if (ReorderBufferRestoreChanges(rb, entry->txn, &entry->file,
&state->entries[off].segno)) &state->entries[off].segno))
{ {
...@@ -2371,9 +2372,9 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, ...@@ -2371,9 +2372,9 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
iterstate = NULL; iterstate = NULL;
/* /*
* Update total transaction count and total transaction bytes * Update total transaction count and total bytes processed by the
* processed. Ensure to not count the streamed transaction multiple * transaction and its subtransactions. Ensure to not count the
* times. * streamed transaction multiple times.
* *
* Note that the statistics computation has to be done after * Note that the statistics computation has to be done after
* ReorderBufferIterTXNFinish as it releases the serialized change * ReorderBufferIterTXNFinish as it releases the serialized change
...@@ -2382,7 +2383,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, ...@@ -2382,7 +2383,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
if (!rbtxn_is_streamed(txn)) if (!rbtxn_is_streamed(txn))
rb->totalTxns++; rb->totalTxns++;
rb->totalBytes += rb->size; rb->totalBytes += txn->total_size;
/* /*
* Done with current changes, send the last message for this set of * Done with current changes, send the last message for this set of
...@@ -3073,7 +3074,7 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ...@@ -3073,7 +3074,7 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
{ {
Size sz; Size sz;
ReorderBufferTXN *txn; ReorderBufferTXN *txn;
ReorderBufferTXN *toptxn = NULL; ReorderBufferTXN *toptxn;
Assert(change->txn); Assert(change->txn);
...@@ -3087,14 +3088,14 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ...@@ -3087,14 +3088,14 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
txn = change->txn; txn = change->txn;
/* If streaming supported, update the total size in top level as well. */ /*
if (ReorderBufferCanStream(rb)) * Update the total size in top level as well. This is later used to
{ * compute the decoding stats.
if (txn->toptxn != NULL) */
toptxn = txn->toptxn; if (txn->toptxn != NULL)
else toptxn = txn->toptxn;
toptxn = txn; else
} toptxn = txn;
sz = ReorderBufferChangeSize(change); sz = ReorderBufferChangeSize(change);
...@@ -3104,8 +3105,7 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ...@@ -3104,8 +3105,7 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
rb->size += sz; rb->size += sz;
/* Update the total size in the top transaction. */ /* Update the total size in the top transaction. */
if (toptxn) toptxn->total_size += sz;
toptxn->total_size += sz;
} }
else else
{ {
...@@ -3114,8 +3114,7 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ...@@ -3114,8 +3114,7 @@ ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb,
rb->size -= sz; rb->size -= sz;
/* Update the total size in the top transaction. */ /* Update the total size in the top transaction. */
if (toptxn) toptxn->total_size -= sz;
toptxn->total_size -= sz;
} }
Assert(txn->size <= rb->size); Assert(txn->size <= rb->size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment