PostgreSQL Source Code git master
Data Structures | Functions
pg_backup_directory.c File Reference
#include "postgres_fe.h"
#include <dirent.h>
#include <sys/stat.h>
#include "common/file_utils.h"
#include "compress_io.h"
#include "dumputils.h"
#include "parallel.h"
#include "pg_backup_utils.h"
Include dependency graph for pg_backup_directory.c:

Go to the source code of this file.

Data Structures

struct   lclContext
 
struct   lclTocEntry
 

Functions

static void  _ArchiveEntry (ArchiveHandle *AH, TocEntry *te)
 
static void  _StartData (ArchiveHandle *AH, TocEntry *te)
 
static void  _EndData (ArchiveHandle *AH, TocEntry *te)
 
static void  _WriteData (ArchiveHandle *AH, const void *data, size_t dLen)
 
static int  _WriteByte (ArchiveHandle *AH, const int i)
 
static int  _ReadByte (ArchiveHandle *AH)
 
static void  _WriteBuf (ArchiveHandle *AH, const void *buf, size_t len)
 
static void  _ReadBuf (ArchiveHandle *AH, void *buf, size_t len)
 
static void  _CloseArchive (ArchiveHandle *AH)
 
static void  _ReopenArchive (ArchiveHandle *AH)
 
static void  _PrintTocData (ArchiveHandle *AH, TocEntry *te)
 
static void  _WriteExtraToc (ArchiveHandle *AH, TocEntry *te)
 
static void  _ReadExtraToc (ArchiveHandle *AH, TocEntry *te)
 
static void  _PrintExtraToc (ArchiveHandle *AH, TocEntry *te)
 
static void  _StartLOs (ArchiveHandle *AH, TocEntry *te)
 
static void  _StartLO (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
static void  _EndLO (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
static void  _EndLOs (ArchiveHandle *AH, TocEntry *te)
 
static void  _LoadLOs (ArchiveHandle *AH, TocEntry *te)
 
static void  _PrepParallelRestore (ArchiveHandle *AH)
 
static void  _Clone (ArchiveHandle *AH)
 
static void  _DeClone (ArchiveHandle *AH)
 
 
 
static void  setFilePath (ArchiveHandle *AH, char *buf, const char *relativeFilename)
 
 
static void  _PrintFileData (ArchiveHandle *AH, char *filename)
 

Function Documentation

_ArchiveEntry()

static void _ArchiveEntry ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 198 of file pg_backup_directory.c.

199{
200 lclTocEntry *tctx;
201 char fn[MAXPGPATH];
202
203 tctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry));
204 if (strcmp(te->desc, "BLOBS") == 0)
205 {
206 snprintf(fn, MAXPGPATH, "blobs_%d.toc", te->dumpId);
207 tctx->filename = pg_strdup(fn);
208 }
209 else if (te->dataDumper)
210 {
211 snprintf(fn, MAXPGPATH, "%d.dat", te->dumpId);
212 tctx->filename = pg_strdup(fn);
213 }
214 else
215 tctx->filename = NULL;
216
217 te->formatData = tctx;
218}
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
#define MAXPGPATH
#define snprintf
Definition: port.h:239
DataDumperPtr dataDumper
void * formatData
static void * fn(void *arg)
Definition: thread-alloc.c:119

References _tocEntry::dataDumper, _tocEntry::desc, _tocEntry::dumpId, lclTocEntry::filename, fn(), _tocEntry::formatData, MAXPGPATH, pg_malloc0(), pg_strdup(), and snprintf.

Referenced by InitArchiveFmt_Directory().

_Clone()

static void _Clone ( ArchiveHandleAH )
static

Definition at line 768 of file pg_backup_directory.c.

769{
770 lclContext *ctx = (lclContext *) AH->formatData;
771
772 AH->formatData = (lclContext *) pg_malloc(sizeof(lclContext));
773 memcpy(AH->formatData, ctx, sizeof(lclContext));
774 ctx = (lclContext *) AH->formatData;
775
776 /*
777 * TOC-entry-local state isn't an issue because any one TOC entry is
778 * touched by just one worker child.
779 */
780
781 /*
782 * We also don't copy the ParallelState pointer (pstate), only the leader
783 * process ever writes to it.
784 */
785}
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47

