Populate the rdbSaveInfo structure used to persist the replication * information inside the RDB file. Currently the structure explicitly * contains just the currently selected DB from the master stream, however * if the rdbSave*() family functions receive a NULL rsi structure also * the Replication ID/offset is not saved. The function popultes 'rsi' * that is normally stack-allocated in the c
| 3031 | * is returned, and the RDB saving will not persist any replication related |
| 3032 | * information. */ |
| 3033 | rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) { |
| 3034 | rdbSaveInfo rsi_init = RDB_SAVE_INFO_INIT; |
| 3035 | *rsi = rsi_init; |
| 3036 | |
| 3037 | /* If the instance is a master, we can populate the replication info |
| 3038 | * only when repl_backlog is not NULL. If the repl_backlog is NULL, |
| 3039 | * it means that the instance isn't in any replication chains. In this |
| 3040 | * scenario the replication info is useless, because when a slave |
| 3041 | * connects to us, the NULL repl_backlog will trigger a full |
| 3042 | * synchronization, at the same time we will use a new replid and clear |
| 3043 | * replid2. */ |
| 3044 | if (!server.masterhost && server.repl_backlog) { |
| 3045 | /* Note that when server.slaveseldb is -1, it means that this master |
| 3046 | * didn't apply any write commands after a full synchronization. |
| 3047 | * So we can let repl_stream_db be 0, this allows a restarted slave |
| 3048 | * to reload replication ID/offset, it's safe because the next write |
| 3049 | * command must generate a SELECT statement. */ |
| 3050 | rsi->repl_stream_db = server.slaveseldb == -1 ? 0 : server.slaveseldb; |
| 3051 | return rsi; |
| 3052 | } |
| 3053 | |
| 3054 | /* If the instance is a slave we need a connected master |
| 3055 | * in order to fetch the currently selected DB. */ |
| 3056 | if (server.master) { |
| 3057 | rsi->repl_stream_db = server.master->db->id; |
| 3058 | return rsi; |
| 3059 | } |
| 3060 | |
| 3061 | /* If we have a cached master we can use it in order to populate the |
| 3062 | * replication selected DB info inside the RDB file: the slave can |
| 3063 | * increment the master_repl_offset only from data arriving from the |
| 3064 | * master, so if we are disconnected the offset in the cached master |
| 3065 | * is valid. */ |
| 3066 | if (server.cached_master) { |
| 3067 | rsi->repl_stream_db = server.cached_master->db->id; |
| 3068 | return rsi; |
| 3069 | } |
| 3070 | return NULL; |
| 3071 | } |
no outgoing calls
no test coverage detected