Skip to content

Commit 57e57a6

Browse files
gsmolkGrigory Smolkin
andauthored
bugfix: do not set is_datafile in set_forkname() (#19)
Co-authored-by: Grigory Smolkin <gsmolkin@ozon.ru>
1 parent 78b3af5 commit 57e57a6

5 files changed

Lines changed: 26 additions & 39 deletions

File tree

src/dir.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pgFileInit(const char *rel_path)
189189
// May be add?
190190
// pg_atomic_clear_flag(file->lock);
191191
file->excluded = false;
192+
file->is_datafile = false;
192193
return file;
193194
}
194195

@@ -627,22 +628,14 @@ dir_check_file(pgFile *file, bool backup_logs)
627628
{
628629
if (strcmp(file->name, "pg_internal.init") == 0)
629630
return CHECK_FALSE;
630-
/* Do not backup ptrack2.x temp map files */
631-
// else if (strcmp(file->name, "ptrack.map") == 0)
632-
// return CHECK_FALSE;
633-
else if (strcmp(file->name, "ptrack.map.mmap") == 0)
634-
return CHECK_FALSE;
635-
else if (strcmp(file->name, "ptrack.map.tmp") == 0)
636-
return CHECK_FALSE;
637631
/* Do not backup temp files */
638632
else if (file->name[0] == 't' && isdigit(file->name[1]))
639633
return CHECK_FALSE;
634+
/* if filename starts with digits, it can be either datafile or fork */
640635
else if (isdigit(file->name[0]))
641636
{
642637
set_forkname(file);
643-
644-
if (file->forkName == ptrack) /* Compatibility with left-overs from ptrack1 */
645-
return CHECK_FALSE;
638+
file->is_datafile = file->forkName == none;
646639
}
647640
}
648641

@@ -1633,7 +1626,7 @@ is_forkname(char *name, size_t *pos, const char *forkname)
16331626
#define SEGNOCHARS 5 /* when BLCKSZ == (1<<15) */
16341627

16351628
/* Set forkName if possible */
1636-
bool
1629+
void
16371630
set_forkname(pgFile *file)
16381631
{
16391632
size_t i = 0;
@@ -1643,16 +1636,15 @@ set_forkname(pgFile *file)
16431636
/* pretend it is not relation file */
16441637
file->relOid = 0;
16451638
file->forkName = none;
1646-
file->is_datafile = false;
16471639

16481640
for (i = 0; isdigit(file->name[i]); i++)
16491641
{
16501642
if (i == 0 && file->name[i] == '0')
1651-
return false;
1643+
return;
16521644
oid = oid * 10 + file->name[i] - '0';
16531645
}
16541646
if (i == 0 || i > OIDCHARS || oid > UINT32_MAX)
1655-
return false;
1647+
return;
16561648

16571649
/* usual fork name */
16581650
/* /^\d+_(vm|fsm|init|ptrack)$/ */
@@ -1673,22 +1665,21 @@ set_forkname(pgFile *file)
16731665
for (i++; isdigit(file->name[i]); i++)
16741666
{
16751667
if (i == start && file->name[i] == '0')
1676-
return false;
1668+
return;
16771669
segno = segno * 10 + file->name[i] - '0';
16781670
}
16791671
if (i - start > SEGNOCHARS || segno > MAXSEGNO)
1680-
return false;
1672+
return;
16811673
}
16821674

16831675
/* If there are excess characters, it is not relation file */
16841676
if (file->name[i] != 0)
16851677
{
16861678
file->forkName = none;
1687-
return false;
1679+
return;
16881680
}
16891681

16901682
file->relOid = oid;
16911683
file->segno = segno;
1692-
file->is_datafile = file->forkName == none;
1693-
return true;
1684+
return;
16941685
}

src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ extern int pgCompareString(const void *str1, const void *str2);
10051005
extern int pgPrefixCompareString(const void *str1, const void *str2);
10061006
extern int pgCompareOid(const void *f1, const void *f2);
10071007
extern void pfilearray_clear_locks(parray *file_list);
1008-
extern bool set_forkname(pgFile *file);
1008+
extern void set_forkname(pgFile *file);
10091009

10101010
/* in data.c */
10111011
extern bool check_data_file(ConnectionArgs *arguments, pgFile *file,

src/validate.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,20 @@ pgBackupValidateFiles(void *arg)
287287
* If option skip-block-validation is set, compute only file-level CRC for
288288
* datafiles, otherwise check them block by block.
289289
*/
290-
if (!file->is_datafile || skip_block_validation)
290+
if (file->is_datafile && !skip_block_validation)
291+
{
292+
/*
293+
* validate relation block by block
294+
* check page headers, checksums (if enabled)
295+
* and compute checksum of the file
296+
*/
297+
if (!validate_file_pages(file, file_fullpath, arguments->stop_lsn,
298+
arguments->checksum_version,
299+
arguments->program_version_num,
300+
arguments->hdr_map))
301+
arguments->corrupted = true;
302+
}
303+
else
291304
{
292305
if (strcmp(file->rel_path, XLOG_CONTROL_FILE) == 0)
293306
crc = get_pgcontrol_checksum(arguments->base_path);
@@ -301,19 +314,6 @@ pgBackupValidateFiles(void *arg)
301314
arguments->corrupted = true;
302315
}
303316
}
304-
else
305-
{
306-
/*
307-
* validate relation block by block
308-
* check page headers, checksums (if enabled)
309-
* and compute checksum of the file
310-
*/
311-
if (!validate_file_pages(file, file_fullpath, arguments->stop_lsn,
312-
arguments->checksum_version,
313-
arguments->program_version_num,
314-
arguments->hdr_map))
315-
arguments->corrupted = true;
316-
}
317317
}
318318

319319
/* Data files validation is successful */

tests/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Note: tests require python3 to work properly.
88

99
```
1010
Check physical correctness of restored instances:
11-
Apply this patch to disable HINT BITS: https://gist.github.com/gsmol/2bb34fd3ba31984369a72cc1c27a36b6
11+
Apply this patch to disable HINT BITS: https://gist.github.com/gsmolk/2bb34fd3ba31984369a72cc1c27a36b6
1212
export PG_PROBACKUP_PARANOIA=ON
1313
1414
Check archive compression:

tests/helpers/ptrack_helpers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ class PostgresNodeExtended(testgres.PostgresNode):
112112

113113
def __init__(self, base_dir=None, *args, **kwargs):
114114
super(PostgresNodeExtended, self).__init__(name='test', base_dir=base_dir, *args, **kwargs)
115-
self.is_started = False
116115

117116
def slow_start(self, replica=False):
118117

@@ -150,13 +149,11 @@ def slow_start(self, replica=False):
150149
def start(self, *args, **kwargs):
151150
if not self.is_started:
152151
super(PostgresNodeExtended, self).start(*args, **kwargs)
153-
self.is_started = True
154152
return self
155153

156154
def stop(self, *args, **kwargs):
157155
if self.is_started:
158156
result = super(PostgresNodeExtended, self).stop(*args, **kwargs)
159-
self.is_started = False
160157
return result
161158

162159
def kill(self, someone = None):
@@ -165,7 +162,6 @@ def kill(self, someone = None):
165162
os.kill(self.pid, signal.SIGKILL)
166163
else:
167164
os.kill(self.auxiliary_pids[someone][0], signal.SIGKILL)
168-
self.is_started = False
169165

170166
def table_checksum(self, table, dbname="postgres"):
171167
con = self.connect(dbname=dbname)

0 commit comments

Comments
 (0)