References _archiveHandle::formatData, and pg_malloc().

Referenced by InitArchiveFmt_Directory().

_CloseArchive()

static void _CloseArchive ( ArchiveHandleAH )
static

Definition at line 531 of file pg_backup_directory.c.

532{
533 lclContext *ctx = (lclContext *) AH->formatData;
534
535 if (AH->mode == archModeWrite)
536 {
537 CompressFileHandle *tocFH;
538 pg_compress_specification compression_spec = {0};
539 char fname[MAXPGPATH];
540
541 setFilePath(AH, fname, "toc.dat");
542
543 /* this will actually fork the processes for a parallel backup */
544 ctx->pstate = ParallelBackupStart(AH);
545
546 /* The TOC is always created uncompressed */
547 compression_spec.algorithm = PG_COMPRESSION_NONE;
548 tocFH = InitCompressFileHandle(compression_spec);
549 if (!tocFH->open_write_func(fname, PG_BINARY_W, tocFH))
550 pg_fatal("could not open output file \"%s\": %m", fname);
551 ctx->dataFH = tocFH;
552
553 /*
554 * Write 'tar' in the format field of the toc.dat file. The directory
555 * is compatible with 'tar', so there's no point having a different
556 * format code for it.
557 */
558 AH->format = archTar;
559 WriteHead(AH);
560 AH->format = archDirectory;
561 WriteToc(AH);
562 if (!EndCompressFileHandle(tocFH))
563 pg_fatal("could not close TOC file: %m");
564 WriteDataChunks(AH, ctx->pstate);
565
566 ParallelBackupEnd(AH, ctx->pstate);
567
568 /*
569 * In directory mode, there is no need to sync all the entries
570 * individually. Just recurse once through all the files generated.
571 */
572 if (AH->dosync)
573 sync_dir_recurse(ctx->directory, AH->sync_method);
574 }
575 AH->FH = NULL;
576}
void ParallelBackupEnd(ArchiveHandle *AH, ParallelState *pstate)
Definition: parallel.c:1061
ParallelState * ParallelBackupStart(ArchiveHandle *AH)
Definition: parallel.c:899
#define PG_BINARY_W
Definition: c.h:1275
bool EndCompressFileHandle(CompressFileHandle *CFH)
Definition: compress_io.c:289
CompressFileHandle * InitCompressFileHandle(const pg_compress_specification compression_spec)
Definition: compress_io.c:194
@ PG_COMPRESSION_NONE
Definition: compression.h:23
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
@ archModeWrite
Definition: pg_backup.h:51
@ archTar
Definition: pg_backup.h:43
@ archDirectory
Definition: pg_backup.h:45
void WriteHead(ArchiveHandle *AH)
void WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate)
void WriteToc(ArchiveHandle *AH)
static void setFilePath(ArchiveHandle *AH, char *buf, const char *relativeFilename)
#define pg_fatal(...)
bool(* open_write_func)(const char *path, const char *mode, CompressFileHandle *CFH)
Definition: compress_io.h:122
ArchiveFormat format
DataDirSyncMethod sync_method
ArchiveMode mode
ParallelState * pstate
CompressFileHandle * dataFH
char * directory
pg_compress_algorithm algorithm
Definition: compression.h:34

References pg_compress_specification::algorithm, archDirectory, archModeWrite, archTar, lclContext::dataFH, lclContext::directory, _archiveHandle::dosync, EndCompressFileHandle(), _archiveHandle::FH, _archiveHandle::format, _archiveHandle::formatData, if(), InitCompressFileHandle(), MAXPGPATH, _archiveHandle::mode, CompressFileHandle::open_write_func, ParallelBackupEnd(), ParallelBackupStart(), PG_BINARY_W, PG_COMPRESSION_NONE, pg_fatal, lclContext::pstate, setFilePath(), _archiveHandle::sync_method, WriteDataChunks(), WriteHead(), and WriteToc().

Referenced by InitArchiveFmt_Directory().

_DeClone()

static void _DeClone ( ArchiveHandleAH )
static

Definition at line 788 of file pg_backup_directory.c.

789{
790 lclContext *ctx = (lclContext *) AH->formatData;
791
792 free(ctx);
793}
#define free(a)
Definition: header.h:65

References _archiveHandle::formatData, and free.

Referenced by InitArchiveFmt_Directory().

_EndData()

static void _EndData ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 331 of file pg_backup_directory.c.

332{
333 lclContext *ctx = (lclContext *) AH->formatData;
334
335 /* Close the file */
337 pg_fatal("could not close data file: %m");
338
339 ctx->dataFH = NULL;
340}

References lclContext::dataFH, EndCompressFileHandle(), _archiveHandle::formatData, if(), and pg_fatal.

Referenced by InitArchiveFmt_Directory().

_EndLO()

static void _EndLO ( ArchiveHandleAH,
TocEntryte,
Oid  oid 
)
static

Definition at line 643 of file pg_backup_directory.c.

644{
645 lclContext *ctx = (lclContext *) AH->formatData;
646 CompressFileHandle *CFH = ctx->LOsTocFH;
647 char buf[50];
648 int len;
649
650 /* Close the BLOB data file itself */
652 pg_fatal("could not close LO data file: %m");
653 ctx->dataFH = NULL;
654
655 /* register the LO in blobs_NNN.toc */
656 len = snprintf(buf, sizeof(buf), "%u blob_%u.dat\n", oid, oid);
657 CFH->write_func(buf, len, CFH);
658}
const void size_t len
static char * buf
Definition: pg_test_fsync.c:72
CompressFileHandle * LOsTocFH

References buf, lclContext::dataFH, EndCompressFileHandle(), _archiveHandle::formatData, if(), len, lclContext::LOsTocFH, pg_fatal, and snprintf.

Referenced by InitArchiveFmt_Directory().

_EndLOs()

static void _EndLOs ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 666 of file pg_backup_directory.c.

667{
668 lclContext *ctx = (lclContext *) AH->formatData;
669
671 pg_fatal("could not close LOs TOC file: %m");
672 ctx->LOsTocFH = NULL;
673}

References EndCompressFileHandle(), _archiveHandle::formatData, if(), lclContext::LOsTocFH, and pg_fatal.

Referenced by InitArchiveFmt_Directory().

_LoadLOs()

static void _LoadLOs ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 396 of file pg_backup_directory.c.

397{
398 Oid oid;
399 lclContext *ctx = (lclContext *) AH->formatData;
400 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
402 char tocfname[MAXPGPATH];
403 char line[MAXPGPATH];
404
405 StartRestoreLOs(AH);
406
407 /*
408 * Note: before archive v16, there was always only one BLOBS TOC entry,
409 * now there can be multiple. Furthermore, although the actual filename
410 * was always "blobs.toc" before v16, the value of tctx->filename did not
411 * match that before commit 548e50976 fixed it. For simplicity we assume
412 * it must be "blobs.toc" in all archives before v16.
413 */
414 if (AH->version < K_VERS_1_16)
415 setFilePath(AH, tocfname, "blobs.toc");
416 else
417 setFilePath(AH, tocfname, tctx->filename);
418
420
421 if (ctx->LOsTocFH == NULL)
422 pg_fatal("could not open large object TOC file \"%s\" for input: %m",
423 tocfname);
424
425 /* Read the LOs TOC file line-by-line, and process each LO */
426 while ((CFH->gets_func(line, MAXPGPATH, CFH)) != NULL)
427 {
428 char lofname[MAXPGPATH + 1];
429 char path[MAXPGPATH];
430
431 /* Can't overflow because line and lofname are the same length */
432 if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, lofname) != 2)
433 pg_fatal("invalid line in large object TOC file \"%s\": \"%s\"",
434 tocfname, line);
435
436 StartRestoreLO(AH, oid, AH->public.ropt->dropSchema);
437 snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, lofname);
438 _PrintFileData(AH, path);
439 EndRestoreLO(AH, oid);
440 }
441 if (!CFH->eof_func(CFH))
442 pg_fatal("error reading large object TOC file \"%s\"",
443 tocfname);
444
446 pg_fatal("could not close large object TOC file \"%s\": %m",
447 tocfname);
448
449 ctx->LOsTocFH = NULL;
450
451 EndRestoreLOs(AH);
452}
#define PG_BINARY_R
Definition: c.h:1274
#define CppAsString2(x)
Definition: c.h:418
CompressFileHandle * InitDiscoverCompressFileHandle(const char *path, const char *mode)
Definition: compress_io.c:240
void StartRestoreLOs(ArchiveHandle *AH)
void EndRestoreLO(ArchiveHandle *AH, Oid oid)
void EndRestoreLOs(ArchiveHandle *AH)
void StartRestoreLO(ArchiveHandle *AH, Oid oid, bool drop)
#define K_VERS_1_16
static void _PrintFileData(ArchiveHandle *AH, char *filename)
unsigned int Oid
Definition: postgres_ext.h:32
RestoreOptions * ropt
Definition: pg_backup.h:229
char *(* gets_func)(char *s, int size, CompressFileHandle *CFH)
Definition: compress_io.h:153
bool(* eof_func)(CompressFileHandle *CFH)
Definition: compress_io.h:169
int dropSchema
Definition: pg_backup.h:108

