Skip to content

Fix segno calculation. #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1786,13 +1786,16 @@ is_forkname(char *name, size_t *pos, const char *forkname)
}

#define OIDCHARS 10
#define MAXSEGNO (((uint64_t)1<<32)/RELSEG_SIZE-1)
#define SEGNOCHARS 5 /* when BLCKSZ == (1<<15) */

/* Set forkName if possible */
bool
set_forkname(pgFile *file)
{
size_t i = 0;
uint64_t oid = 0; /* use 64bit to not check for overflow in a loop */
uint64_t segno = 0;

/* pretend it is not relation file */
file->relOid = 0;
Expand Down Expand Up @@ -1823,8 +1826,15 @@ set_forkname(pgFile *file)
/* /^\d+(_(vm|fsm|init|ptrack))?\.\d+$/ */
if (file->name[i] == '.' && isdigit(file->name[i+1]))
{
size_t start = i+1;
for (i++; isdigit(file->name[i]); i++)
;
{
if (i == start && file->name[i] == '0')
return false;
segno = segno * 10 + file->name[i] - '0';
}
if (i - start > SEGNOCHARS || segno > MAXSEGNO)
return false;
}

/* CFS "fork name" */
Expand All @@ -1843,6 +1853,7 @@ set_forkname(pgFile *file)
}

file->relOid = oid;
file->segno = segno;
file->is_datafile = file->forkName == none;
return true;
}
32 changes: 32 additions & 0 deletions tests/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@

class BackupTest(ProbackupTest, unittest.TestCase):

def test_basic_full_backup(self):
"""
Just test full backup with at least two segments
"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
initdb_params=['--data-checksums'],
# we need to write a lot. Lets speedup a bit.
pg_options={"fsync": "off", "synchronous_commit": "off"})

backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.slow_start()

# Fill with data
# Have to use scale=100 to create second segment.
node.pgbench_init(scale=100, no_vacuum=True)

# FULL
backup_id = self.backup_node(backup_dir, 'node', node)

out = self.validate_pb(backup_dir, 'node', backup_id)
self.assertIn(
"INFO: Backup {0} is valid".format(backup_id),
out)

# Clean after yourself
self.del_test_dir(module_name, fname)

# @unittest.skip("skip")
# @unittest.expectedFailure
# PGPRO-707
Expand Down
2 changes: 1 addition & 1 deletion tests/ptrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class PtrackTest(ProbackupTest, unittest.TestCase):
def setUp(self):
if self.pg_config_version < self.version_to_num('11.0'):
return unittest.skip('You need PostgreSQL >= 11 for this test')
self.skipTest('You need PostgreSQL >= 11 for this test')
self.fname = self.id().split('.')[3]

# @unittest.skip("skip")
Expand Down