@@ -162,7 +162,7 @@ def test_incremental_backup_corrupt_full(self):
162162 except ProbackupException as e :
163163 self .assertTrue ("INFO: Validate backups of the instance 'node'\n " in e .message
164164 and 'WARNING: Backup file "{0}" is not found\n ' .format (file ) in e .message
165- and "WARNING: Backup {0} is corrupted\n " .format (backup_id ) in e .message
165+ and "WARNING: Backup {0} data files are corrupted\n " .format (backup_id ) in e .message
166166 and "INFO: Some backups are not valid\n " in e .message ,
167167 "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
168168
@@ -231,50 +231,125 @@ def test_ptrack_threads_stream(self):
231231 self .del_test_dir (module_name , fname )
232232
233233 # @unittest.skip("skip")
234- def test_page_checksumm_fail (self ):
234+ def test_checksumm_fail_heal_via_ptrack (self ):
235235 """make node, corrupt some page, check that backup failed"""
236236 fname = self .id ().split ('.' )[3 ]
237- node = self .make_simple_node (base_dir = "{0}/{1}/node" .format (module_name , fname ),
237+ node = self .make_simple_node (
238+ base_dir = "{0}/{1}/node" .format (module_name , fname ),
238239 set_replication = True ,
239240 initdb_params = ['--data-checksums' ],
240241 pg_options = {'wal_level' : 'replica' , 'max_wal_senders' : '2' }
241242 )
242243 backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
244+
243245 self .init_pb (backup_dir )
244246 self .add_instance (backup_dir , 'node' , node )
245247 node .start ()
246248
247- self .backup_node (backup_dir , 'node' , node , backup_type = "full" , options = ["-j" , "4" , "--stream" ])
249+ self .backup_node (
250+ backup_dir , 'node' , node ,
251+ backup_type = "full" , options = ["-j" , "4" , "--stream" ])
248252
249253 node .safe_psql (
250254 "postgres" ,
251- "create table t_heap as select 1 as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(0,1000) i" )
255+ "create table t_heap as select 1 as id, md5(i::text) as text, "
256+ "md5(repeat(i::text,10))::tsvector as tsvector "
257+ "from generate_series(0,1000) i" )
252258 node .safe_psql (
253259 "postgres" ,
254260 "CHECKPOINT;" )
255261
256- heap_path = node .safe_psql ("postgres" , "select pg_relation_filepath('t_heap')" ).rstrip ()
262+ heap_path = node .safe_psql (
263+ "postgres" ,
264+ "select pg_relation_filepath('t_heap')" ).rstrip ()
265+
266+ with open (os .path .join (node .data_dir , heap_path ), "rb+" , 0 ) as f :
267+ f .seek (9000 )
268+ f .write (b"bla" )
269+ f .flush ()
270+ f .close
271+
272+ self .backup_node (
273+ backup_dir , 'node' , node , backup_type = "full" ,
274+ options = ["-j" , "4" , "--stream" , '--log-level-file=verbose' ])
275+
276+ # open log file and check
277+ with open (os .path .join (backup_dir , 'log' , 'pg_probackup.log' )) as f :
278+ log_content = f .read ()
279+ self .assertIn ('block 1, try fetching via SQL' , log_content )
280+ self .assertIn ('SELECT pg_ptrack_get_block' , log_content )
281+ f .close
282+
283+ self .assertTrue (
284+ self .show_pb (backup_dir , 'node' )[1 ]['Status' ] == 'OK' ,
285+ "Backup Status should be OK" )
286+
287+ # Clean after yourself
288+ # self.del_test_dir(module_name, fname)
289+
290+ # @unittest.skip("skip")
291+ def test_checksumm_fail_heal_via_ptrack_fail (self ):
292+ """make node, corrupt some page, check that backup failed"""
293+ fname = self .id ().split ('.' )[3 ]
294+ node = self .make_simple_node (
295+ base_dir = "{0}/{1}/node" .format (module_name , fname ),
296+ set_replication = True ,
297+ initdb_params = ['--data-checksums' ],
298+ pg_options = {'wal_level' : 'replica' , 'max_wal_senders' : '2' }
299+ )
300+ backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
301+
302+ self .init_pb (backup_dir )
303+ self .add_instance (backup_dir , 'node' , node )
304+ node .start ()
305+
306+ self .backup_node (
307+ backup_dir , 'node' , node , backup_type = "full" ,
308+ options = ["-j" , "4" , "--stream" ])
309+
310+ node .safe_psql (
311+ "postgres" ,
312+ "create table t_heap as select 1 as id, md5(i::text) as text, "
313+ "md5(repeat(i::text,10))::tsvector as tsvector "
314+ "from generate_series(0,1000) i" )
315+ node .safe_psql (
316+ "postgres" ,
317+ "CHECKPOINT;" )
318+
319+ heap_path = node .safe_psql (
320+ "postgres" ,
321+ "select pg_relation_filepath('t_heap')" ).rstrip ()
257322 node .stop ()
258323
259- with open (os .path .join (node .data_dir ,heap_path ), "rb+" , 0 ) as f :
324+ with open (os .path .join (node .data_dir , heap_path ), "rb+" , 0 ) as f :
260325 f .seek (9000 )
261326 f .write (b"bla" )
262327 f .flush ()
263328 f .close
264329 node .start ()
265330
266331 try :
267- self .backup_node (backup_dir , 'node' , node , backup_type = "full" , options = ["-j" , "4" , "--stream" ])
332+ self .backup_node (
333+ backup_dir , 'node' , node ,
334+ backup_type = "full" , options = ["-j" , "4" , "--stream" ])
268335 # we should die here because exception is what we expect to happen
269- self .assertEqual (1 , 0 , "Expecting Error because of page corruption in PostgreSQL instance.\n Output: {0} \n CMD: {1}" .format (
270- repr (self .output ), self .cmd ))
336+ self .assertEqual (
337+ 1 , 0 ,
338+ "Expecting Error because of page "
339+ "corruption in PostgreSQL instance.\n "
340+ " Output: {0} \n CMD: {1}" .format (
341+ repr (self .output ), self .cmd ))
271342 except ProbackupException as e :
272- self .assertIn ("ERROR: File" , e .message ,
273- "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
274- self .assertIn ("blknum" , e .message ,
275- "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
276- self .assertIn ("have wrong checksum" , e .message ,
277- "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
343+ self .assertTrue (
344+ "WARNING: File" in e .message and
345+ "blknum" in e .message and
346+ "have wrong checksum" in e .message ,
347+ "\n Unexpected Error Message: {0}\n CMD: {1}" .format (
348+ repr (e .message ), self .cmd ))
349+
350+ self .assertTrue (
351+ self .show_pb (backup_dir , 'node' )[1 ]['Status' ] == 'ERROR' ,
352+ "Backup Status should be ERROR" )
278353
279354 # Clean after yourself
280- self .del_test_dir (module_name , fname )
355+ # self.del_test_dir(module_name, fname)
0 commit comments