References _PrintFileData(), CppAsString2, lclContext::directory, _restoreOptions::dropSchema, EndCompressFileHandle(), EndRestoreLO(), EndRestoreLOs(), CompressFileHandle::eof_func, _archiveHandle::formatData, _tocEntry::formatData, CompressFileHandle::gets_func, InitDiscoverCompressFileHandle(), K_VERS_1_16, lclContext::LOsTocFH, MAXPGPATH, PG_BINARY_R, pg_fatal, _archiveHandle::public, Archive::ropt, setFilePath(), snprintf, StartRestoreLO(), StartRestoreLOs(), and _archiveHandle::version.

Referenced by _PrintTocData().

_PrepParallelRestore()

static void _PrepParallelRestore ( ArchiveHandleAH )
static

Definition at line 708 of file pg_backup_directory.c.

709{
710 TocEntry *te;
711
712 for (te = AH->toc->next; te != AH->toc; te = te->next)
713 {
714 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
715 char fname[MAXPGPATH];
716 struct stat st;
717
718 /*
719 * A dumpable object has set tctx->filename, any other object has not.
720 * (see _ArchiveEntry).
721 */
722 if (tctx->filename == NULL)
723 continue;
724
725 /* We may ignore items not due to be restored */
726 if ((te->reqs & (REQ_DATA | REQ_STATS)) == 0)
727 continue;
728
729 /*
730 * Stat the file and, if successful, put its size in dataLength. When
731 * using compression, the physical file size might not be a very good
732 * guide to the amount of work involved in restoring the file, but we
733 * only need an approximate indicator of that.
734 */
735 setFilePath(AH, fname, tctx->filename);
736
737 if (stat(fname, &st) == 0)
738 te->dataLength = st.st_size;
740 {
742 strlcat(fname, ".gz", sizeof(fname));
744 strlcat(fname, ".lz4", sizeof(fname));
746 strlcat(fname, ".zst", sizeof(fname));
747
748 if (stat(fname, &st) == 0)
749 te->dataLength = st.st_size;
750 }
751
752 /*
753 * If this is a BLOBS entry, what we stat'd was blobs_NNN.toc, which
754 * most likely is a lot smaller than the actual blob data. We don't
755 * have a cheap way to estimate how much smaller, but fortunately it
756 * doesn't matter too much as long as we get the LOs processed
757 * reasonably early. Arbitrarily scale up by a factor of 1K.
758 */
759 if (strcmp(te->desc, "BLOBS") == 0)
760 te->dataLength *= 1024;
761 }
762}
@ PG_COMPRESSION_GZIP
Definition: compression.h:24
@ PG_COMPRESSION_LZ4
Definition: compression.h:25
@ PG_COMPRESSION_ZSTD
Definition: compression.h:26
#define REQ_STATS
#define REQ_DATA
size_t strlcat(char *dst, const char *src, size_t siz)
Definition: strlcat.c:33
struct _tocEntry * toc
pg_compress_specification compression_spec
pgoff_t dataLength
struct _tocEntry * next
Definition: win32_port.h:255
#define stat
Definition: win32_port.h:274

References pg_compress_specification::algorithm, _archiveHandle::compression_spec, _tocEntry::dataLength, _tocEntry::desc, lclTocEntry::filename, _tocEntry::formatData, if(), MAXPGPATH, _tocEntry::next, PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, REQ_DATA, REQ_STATS, _tocEntry::reqs, setFilePath(), stat, strlcat(), and _archiveHandle::toc.

