Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93c39d2

Browse files
committed
tests: test_tablespace_handling() added
1 parent1dbc0c9 commit93c39d2

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

‎tests/backup_test.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,118 @@ def test_tablespace_in_pgdata_pgpro_1376(self):
512512

513513
# Clean after yourself
514514
self.del_test_dir(module_name,fname)
515+
516+
# @unittest.skip("skip")
517+
deftest_tablespace_handling(self):
518+
"""
519+
make node, take full backup, check that restore with
520+
tablespace mapping will end with error, take page backup,
521+
check that restore with tablespace mapping will end with
522+
success
523+
"""
524+
fname=self.id().split('.')[3]
525+
node=self.make_simple_node(
526+
base_dir=os.path.join(module_name,fname,'node'),
527+
set_replication=True,
528+
initdb_params=['--data-checksums'],
529+
pg_options={
530+
'wal_level':'replica',
531+
'max_wal_senders':'2'})
532+
533+
backup_dir=os.path.join(self.tmp_path,module_name,fname,'backup')
534+
535+
self.init_pb(backup_dir)
536+
self.add_instance(backup_dir,'node',node)
537+
node.slow_start()
538+
539+
self.backup_node(
540+
backup_dir,'node',node,backup_type="full",
541+
options=["-j","4","--stream"])
542+
543+
tblspace1_old_path=self.get_tblspace_path(node,'tblspace1_old')
544+
tblspace2_old_path=self.get_tblspace_path(node,'tblspace2_old')
545+
546+
self.create_tblspace_in_node(
547+
node,'some_lame_tablespace')
548+
549+
self.create_tblspace_in_node(
550+
node,'tblspace1',
551+
tblspc_path=tblspace1_old_path)
552+
553+
self.create_tblspace_in_node(
554+
node,'tblspace2',
555+
tblspc_path=tblspace2_old_path)
556+
557+
node.safe_psql(
558+
"postgres",
559+
"create table t_heap_lame tablespace some_lame_tablespace "
560+
"as select 1 as id, md5(i::text) as text, "
561+
"md5(repeat(i::text,10))::tsvector as tsvector "
562+
"from generate_series(0,1000) i")
563+
564+
node.safe_psql(
565+
"postgres",
566+
"create table t_heap2 tablespace tblspace2 as select 1 as id, "
567+
"md5(i::text) as text, "
568+
"md5(repeat(i::text,10))::tsvector as tsvector "
569+
"from generate_series(0,1000) i")
570+
571+
tblspace1_new_path=self.get_tblspace_path(node,'tblspace1_new')
572+
tblspace2_new_path=self.get_tblspace_path(node,'tblspace2_new')
573+
574+
node_restored=self.make_simple_node(
575+
base_dir=os.path.join(module_name,fname,'node_restored'))
576+
node_restored.cleanup()
577+
578+
try:
579+
self.restore_node(
580+
backup_dir,'node',node_restored,
581+
options=[
582+
"-j","4",
583+
"-T","{0}={1}".format(
584+
tblspace1_old_path,tblspace1_new_path),
585+
"-T","{0}={1}".format(
586+
tblspace2_old_path,tblspace2_new_path)])
587+
# we should die here because exception is what we expect to happen
588+
self.assertEqual(
589+
1,0,
590+
"Expecting Error because tablespace mapping is incorrect"
591+
"\n Output: {0}\n CMD: {1}".format(
592+
repr(self.output),self.cmd))
593+
exceptProbackupExceptionase:
594+
self.assertTrue(
595+
'ERROR: --tablespace-mapping option'ine.messageand
596+
'have an entry in tablespace_map file'ine.message,
597+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
598+
repr(e.message),self.cmd))
599+
600+
node.safe_psql(
601+
"postgres",
602+
"drop table t_heap_lame")
603+
604+
node.safe_psql(
605+
"postgres",
606+
"drop tablespace some_lame_tablespace")
607+
608+
self.backup_node(
609+
backup_dir,'node',node,backup_type="delta",
610+
options=["-j","4","--stream"])
611+
612+
self.restore_node(
613+
backup_dir,'node',node_restored,
614+
options=[
615+
"-j","4",
616+
"-T","{0}={1}".format(
617+
tblspace1_old_path,tblspace1_new_path),
618+
"-T","{0}={1}".format(
619+
tblspace2_old_path,tblspace2_new_path)])
620+
621+
ifself.paranoia:
622+
pgdata=self.pgdata_content(node.data_dir)
623+
624+
ifself.paranoia:
625+
pgdata_restored=self.pgdata_content(node_restored.data_dir)
626+
self.compare_pgdata(pgdata,pgdata_restored)
627+
628+
# Clean after yourself
629+
self.del_test_dir(module_name,fname)

‎tests/helpers/ptrack_helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,16 @@ def add_instance(self, backup_dir, instance, node, old_binary=False, options=[])
626626

627627
returnself.run_pb(cmd+options,old_binary=old_binary)
628628

629+
defset_config(self,backup_dir,instance,old_binary=False,options=[]):
630+
631+
cmd= [
632+
'set-config',
633+
'--instance={0}'.format(instance),
634+
'-B',backup_dir,
635+
]
636+
637+
returnself.run_pb(cmd+options,old_binary=old_binary)
638+
629639
defdel_instance(self,backup_dir,instance,old_binary=False):
630640

631641
returnself.run_pb([
@@ -1087,6 +1097,7 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
10871097
directory_dict['files'][file_relpath]['md5']=hashlib.md5(
10881098
open(file_fullpath,'rb').read()).hexdigest()
10891099

1100+
# crappy algorithm
10901101
iffile.isdigit():
10911102
directory_dict['files'][file_relpath]['is_datafile']=True
10921103
size_in_pages=os.path.getsize(file_fullpath)/8192

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp