PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <fcntl.h>
#include "storage/buffile.h"
#include "utils/builtins.h"
#include "utils/logtape.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
Go to the source code of this file.
Data Structures | |
struct | TapeBlockTrailer |
struct | LogicalTape |
struct | LogicalTapeSet |
Macros | |
#define | TapeBlockPayloadSize (BLCKSZ - sizeof(TapeBlockTrailer)) |
#define | TapeBlockGetTrailer(buf) ((TapeBlockTrailer *) ((char *) buf + TapeBlockPayloadSize)) |
#define | TapeBlockIsLast(buf) (TapeBlockGetTrailer(buf)->next < 0) |
#define | TapeBlockGetNBytes(buf) |
#define | TapeBlockSetNBytes(buf, nbytes) (TapeBlockGetTrailer(buf)->next = -(nbytes)) |
#define | TAPE_WRITE_PREALLOC_MIN 8 |
#define | TAPE_WRITE_PREALLOC_MAX 128 |
Typedefs | |
typedef struct TapeBlockTrailer | TapeBlockTrailer |
#define TapeBlockGetNBytes | ( | buf | ) |
#define TapeBlockGetTrailer | ( | buf | ) | ((TapeBlockTrailer *) ((char *) buf + TapeBlockPayloadSize)) |
#define TapeBlockIsLast | ( | buf | ) | (TapeBlockGetTrailer(buf)->next < 0) |
#define TapeBlockPayloadSize (BLCKSZ - sizeof(TapeBlockTrailer)) |
#define TapeBlockSetNBytes | ( | buf, | |
nbytes | |||
) | (TapeBlockGetTrailer(buf)->next = -(nbytes)) |
typedef struct TapeBlockTrailer TapeBlockTrailer |
|
inlinestatic |
size_t LogicalTapeBackspace | ( | LogicalTape * | lt, |
size_t | size | ||
) |
Definition at line 1062 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, elog, ERROR, LogicalTape::firstBlockNumber, LogicalTape::frozen, ltsInitReadBuffer(), ltsReadBlock(), LogicalTape::nbytes, LogicalTape::nextBlockNumber, LogicalTape::pos, size, TapeBlockGetTrailer, TapeBlockPayloadSize, LogicalTape::tapeSet, and while().
Referenced by tuplesort_gettuple_common().
void LogicalTapeClose | ( | LogicalTape * | lt | ) |
Definition at line 733 of file logtape.c.
References LogicalTape::buffer, and pfree().
Referenced by agg_refill_hash_table(), mergeruns(), and tuplesort_gettuple_common().
LogicalTape* LogicalTapeCreate | ( | LogicalTapeSet * | lts | ) |
Definition at line 680 of file logtape.c.
References elog, ERROR, LogicalTapeSet::fileset, ltsCreateTape(), and LogicalTapeSet::worker.
Referenced by hashagg_spill_init(), and selectnewtape().
void LogicalTapeFreeze | ( | LogicalTape * | lt, |
TapeShare * | share | ||
) |
Definition at line 981 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, BufFileExportFileSet(), LogicalTape::curBlockNumber, LogicalTape::dirty, LogicalTape::firstBlockNumber, TapeShare::firstblocknumber, LogicalTape::frozen, ltsReadBlock(), ltsWriteBlock(), LogicalTape::nbytes, LogicalTape::nextBlockNumber, LogicalTape::offsetBlockNumber, palloc(), LogicalTapeSet::pfile, pfree(), LogicalTape::pos, TapeBlockGetNBytes, TapeBlockGetTrailer, TapeBlockIsLast, TapeBlockSetNBytes, LogicalTape::tapeSet, VALGRIND_MAKE_MEM_DEFINED, and LogicalTape::writing.
Referenced by mergeruns(), and worker_freeze_result_tape().
LogicalTape* LogicalTapeImport | ( | LogicalTapeSet * | lts, |
int | worker, | ||
TapeShare * | shared | ||
) |
Definition at line 609 of file logtape.c.
References BufFileAppend(), BufFileOpenFileSet(), BufFileSize(), filename, LogicalTapeSet::fileset, LogicalTape::firstBlockNumber, TapeShare::firstblocknumber, SharedFileSet::fs, ltsCreateTape(), LogicalTape::max_size, MaxAllocSize, MAXPGPATH, Min, LogicalTapeSet::nBlocksAllocated, LogicalTapeSet::nBlocksWritten, LogicalTapeSet::nHoleBlocks, LogicalTape::offsetBlockNumber, LogicalTapeSet::pfile, and pg_itoa().
Referenced by leader_takeover_tapes().
size_t LogicalTapeRead | ( | LogicalTape * | lt, |
void * | ptr, | ||
size_t | size | ||
) |
Definition at line 928 of file logtape.c.
References Assert, LogicalTape::buffer, ltsInitReadBuffer(), ltsReadFillBuffer(), LogicalTape::nbytes, LogicalTape::pos, size, and LogicalTape::writing.
Referenced by getlen(), and hashagg_batch_read().
void LogicalTapeRewindForRead | ( | LogicalTape * | lt, |
size_t | buffer_size | ||
) |
Definition at line 846 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, LogicalTape::dirty, LogicalTape::frozen, i, ltsReleaseBlock(), ltsWriteBlock(), LogicalTape::max_size, LogicalTape::nbytes, LogicalTape::nprealloc, pfree(), LogicalTape::prealloc, LogicalTape::prealloc_size, TapeBlockSetNBytes, LogicalTape::tapeSet, VALGRIND_MAKE_MEM_DEFINED, and LogicalTape::writing.
Referenced by hashagg_spill_finish(), mergeruns(), and tuplesort_rescan().
void LogicalTapeSeek | ( | LogicalTape * | lt, |
int64 | blocknum, | ||
int | offset | ||
) |
Definition at line 1133 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, elog, ERROR, LogicalTape::frozen, ltsInitReadBuffer(), ltsReadBlock(), LogicalTape::nbytes, LogicalTape::nextBlockNumber, LogicalTape::pos, TapeBlockGetTrailer, TapeBlockPayloadSize, and LogicalTape::tapeSet.
Referenced by tuplesort_restorepos().
int64 LogicalTapeSetBlocks | ( | LogicalTapeSet * | lts | ) |
Definition at line 1181 of file logtape.c.
References LogicalTapeSet::nBlocksWritten, and LogicalTapeSet::nHoleBlocks.
Referenced by hash_agg_update_metrics(), tuplesort_free(), and tuplesort_updatemax().
void LogicalTapeSetClose | ( | LogicalTapeSet * | lts | ) |
Definition at line 667 of file logtape.c.
References BufFileClose(), LogicalTapeSet::freeBlocks, LogicalTapeSet::pfile, and pfree().
Referenced by hashagg_reset_spill_state(), and tuplesort_free().
LogicalTapeSet* LogicalTapeSetCreate | ( | bool | preallocate, |
SharedFileSet * | fileset, | ||
int | worker | ||
) |
Definition at line 556 of file logtape.c.
References BufFileCreateFileSet(), BufFileCreateTemp(), LogicalTapeSet::enable_prealloc, filename, LogicalTapeSet::fileset, LogicalTapeSet::forgetFreeSpace, LogicalTapeSet::freeBlocks, LogicalTapeSet::freeBlocksLen, SharedFileSet::fs, MAXPGPATH, LogicalTapeSet::nBlocksAllocated, LogicalTapeSet::nBlocksWritten, LogicalTapeSet::nFreeBlocks, LogicalTapeSet::nHoleBlocks, palloc(), LogicalTapeSet::pfile, pg_itoa(), and LogicalTapeSet::worker.
Referenced by hash_agg_enter_spill_mode(), inittapes(), and leader_takeover_tapes().
void LogicalTapeSetForgetFreeSpace | ( | LogicalTapeSet * | lts | ) |
Definition at line 750 of file logtape.c.
References LogicalTapeSet::forgetFreeSpace.
Referenced by mergeruns().
void LogicalTapeTell | ( | LogicalTape * | lt, |
int64 * | blocknum, | ||
int * | offset | ||
) |
Definition at line 1162 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, ltsInitReadBuffer(), LogicalTape::offsetBlockNumber, and LogicalTape::pos.
Referenced by tuplesort_markpos().
void LogicalTapeWrite | ( | LogicalTape * | lt, |
const void * | ptr, | ||
size_t | size | ||
) |
Definition at line 761 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, LogicalTape::dirty, elog, ERROR, LogicalTape::firstBlockNumber, ltsGetBlock(), ltsWriteBlock(), LogicalTape::nbytes, LogicalTape::offsetBlockNumber, palloc(), LogicalTape::pos, size, TapeBlockGetTrailer, TapeBlockPayloadSize, LogicalTape::tapeSet, and LogicalTape::writing.
Referenced by hashagg_spill_tuple(), markrunend(), writetup_cluster(), writetup_datum(), writetup_heap(), writetup_index(), and writetup_index_brin().
|
static |
Definition at line 696 of file logtape.c.
References LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, LogicalTape::dirty, LogicalTape::firstBlockNumber, LogicalTape::frozen, LogicalTape::max_size, MaxAllocSize, LogicalTape::nbytes, LogicalTape::nextBlockNumber, LogicalTape::nprealloc, LogicalTape::offsetBlockNumber, palloc(), LogicalTape::pos, LogicalTape::prealloc, LogicalTape::prealloc_size, LogicalTape::tapeSet, and LogicalTape::writing.
Referenced by LogicalTapeCreate(), and LogicalTapeImport().
|
static |
Definition at line 358 of file logtape.c.
References LogicalTapeSet::enable_prealloc, ltsGetFreeBlock(), and ltsGetPreallocBlock().
Referenced by LogicalTapeWrite().
|
static |
Definition at line 371 of file logtape.c.
References LogicalTapeSet::freeBlocks, left_offset(), LogicalTapeSet::nBlocksAllocated, LogicalTapeSet::nFreeBlocks, and right_offset().
Referenced by ltsGetBlock(), and ltsGetPreallocBlock().
|
static |
Definition at line 431 of file logtape.c.
References Assert, i, ltsGetFreeBlock(), LogicalTape::nprealloc, palloc(), LogicalTape::prealloc, LogicalTape::prealloc_size, repalloc(), TAPE_WRITE_PREALLOC_MAX, and TAPE_WRITE_PREALLOC_MIN.
Referenced by ltsGetBlock().
|
static |
Definition at line 522 of file logtape.c.
References Assert, LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::firstBlockNumber, ltsReadFillBuffer(), LogicalTape::nbytes, LogicalTape::nextBlockNumber, palloc(), and LogicalTape::pos.
Referenced by LogicalTapeBackspace(), LogicalTapeRead(), LogicalTapeSeek(), and LogicalTapeTell().
|
static |
Definition at line 282 of file logtape.c.
References BufFileReadExact(), BufFileSeekBlock(), ereport, errcode_for_file_access(), errmsg(), ERROR, and LogicalTapeSet::pfile.
Referenced by LogicalTapeBackspace(), LogicalTapeFreeze(), LogicalTapeSeek(), and ltsReadFillBuffer().
|
static |
Definition at line 298 of file logtape.c.
References LogicalTape::buffer, LogicalTape::buffer_size, LogicalTape::curBlockNumber, LogicalTape::frozen, ltsReadBlock(), ltsReleaseBlock(), LogicalTape::nbytes, LogicalTape::nextBlockNumber, LogicalTape::offsetBlockNumber, LogicalTape::pos, TapeBlockGetNBytes, TapeBlockGetTrailer, TapeBlockIsLast, and LogicalTape::tapeSet.
Referenced by LogicalTapeRead(), and ltsInitReadBuffer().
|
static |
Definition at line 469 of file logtape.c.
References LogicalTapeSet::forgetFreeSpace, LogicalTapeSet::freeBlocks, LogicalTapeSet::freeBlocksLen, MaxAllocSize, LogicalTapeSet::nFreeBlocks, parent_offset(), and repalloc().
Referenced by LogicalTapeRewindForRead(), and ltsReadFillBuffer().
|
static |
Definition at line 238 of file logtape.c.
References BufFileSeekBlock(), BufFileWrite(), PGIOAlignedBlock::data, ereport, errcode_for_file_access(), errmsg(), ERROR, MemSet, LogicalTapeSet::nBlocksWritten, and LogicalTapeSet::pfile.
Referenced by LogicalTapeFreeze(), LogicalTapeRewindForRead(), and LogicalTapeWrite().
|
inlinestatic |
|
inlinestatic |