Perf fixes on expire lock

Former-commit-id: 7f23ac087720317f54a0bc0e0c4774e7b0ef4337
This commit is contained in:
John Sully 2020-07-13 18:14:52 +00:00
parent ad5ad52841
commit 503ca68e8c
3 changed files with 14 additions and 12 deletions

View File

@ -1460,9 +1460,9 @@ int rewriteAppendOnlyFileRio(rio *aof) {
serverPanic("Unknown object type");
}
/* Save the expire time */
std::unique_lock<fastlock> ul(g_expireLock);
expireEntry *pexpire = db->getExpire(&key);
if (pexpire != nullptr) {
if (o->FExpires()) {
std::unique_lock<fastlock> ul(g_expireLock);
expireEntry *pexpire = db->getExpire(&key);
for (auto &subExpire : *pexpire) {
if (subExpire.subkey() == nullptr)
{
@ -1480,7 +1480,6 @@ int rewriteAppendOnlyFileRio(rio *aof) {
if (rioWriteBulkLongLong(aof,subExpire.when()) == 0) return false; // common
}
}
ul.unlock();
/* Read some diff from the parent process from time to time. */
if (aof->processed_bytes > processed+AOF_READ_DIFF_INTERVAL_BYTES) {

View File

@ -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 */
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);
const expireEntry *pexpire = db->getExpire(key);
mstime_t now;
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;
for (auto &exp : *pexpire)
{

View File

@ -1150,11 +1150,14 @@ int saveKey(rio *rdb, const redisDbPersistentDataSnapshot *db, int flags, size_t
robj key;
initStaticStringObject(key,(char*)keystr);
std::unique_lock<fastlock> ul(g_expireLock);
const expireEntry *pexpire = db->getExpire(&key);
serverAssert((o->FExpires() && pexpire != nullptr) || (!o->FExpires() && pexpire == nullptr));
if (pexpire == nullptr)
ul.unlock(); // no need to hold the lock if we're not saving the expire
std::unique_lock<fastlock> ul(g_expireLock, std::defer_lock);
const expireEntry *pexpire = nullptr;
if (o->FExpires())
{
ul.lock();
pexpire = db->getExpire(&key);
serverAssert((o->FExpires() && pexpire != nullptr) || (!o->FExpires() && pexpire == nullptr));
}
if (rdbSaveKeyValuePair(rdb,&key,o,pexpire) == -1)
return 0;