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). */
| 521 | * This function should be called after the current contents of the database |
| 522 | * was emptied with a previous call to emptyDb (possibly using the async mode). */ |
| 523 | void restoreDbBackup(dbBackup *buckup) { |
| 524 | /* Restore main DBs. */ |
| 525 | for (int i=0; i<server.dbnum; i++) { |
| 526 | serverAssert(dictSize(server.db[i].dict) == 0); |
| 527 | serverAssert(dictSize(server.db[i].expires) == 0); |
| 528 | dictRelease(server.db[i].dict); |
| 529 | dictRelease(server.db[i].expires); |
| 530 | server.db[i] = buckup->dbarray[i]; |
| 531 | } |
| 532 | |
| 533 | /* Restore slots to keys map backup if enable cluster. */ |
| 534 | if (server.cluster_enabled) { |
| 535 | serverAssert(server.cluster->slots_to_keys->numele == 0); |
| 536 | raxFree(server.cluster->slots_to_keys); |
| 537 | server.cluster->slots_to_keys = buckup->slots_to_keys; |
| 538 | memcpy(server.cluster->slots_keys_count, buckup->slots_keys_count, |
| 539 | sizeof(server.cluster->slots_keys_count)); |
| 540 | } |
| 541 | |
| 542 | /* Release buckup. */ |
| 543 | zfree(buckup->dbarray); |
| 544 | zfree(buckup); |
| 545 | |
| 546 | moduleFireServerEvent(REDISMODULE_EVENT_REPL_BACKUP, |
| 547 | REDISMODULE_SUBEVENT_REPL_BACKUP_RESTORE, |
| 548 | NULL); |
| 549 | } |
| 550 | |
| 551 | int selectDb(client *c, int id) { |
| 552 | if (id < 0 || id >= server.dbnum) |
no test coverage detected