• Ozan Tezcan's avatar
    Reply LOADING on replica while flushing the db (#13495) · a7afd1d2
    Ozan Tezcan authored
    On a full sync, replica starts discarding existing db. If the existing 
    db is huge and flush is happening synchronously, replica may become 
    unresponsive. 
    
    Adding a change to yield back to event loop while flushing db on 
    a replica. Replica will reply -LOADING in this case. Note that while 
    replica is loading the new rdb, it may get an error and start flushing
    the partial db. This step may take a long time as well. Similarly, 
    replica will reply -LOADING in this case. 
    
    To call processEventsWhileBlocked() and reply -LOADING, we need to do:
    - Set connSetReadHandler() null not to process further data from the master
    - Set server.loading flag
    - Call blockingOperationStarts()
    
    rdbload() already does these steps and calls processEventsWhileBlocked()
    while loading the rdb. Added a new call rdbLoadWithEmptyFunc() which 
    accepts callback to flush db before loading rdb or when an error 
    happens while loading. 
    
    For diskless replication, doing something similar and calling emptyData()
    after setting required flags.
    
    Additional changes:
    - Allow `appendonly` config change during loading. 
     Config can be changed while loading data on startup or on replication 
     when slave is loading RDB. We allow config change command to update 
     `server.aof_enabled` and then lazily apply config change after loading
     operation is completed.
     
     - Added a test for `replica-lazy-flush` config
    a7afd1d2
aof.c 103 KB