Restore the previously created backup (discarding what currently resides * in the db). * This function should be called after the current contents of the database * was emptied with a previous call to emptyDb (possibly using the async mode). */
| 700 | * This function should be called after the current contents of the database |
| 701 | * was emptied with a previous call to emptyDb (possibly using the async mode). */ |
| 702 | void restoreDbBackup(const dbBackup *backup) { |
| 703 | /* Restore main DBs. */ |
| 704 | for (int i=0; i<cserver.dbnum; i++) { |
| 705 | g_pserver->db[i]->restoreSnapshot(backup->dbarray[i]); |
| 706 | } |
| 707 | |
| 708 | /* Restore slots to keys map backup if enable cluster. */ |
| 709 | if (g_pserver->cluster_enabled) { |
| 710 | serverAssert(g_pserver->cluster->slots_to_keys->numele == 0); |
| 711 | raxFree(g_pserver->cluster->slots_to_keys); |
| 712 | g_pserver->cluster->slots_to_keys = backup->slots_to_keys; |
| 713 | memcpy(g_pserver->cluster->slots_keys_count, backup->slots_keys_count, |
| 714 | sizeof(g_pserver->cluster->slots_keys_count)); |
| 715 | } |
| 716 | |
| 717 | /* Release buckup. */ |
| 718 | zfree(backup->dbarray); |
| 719 | delete backup; |
| 720 | |
| 721 | moduleFireServerEvent(REDISMODULE_EVENT_REPL_BACKUP, |
| 722 | REDISMODULE_SUBEVENT_REPL_BACKUP_RESTORE, |
| 723 | NULL); |
| 724 | } |
| 725 | |
| 726 | int selectDb(client *c, int id) { |
| 727 | if (id < 0 || id >= cserver.dbnum) |
no test coverage detected