Skip to content

Commit a6f5a39

Browse files
committed
Merge branch 'unstable' into RELEASE_6
2 parents a6782a3 + 676644f commit a6f5a39

27 files changed

+693
-373
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
- uses: actions/checkout@v1
1111
- name: make
1212
run: |
13+
sudo apt-get update
1314
sudo apt-get -y install uuid-dev libcurl4-openssl-dev
1415
make BUILD_TLS=yes -j2
1516
- name: gen-cert
@@ -34,6 +35,7 @@ jobs:
3435
- uses: actions/checkout@v1
3536
- name: make -j2
3637
run: |
38+
sudo apt-get update
3739
sudo apt-get -y install uuid-dev libcurl4-openssl-dev
3840
make -j2
3941
@@ -50,6 +52,7 @@ jobs:
5052
- uses: actions/checkout@v1
5153
- name: make
5254
run: |
55+
sudo apt-get update
5356
sudo apt-get -y install uuid-dev libcurl4-openssl-dev
5457
make MALLOC=libc -j2
5558

.github/workflows/endurance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
make -j8
1818
- name: test-multithread (5X)
1919
run: |
20-
sudo apt-get install -y tcl8.5
20+
sudo apt-get install -y tcl tcl-tls
2121
./runtest --loopn 5 --config server-threads 3 --clients 5 --endurance
2222

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
![Current Release](https://img.shields.io/github/release/JohnSully/KeyDB.svg)
22
![CI](https://github.com/JohnSully/KeyDB/workflows/CI/badge.svg?branch=unstable)
3-
[![Join the chat at https://gitter.im/KeyDB/community](https://badges.gitter.im/KeyDB/community.svg)](https://gitter.im/KeyDB/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
43
[![StackShare](http://img.shields.io/badge/tech-stack-0690fa.svg?style=flat)](https://stackshare.io/eq-alpha-technology-inc/eq-alpha-technology-inc)
54

65
##### New! Want to extend KeyDB with Javascript? Try [ModJS](https://github.com/JohnSully/ModJS)

TLS.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ Note that unlike Redis, KeyDB fully supports multithreading of TLS connections.
5656
To-Do List
5757
----------
5858

59-
- [ ] Add session caching support. Check if/how it's handled by clients to
60-
assess how useful/important it is.
6159
- [ ] redis-benchmark support. The current implementation is a mix of using
6260
hiredis for parsing and basic networking (establishing connections), but
6361
directly manipulating sockets for most actions. This will need to be cleaned

keydb.conf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ tcp-keepalive 300
199199
#
200200
# tls-prefer-server-ciphers yes
201201

202+
# By default, TLS session caching is enabled to allow faster and less expensive
203+
# reconnections by clients that support it. Use the following directive to disable
204+
# caching.
205+
#
206+
# tls-session-caching no
207+
208+
# Change the default number of TLS sessions cached. A zero value sets the cache
209+
# to unlimited size. The default size is 20480.
210+
#
211+
# tls-session-cache-size 5000
212+
213+
# Change the default timeout of cached TLS sessions. The default timeout is 300
214+
# seconds.
215+
#
216+
# tls-session-cache-timeout 60
217+
202218
################################# GENERAL #####################################
203219

204220
# By default KeyDB does not run as a daemon. Use 'yes' if you need it.
@@ -401,6 +417,20 @@ dir ./
401417
#
402418
replica-serve-stale-data yes
403419

420+
# Active Replicas will allow read only data access while loading remote RDBs
421+
# provided they are permitted to serve stale data. As an option you may also
422+
# permit them to accept write commands. This is an EXPERIMENTAL feature and
423+
# may result in commands not being fully synchronized
424+
#
425+
# allow-write-during-load no
426+
427+
# You can modify the number of masters necessary to form a replica quorum when
428+
# multi-master is enabled and replica-serve-stale-data is "no". By default
429+
# this is set to -1 which implies the number of known masters (e.g. those
430+
# you added with replicaof)
431+
#
432+
# replica-quorum -1
433+
404434
# You can configure a replica instance to accept writes or not. Writing against
405435
# a replica instance may be useful to store some ephemeral data (because data
406436
# written on a replica will be easily deleted after resync with the master) but

src/ae.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask,
258258

259259
if (fSynchronous)
260260
{
261+
{
261262
std::unique_lock<std::mutex> ulock(cmd.pctl->mutexcv, std::adopt_lock);
262263
cmd.pctl->cv.wait(ulock);
263264
ret = cmd.pctl->rval;
265+
}
264266
delete cmd.pctl;
265267
}
266268

@@ -300,7 +302,7 @@ int aePostFunction(aeEventLoop *eventLoop, std::function<void()> fn, bool fSynch
300302
cmd.fLock = fLock;
301303
if (fSynchronous)
302304
{
303-
cmd.pctl = new (MALLOC_LOCAL) aeCommandControl();
305+
cmd.pctl = new (MALLOC_LOCAL) aeCommandControl;
304306
cmd.pctl->mutexcv.lock();
305307
}
306308

@@ -311,9 +313,11 @@ int aePostFunction(aeEventLoop *eventLoop, std::function<void()> fn, bool fSynch
311313
int ret = AE_OK;
312314
if (fSynchronous)
313315
{
316+
{
314317
std::unique_lock<std::mutex> ulock(cmd.pctl->mutexcv, std::adopt_lock);
315318
cmd.pctl->cv.wait(ulock);
316319
ret = cmd.pctl->rval;
320+
}
317321
delete cmd.pctl;
318322
}
319323
return ret;

src/aelocker.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ class AeLocker
99
{
1010
}
1111

12-
void arm(client *c) // if a client is passed, then the client is already locked
12+
void arm(client *c, bool fIfNeeded = false) // if a client is passed, then the client is already locked
1313
{
1414
if (m_fArmed)
1515
return;
1616

17+
if (fIfNeeded && aeThreadOwnsLock())
18+
return;
19+
1720
serverAssertDebug(!GlobalLocksAcquired());
1821

1922
if (c != nullptr)

src/aof.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,8 @@ int rewriteAppendOnlyFileRio(rio *aof) {
14261426
/* Iterate this DB writing every entry */
14271427
while((de = dictNext(di)) != NULL) {
14281428
sds keystr;
1429-
robj key, *o;
1429+
redisObjectStack key;
1430+
robj *o = nullptr;
14301431

14311432
keystr = (sds)dictGetKey(de);
14321433
o = (robj*)dictGetVal(de);

src/config.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ static int updateTlsCfg(char *val, char *prev, const char **err) {
21802180
UNUSED(prev);
21812181
UNUSED(err);
21822182
if (tlsConfigure(&g_pserver->tls_ctx_config) == C_ERR) {
2183-
*err = "Unable to configure tls-cert-file. Check server logs.";
2183+
*err = "Unable to update TLS configuration. Check server logs.";
21842184
return 0;
21852185
}
21862186
return 1;
@@ -2190,6 +2190,12 @@ static int updateTlsCfgBool(int val, int prev, const char **err) {
21902190
UNUSED(prev);
21912191
return updateTlsCfg(NULL, NULL, err);
21922192
}
2193+
2194+
static int updateTlsCfgInt(long long val, long long prev, const char **err) {
2195+
UNUSED(val);
2196+
UNUSED(prev);
2197+
return updateTlsCfg(NULL, NULL, err);
2198+
}
21932199
#endif /* USE_OPENSSL */
21942200

21952201
int fDummy = false;
@@ -2230,6 +2236,8 @@ standardConfig configs[] = {
22302236
createBoolConfig("appendonly", NULL, MODIFIABLE_CONFIG, g_pserver->aof_enabled, 0, NULL, updateAppendonly),
22312237
createBoolConfig("cluster-allow-reads-when-down", NULL, MODIFIABLE_CONFIG, g_pserver->cluster_allow_reads_when_down, 0, NULL, NULL),
22322238
createBoolConfig("multi-master-no-forward", NULL, MODIFIABLE_CONFIG, cserver.multimaster_no_forward, 0, validateMultiMasterNoForward, NULL),
2239+
createBoolConfig("allow-write-during-load", NULL, MODIFIABLE_CONFIG, g_pserver->fWriteDuringActiveLoad, 0, NULL, NULL),
2240+
createBoolConfig("io-threads-do-reads", NULL, IMMUTABLE_CONFIG, fDummy, 0, NULL, NULL),
22332241

22342242
/* String Configs */
22352243
createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, g_pserver->acl_filename, "", NULL, NULL),
@@ -2287,6 +2295,7 @@ standardConfig configs[] = {
22872295
createIntConfig("min-replicas-to-write", "min-slaves-to-write", MODIFIABLE_CONFIG, 0, INT_MAX, g_pserver->repl_min_slaves_to_write, 0, INTEGER_CONFIG, NULL, updateGoodSlaves),
22882296
createIntConfig("min-replicas-max-lag", "min-slaves-max-lag", MODIFIABLE_CONFIG, 0, INT_MAX, g_pserver->repl_min_slaves_max_lag, 10, INTEGER_CONFIG, NULL, updateGoodSlaves),
22892297
createIntConfig("min-clients-per-thread", NULL, MODIFIABLE_CONFIG, 0, 400, cserver.thread_min_client_threshold, 50, INTEGER_CONFIG, NULL, NULL),
2298+
createIntConfig("replica-quorum", NULL, MODIFIABLE_CONFIG, -1, INT_MAX, g_pserver->repl_quorum, -1, INTEGER_CONFIG, NULL, NULL),
22902299
/* Unsigned int configs */
22912300
createUIntConfig("maxclients", NULL, MODIFIABLE_CONFIG, 1, UINT_MAX, g_pserver->maxclients, 10000, INTEGER_CONFIG, NULL, updateMaxclients),
22922301

@@ -2324,10 +2333,13 @@ standardConfig configs[] = {
23242333

23252334
#ifdef USE_OPENSSL
23262335
createIntConfig("tls-port", NULL, IMMUTABLE_CONFIG, 0, 65535, g_pserver->tls_port, 0, INTEGER_CONFIG, NULL, NULL), /* TCP port. */
2336+
createIntConfig("tls-session-cache-size", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, g_pserver->tls_ctx_config.session_cache_size, 20*1024, INTEGER_CONFIG, NULL, updateTlsCfgInt),
2337+
createIntConfig("tls-session-cache-timeout", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, g_pserver->tls_ctx_config.session_cache_timeout, 300, INTEGER_CONFIG, NULL, updateTlsCfgInt),
23272338
createBoolConfig("tls-cluster", NULL, MODIFIABLE_CONFIG, g_pserver->tls_cluster, 0, NULL, NULL),
23282339
createBoolConfig("tls-replication", NULL, MODIFIABLE_CONFIG, g_pserver->tls_replication, 0, NULL, NULL),
23292340
createBoolConfig("tls-auth-clients", NULL, MODIFIABLE_CONFIG, g_pserver->tls_auth_clients, 1, NULL, NULL),
23302341
createBoolConfig("tls-prefer-server-ciphers", NULL, MODIFIABLE_CONFIG, g_pserver->tls_ctx_config.prefer_server_ciphers, 0, NULL, updateTlsCfgBool),
2342+
createBoolConfig("tls-session-caching", NULL, MODIFIABLE_CONFIG, g_pserver->tls_ctx_config.session_caching, 1, NULL, updateTlsCfgBool),
23312343
createStringConfig("tls-cert-file", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, g_pserver->tls_ctx_config.cert_file, NULL, NULL, updateTlsCfg),
23322344
createStringConfig("tls-key-file", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, g_pserver->tls_ctx_config.key_file, NULL, NULL, updateTlsCfg),
23332345
createStringConfig("tls-dh-params-file", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, g_pserver->tls_ctx_config.dh_params_file, NULL, NULL, updateTlsCfg),

src/db.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static robj *lookupKey(redisDb *db, robj *key, int flags) {
9393
updateDbValAccess(de, flags);
9494

9595
if (flags & LOOKUP_UPDATEMVCC) {
96-
val->mvcc_tstamp = getMvccTstamp();
96+
setMvccTstamp(val, getMvccTstamp());
9797
}
9898
return val;
9999
} else {
@@ -206,7 +206,9 @@ int dbAddCore(redisDb *db, robj *key, robj *val) {
206206
serverAssert(!val->FExpires());
207207
sds copy = sdsdup(szFromObj(key));
208208
int retval = dictAdd(db->pdict, copy, val);
209-
val->mvcc_tstamp = key->mvcc_tstamp = getMvccTstamp();
209+
uint64_t mvcc = getMvccTstamp();
210+
setMvccTstamp(key, mvcc);
211+
setMvccTstamp(val, mvcc);
210212

211213
if (retval == DICT_OK)
212214
{
@@ -256,7 +258,7 @@ void dbOverwriteCore(redisDb *db, dictEntry *de, robj *key, robj *val, bool fUpd
256258
if (fUpdateMvcc) {
257259
if (val->getrefcount(std::memory_order_relaxed) == OBJ_SHARED_REFCOUNT)
258260
val = dupStringObject(val);
259-
val->mvcc_tstamp = getMvccTstamp();
261+
setMvccTstamp(val, getMvccTstamp());
260262
}
261263

262264
dictSetVal(db->pdict, de, val);
@@ -291,12 +293,12 @@ int dbMerge(redisDb *db, robj *key, robj *val, int fReplace)
291293
return (dbAddCore(db, key, val) == DICT_OK);
292294

293295
robj *old = (robj*)dictGetVal(de);
294-
if (old->mvcc_tstamp <= val->mvcc_tstamp)
296+
if (mvccFromObj(old) <= mvccFromObj(val))
295297
{
296298
dbOverwriteCore(db, de, key, val, false, true);
297299
return true;
298300
}
299-
301+
300302
return false;
301303
}
302304
else
@@ -1393,7 +1395,7 @@ void setExpire(client *c, redisDb *db, robj *key, robj *subkey, long long when)
13931395
db->setexpire->insert(e);
13941396
}
13951397

1396-
int writable_slave = listLength(g_pserver->masters) && g_pserver->repl_slave_ro == 0;
1398+
int writable_slave = listLength(g_pserver->masters) && g_pserver->repl_slave_ro == 0 && !g_pserver->fActiveReplica;
13971399
if (c && writable_slave && !(c->flags & CLIENT_MASTER))
13981400
rememberSlaveKeyWithExpire(db,key);
13991401
}
@@ -1430,7 +1432,7 @@ void setExpire(client *c, redisDb *db, robj *key, expireEntry &&e)
14301432
((robj*)dictGetVal(kde))->SetFExpires(true);
14311433

14321434

1433-
int writable_slave = listLength(g_pserver->masters) && g_pserver->repl_slave_ro == 0;
1435+
int writable_slave = listLength(g_pserver->masters) && g_pserver->repl_slave_ro == 0 && !g_pserver->fActiveReplica;
14341436
if (c && writable_slave && !(c->flags & CLIENT_MASTER))
14351437
rememberSlaveKeyWithExpire(db,key);
14361438
}
@@ -1486,7 +1488,6 @@ void propagateExpire(redisDb *db, robj *key, int lazy) {
14861488
void propagateSubkeyExpire(redisDb *db, int type, robj *key, robj *subkey)
14871489
{
14881490
robj *argv[3];
1489-
robj objT;
14901491
redisCommand *cmd = nullptr;
14911492
switch (type)
14921493
{

0 commit comments

Comments
 (0)