fixed up backup stuff
Former-commit-id: 8a23162c24dc13a4268928c5defd85b0b5249d39
This commit is contained in:
parent
0fd43cdc82
commit
511f01bd14
63
src/db.cpp
63
src/db.cpp
@ -516,12 +516,7 @@ long long emptyDbStructure(redisDb **dbarray, int dbnum, int async,
|
|||||||
|
|
||||||
for (int j = startdb; j <= enddb; j++) {
|
for (int j = startdb; j <= enddb; j++) {
|
||||||
removed += dbarray[j]->size();
|
removed += dbarray[j]->size();
|
||||||
if (async) {
|
dbarray[j]->clear(async, callback);
|
||||||
dbarray[j]->emptyDbAsync();
|
|
||||||
} else {
|
|
||||||
dictEmpty(dbarray[j]->dictUnsafeKeyOnly(),callback);
|
|
||||||
dbarray[j]->setexpireUnsafe()->clear();
|
|
||||||
}
|
|
||||||
/* Because all keys of database are removed, reset average ttl. */
|
/* Because all keys of database are removed, reset average ttl. */
|
||||||
dbarray[j]->avg_ttl = 0;
|
dbarray[j]->avg_ttl = 0;
|
||||||
dbarray[j]->last_expire_set = 0;
|
dbarray[j]->last_expire_set = 0;
|
||||||
@ -585,47 +580,21 @@ long long emptyDb(int dbnum, int flags, void(callback)(void*)) {
|
|||||||
|
|
||||||
/* Store a backup of the database for later use, and put an empty one
|
/* Store a backup of the database for later use, and put an empty one
|
||||||
* instead of it. */
|
* instead of it. */
|
||||||
dbBackup *backupDb(void) {
|
const redisDbPersistentDataSnapshot **backupDb(void) {
|
||||||
dbBackup *backup = (dbBackup*)zmalloc(sizeof(dbBackup));
|
const redisDbPersistentDataSnapshot **backup = (const redisDbPersistentDataSnapshot**)zmalloc(sizeof(redisDbPersistentDataSnapshot*)*cserver.dbnum);
|
||||||
|
|
||||||
/* Backup main DBs. */
|
|
||||||
backup->dbarray = (redisDb**)zmalloc(sizeof(redisDb*)*cserver.dbnum);
|
|
||||||
for (int i=0; i<cserver.dbnum; i++) {
|
for (int i=0; i<cserver.dbnum; i++) {
|
||||||
backup->dbarray[i] = g_pserver->db[i];
|
backup[i] = g_pserver->db[i]->createSnapshot(LLONG_MAX, false);
|
||||||
g_pserver->db[i] = new (MALLOC_LOCAL) redisDb();
|
|
||||||
g_pserver->db[i]->initialize(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Backup cluster slots to keys map if enable cluster. */
|
|
||||||
if (g_pserver->cluster_enabled) {
|
|
||||||
backup->slots_to_keys = g_pserver->cluster->slots_to_keys;
|
|
||||||
memcpy(backup->slots_keys_count, g_pserver->cluster->slots_keys_count,
|
|
||||||
sizeof(g_pserver->cluster->slots_keys_count));
|
|
||||||
g_pserver->cluster->slots_to_keys = raxNew();
|
|
||||||
memset(g_pserver->cluster->slots_keys_count, 0,
|
|
||||||
sizeof(g_pserver->cluster->slots_keys_count));
|
|
||||||
}
|
|
||||||
|
|
||||||
return backup;
|
return backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Discard a previously created backup, this can be slow (similar to FLUSHALL)
|
/* Discard a previously created backup, this can be slow (similar to FLUSHALL)
|
||||||
* Arguments are similar to the ones of emptyDb, see EMPTYDB_ flags. */
|
* Arguments are similar to the ones of emptyDb, see EMPTYDB_ flags. */
|
||||||
void discardDbBackup(dbBackup *buckup, int flags, void(callback)(void*)) {
|
void discardDbBackup(const redisDbPersistentDataSnapshot **buckup, int flags, void(callback)(void*)) {
|
||||||
int async = (flags & EMPTYDB_ASYNC);
|
|
||||||
|
|
||||||
/* Release main DBs backup . */
|
/* Release main DBs backup . */
|
||||||
emptyDbStructure(buckup->dbarray, -1, async, callback);
|
|
||||||
for (int i=0; i<cserver.dbnum; i++) {
|
for (int i=0; i<cserver.dbnum; i++) {
|
||||||
dictRelease(buckup->dbarray[i]->dictUnsafeKeyOnly());
|
g_pserver->db[i]->endSnapshot(buckup[i]);
|
||||||
buckup->dbarray[i]->delete_setexpire();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release slots to keys map backup if enable cluster. */
|
|
||||||
if (g_pserver->cluster_enabled) freeSlotsToKeysMap(buckup->slots_to_keys, async);
|
|
||||||
|
|
||||||
/* Release buckup. */
|
|
||||||
zfree(buckup->dbarray);
|
|
||||||
zfree(buckup);
|
zfree(buckup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,27 +602,11 @@ void discardDbBackup(dbBackup *buckup, int flags, void(callback)(void*)) {
|
|||||||
* in the db).
|
* in the db).
|
||||||
* This function should be called after the current contents of the database
|
* 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). */
|
* was emptied with a previous call to emptyDb (possibly using the async mode). */
|
||||||
void restoreDbBackup(dbBackup *buckup) {
|
void restoreDbBackup(const redisDbPersistentDataSnapshot **buckup) {
|
||||||
/* Restore main DBs. */
|
/* Restore main DBs. */
|
||||||
for (int i=0; i<cserver.dbnum; i++) {
|
for (int i=0; i<cserver.dbnum; i++) {
|
||||||
serverAssert(g_pserver->db[i]->size() == 0);
|
g_pserver->db[i]->restoreSnapshot(buckup[i]);
|
||||||
serverAssert(g_pserver->db[i]->expireSize() == 0);
|
|
||||||
dictRelease(g_pserver->db[i]->dictUnsafeKeyOnly());
|
|
||||||
g_pserver->db[i]->delete_setexpire();
|
|
||||||
g_pserver->db[i] = buckup->dbarray[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore slots to keys map backup if enable cluster. */
|
|
||||||
if (g_pserver->cluster_enabled) {
|
|
||||||
serverAssert(g_pserver->cluster->slots_to_keys->numele == 0);
|
|
||||||
raxFree(g_pserver->cluster->slots_to_keys);
|
|
||||||
g_pserver->cluster->slots_to_keys = buckup->slots_to_keys;
|
|
||||||
memcpy(g_pserver->cluster->slots_keys_count, buckup->slots_keys_count,
|
|
||||||
sizeof(g_pserver->cluster->slots_keys_count));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release buckup. */
|
|
||||||
zfree(buckup->dbarray);
|
|
||||||
zfree(buckup);
|
zfree(buckup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1874,7 +1874,7 @@ static int useDisklessLoad() {
|
|||||||
/* Helper function for readSyncBulkPayload() to make backups of the current
|
/* Helper function for readSyncBulkPayload() to make backups of the current
|
||||||
* databases before socket-loading the new ones. The backups may be restored
|
* databases before socket-loading the new ones. The backups may be restored
|
||||||
* by disklessLoadRestoreBackup or freed by disklessLoadDiscardBackup later. */
|
* by disklessLoadRestoreBackup or freed by disklessLoadDiscardBackup later. */
|
||||||
dbBackup *disklessLoadMakeBackup(void) {
|
const redisDbPersistentDataSnapshot **disklessLoadMakeBackup(void) {
|
||||||
return backupDb();
|
return backupDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1884,13 +1884,13 @@ dbBackup *disklessLoadMakeBackup(void) {
|
|||||||
*
|
*
|
||||||
* If the socket loading went wrong, we want to restore the old backups
|
* If the socket loading went wrong, we want to restore the old backups
|
||||||
* into the server databases. */
|
* into the server databases. */
|
||||||
void disklessLoadRestoreBackup(dbBackup *buckup) {
|
void disklessLoadRestoreBackup(const redisDbPersistentDataSnapshot **buckup) {
|
||||||
restoreDbBackup(buckup);
|
restoreDbBackup(buckup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function for readSyncBulkPayload() to discard our old backups
|
/* Helper function for readSyncBulkPayload() to discard our old backups
|
||||||
* when the loading succeeded. */
|
* when the loading succeeded. */
|
||||||
void disklessLoadDiscardBackup(dbBackup *buckup, int flag) {
|
void disklessLoadDiscardBackup(const redisDbPersistentDataSnapshot **buckup, int flag) {
|
||||||
discardDbBackup(buckup, flag, replicationEmptyDbCallback);
|
discardDbBackup(buckup, flag, replicationEmptyDbCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1900,7 +1900,7 @@ void readSyncBulkPayload(connection *conn) {
|
|||||||
char buf[PROTO_IOBUF_LEN];
|
char buf[PROTO_IOBUF_LEN];
|
||||||
ssize_t nread, readlen, nwritten;
|
ssize_t nread, readlen, nwritten;
|
||||||
int use_diskless_load = useDisklessLoad();
|
int use_diskless_load = useDisklessLoad();
|
||||||
dbBackup *diskless_load_backup = NULL;
|
const redisDbPersistentDataSnapshot **diskless_load_backup = NULL;
|
||||||
rdbSaveInfo rsi = RDB_SAVE_INFO_INIT;
|
rdbSaveInfo rsi = RDB_SAVE_INFO_INIT;
|
||||||
int empty_db_flags = g_pserver->repl_slave_lazy_flush ? EMPTYDB_ASYNC :
|
int empty_db_flags = g_pserver->repl_slave_lazy_flush ? EMPTYDB_ASYNC :
|
||||||
EMPTYDB_NO_FLAGS;
|
EMPTYDB_NO_FLAGS;
|
||||||
|
12
src/server.h
12
src/server.h
@ -1074,11 +1074,6 @@ public:
|
|||||||
return m_setexpire->random_value();
|
return m_setexpire->random_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_setexpire()
|
|
||||||
{
|
|
||||||
delete m_setexpire;
|
|
||||||
}
|
|
||||||
|
|
||||||
dict_iter end() { return dict_iter(nullptr, nullptr); }
|
dict_iter end() { return dict_iter(nullptr, nullptr); }
|
||||||
dict_const_iter end() const { return dict_const_iter(nullptr); }
|
dict_const_iter end() const { return dict_const_iter(nullptr); }
|
||||||
|
|
||||||
@ -1291,7 +1286,6 @@ struct redisDb : public redisDbPersistentDataSnapshot
|
|||||||
using redisDbPersistentData::expireSize;
|
using redisDbPersistentData::expireSize;
|
||||||
using redisDbPersistentData::removeExpire;
|
using redisDbPersistentData::removeExpire;
|
||||||
using redisDbPersistentData::removeSubkeyExpire;
|
using redisDbPersistentData::removeSubkeyExpire;
|
||||||
using redisDbPersistentData::delete_setexpire;
|
|
||||||
using redisDbPersistentData::clear;
|
using redisDbPersistentData::clear;
|
||||||
using redisDbPersistentData::emptyDbAsync;
|
using redisDbPersistentData::emptyDbAsync;
|
||||||
using redisDbPersistentData::iterate;
|
using redisDbPersistentData::iterate;
|
||||||
@ -3031,9 +3025,9 @@ long long emptyDb(int dbnum, int flags, void(callback)(void*));
|
|||||||
long long emptyDbStructure(redisDb **dbarray, int dbnum, int flags, void(callback)(void*));
|
long long emptyDbStructure(redisDb **dbarray, int dbnum, int flags, void(callback)(void*));
|
||||||
void flushAllDataAndResetRDB(int flags);
|
void flushAllDataAndResetRDB(int flags);
|
||||||
long long dbTotalServerKeyCount();
|
long long dbTotalServerKeyCount();
|
||||||
dbBackup *backupDb(void);
|
const redisDbPersistentDataSnapshot **backupDb(void);
|
||||||
void restoreDbBackup(dbBackup *buckup);
|
void restoreDbBackup(const redisDbPersistentDataSnapshot **buckup);
|
||||||
void discardDbBackup(dbBackup *buckup, int flags, void(callback)(void*));
|
void discardDbBackup(const redisDbPersistentDataSnapshot **buckup, int flags, void(callback)(void*));
|
||||||
|
|
||||||
|
|
||||||
int selectDb(client *c, int id);
|
int selectDb(client *c, int id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user