add g_expirelock to previously async accesses to expireset (#618)

* add expire_lock to previously async access to expireset

* add flash option to create-cluster
This commit is contained in:
Malavan Sotheeswaran 2023-03-30 20:23:56 -07:00 committed by GitHub
parent 06380e5fe1
commit 858db2645d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -1931,6 +1931,7 @@ void setExpire(client *c, redisDb *db, robj *key, expireEntry &&e)
* is associated with this key (i.e. the key is non volatile) */ * is associated with this key (i.e. the key is non volatile) */
expireEntry *redisDbPersistentDataSnapshot::getExpire(const char *key) { expireEntry *redisDbPersistentDataSnapshot::getExpire(const char *key) {
/* No expire? return ASAP */ /* No expire? return ASAP */
std::unique_lock<fastlock> ul(g_expireLock);
if (expireSize() == 0) if (expireSize() == 0)
return nullptr; return nullptr;
@ -2727,8 +2728,11 @@ void redisDbPersistentData::clear(void(callback)(void*))
m_cnewKeysPending = 0; m_cnewKeysPending = 0;
m_fAllChanged++; m_fAllChanged++;
} }
{
std::unique_lock<fastlock> ul(g_expireLock);
delete m_setexpire; delete m_setexpire;
m_setexpire = new (MALLOC_LOCAL) expireset(); m_setexpire = new (MALLOC_LOCAL) expireset();
}
if (m_spstorage != nullptr) if (m_spstorage != nullptr)
m_spstorage->clear(callback); m_spstorage->clear(callback);
dictEmpty(m_pdictTombstone,callback); dictEmpty(m_pdictTombstone,callback);
@ -2862,6 +2866,7 @@ LNotFound:
dictAdd(m_pdict, sdsNewKey, o); dictAdd(m_pdict, sdsNewKey, o);
o->SetFExpires(spexpire != nullptr); o->SetFExpires(spexpire != nullptr);
std::unique_lock<fastlock> ul(g_expireLock);
if (spexpire != nullptr) if (spexpire != nullptr)
{ {
auto itr = m_setexpire->find(sdsKey); auto itr = m_setexpire->find(sdsKey);
@ -2884,6 +2889,7 @@ LNotFound:
if (*pde != nullptr && dictGetVal(*pde) != nullptr) if (*pde != nullptr && dictGetVal(*pde) != nullptr)
{ {
robj *o = (robj*)dictGetVal(*pde); robj *o = (robj*)dictGetVal(*pde);
std::unique_lock<fastlock> ul(g_expireLock);
serverAssert(o->FExpires() == (m_setexpire->find(sdsKey) != m_setexpire->end())); serverAssert(o->FExpires() == (m_setexpire->find(sdsKey) != m_setexpire->end()));
} }
} }
@ -3256,6 +3262,7 @@ std::unique_ptr<expireEntry> deserializeExpire(sds key, const char *str, size_t
sds serializeStoredObjectAndExpire(redisDbPersistentData *db, const char *key, robj_roptr o) sds serializeStoredObjectAndExpire(redisDbPersistentData *db, const char *key, robj_roptr o)
{ {
std::unique_lock<fastlock> ul(g_expireLock);
auto itrExpire = db->setexpire()->find(key); auto itrExpire = db->setexpire()->find(key);
const expireEntry *pexpire = nullptr; const expireEntry *pexpire = nullptr;
if (itrExpire != db->setexpire()->end()) if (itrExpire != db->setexpire()->end())
@ -3380,6 +3387,7 @@ void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command
dictAdd(m_pdict, sharedKey, o); dictAdd(m_pdict, sharedKey, o);
o->SetFExpires(spexpire != nullptr); o->SetFExpires(spexpire != nullptr);
std::unique_lock<fastlock> ul(g_expireLock);
if (spexpire != nullptr) if (spexpire != nullptr)
{ {
auto itr = m_setexpire->find(sharedKey); auto itr = m_setexpire->find(sharedKey);

View File

@ -481,6 +481,7 @@ void expireSlaveKeys(void) {
if (slaveKeysWithExpire == NULL || if (slaveKeysWithExpire == NULL ||
dictSize(slaveKeysWithExpire) == 0) return; dictSize(slaveKeysWithExpire) == 0) return;
std::unique_lock<fastlock> ul(g_expireLock);
int cycles = 0, noexpire = 0; int cycles = 0, noexpire = 0;
mstime_t start = mstime(); mstime_t start = mstime();
while(1) { while(1) {

View File

@ -1668,6 +1668,7 @@ robj *deserializeStoredObjectCore(const void *data, size_t cb)
robj *deserializeStoredObject(const redisDbPersistentData *db, const char *key, const void *data, size_t cb) robj *deserializeStoredObject(const redisDbPersistentData *db, const char *key, const void *data, size_t cb)
{ {
robj *o = deserializeStoredObjectCore(data, cb); robj *o = deserializeStoredObjectCore(data, cb);
std::unique_lock<fastlock> ul(g_expireLock);
o->SetFExpires(db->setexpire()->exists(key)); o->SetFExpires(db->setexpire()->exists(key));
return o; return o;
} }

View File

@ -26,7 +26,11 @@ then
while [ $((PORT < ENDPORT)) != "0" ]; do while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1)) PORT=$((PORT+1))
echo "Starting $PORT" echo "Starting $PORT"
$BIN_PATH/keydb-server --port $PORT --protected-mode $PROTECTED_MODE --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes ${ADDITIONAL_OPTIONS} if [ "$2" == "flash" ]
then
ADDITIONAL_OPTIONS="--save \"\" \"\" \"\" --semi-ordered-set-bucket-size 8 --client-output-buffer-limit replica 1 1 0 --maxmemory 100000000 --storage-provider flash ./$PORT.flash"
fi
$BIN_PATH/keydb-server --server-threads 4 --port $PORT --protected-mode $PROTECTED_MODE --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes ${ADDITIONAL_OPTIONS}
done done
exit 0 exit 0
fi fi
@ -97,6 +101,8 @@ then
rm -rf appendonly*.aof rm -rf appendonly*.aof
rm -rf dump*.rdb rm -rf dump*.rdb
rm -rf nodes*.conf rm -rf nodes*.conf
rm -rf *.flash
rm -rf temp*.rdb
exit 0 exit 0
fi fi