17-diskless-load-swapdb.tcl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Check replica can restore database backup correctly if fail to diskless load.
  2. source "../tests/includes/init-tests.tcl"
  3. test "Create a primary with a replica" {
  4. create_cluster 1 1
  5. }
  6. test "Cluster should start ok" {
  7. assert_cluster_state ok
  8. }
  9. test "Cluster is writable" {
  10. cluster_write_test 0
  11. }
  12. test "Right to restore backups when fail to diskless load " {
  13. set master [Rn 0]
  14. set replica [Rn 1]
  15. set master_id 0
  16. set replica_id 1
  17. $replica READONLY
  18. $replica config set repl-diskless-load swapdb
  19. $replica config set appendonly no
  20. $replica config set save ""
  21. $replica config rewrite
  22. $master config set repl-backlog-size 1024
  23. $master config set repl-diskless-sync yes
  24. $master config set repl-diskless-sync-delay 0
  25. $master config set rdb-key-save-delay 10000
  26. $master config set rdbcompression no
  27. $master config set appendonly no
  28. $master config set save ""
  29. # Write a key that belongs to slot 0
  30. set slot0_key "06S"
  31. $master set $slot0_key 1
  32. wait_for_ofs_sync $master $replica
  33. assert_equal {1} [$replica get $slot0_key]
  34. assert_equal $slot0_key [$replica CLUSTER GETKEYSINSLOT 0 1]
  35. # Save an RDB and kill the replica
  36. $replica save
  37. kill_instance redis $replica_id
  38. # Delete the key from master
  39. $master del $slot0_key
  40. # Replica must full sync with master when start because replication
  41. # backlog size is very small, and dumping rdb will cost several seconds.
  42. set num 10000
  43. set value [string repeat A 1024]
  44. set rd [redis_deferring_client redis $master_id]
  45. for {set j 0} {$j < $num} {incr j} {
  46. $rd set $j $value
  47. }
  48. for {set j 0} {$j < $num} {incr j} {
  49. $rd read
  50. }
  51. # Start the replica again
  52. restart_instance redis $replica_id
  53. $replica READONLY
  54. # Start full sync, wait till after db is flushed (backed up)
  55. wait_for_condition 500 10 {
  56. [s $replica_id loading] eq 1
  57. } else {
  58. fail "Fail to full sync"
  59. }
  60. # Kill master, abort full sync
  61. kill_instance redis $master_id
  62. # Start full sync, wait till the replica detects the disconnection
  63. wait_for_condition 500 10 {
  64. [s $replica_id loading] eq 0
  65. } else {
  66. fail "Fail to full sync"
  67. }
  68. # Replica keys and keys to slots map still both are right
  69. assert_equal {1} [$replica get $slot0_key]
  70. assert_equal $slot0_key [$replica CLUSTER GETKEYSINSLOT 0 1]
  71. }