aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/sort/logtape.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2020-09-15 21:34:05 -0700
committerJeff Davis <jdavis@postgresql.org>2020-09-15 21:42:25 -0700
commitc8aeaf3ab31edeedf1791e37c74bcedf61a916ed (patch)
tree601b35f13b5a01780faeda155851ff80646a6af8 /src/backend/utils/sort/logtape.c
parent3bd35d4f516adfc492360b20e72911949c961e47 (diff)
downloadpostgresql-c8aeaf3ab31edeedf1791e37c74bcedf61a916ed.tar.gz
postgresql-c8aeaf3ab31edeedf1791e37c74bcedf61a916ed.zip
Change LogicalTapeSetBlocks() to use nBlocksWritten.
Previously, it was based on nBlocksAllocated to account for tapes with open write buffers that may not have made it to the BufFile yet. That was unnecessary, because callers do not need to get the number of blocks while a tape has an open write buffer; and it also conflicted with the preallocation logic added for HashAgg. Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/ce5af05900fdbd0e9185747825a7423c48501964.camel@j-davis.com Backpatch-through: 13
Diffstat (limited to 'src/backend/utils/sort/logtape.c')
-rw-r--r--src/backend/utils/sort/logtape.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c
index d6d1e1911ea..28905124f96 100644
--- a/src/backend/utils/sort/logtape.c
+++ b/src/backend/utils/sort/logtape.c
@@ -1264,9 +1264,19 @@ LogicalTapeTell(LogicalTapeSet *lts, int tapenum,
/*
* Obtain total disk space currently used by a LogicalTapeSet, in blocks.
+ *
+ * This should not be called while there are open write buffers; otherwise it
+ * may not account for buffered data.
*/
long
LogicalTapeSetBlocks(LogicalTapeSet *lts)
{
- return lts->nBlocksAllocated - lts->nHoleBlocks;
+#ifdef USE_ASSERT_CHECKING
+ for (int i = 0; i < lts->nTapes; i++)
+ {
+ LogicalTape *lt = &lts->tapes[i];
+ Assert(!lt->writing || lt->buffer == NULL);
+ }
+#endif
+ return lts->nBlocksWritten - lts->nHoleBlocks;
}