Perf fixes on expire lock
Former-commit-id: 7f23ac087720317f54a0bc0e0c4774e7b0ef4337
This commit is contained in:
parent
ad5ad52841
commit
503ca68e8c
@ -1460,9 +1460,9 @@ int rewriteAppendOnlyFileRio(rio *aof) {
|
|||||||
serverPanic("Unknown object type");
|
serverPanic("Unknown object type");
|
||||||
}
|
}
|
||||||
/* Save the expire time */
|
/* Save the expire time */
|
||||||
std::unique_lock<fastlock> ul(g_expireLock);
|
if (o->FExpires()) {
|
||||||
expireEntry *pexpire = db->getExpire(&key);
|
std::unique_lock<fastlock> ul(g_expireLock);
|
||||||
if (pexpire != nullptr) {
|
expireEntry *pexpire = db->getExpire(&key);
|
||||||
for (auto &subExpire : *pexpire) {
|
for (auto &subExpire : *pexpire) {
|
||||||
if (subExpire.subkey() == nullptr)
|
if (subExpire.subkey() == nullptr)
|
||||||
{
|
{
|
||||||
@ -1480,7 +1480,6 @@ int rewriteAppendOnlyFileRio(rio *aof) {
|
|||||||
if (rioWriteBulkLongLong(aof,subExpire.when()) == 0) return false; // common
|
if (rioWriteBulkLongLong(aof,subExpire.when()) == 0) return false; // common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ul.unlock();
|
|
||||||
|
|
||||||
/* Read some diff from the parent process from time to time. */
|
/* Read some diff from the parent process from time to time. */
|
||||||
if (aof->processed_bytes > processed+AOF_READ_DIFF_INTERVAL_BYTES) {
|
if (aof->processed_bytes > processed+AOF_READ_DIFF_INTERVAL_BYTES) {
|
||||||
|
@ -1738,15 +1738,15 @@ void propagateSubkeyExpire(redisDb *db, int type, robj *key, robj *subkey)
|
|||||||
|
|
||||||
/* Check if the key is expired. Note, this does not check subexpires */
|
/* Check if the key is expired. Note, this does not check subexpires */
|
||||||
int keyIsExpired(const redisDbPersistentDataSnapshot *db, robj *key) {
|
int keyIsExpired(const redisDbPersistentDataSnapshot *db, robj *key) {
|
||||||
|
/* Don't expire anything while loading. It will be done later. */
|
||||||
|
if (g_pserver->loading) return 0;
|
||||||
|
|
||||||
std::unique_lock<fastlock> ul(g_expireLock);
|
std::unique_lock<fastlock> ul(g_expireLock);
|
||||||
const expireEntry *pexpire = db->getExpire(key);
|
const expireEntry *pexpire = db->getExpire(key);
|
||||||
mstime_t now;
|
mstime_t now;
|
||||||
|
|
||||||
if (pexpire == nullptr) return 0; /* No expire for this key */
|
if (pexpire == nullptr) return 0; /* No expire for this key */
|
||||||
|
|
||||||
/* Don't expire anything while loading. It will be done later. */
|
|
||||||
if (g_pserver->loading) return 0;
|
|
||||||
|
|
||||||
long long when = -1;
|
long long when = -1;
|
||||||
for (auto &exp : *pexpire)
|
for (auto &exp : *pexpire)
|
||||||
{
|
{
|
||||||
|
13
src/rdb.cpp
13
src/rdb.cpp
@ -1150,11 +1150,14 @@ int saveKey(rio *rdb, const redisDbPersistentDataSnapshot *db, int flags, size_t
|
|||||||
robj key;
|
robj key;
|
||||||
|
|
||||||
initStaticStringObject(key,(char*)keystr);
|
initStaticStringObject(key,(char*)keystr);
|
||||||
std::unique_lock<fastlock> ul(g_expireLock);
|
std::unique_lock<fastlock> ul(g_expireLock, std::defer_lock);
|
||||||
const expireEntry *pexpire = db->getExpire(&key);
|
const expireEntry *pexpire = nullptr;
|
||||||
serverAssert((o->FExpires() && pexpire != nullptr) || (!o->FExpires() && pexpire == nullptr));
|
if (o->FExpires())
|
||||||
if (pexpire == nullptr)
|
{
|
||||||
ul.unlock(); // no need to hold the lock if we're not saving the expire
|
ul.lock();
|
||||||
|
pexpire = db->getExpire(&key);
|
||||||
|
serverAssert((o->FExpires() && pexpire != nullptr) || (!o->FExpires() && pexpire == nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
if (rdbSaveKeyValuePair(rdb,&key,o,pexpire) == -1)
|
if (rdbSaveKeyValuePair(rdb,&key,o,pexpire) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user