103#define TapeBlockPayloadSize (BLCKSZ - sizeof(TapeBlockTrailer))
104#define TapeBlockGetTrailer(buf) \
105 ((TapeBlockTrailer *) ((char *) buf + TapeBlockPayloadSize))
107#define TapeBlockIsLast(buf) (TapeBlockGetTrailer(buf)->next < 0)
108#define TapeBlockGetNBytes(buf) \
109 (TapeBlockIsLast(buf) ? \
110 (- TapeBlockGetTrailer(buf)->next) : TapeBlockPayloadSize)
111#define TapeBlockSetNBytes(buf, nbytes) \
112 (TapeBlockGetTrailer(buf)->next = -(nbytes))
124#define TAPE_WRITE_PREALLOC_MIN 8
125#define TAPE_WRITE_PREALLOC_MAX 128
253 while (blocknum >
lts->nBlocksWritten)
266 errmsg(
"could not seek to block %" PRId64 " of temporary file",
271 if (blocknum ==
lts->nBlocksWritten)
272 lts->nBlocksWritten++;
287 errmsg(
"could not seek to block %" PRId64 " of temporary file",
360 if (
lts->enable_prealloc)
380 if (
lts->nFreeBlocks == 0)
381 return lts->nBlocksAllocated++;
384 if (
lts->nFreeBlocks == 1)
387 return lts->freeBlocks[0];
406 min_child = (heap[left] < heap[right]) ? left : right;
477 if (
lts->forgetFreeSpace)
483 if (
lts->nFreeBlocks >=
lts->freeBlocksLen)
492 lts->freeBlocksLen *= 2;
494 lts->freeBlocksLen *
sizeof(
int64));
498 heap =
lts->freeBlocks;
507 if (heap[parent] < blocknum)
564 lts->nBlocksAllocated = 0
L;
565 lts->nBlocksWritten = 0
L;
566 lts->nHoleBlocks = 0
L;
567 lts->forgetFreeSpace =
false;
568 lts->freeBlocksLen = 32;
570 lts->nFreeBlocks = 0;
573 lts->fileset = fileset;
574 lts->worker = worker;
585 if (fileset && worker == -1)
655 lts->nBlocksWritten =
lts->nBlocksAllocated;
689 if (
lts->fileset &&
lts->worker == -1)
690 elog(
ERROR,
"cannot create new tapes in leader process");
752 lts->forgetFreeSpace =
true;
792 int64 nextBlockNumber;
797 elog(
ERROR,
"invalid logtape state: should be dirty");
866 buffer_size -= buffer_size %
BLCKSZ;
1075 if (size <= (
size_t) lt->
pos)
1087 while (size > seekpos)
1120 lt->
pos = seekpos - size;
1151 elog(
ERROR,
"invalid tape seek position");
1183 return lts->nBlocksWritten -
lts->nHoleBlocks;
BufFile * BufFileOpenFileSet(FileSet *fileset, const char *name, int mode, bool missing_ok)
int BufFileSeekBlock(BufFile *file, int64 blknum)
void BufFileExportFileSet(BufFile *file)
void BufFileReadExact(BufFile *file, void *ptr, size_t size)
BufFile * BufFileCreateTemp(bool interXact)
void BufFileWrite(BufFile *file, const void *ptr, size_t size)
BufFile * BufFileCreateFileSet(FileSet *fileset, const char *name)
int64 BufFileSize(BufFile *file)
void BufFileClose(BufFile *file)
int64 BufFileAppend(BufFile *target, BufFile *source)
#define Assert(condition)
#define MemSet(start, val, len)
int errcode_for_file_access(void)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
void LogicalTapeRewindForRead(LogicalTape *lt, size_t buffer_size)
#define TapeBlockGetTrailer(buf)
static LogicalTape * ltsCreateTape(LogicalTapeSet *lts)
void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts)
size_t LogicalTapeBackspace(LogicalTape *lt, size_t size)
static int64 ltsGetPreallocBlock(LogicalTapeSet *lts, LogicalTape *lt)
size_t LogicalTapeRead(LogicalTape *lt, void *ptr, size_t size)
static uint64 parent_offset(uint64 i)
int64 LogicalTapeSetBlocks(LogicalTapeSet *lts)
void LogicalTapeClose(LogicalTape *lt)
#define TapeBlockPayloadSize
void LogicalTapeSetClose(LogicalTapeSet *lts)
static bool ltsReadFillBuffer(LogicalTape *lt)
static void ltsInitReadBuffer(LogicalTape *lt)
#define TAPE_WRITE_PREALLOC_MIN
static uint64 left_offset(uint64 i)
static void ltsWriteBlock(LogicalTapeSet *lts, int64 blocknum, const void *buffer)
static int64 ltsGetBlock(LogicalTapeSet *lts, LogicalTape *lt)
#define TapeBlockIsLast(buf)
#define TAPE_WRITE_PREALLOC_MAX
void LogicalTapeSeek(LogicalTape *lt, int64 blocknum, int offset)
static void ltsReadBlock(LogicalTapeSet *lts, int64 blocknum, void *buffer)
LogicalTapeSet * LogicalTapeSetCreate(bool preallocate, SharedFileSet *fileset, int worker)
void LogicalTapeTell(LogicalTape *lt, int64 *blocknum, int *offset)
void LogicalTapeWrite(LogicalTape *lt, const void *ptr, size_t size)
#define TapeBlockGetNBytes(buf)
static void ltsReleaseBlock(LogicalTapeSet *lts, int64 blocknum)
#define TapeBlockSetNBytes(buf, nbytes)
static int64 ltsGetFreeBlock(LogicalTapeSet *lts)
static uint64 right_offset(uint64 i)
LogicalTape * LogicalTapeCreate(LogicalTapeSet *lts)
void LogicalTapeFreeze(LogicalTape *lt, TapeShare *share)
LogicalTape * LogicalTapeImport(LogicalTapeSet *lts, int worker, TapeShare *shared)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
int pg_itoa(int16 i, char *a)