@@ -353,6 +353,29 @@ function test_bad_inputs_with_werror() {
353353 )
354354}
355355
356+ function test_source_table_does_not_exist() {
357+ (
358+ # Given
359+ local dst_tbl=foo
360+ query_dst_db " create table $dst_tbl (i int)"
361+ trap " query_dst_db 'drop table $dst_tbl '" EXIT
362+
363+ # When
364+ err=$( query_dst_db " replace table $dst_tbl with LOCAL_$SRC_DBNAME .donut_exist" 2>&1 )
365+
366+ # Then
367+ if (( $? == 0 )) ; then
368+ echo " FAIL: Expected import to fail"
369+ return 1
370+ fi
371+
372+ if ! echo $err | grep " Source table does not exist" ; then
373+ echo " FAIL: Expected 'table does not exist' error"
374+ return 1
375+ fi
376+ )
377+ }
378+
356379function test_resume_is_blocked() {
357380 (
358381 # Given
@@ -380,6 +403,116 @@ function test_resume_is_blocked() {
380403 )
381404}
382405
406+ function test_src_db_table_dropped_during_import() {
407+ (
408+ # Given
409+ # create tables
410+ local src_tbl=foo dst_tbl=bar start_timestamp=$( date ' +%Y/%m/%d %H:%M:%S' )
411+ fixture_src_tbl_and_dst_tbl_have_same_schema $src_tbl $dst_tbl > /dev/null
412+
413+ # set tunables
414+ # the 30 second sleep gives the db time to flush logs reflecting the table drop
415+ set_src_tunable ' comdb2_files_sleep_secs_after_processing_llmeta 30'
416+ set_src_tunable ' logmsg level debug'
417+
418+ # teardown routines
419+ trap " set_src_tunable 'comdb2_files_sleep_secs_after_processing_llmeta 0';
420+ set_src_tunable 'logmsg level warn';
421+ query_dst_db 'drop table $dst_tbl '" EXIT
422+
423+ # start import and wait for the source db to sleep after
424+ # sending llmeta to the dst db
425+ query_dst_db " replace table $dst_tbl with LOCAL_$SRC_DBNAME .$src_tbl " 2> err.txt &
426+ waitpid=$!
427+ wait_for_src_trace " just processed llmeta" " $start_timestamp "
428+
429+ # When
430+ query_src_db " drop table $src_tbl "
431+
432+ # Then
433+ # We dropped the table between the point where it sent
434+ # llmeta and the point when it sent the txn logs.
435+ #
436+ # Therefore, the drop will be reflected in the txn logs,
437+ # which means that recovery will drop it from llmeta.
438+ #
439+ # So we expect the import to fail because
440+ # the source table will not exist.
441+
442+ if check_for_src_trace " read_next_chunk.*done sleeping" " $start_timestamp " ; then
443+ echo " FAIL: Expected source database to still be sleeping. Test is buggy"
444+ return 1
445+ fi
446+
447+ if wait $waitpid ; then
448+ echo " FAIL: Expected import to fail."
449+ return 1
450+ fi
451+
452+ if ! cat err.txt | grep " Source table does not exist" ; then
453+ echo " FAIL: Expected 'table does not exist' error"
454+ return 1
455+ fi
456+
457+ if verify_eq $src_tbl $dst_tbl ; then
458+ echo " FAIL: Expected tables to not match"
459+ return 1
460+ fi
461+ )
462+ }
463+
464+ function test_src_db_election_during_import() {
465+ (
466+ # Given
467+ # create tables
468+ local src_tbl=foo dst_tbl=bar start_timestamp=$( date ' +%Y/%m/%d %H:%M:%S' )
469+ fixture_src_tbl_and_dst_tbl_have_same_schema $src_tbl $dst_tbl > /dev/null
470+
471+ # set tunables
472+ set_src_tunable ' comdb2_files_sleep_secs_after_processing_llmeta 10'
473+ set_src_tunable ' logmsg level debug'
474+
475+ # teardown routines
476+ trap " set_src_tunable 'comdb2_files_sleep_secs_after_processing_llmeta 0';
477+ set_src_tunable 'logmsg level warn';
478+ query_src_db 'drop table $src_tbl ';
479+ query_dst_db 'drop table $dst_tbl '" EXIT
480+
481+
482+ # start import and wait for the source db to sleep after
483+ # sending llmeta to the dst db
484+ query_dst_db " replace table $dst_tbl with LOCAL_$SRC_DBNAME .$src_tbl " &
485+ waitpid=$!
486+ wait_for_src_trace " just processed llmeta" " $start_timestamp "
487+
488+ # When
489+ downgrade_src_db
490+
491+ # Then
492+
493+ downgrade_rc=$?
494+ if (( downgrade_rc != 0 )) ; then
495+ echo " FAIL: Expected downgrade to succeed"
496+ return 1
497+ fi
498+
499+ if check_for_src_trace " read_next_chunk.*done sleeping" " $start_timestamp " ; then
500+ echo " FAIL: Expected source database to still be sleeping. Test is buggy"
501+ return 1
502+ fi
503+
504+ if ! wait $waitpid ; then
505+ echo " FAIL: Expected import to succeed"
506+ return 1
507+ fi
508+
509+ if ! verify_eq $src_tbl $dst_tbl ; then
510+ echo " FAIL: Expected tables to match"
511+ return 1
512+ fi
513+ )
514+ }
515+
383516function run_basic_test() {
384517 (
385518 # Given
0 commit comments