1
0

lazyfree.tcl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. start_server {tags {"lazyfree"}} {
  2. test "UNLINK can reclaim memory in background" {
  3. set orig_mem [s used_memory]
  4. set args {}
  5. for {set i 0} {$i < 100000} {incr i} {
  6. lappend args $i
  7. }
  8. r sadd myset {*}$args
  9. assert {[r scard myset] == 100000}
  10. set peak_mem [s used_memory]
  11. assert {[r unlink myset] == 1}
  12. assert {$peak_mem > $orig_mem+1000000}
  13. wait_for_condition 50 100 {
  14. [s used_memory] < $peak_mem &&
  15. [s used_memory] < $orig_mem*2
  16. } else {
  17. fail "Memory is not reclaimed by UNLINK"
  18. }
  19. }
  20. test "FLUSHDB ASYNC can reclaim memory in background" {
  21. set orig_mem [s used_memory]
  22. set args {}
  23. for {set i 0} {$i < 100000} {incr i} {
  24. lappend args $i
  25. }
  26. r sadd myset {*}$args
  27. assert {[r scard myset] == 100000}
  28. set peak_mem [s used_memory]
  29. r flushdb async
  30. assert {$peak_mem > $orig_mem+1000000}
  31. wait_for_condition 50 100 {
  32. [s used_memory] < $peak_mem &&
  33. [s used_memory] < $orig_mem*2
  34. } else {
  35. fail "Memory is not reclaimed by FLUSHDB ASYNC"
  36. }
  37. }
  38. test "lazy free a stream with all types of metadata" {
  39. # make the previous test is really done before doing RESETSTAT
  40. wait_for_condition 5 100 {
  41. [s lazyfree_pending_objects] == 0
  42. } else {
  43. fail "lazyfree isn't done"
  44. }
  45. r config resetstat
  46. r config set stream-node-max-entries 5
  47. for {set j 0} {$j < 1000} {incr j} {
  48. if {rand() < 0.9} {
  49. r xadd stream * foo $j
  50. } else {
  51. r xadd stream * bar $j
  52. }
  53. }
  54. r xgroup create stream mygroup 0
  55. set records [r xreadgroup GROUP mygroup Alice COUNT 2 STREAMS stream >]
  56. r xdel stream [lindex [lindex [lindex [lindex $records 0] 1] 1] 0]
  57. r xack stream mygroup [lindex [lindex [lindex [lindex $records 0] 1] 0] 0]
  58. r unlink stream
  59. # make sure it was lazy freed
  60. wait_for_condition 5 100 {
  61. [s lazyfree_pending_objects] == 0
  62. } else {
  63. fail "lazyfree isn't done"
  64. }
  65. assert_equal [s lazyfreed_objects] 1
  66. } {} {needs:config-resetstat}
  67. test "lazy free a stream with deleted cgroup" {
  68. r config resetstat
  69. r xadd s * a b
  70. r xgroup create s bla $
  71. r xgroup destroy s bla
  72. r unlink s
  73. # make sure it was not lazy freed
  74. wait_for_condition 5 100 {
  75. [s lazyfree_pending_objects] == 0
  76. } else {
  77. fail "lazyfree isn't done"
  78. }
  79. assert_equal [s lazyfreed_objects] 0
  80. } {} {needs:config-resetstat}
  81. }