Referenced by InitArchiveFmt_Directory().

_PrintExtraToc()

static void _PrintExtraToc ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 272 of file pg_backup_directory.c.

273{
274 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
275
276 if (AH->public.verbose && tctx->filename)
277 ahprintf(AH, "-- File: %s\n", tctx->filename);
278}
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
int verbose
Definition: pg_backup.h:231

References ahprintf(), lclTocEntry::filename, _tocEntry::formatData, if(), _archiveHandle::public, and Archive::verbose.

Referenced by InitArchiveFmt_Directory().

_PrintFileData()

static void _PrintFileData ( ArchiveHandleAH,
char *  filename 
)
static

Definition at line 346 of file pg_backup_directory.c.

347{
348 size_t cnt;
349 char *buf;
350 size_t buflen;
352
353 if (!filename)
354 return;
355
357 if (!CFH)
358 pg_fatal("could not open input file \"%s\": %m", filename);
359
360 buflen = DEFAULT_IO_BUFFER_SIZE;
361 buf = pg_malloc(buflen);
362
363 while ((cnt = CFH->read_func(buf, buflen, CFH)) > 0)
364 {
365 ahwrite(buf, 1, cnt, AH);
366 }
367
368 free(buf);
369 if (!EndCompressFileHandle(CFH))
370 pg_fatal("could not close data file \"%s\": %m", filename);
371}
#define DEFAULT_IO_BUFFER_SIZE
Definition: compress_io.h:27
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
static char * filename
Definition: pg_dumpall.c:120
size_t(* read_func)(void *ptr, size_t size, CompressFileHandle *CFH)
Definition: compress_io.h:132

References ahwrite(), buf, DEFAULT_IO_BUFFER_SIZE, EndCompressFileHandle(), filename, free, InitDiscoverCompressFileHandle(), PG_BINARY_R, pg_fatal, pg_malloc(), and CompressFileHandle::read_func.

Referenced by _LoadLOs(), and _PrintTocData().

_PrintTocData()

static void _PrintTocData ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 377 of file pg_backup_directory.c.

378{
379 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
380
381 if (!tctx->filename)
382 return;
383
384 if (strcmp(te->desc, "BLOBS") == 0)
385 _LoadLOs(AH, te);
386 else
387 {
388 char fname[MAXPGPATH];
389
390 setFilePath(AH, fname, tctx->filename);
391 _PrintFileData(AH, fname);
392 }
393}
static void _LoadLOs(ArchiveHandle *AH, TocEntry *te)

References _LoadLOs(), _PrintFileData(), _tocEntry::desc, lclTocEntry::filename, _tocEntry::formatData, if(), MAXPGPATH, and setFilePath().

Referenced by InitArchiveFmt_Directory().

_ReadBuf()

static void _ReadBuf ( ArchiveHandleAH,
void *  buf,
size_t  len 
)
static

Definition at line 505 of file pg_backup_directory.c.

506{
507 lclContext *ctx = (lclContext *) AH->formatData;
508 CompressFileHandle *CFH = ctx->dataFH;
509
510 /*
511 * We do not expect a short read, so fail if we get one. The read_func
512 * already dealt with any outright I/O error.
513 */
514 if (CFH->read_func(buf, len, CFH) != len)
515 pg_fatal("could not read from input file: end of file");
516}

References buf, lclContext::dataFH, _archiveHandle::formatData, if(), len, and pg_fatal.

Referenced by InitArchiveFmt_Directory().

_ReadByte()

static int _ReadByte ( ArchiveHandleAH )
static

Definition at line 478 of file pg_backup_directory.c.

479{
480 lclContext *ctx = (lclContext *) AH->formatData;
481 CompressFileHandle *CFH = ctx->dataFH;
482
483 return CFH->getc_func(CFH);
484}
int(* getc_func)(CompressFileHandle *CFH)
Definition: compress_io.h:162

References lclContext::dataFH, _archiveHandle::formatData, and CompressFileHandle::getc_func.

Referenced by InitArchiveFmt_Directory().

_ReadExtraToc()

