0004-Use-pgoff_t-instead-of-off_t-in-more-places.patch
text/x-patch
Filename: 0004-Use-pgoff_t-instead-of-off_t-in-more-places.patch
Type: text/x-patch
Part: 3
Message:
Large files for relations
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0004
Subject: Use pgoff_t instead of off_t in more places.
| File | + | − |
|---|---|---|
| src/backend/access/heap/rewriteheap.c | 1 | 1 |
| src/backend/backup/basebackup.c | 4 | 3 |
| src/backend/storage/file/copydir.c | 2 | 2 |
| src/bin/pg_basebackup/receivelog.c | 1 | 1 |
| src/bin/pg_rewind/filemap.c | 2 | 0 |
| src/bin/pg_rewind/file_ops.c | 2 | 2 |
| src/bin/pg_rewind/file_ops.h | 2 | 2 |
| src/bin/pg_rewind/libpq_source.c | 3 | 3 |
| src/bin/pg_rewind/local_source.c | 4 | 4 |
| src/bin/pg_rewind/pg_rewind.c | 1 | 1 |
| src/bin/pg_rewind/rewind_source.h | 1 | 1 |
| src/include/access/heapam_xlog.h | 1 | 1 |
From ed3a5558a03afaabb7c4c206c053c288c104cb02 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Sun, 5 Mar 2023 12:36:55 +1300
Subject: [PATCH 04/11] Use pgoff_t instead of off_t in more places.
XXX Incomplete
---
src/backend/access/heap/rewriteheap.c | 2 +-
src/backend/backup/basebackup.c | 7 ++++---
src/backend/storage/file/copydir.c | 4 ++--
src/bin/pg_basebackup/receivelog.c | 2 +-
src/bin/pg_rewind/file_ops.c | 4 ++--
src/bin/pg_rewind/file_ops.h | 4 ++--
src/bin/pg_rewind/filemap.c | 2 ++
src/bin/pg_rewind/libpq_source.c | 6 +++---
src/bin/pg_rewind/local_source.c | 8 ++++----
src/bin/pg_rewind/pg_rewind.c | 2 +-
src/bin/pg_rewind/rewind_source.h | 2 +-
src/include/access/heapam_xlog.h | 2 +-
12 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 424958912c..5e5b00d25a 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -194,7 +194,7 @@ typedef struct RewriteMappingFile
{
TransactionId xid; /* xid that might need to see the row */
int vfd; /* fd of mappings file */
- off_t off; /* how far have we written yet */
+ pgoff_t off; /* how far have we written yet */
dclist_head mappings; /* list of in-memory mappings */
char path[MAXPGPATH]; /* path, for error messages */
} RewriteMappingFile;
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 5baea7535b..2dcc04fef2 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -95,7 +95,8 @@ static void perform_base_backup(basebackup_options *opt, bbsink *sink);
static void parse_basebackup_options(List *options, basebackup_options *opt);
static int compareWalFileNames(const ListCell *a, const ListCell *b);
static bool is_checksummed_file(const char *fullpath, const char *filename);
-static int basebackup_read_file(int fd, char *buf, size_t nbytes, off_t offset,
+static int basebackup_read_file(int fd, char *buf, size_t nbytes,
+ pgoff_t offset,
const char *filename, bool partial_read_ok);
/* Was the backup currently in-progress initiated in recovery mode? */
@@ -1488,7 +1489,7 @@ sendFile(bbsink *sink, const char *readfilename, const char *tarfilename,
bool block_retry = false;
uint16 checksum;
int checksum_failures = 0;
- off_t cnt;
+ pgoff_t cnt;
int i;
pgoff_t len = 0;
char *page;
@@ -1827,7 +1828,7 @@ convert_link_to_directory(const char *pathbuf, struct stat *statbuf)
* Returns the number of bytes read.
*/
static int
-basebackup_read_file(int fd, char *buf, size_t nbytes, off_t offset,
+basebackup_read_file(int fd, char *buf, size_t nbytes, pgoff_t offset,
const char *filename, bool partial_read_ok)
{
int rc;
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index e04bc3941a..82f77536b4 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -120,8 +120,8 @@ copy_file(const char *fromfile, const char *tofile)
int srcfd;
int dstfd;
int nbytes;
- off_t offset;
- off_t flush_offset;
+ pgoff_t offset;
+ pgoff_t flush_offset;
/* Size of copy buffer (read and write requests) */
#define COPY_BUF_SIZE (8 * BLCKSZ)
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 504d82bef6..e69ad912a2 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -192,7 +192,7 @@ static bool
close_walfile(StreamCtl *stream, XLogRecPtr pos)
{
char *fn;
- off_t currpos;
+ pgoff_t currpos;
int r;
char walfile_name[MAXPGPATH];
diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c
index 25996b4da4..3e96b8b0a8 100644
--- a/src/bin/pg_rewind/file_ops.c
+++ b/src/bin/pg_rewind/file_ops.c
@@ -85,7 +85,7 @@ close_target_file(void)
}
void
-write_target_range(char *buf, off_t begin, size_t size)
+write_target_range(char *buf, pgoff_t begin, size_t size)
{
size_t writeleft;
char *p;
@@ -203,7 +203,7 @@ remove_target_file(const char *path, bool missing_ok)
}
void
-truncate_target_file(const char *path, off_t newsize)
+truncate_target_file(const char *path, pgoff_t newsize)
{
char dstpath[MAXPGPATH];
int fd;
diff --git a/src/bin/pg_rewind/file_ops.h b/src/bin/pg_rewind/file_ops.h
index 427cf8e0b5..41a41cb6cb 100644
--- a/src/bin/pg_rewind/file_ops.h
+++ b/src/bin/pg_rewind/file_ops.h
@@ -13,10 +13,10 @@
#include "filemap.h"
extern void open_target_file(const char *path, bool trunc);
-extern void write_target_range(char *buf, off_t begin, size_t size);
+extern void write_target_range(char *buf, pgoff_t begin, size_t size);
extern void close_target_file(void);
extern void remove_target_file(const char *path, bool missing_ok);
-extern void truncate_target_file(const char *path, off_t newsize);
+extern void truncate_target_file(const char *path, pgoff_t newsize);
extern void create_target(file_entry_t *entry);
extern void remove_target(file_entry_t *entry);
extern void sync_target_dir(void);
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index bd5c598e20..a5855ccaa9 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -296,6 +296,8 @@ process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator,
BlockNumber blkno_inseg;
int segno;
+ /* XXX We need to know if it is segmented! */
+
segno = blkno / RELSEG_SIZE;
blkno_inseg = blkno % RELSEG_SIZE;
diff --git a/src/bin/pg_rewind/libpq_source.c b/src/bin/pg_rewind/libpq_source.c
index 5f486b2a61..d4832ccb76 100644
--- a/src/bin/pg_rewind/libpq_source.c
+++ b/src/bin/pg_rewind/libpq_source.c
@@ -30,7 +30,7 @@
typedef struct
{
const char *path; /* path relative to data directory root */
- off_t offset;
+ pgoff_t offset;
size_t length;
} fetch_range_request;
@@ -65,7 +65,7 @@ static void libpq_traverse_files(rewind_source *source,
process_file_callback_t callback);
static void libpq_queue_fetch_file(rewind_source *source, const char *path, size_t len);
static void libpq_queue_fetch_range(rewind_source *source, const char *path,
- off_t off, size_t len);
+ pgoff_t off, size_t len);
static void libpq_finish_fetch(rewind_source *source);
static char *libpq_fetch_file(rewind_source *source, const char *path,
size_t *filesize);
@@ -343,7 +343,7 @@ libpq_queue_fetch_file(rewind_source *source, const char *path, size_t len)
* Queue up a request to fetch a piece of a file from remote system.
*/
static void
-libpq_queue_fetch_range(rewind_source *source, const char *path, off_t off,
+libpq_queue_fetch_range(rewind_source *source, const char *path, pgoff_t off,
size_t len)
{
libpq_source *src = (libpq_source *) source;
diff --git a/src/bin/pg_rewind/local_source.c b/src/bin/pg_rewind/local_source.c
index 4e2a1376c6..fb84309c12 100644
--- a/src/bin/pg_rewind/local_source.c
+++ b/src/bin/pg_rewind/local_source.c
@@ -32,7 +32,7 @@ static char *local_fetch_file(rewind_source *source, const char *path,
static void local_queue_fetch_file(rewind_source *source, const char *path,
size_t len);
static void local_queue_fetch_range(rewind_source *source, const char *path,
- off_t off, size_t len);
+ pgoff_t off, size_t len);
static void local_finish_fetch(rewind_source *source);
static void local_destroy(rewind_source *source);
@@ -125,15 +125,15 @@ local_queue_fetch_file(rewind_source *source, const char *path, size_t len)
* Copy a file from source to target, starting at 'off', for 'len' bytes.
*/
static void
-local_queue_fetch_range(rewind_source *source, const char *path, off_t off,
+local_queue_fetch_range(rewind_source *source, const char *path, pgoff_t off,
size_t len)
{
const char *datadir = ((local_source *) source)->datadir;
PGIOAlignedBlock buf;
char srcpath[MAXPGPATH];
int srcfd;
- off_t begin = off;
- off_t end = off + len;
+ pgoff_t begin = off;
+ pgoff_t end = off + len;
snprintf(srcpath, sizeof(srcpath), "%s/%s", datadir, path);
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index f7f3b8227f..500842e169 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -566,7 +566,7 @@ perform_rewind(filemap_t *filemap, rewind_source *source,
{
datapagemap_iterator_t *iter;
BlockNumber blkno;
- off_t offset;
+ pgoff_t offset;
iter = datapagemap_iterate(&entry->target_pages_to_overwrite);
while (datapagemap_next(iter, &blkno))
diff --git a/src/bin/pg_rewind/rewind_source.h b/src/bin/pg_rewind/rewind_source.h
index 69ad0e495f..e17526ce86 100644
--- a/src/bin/pg_rewind/rewind_source.h
+++ b/src/bin/pg_rewind/rewind_source.h
@@ -45,7 +45,7 @@ typedef struct rewind_source
* queue and execute all requests.
*/
void (*queue_fetch_range) (struct rewind_source *, const char *path,
- off_t offset, size_t len);
+ pgoff_t offset, size_t len);
/*
* Like queue_fetch_range(), but requests replacing the whole local file
diff --git a/src/include/access/heapam_xlog.h b/src/include/access/heapam_xlog.h
index a038450787..d82cd027f4 100644
--- a/src/include/access/heapam_xlog.h
+++ b/src/include/access/heapam_xlog.h
@@ -396,7 +396,7 @@ typedef struct xl_heap_rewrite_mapping
TransactionId mapped_xid; /* xid that might need to see the row */
Oid mapped_db; /* DbOid or InvalidOid for shared rels */
Oid mapped_rel; /* Oid of the mapped relation */
- off_t offset; /* How far have we written so far */
+ pgoff_t offset; /* How far have we written so far */
uint32 num_mappings; /* Number of in-memory mappings */
XLogRecPtr start_lsn; /* Insert LSN at begin of rewrite */
} xl_heap_rewrite_mapping;
--
2.40.1