Beispiel #1
0
    int Master::CreateSnapshot(bool is_redis_type)
    {
        Snapshot rdb;
        int ret = rdb.Save(false, is_redis_type ? REDIS_SNAPSHOT : MMKV_SNAPSHOT, DumpRDBRoutine, this);

        if (0 == ret)
        {
            INFO_LOG("[Master]Saved snapshot file.");
            FullResyncSlaves(is_redis_type);
        }
        else if (ERR_SNAPSHOT_SAVING == ret)
        {
            return 0;
        }
        else
        {
            WARN_LOG("Failed to create snapshot file.");
            SlaveConnTable::iterator it = m_slaves.begin();
            while (it != m_slaves.end())
            {
                if (it->second != NULL && it->second->state == SYNC_STATE_WAITING_SNAPSHOT)
                {
                    it->second->conn->Close();
                }
                it++;
            }
        }
        return 0;
    }