static void _ReadExtraToc ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 249 of file pg_backup_directory.c.

250{
251 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
252
253 if (tctx == NULL)
254 {
255 tctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry));
256 te->formatData = tctx;
257 }
258
259 tctx->filename = ReadStr(AH);
260 if (strlen(tctx->filename) == 0)
261 {
262 free(tctx->filename);
263 tctx->filename = NULL;
264 }
265}
char * ReadStr(ArchiveHandle *AH)

References lclTocEntry::filename, _tocEntry::formatData, free, if(), pg_malloc0(), and ReadStr().

Referenced by InitArchiveFmt_Directory().

_ReopenArchive()

static void _ReopenArchive ( ArchiveHandleAH )
static

Definition at line 582 of file pg_backup_directory.c.

583{
584 /*
585 * Our TOC is in memory, our data files are opened by each child anyway as
586 * they are separate. We support reopening the archive by just doing
587 * nothing.
588 */
589}

Referenced by InitArchiveFmt_Directory().

_StartData()

static void _StartData ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 290 of file pg_backup_directory.c.

291{
292 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
293 lclContext *ctx = (lclContext *) AH->formatData;
294 char fname[MAXPGPATH];
295
296 setFilePath(AH, fname, tctx->filename);
297
298 ctx->dataFH = InitCompressFileHandle(AH->compression_spec);
299
300 if (!ctx->dataFH->open_write_func(fname, PG_BINARY_W, ctx->dataFH))
301 pg_fatal("could not open output file \"%s\": %m", fname);
302}

References _archiveHandle::compression_spec, lclTocEntry::filename, _archiveHandle::formatData, _tocEntry::formatData, InitCompressFileHandle(), MAXPGPATH, PG_BINARY_W, pg_fatal, and setFilePath().

Referenced by InitArchiveFmt_Directory().

_StartLO()

static void _StartLO ( ArchiveHandleAH,
TocEntryte,
Oid  oid 
)
static

Definition at line 625 of file pg_backup_directory.c.

626{
627 lclContext *ctx = (lclContext *) AH->formatData;
628 char fname[MAXPGPATH];
629
630 snprintf(fname, MAXPGPATH, "%s/blob_%u.dat", ctx->directory, oid);
631
633 if (!ctx->dataFH->open_write_func(fname, PG_BINARY_W, ctx->dataFH))
634 pg_fatal("could not open output file \"%s\": %m", fname);
635}

References _archiveHandle::compression_spec, lclContext::dataFH, lclContext::directory, _archiveHandle::formatData, InitCompressFileHandle(), MAXPGPATH, CompressFileHandle::open_write_func, PG_BINARY_W, pg_fatal, and snprintf.

Referenced by InitArchiveFmt_Directory().

_StartLOs()

static void _StartLOs ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 603 of file pg_backup_directory.c.

604{
605 lclContext *ctx = (lclContext *) AH->formatData;
606 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
607 pg_compress_specification compression_spec = {0};
608 char fname[MAXPGPATH];
609
610 setFilePath(AH, fname, tctx->filename);
611
612 /* The LO TOC file is never compressed */
613 compression_spec.algorithm = PG_COMPRESSION_NONE;
614 ctx->LOsTocFH = InitCompressFileHandle(compression_spec);
615 if (!ctx->LOsTocFH->open_write_func(fname, "ab", ctx->LOsTocFH))
616 pg_fatal("could not open output file \"%s\": %m", fname);
617}

References pg_compress_specification::algorithm, _archiveHandle::formatData, _tocEntry::formatData, InitCompressFileHandle(), lclContext::LOsTocFH, MAXPGPATH, CompressFileHandle::open_write_func, PG_COMPRESSION_NONE, pg_fatal, and setFilePath().

Referenced by InitArchiveFmt_Directory().

_WorkerJobDumpDirectory()

static int _WorkerJobDumpDirectory ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 800 of file pg_backup_directory.c.

801{
802 /*
803 * This function returns void. We either fail and die horribly or
804 * succeed... A failure will be detected by the parent when the child dies
805 * unexpectedly.
806 */
808
809 return 0;
810}
void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)

References WriteDataChunksForTocEntry().

Referenced by InitArchiveFmt_Directory().

_WorkerJobRestoreDirectory()

