@@ -221,4 +221,65 @@ start_server {} {
221221 assert {$digest eq [$replica debug digest]}
222222 assert {$digest eq [$sub_replica debug digest]}
223223 }
224+
225+ test " PSYNC2: Primary reloading RDB will propagate expired hash fields deletion to replica" {
226+ # Disable active expiration on master
227+ $master debug set-active-expire 0
228+
229+ # Create hash with expiring fields and one permanent field
230+ $master hsetex myhash PX 1000 FIELDS 3 f1 v1 f2 v2 f3 v3
231+ $master hset myhash permanent permanent_value
232+
233+ # Wait for replica to sync
234+ wait_for_condition 50 100 {
235+ [$replica hlen myhash] == 4 &&
236+ [$sub_replica hlen myhash] == 4
237+ } else {
238+ fail " Replicas did not receive hash"
239+ }
240+
241+ # Wait until all fields are expired
242+ wait_for_condition 50 100 {
243+ [lindex [$master httl myhash FIELDS 1 f1] 0] == -2 &&
244+ [lindex [$master httl myhash FIELDS 1 f2] 0] == -2 &&
245+ [lindex [$master httl myhash FIELDS 1 f3] 0] == -2
246+ } else {
247+ fail " Hash fields did not expire"
248+ }
249+
250+ # Save RDB
251+ $master save
252+
253+ # Restart master - this will reload RDB and skip expired fields
254+ catch {
255+ restart_server 0 true false
256+ set master [srv 0 client]
257+ }
258+
259+ # Wait for replicas to reconnect
260+ wait_for_condition 50 1000 {
261+ [status $replica master_link_status] eq {up} &&
262+ [status $sub_replica master_link_status] eq {up}
263+ } else {
264+ fail " Replicas didn't sync after master restart"
265+ }
266+
267+ # Re-enable active expiration
268+ $master debug set-active-expire 1
269+
270+ # Verify master has only the permanent field
271+ assert_equal 1 [$master hlen myhash]
272+ assert_equal " permanent_value" [$master hget myhash permanent]
273+
274+ # Verify replicas also have only the permanent field (received HDEL)
275+ wait_for_condition 50 100 {
276+ [$replica hlen myhash] == 1 &&
277+ [$sub_replica hlen myhash] == 1
278+ } else {
279+ fail " Replicas did not delete expired hash fields"
280+ }
281+
282+ assert_equal " permanent_value" [$replica hget myhash permanent]
283+ assert_equal " permanent_value" [$sub_replica hget myhash permanent]
284+ }
224285}}}
0 commit comments