static int _WorkerJobRestoreDirectory ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 817 of file pg_backup_directory.c.

818{
819 return parallel_restore(AH, te);
820}
int parallel_restore(ArchiveHandle *AH, TocEntry *te)

References parallel_restore().

Referenced by InitArchiveFmt_Directory().

_WriteBuf()

static void _WriteBuf ( ArchiveHandleAH,
const void *  buf,
size_t  len 
)
static

Definition at line 491 of file pg_backup_directory.c.

492{
493 lclContext *ctx = (lclContext *) AH->formatData;
494 CompressFileHandle *CFH = ctx->dataFH;
495
496 CFH->write_func(buf, len, CFH);
497}
void(* write_func)(const void *ptr, size_t size, CompressFileHandle *CFH)
Definition: compress_io.h:140

References buf, lclContext::dataFH, _archiveHandle::formatData, len, and CompressFileHandle::write_func.

Referenced by InitArchiveFmt_Directory().

_WriteByte()

static int _WriteByte ( ArchiveHandleAH,
const int  i 
)
static

Definition at line 461 of file pg_backup_directory.c.

462{
463 unsigned char c = (unsigned char) i;
464 lclContext *ctx = (lclContext *) AH->formatData;
465 CompressFileHandle *CFH = ctx->dataFH;
466
467 CFH->write_func(&c, 1, CFH);
468 return 1;
469}
i
int i
Definition: isn.c:77
c
char * c
Definition: preproc-cursor.c:31

References lclContext::dataFH, _archiveHandle::formatData, i, and CompressFileHandle::write_func.

Referenced by InitArchiveFmt_Directory().

_WriteData()

static void _WriteData ( ArchiveHandleAH,
const void *  data,
size_t  dLen 
)
static

Definition at line 314 of file pg_backup_directory.c.

315{
316 lclContext *ctx = (lclContext *) AH->formatData;
317 CompressFileHandle *CFH = ctx->dataFH;
318
319 if (dLen <= 0)
320 return;
321 CFH->write_func(data, dLen, CFH);
322}
const void * data

References data, lclContext::dataFH, _archiveHandle::formatData, and if().

Referenced by InitArchiveFmt_Directory().

_WriteExtraToc()

static void _WriteExtraToc ( ArchiveHandleAH,
TocEntryte 
)
static

Definition at line 228 of file pg_backup_directory.c.

229{
230 lclTocEntry *tctx = (lclTocEntry *) te->formatData;
231
232 /*
233 * A dumpable object has set tctx->filename, any other object has not.
234 * (see _ArchiveEntry).
235 */
236 if (tctx->filename)
237 WriteStr(AH, tctx->filename);
238 else
239 WriteStr(AH, "");
240}
size_t WriteStr(ArchiveHandle *AH, const char *c)

References lclTocEntry::filename, _tocEntry::formatData, if(), and WriteStr().

Referenced by InitArchiveFmt_Directory().

InitArchiveFmt_Directory()

void InitArchiveFmt_Directory ( ArchiveHandleAH )

Definition at line 110 of file pg_backup_directory.c.

111{
112 lclContext *ctx;
113
114 /* Assuming static functions, this can be copied for each format. */
118 AH->EndDataPtr = _EndData;
122 AH->ReadBufPtr = _ReadBuf;
129
131 AH->StartLOPtr = _StartLO;
132 AH->EndLOPtr = _EndLO;
133 AH->EndLOsPtr = _EndLOs;
134
136 AH->ClonePtr = _Clone;
137 AH->DeClonePtr = _DeClone;
138
141
142 /* Set up our private context */
143 ctx = (lclContext *) pg_malloc0(sizeof(lclContext));
144 AH->formatData = ctx;
145
146 ctx->dataFH = NULL;
147 ctx->LOsTocFH = NULL;
148
149 /*
150 * Now open the TOC file
151 */
152
153 if (!AH->fSpec || strcmp(AH->fSpec, "") == 0)
154 pg_fatal("no output directory specified");
155
156 ctx->directory = AH->fSpec;
157
158 if (AH->mode == archModeWrite)
159 {
160 /* we accept an empty existing directory */
162 }
163 else
164 { /* Read Mode */
165 char fname[MAXPGPATH];
166 CompressFileHandle *tocFH;
167
168 setFilePath(AH, fname, "toc.dat");
169
171 if (tocFH == NULL)
172 pg_fatal("could not open input file \"%s\": %m", fname);
173
174 ctx->dataFH = tocFH;
175
176 /*
177 * The TOC of a directory format dump shares the format code of the
178 * tar format.
179 */
180 AH->format = archTar;
181 ReadHead(AH);
182 AH->format = archDirectory;
183 ReadToc(AH);
184
185 /* Nothing else in the file, so close it again... */
186 if (!EndCompressFileHandle(tocFH))
187 pg_fatal("could not close TOC file: %m");
188 ctx->dataFH = NULL;
189 }
190}
void create_or_open_dir(const char *dirname)
Definition: dumputils.c:935
void ReadHead(ArchiveHandle *AH)
void ReadToc(ArchiveHandle *AH)
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static void _DeClone(ArchiveHandle *AH)
static void _ReopenArchive(ArchiveHandle *AH)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _Clone(ArchiveHandle *AH)
static int _WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te)
static int _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
DeClonePtrType DeClonePtr
EndLOsPtrType EndLOsPtr
ReadExtraTocPtrType ReadExtraTocPtr
WorkerJobDumpPtrType WorkerJobDumpPtr
StartLOsPtrType StartLOsPtr
ArchiveEntryPtrType ArchiveEntryPtr
WriteDataPtrType WriteDataPtr
StartLOPtrType StartLOPtr
ClonePtrType ClonePtr
WriteBufPtrType WriteBufPtr
PrepParallelRestorePtrType PrepParallelRestorePtr
EndLOPtrType EndLOPtr
WriteExtraTocPtrType WriteExtraTocPtr
ReadBytePtrType ReadBytePtr
WorkerJobRestorePtrType WorkerJobRestorePtr
PrintTocDataPtrType PrintTocDataPtr
WriteBytePtrType WriteBytePtr
ReadBufPtrType ReadBufPtr
PrintExtraTocPtrType PrintExtraTocPtr
StartDataPtrType StartDataPtr
ReopenPtrType ReopenPtr
EndDataPtrType EndDataPtr
ClosePtrType ClosePtr

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndData(), _EndLO(), _EndLOs(), _PrepParallelRestore(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartData(), _StartLO(), _StartLOs(), _WorkerJobDumpDirectory(), _WorkerJobRestoreDirectory(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archDirectory, _archiveHandle::ArchiveEntryPtr, archModeWrite, archTar, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, create_or_open_dir(), lclContext::dataFH, _archiveHandle::DeClonePtr, lclContext::directory, EndCompressFileHandle(), _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, _archiveHandle::format, _archiveHandle::formatData, _archiveHandle::fSpec, InitDiscoverCompressFileHandle(), lclContext::LOsTocFH, MAXPGPATH, _archiveHandle::mode, PG_BINARY_R, pg_fatal, pg_malloc0(), _archiveHandle::PrepParallelRestorePtr, _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, setFilePath(), _archiveHandle::StartDataPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, _archiveHandle::WorkerJobDumpPtr, _archiveHandle::WorkerJobRestorePtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, _archiveHandle::WriteDataPtr, and _archiveHandle::WriteExtraTocPtr.

Referenced by _allocAH().

setFilePath()

static void setFilePath ( ArchiveHandleAH,
char *  buf,
const char *  relativeFilename 
)
static

Definition at line 682 of file pg_backup_directory.c.

683{
684 lclContext *ctx = (lclContext *) AH->formatData;
685 char *dname;
686
687 dname = ctx->directory;
688
689 if (strlen(dname) + 1 + strlen(relativeFilename) + 1 > MAXPGPATH)
690 pg_fatal("file name too long: \"%s\"", dname);
691
692 strcpy(buf, dname);
693 strcat(buf, "/");
694 strcat(buf, relativeFilename);
695}

References buf, lclContext::directory, _archiveHandle::formatData, if(), MAXPGPATH, and pg_fatal.

Referenced by _CloseArchive(), _LoadLOs(), _PrepParallelRestore(), _PrintTocData(), _StartData(), _StartLOs(), and InitArchiveFmt_Directory().

AltStyle によって変換されたページ (->オリジナル) /