2012-11-08 18:25:23 +01:00
/* Redis Object implementation.
*
* Copyright ( c ) 2009 - 2012 , Salvatore Sanfilippo < antirez at gmail dot com >
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
*
* * Redistributions of source code must retain the above copyright notice ,
* this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS "
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
* CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
* CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE .
*/
2015-07-26 15:14:57 +02:00
# include "server.h"
2021-10-07 14:41:26 +03:00
# include "functions.h"
Fix zuiFind crash / RM_ScanKey hang on SET object listpack encoding (#11581)
In #11290, we added listpack encoding for SET object.
But forgot to support it in zuiFind, causes ZINTER, ZINTERSTORE,
ZINTERCARD, ZIDFF, ZDIFFSTORE to crash.
And forgot to support it in RM_ScanKey, causes it hang.
This PR add support SET listpack in zuiFind, and in RM_ScanKey.
And add tests for related commands to cover this case.
Other changes:
- There is no reason for zuiFind to go into the internals of the SET.
It can simply use setTypeIsMember and don't care about encoding.
- Remove the `#include "intset.h"` from server.h reduce the chance of
accidental intset API use.
- Move setTypeAddAux, setTypeRemoveAux and setTypeIsMemberAux
interfaces to the header.
- In scanGenericCommand, use setTypeInitIterator and setTypeNext
to handle OBJ_SET scan.
- In RM_ScanKey, improve hash scan mode, use lpGetValue like zset,
they can share code and better performance.
The zuiFind part fixes #11578
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
2022-12-09 23:08:01 +08:00
# include "intset.h" /* Compact integer set structure */
2010-07-29 22:13:31 +02:00
# include <math.h>
2011-11-14 15:34:44 +01:00
# include <ctype.h>
2010-06-22 00:07:48 +02:00
2014-05-12 11:09:07 -04:00
# ifdef __CYGWIN__
# define strtold(a,b) ((long double)strtod((a),(b)))
# endif
2016-05-09 18:01:09 +03:00
/* ===================== Creation and parsing of objects ==================== */
2010-06-22 00:07:48 +02:00
robj * createObject ( int type , void * ptr ) {
2010-11-04 10:09:30 +01:00
robj * o = zmalloc ( sizeof ( * o ) ) ;
2010-06-22 00:07:48 +02:00
o - > type = type ;
2015-07-26 15:28:00 +02:00
o - > encoding = OBJ_ENCODING_RAW ;
2010-06-22 00:07:48 +02:00
o - > ptr = ptr ;
o - > refcount = 1 ;
2010-11-04 10:09:30 +01:00
2016-07-15 12:12:52 +02:00
/* Set the LRU to the current lruclock (minutes resolution), or
* alternatively the LFU counter . */
if ( server . maxmemory_policy & MAXMEMORY_FLAG_LFU ) {
o - > lru = ( LFUGetTimeInMinutes ( ) < < 8 ) | LFU_INIT_VAL ;
} else {
o - > lru = LRU_CLOCK ( ) ;
}
2010-06-22 00:07:48 +02:00
return o ;
}
2015-07-30 11:46:31 +02:00
/* Set a special refcount in the object to make it "shared":
* incrRefCount and decrRefCount ( ) will test for this special refcount
* and will not touch the object . This way it is free to access shared
* objects such as small integers from different threads without any
* mutex .
*
2022-08-24 20:07:43 +08:00
* A common pattern to create shared objects :
2015-07-30 11:46:31 +02:00
*
* robj * myobject = makeObjectShared ( createObject ( . . . ) ) ;
*
*/
robj * makeObjectShared ( robj * o ) {
serverAssert ( o - > refcount = = 1 ) ;
o - > refcount = OBJ_SHARED_REFCOUNT ;
return o ;
}
2015-07-26 15:28:00 +02:00
/* Create a string object with encoding OBJ_ENCODING_RAW, that is a plain
2012-06-05 21:50:10 +02:00
* string object where o - > ptr points to a proper sds string . */
2015-03-11 16:59:56 +01:00
robj * createRawStringObject ( const char * ptr , size_t len ) {
2016-09-21 12:30:38 +03:00
return createObject ( OBJ_STRING , sdsnewlen ( ptr , len ) ) ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 15:28:00 +02:00
/* Create a string object with encoding OBJ_ENCODING_EMBSTR, that is
2012-06-05 21:50:10 +02:00
* an object where the sds string is actually an unmodifiable string
* allocated in the same chunk as the object itself . */
2015-03-11 16:59:56 +01:00
robj * createEmbeddedStringObject ( const char * ptr , size_t len ) {
2015-04-09 10:37:01 +03:00
robj * o = zmalloc ( sizeof ( robj ) + sizeof ( struct sdshdr8 ) + len + 1 ) ;
struct sdshdr8 * sh = ( void * ) ( o + 1 ) ;
2012-06-05 21:50:10 +02:00
2015-07-26 15:28:00 +02:00
o - > type = OBJ_STRING ;
o - > encoding = OBJ_ENCODING_EMBSTR ;
2012-06-05 21:50:10 +02:00
o - > ptr = sh + 1 ;
o - > refcount = 1 ;
2016-07-15 12:12:52 +02:00
if ( server . maxmemory_policy & MAXMEMORY_FLAG_LFU ) {
o - > lru = ( LFUGetTimeInMinutes ( ) < < 8 ) | LFU_INIT_VAL ;
} else {
o - > lru = LRU_CLOCK ( ) ;
}
2012-06-05 21:50:10 +02:00
sh - > len = len ;
2015-04-09 10:37:01 +03:00
sh - > alloc = len ;
sh - > flags = SDS_TYPE_8 ;
2017-02-23 03:04:08 -08:00
if ( ptr = = SDS_NOINIT )
sh - > buf [ len ] = ' \0 ' ;
else if ( ptr ) {
2012-06-05 21:50:10 +02:00
memcpy ( sh - > buf , ptr , len ) ;
sh - > buf [ len ] = ' \0 ' ;
} else {
memset ( sh - > buf , 0 , len + 1 ) ;
}
return o ;
}
/* Create a string object with EMBSTR encoding if it is smaller than
2016-05-30 16:57:36 +08:00
* OBJ_ENCODING_EMBSTR_SIZE_LIMIT , otherwise the RAW encoding is
2014-05-07 17:05:09 +02:00
* used .
*
2018-02-22 20:57:54 -06:00
* The current limit of 44 is chosen so that the biggest string object
2014-05-07 17:05:09 +02:00
* we allocate as EMBSTR will still fit into the 64 byte arena of jemalloc . */
2015-07-26 15:28:00 +02:00
# define OBJ_ENCODING_EMBSTR_SIZE_LIMIT 44
2015-03-11 16:59:56 +01:00
robj * createStringObject ( const char * ptr , size_t len ) {
2015-07-26 15:28:00 +02:00
if ( len < = OBJ_ENCODING_EMBSTR_SIZE_LIMIT )
2012-06-05 21:50:10 +02:00
return createEmbeddedStringObject ( ptr , len ) ;
else
return createRawStringObject ( ptr , len ) ;
}
2021-08-05 22:56:14 +03:00
/* Same as CreateRawStringObject, can return NULL if allocation fails */
robj * tryCreateRawStringObject ( const char * ptr , size_t len ) {
sds str = sdstrynewlen ( ptr , len ) ;
if ( ! str ) return NULL ;
return createObject ( OBJ_STRING , str ) ;
}
/* Same as createStringObject, can return NULL if allocation fails */
robj * tryCreateStringObject ( const char * ptr , size_t len ) {
if ( len < = OBJ_ENCODING_EMBSTR_SIZE_LIMIT )
return createEmbeddedStringObject ( ptr , len ) ;
else
return tryCreateRawStringObject ( ptr , len ) ;
}
2018-06-18 16:54:13 +02:00
/* Create a string object from a long long value. When possible returns a
* shared integer object , or at least an integer encoded one .
*
Squash merging 125 typo/grammar/comment/doc PRs (#7773)
List of squashed commits or PRs
===============================
commit 66801ea
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Jan 13 00:54:31 2020 -0500
typo fix in acl.c
commit 46f55db
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun Sep 6 18:24:11 2020 +0300
Updates a couple of comments
Specifically:
* RM_AutoMemory completed instead of pointing to docs
* Updated link to custom type doc
commit 61a2aa0
Author: xindoo <xindoo@qq.com>
Date: Tue Sep 1 19:24:59 2020 +0800
Correct errors in code comments
commit a5871d1
Author: yz1509 <pro-756@qq.com>
Date: Tue Sep 1 18:36:06 2020 +0800
fix typos in module.c
commit 41eede7
Author: bookug <bookug@qq.com>
Date: Sat Aug 15 01:11:33 2020 +0800
docs: fix typos in comments
commit c303c84
Author: lazy-snail <ws.niu@outlook.com>
Date: Fri Aug 7 11:15:44 2020 +0800
fix spelling in redis.conf
commit 1eb76bf
Author: zhujian <zhujianxyz@gmail.com>
Date: Thu Aug 6 15:22:10 2020 +0800
add a missing 'n' in comment
commit 1530ec2
Author: Daniel Dai <764122422@qq.com>
Date: Mon Jul 27 00:46:35 2020 -0400
fix spelling in tracking.c
commit e517b31
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:32 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit c300eff
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:23 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit 4c058a8
Author: 陈浩鹏 <chenhaopeng@heytea.com>
Date: Thu Jun 25 19:00:56 2020 +0800
Grammar fix and clarification
commit 5fcaa81
Author: bodong.ybd <bodong.ybd@alibaba-inc.com>
Date: Fri Jun 19 10:09:00 2020 +0800
Fix typos
commit 4caca9a
Author: Pruthvi P <pruthvi@ixigo.com>
Date: Fri May 22 00:33:22 2020 +0530
Fix typo eviciton => eviction
commit b2a25f6
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Sun May 17 12:39:59 2020 -0400
Fix a typo.
commit 12842ae
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun May 3 17:16:59 2020 -0400
fix spelling in redis conf
commit ddba07c
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sat May 2 23:25:34 2020 +0100
Correct a "conflicts" spelling error.
commit 8fc7bf2
Author: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Date: Thu Apr 30 10:25:27 2020 +0900
docs: fix EXPIRE_FAST_CYCLE_DURATION to ACTIVE_EXPIRE_CYCLE_FAST_DURATION
commit 9b2b67a
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Fri Apr 24 11:46:22 2020 -0400
Fix a typo.
commit 0746f10
Author: devilinrust <63737265+devilinrust@users.noreply.github.com>
Date: Thu Apr 16 00:17:53 2020 +0200
Fix typos in server.c
commit 92b588d
Author: benjessop12 <56115861+benjessop12@users.noreply.github.com>
Date: Mon Apr 13 13:43:55 2020 +0100
Fix spelling mistake in lazyfree.c
commit 1da37aa
Merge: 2d4ba28 af347a8
Author: hwware <wen.hui.ware@gmail.com>
Date: Thu Mar 5 22:41:31 2020 -0500
Merge remote-tracking branch 'upstream/unstable' into expiretypofix
commit 2d4ba28
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Mar 2 00:09:40 2020 -0500
fix typo in expire.c
commit 1a746f7
Author: SennoYuki <minakami1yuki@gmail.com>
Date: Thu Feb 27 16:54:32 2020 +0800
fix typo
commit 8599b1a
Author: dongheejeong <donghee950403@gmail.com>
Date: Sun Feb 16 20:31:43 2020 +0000
Fix typo in server.c
commit f38d4e8
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun Feb 2 22:58:38 2020 -0500
fix typo in evict.c
commit fe143fc
Author: Leo Murillo <leonardo.murillo@gmail.com>
Date: Sun Feb 2 01:57:22 2020 -0600
Fix a few typos in redis.conf
commit 1ab4d21
Author: viraja1 <anchan.viraj@gmail.com>
Date: Fri Dec 27 17:15:58 2019 +0530
Fix typo in Latency API docstring
commit ca1f70e
Author: gosth <danxuedexing@qq.com>
Date: Wed Dec 18 15:18:02 2019 +0800
fix typo in sort.c
commit a57c06b
Author: ZYunH <zyunhjob@163.com>
Date: Mon Dec 16 22:28:46 2019 +0800
fix-zset-typo
commit b8c92b5
Author: git-hulk <hulk.website@gmail.com>
Date: Mon Dec 16 15:51:42 2019 +0800
FIX: typo in cluster.c, onformation->information
commit 9dd981c
Author: wujm2007 <jim.wujm@gmail.com>
Date: Mon Dec 16 09:37:52 2019 +0800
Fix typo
commit e132d7a
Author: Sebastien Williams-Wynn <s.williamswynn.mail@gmail.com>
Date: Fri Nov 15 00:14:07 2019 +0000
Minor typo change
commit 47f44d5
Author: happynote3966 <01ssrmikururudevice01@gmail.com>
Date: Mon Nov 11 22:08:48 2019 +0900
fix comment typo in redis-cli.c
commit b8bdb0d
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 18:00:17 2019 +0800
Fix a spelling mistake of comments in defragDictBucketCallback
commit 0def46a
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 13:09:27 2019 +0800
fix some spelling mistakes of comments in defrag.c
commit f3596fd
Author: Phil Rajchgot <tophil@outlook.com>
Date: Sun Oct 13 02:02:32 2019 -0400
Typo and grammar fixes
Redis and its documentation are great -- just wanted to submit a few corrections in the spirit of Hacktoberfest. Thanks for all your work on this project. I use it all the time and it works beautifully.
commit 2b928cd
Author: KangZhiDong <worldkzd@gmail.com>
Date: Sun Sep 1 07:03:11 2019 +0800
fix typos
commit 33aea14
Author: Axlgrep <axlgrep@gmail.com>
Date: Tue Aug 27 11:02:18 2019 +0800
Fixed eviction spelling issues
commit e282a80
Author: Simen Flatby <simen@oms.no>
Date: Tue Aug 20 15:25:51 2019 +0200
Update comments to reflect prop name
In the comments the prop is referenced as replica-validity-factor,
but it is really named cluster-replica-validity-factor.
commit 74d1f9a
Author: Jim Green <jimgreen2013@qq.com>
Date: Tue Aug 20 20:00:31 2019 +0800
fix comment error, the code is ok
commit eea1407
Author: Liao Tonglang <liaotonglang@gmail.com>
Date: Fri May 31 10:16:18 2019 +0800
typo fix
fix cna't to can't
commit 0da553c
Author: KAWACHI Takashi <tkawachi@gmail.com>
Date: Wed Jul 17 00:38:16 2019 +0900
Fix typo
commit 7fc8fb6
Author: Michael Prokop <mika@grml.org>
Date: Tue May 28 17:58:42 2019 +0200
Typo fixes
s/familar/familiar/
s/compatiblity/compatibility/
s/ ot / to /
s/itsef/itself/
commit 5f46c9d
Author: zhumoing <34539422+zhumoing@users.noreply.github.com>
Date: Tue May 21 21:16:50 2019 +0800
typo-fixes
typo-fixes
commit 321dfe1
Author: wxisme <850885154@qq.com>
Date: Sat Mar 16 15:10:55 2019 +0800
typo fix
commit b4fb131
Merge: 267e0e6 3df1eb8
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Fri Feb 8 22:55:45 2019 +0200
Merge branch 'unstable' of antirez/redis into unstable
commit 267e0e6
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Wed Jan 30 21:26:04 2019 +0200
Minor typo fix
commit 30544e7
Author: inshal96 <39904558+inshal96@users.noreply.github.com>
Date: Fri Jan 4 16:54:50 2019 +0500
remove an extra 'a' in the comments
commit 337969d
Author: BrotherGao <yangdongheng11@gmail.com>
Date: Sat Dec 29 12:37:29 2018 +0800
fix typo in redis.conf
commit 9f4b121
Merge: 423a030 e504583
Author: BrotherGao <yangdongheng@xiaomi.com>
Date: Sat Dec 29 11:41:12 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 423a030
Merge: 42b02b7 46a51cd
Author: 杨东衡 <yangdongheng@xiaomi.com>
Date: Tue Dec 4 23:56:11 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 42b02b7
Merge: 68c0e6e b8febe6
Author: Dongheng Yang <yangdongheng11@gmail.com>
Date: Sun Oct 28 15:54:23 2018 +0800
Merge pull request #1 from antirez/unstable
update local data
commit 714b589
Author: Christian <crifei93@gmail.com>
Date: Fri Dec 28 01:17:26 2018 +0100
fix typo "resulution"
commit e23259d
Author: garenchan <1412950785@qq.com>
Date: Wed Dec 26 09:58:35 2018 +0800
fix typo: segfauls -> segfault
commit a9359f8
Author: xjp <jianping_xie@aliyun.com>
Date: Tue Dec 18 17:31:44 2018 +0800
Fixed REDISMODULE_H spell bug
commit a12c3e4
Author: jdiaz <jrd.palacios@gmail.com>
Date: Sat Dec 15 23:39:52 2018 -0600
Fixes hyperloglog hash function comment block description
commit 770eb11
Author: 林上耀 <1210tom@163.com>
Date: Sun Nov 25 17:16:10 2018 +0800
fix typo
commit fd97fbb
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Fri Nov 23 17:14:01 2018 +0100
Correct "unsupported" typo.
commit a85522d
Author: Jungnam Lee <jungnam.lee@oracle.com>
Date: Thu Nov 8 23:01:29 2018 +0900
fix typo in test comments
commit ade8007
Author: Arun Kumar <palerdot@users.noreply.github.com>
Date: Tue Oct 23 16:56:35 2018 +0530
Fixed grammatical typo
Fixed typo for word 'dictionary'
commit 869ee39
Author: Hamid Alaei <hamid.a85@gmail.com>
Date: Sun Aug 12 16:40:02 2018 +0430
fix documentations: (ThreadSafeContextStart/Stop -> ThreadSafeContextLock/Unlock), minor typo
commit f89d158
Author: Mayank Jain <mayankjain255@gmail.com>
Date: Tue Jul 31 23:01:21 2018 +0530
Updated README.md with some spelling corrections.
Made correction in spelling of some misspelled words.
commit 892198e
Author: dsomeshwar <someshwar.dhayalan@gmail.com>
Date: Sat Jul 21 23:23:04 2018 +0530
typo fix
commit 8a4d780
Author: Itamar Haber <itamar@redislabs.com>
Date: Mon Apr 30 02:06:52 2018 +0300
Fixes some typos
commit e3acef6
Author: Noah Rosamilia <ivoahivoah@gmail.com>
Date: Sat Mar 3 23:41:21 2018 -0500
Fix typo in /deps/README.md
commit 04442fb
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:32:42 2018 +0800
Fix typo in readSyncBulkPayload() comment.
commit 9f36880
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:20:37 2018 +0800
replication.c comment: run_id -> replid.
commit f866b4a
Author: Francesco 'makevoid' Canessa <makevoid@gmail.com>
Date: Thu Feb 22 22:01:56 2018 +0000
fix comment typo in server.c
commit 0ebc69b
Author: 줍 <jubee0124@gmail.com>
Date: Mon Feb 12 16:38:48 2018 +0900
Fix typo in redis.conf
Fix `five behaviors` to `eight behaviors` in [this sentence ](antirez/redis@unstable/redis.conf#L564)
commit b50a620
Author: martinbroadhurst <martinbroadhurst@users.noreply.github.com>
Date: Thu Dec 28 12:07:30 2017 +0000
Fix typo in valgrind.sup
commit 7d8f349
Author: Peter Boughton <peter@sorcerersisle.com>
Date: Mon Nov 27 19:52:19 2017 +0000
Update CONTRIBUTING; refer doc updates to redis-doc repo.
commit 02dec7e
Author: Klauswk <klauswk1@hotmail.com>
Date: Tue Oct 24 16:18:38 2017 -0200
Fix typo in comment
commit e1efbc8
Author: chenshi <baiwfg2@gmail.com>
Date: Tue Oct 3 18:26:30 2017 +0800
Correct two spelling errors of comments
commit 93327d8
Author: spacewander <spacewanderlzx@gmail.com>
Date: Wed Sep 13 16:47:24 2017 +0800
Update the comment for OBJ_ENCODING_EMBSTR_SIZE_LIMIT's value
The value of OBJ_ENCODING_EMBSTR_SIZE_LIMIT is 44 now instead of 39.
commit 63d361f
Author: spacewander <spacewanderlzx@gmail.com>
Date: Tue Sep 12 15:06:42 2017 +0800
Fix <prevlen> related doc in ziplist.c
According to the definition of ZIP_BIG_PREVLEN and other related code,
the guard of single byte <prevlen> should be 254 instead of 255.
commit ebe228d
Author: hanael80 <hanael80@gmail.com>
Date: Tue Aug 15 09:09:40 2017 +0900
Fix typo
commit 6b696e6
Author: Matt Robenolt <matt@ydekproductions.com>
Date: Mon Aug 14 14:50:47 2017 -0700
Fix typo in LATENCY DOCTOR output
commit a2ec6ae
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 15 14:15:16 2017 +0800
Fix a typo: form => from
commit 3ab7699
Author: caosiyang <caosiyang@qiyi.com>
Date: Thu Aug 10 18:40:33 2017 +0800
Fix a typo: replicationFeedSlavesFromMaster() => replicationFeedSlavesFromMasterStream()
commit 72d43ef
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 8 15:57:25 2017 +0800
fix a typo: servewr => server
commit 707c958
Author: Bo Cai <charpty@gmail.com>
Date: Wed Jul 26 21:49:42 2017 +0800
redis-cli.c typo: conut -> count.
Signed-off-by: Bo Cai <charpty@gmail.com>
commit b9385b2
Author: JackDrogon <jack.xsuperman@gmail.com>
Date: Fri Jun 30 14:22:31 2017 +0800
Fix some spell problems
commit 20d9230
Author: akosel <aaronjkosel@gmail.com>
Date: Sun Jun 4 19:35:13 2017 -0500
Fix typo
commit b167bfc
Author: Krzysiek Witkowicz <krzysiekwitkowicz@gmail.com>
Date: Mon May 22 21:32:27 2017 +0100
Fix #4008 small typo in comment
commit 2b78ac8
Author: Jake Clarkson <jacobwclarkson@gmail.com>
Date: Wed Apr 26 15:49:50 2017 +0100
Correct typo in tests/unit/hyperloglog.tcl
commit b0f1cdb
Author: Qi Luo <qiluo-msft@users.noreply.github.com>
Date: Wed Apr 19 14:25:18 2017 -0700
Fix typo
commit a90b0f9
Author: charsyam <charsyam@naver.com>
Date: Thu Mar 16 18:19:53 2017 +0900
fix typos
fix typos
fix typos
commit 8430a79
Author: Richard Hart <richardhart92@gmail.com>
Date: Mon Mar 13 22:17:41 2017 -0400
Fixed log message typo in listenToPort.
commit 481a1c2
Author: Vinod Kumar <kumar003vinod@gmail.com>
Date: Sun Jan 15 23:04:51 2017 +0530
src/db.c: Correct "save" -> "safe" typo
commit 586b4d3
Author: wangshaonan <wshn13@gmail.com>
Date: Wed Dec 21 20:28:27 2016 +0800
Fix typo they->the in helloworld.c
commit c1c4b5e
Author: Jenner <hypxm@qq.com>
Date: Mon Dec 19 16:39:46 2016 +0800
typo error
commit 1ee1a3f
Author: tielei <43289893@qq.com>
Date: Mon Jul 18 13:52:25 2016 +0800
fix some comments
commit 11a41fb
Author: Otto Kekäläinen <otto@seravo.fi>
Date: Sun Jul 3 10:23:55 2016 +0100
Fix spelling in documentation and comments
commit 5fb5d82
Author: francischan <f1ancis621@gmail.com>
Date: Tue Jun 28 00:19:33 2016 +0800
Fix outdated comments about redis.c file.
It should now refer to server.c file.
commit 6b254bc
Author: lmatt-bit <lmatt123n@gmail.com>
Date: Thu Apr 21 21:45:58 2016 +0800
Refine the comment of dictRehashMilliseconds func
SLAVECONF->REPLCONF in comment - by andyli029
commit ee9869f
Author: clark.kang <charsyam@naver.com>
Date: Tue Mar 22 11:09:51 2016 +0900
fix typos
commit f7b3b11
Author: Harisankar H <harisankarh@gmail.com>
Date: Wed Mar 9 11:49:42 2016 +0530
Typo correction: "faield" --> "failed"
Typo correction: "faield" --> "failed"
commit 3fd40fc
Author: Itamar Haber <itamar@redislabs.com>
Date: Thu Feb 25 10:31:51 2016 +0200
Fixes a typo in comments
commit 621c160
Author: Prayag Verma <prayag.verma@gmail.com>
Date: Mon Feb 1 12:36:20 2016 +0530
Fix typo in Readme.md
Spelling mistakes -
`eviciton` > `eviction`
`familar` > `familiar`
commit d7d07d6
Author: WonCheol Lee <toctoc21c@gmail.com>
Date: Wed Dec 30 15:11:34 2015 +0900
Typo fixed
commit a4dade7
Author: Felix Bünemann <buenemann@louis.info>
Date: Mon Dec 28 11:02:55 2015 +0100
[ci skip] Improve supervised upstart config docs
This mentions that "expect stop" is required for supervised upstart
to work correctly. See http://upstart.ubuntu.com/cookbook/#expect-stop
for an explanation.
commit d9caba9
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:30:03 2015 +1100
README: Remove trailing whitespace
commit 72d42e5
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:32 2015 +1100
README: Fix typo. th => the
commit dd6e957
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:20 2015 +1100
README: Fix typo. familar => familiar
commit 3a12b23
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:28:54 2015 +1100
README: Fix typo. eviciton => eviction
commit 2d1d03b
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:21:45 2015 +1100
README: Fix typo. sever => server
commit 3973b06
Author: Itamar Haber <itamar@garantiadata.com>
Date: Sat Dec 19 17:01:20 2015 +0200
Typo fix
commit 4f2e460
Author: Steve Gao <fu@2token.com>
Date: Fri Dec 4 10:22:05 2015 +0800
Update README - fix typos
commit b21667c
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:48:37 2015 +0800
delete redundancy color judge in sdscatcolor
commit 88894c7
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:14:42 2015 +0800
the example output shoule be HelloWorld
commit 2763470
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 17:41:39 2015 +0800
modify error word keyevente
Signed-off-by: binyan <binbin.yan@nokia.com>
commit 0847b3d
Author: Bruno Martins <bscmartins@gmail.com>
Date: Wed Nov 4 11:37:01 2015 +0000
typo
commit bbb9e9e
Author: dawedawe <dawedawe@gmx.de>
Date: Fri Mar 27 00:46:41 2015 +0100
typo: zimap -> zipmap
commit 5ed297e
Author: Axel Advento <badwolf.bloodseeker.rev@gmail.com>
Date: Tue Mar 3 15:58:29 2015 +0800
Fix 'salve' typos to 'slave'
commit edec9d6
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Wed Jun 12 14:12:47 2019 +0200
Update README.md
Co-Authored-By: Qix <Qix-@users.noreply.github.com>
commit 692a7af
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Tue May 28 14:32:04 2019 +0200
grammar
commit d962b0a
Author: Nick Frost <nickfrostatx@gmail.com>
Date: Wed Jul 20 15:17:12 2016 -0700
Minor grammar fix
commit 24fff01aaccaf5956973ada8c50ceb1462e211c6 (typos)
Author: Chad Miller <chadm@squareup.com>
Date: Tue Sep 8 13:46:11 2020 -0400
Fix faulty comment about operation of unlink()
commit 3cd5c1f3326c52aa552ada7ec797c6bb16452355
Author: Kevin <kevin.xgr@gmail.com>
Date: Wed Nov 20 00:13:50 2019 +0800
Fix typo in server.c.
From a83af59 Mon Sep 17 00:00:00 2001
From: wuwo <wuwo@wacai.com>
Date: Fri, 17 Mar 2017 20:37:45 +0800
Subject: [PATCH] falure to failure
From c961896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B7=A6=E6=87=B6?= <veficos@gmail.com>
Date: Sat, 27 May 2017 15:33:04 +0800
Subject: [PATCH] fix typo
From e600ef2 Mon Sep 17 00:00:00 2001
From: "rui.zou" <rui.zou@yunify.com>
Date: Sat, 30 Sep 2017 12:38:15 +0800
Subject: [PATCH] fix a typo
From c7d07fa Mon Sep 17 00:00:00 2001
From: Alexandre Perrin <alex@kaworu.ch>
Date: Thu, 16 Aug 2018 10:35:31 +0200
Subject: [PATCH] deps README.md typo
From b25cb67 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 10:55:37 +0300
Subject: [PATCH 1/2] fix typos in header
From ad28ca6 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 11:02:36 +0300
Subject: [PATCH 2/2] fix typos
commit 34924cdedd8552466fc22c1168d49236cb7ee915
Author: Adrian Lynch <adi_ady_ade@hotmail.com>
Date: Sat Apr 4 21:59:15 2015 +0100
Typos fixed
commit fd2a1e7
Author: Jan <jsteemann@users.noreply.github.com>
Date: Sat Oct 27 19:13:01 2018 +0200
Fix typos
Fix typos
commit e14e47c1a234b53b0e103c5f6a1c61481cbcbb02
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:30:07 2019 -0500
Fix multiple misspellings of "following"
commit 79b948ce2dac6b453fe80995abbcaac04c213d5a
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:24:28 2019 -0500
Fix misspelling of create-cluster
commit 1fffde52666dc99ab35efbd31071a4c008cb5a71
Author: Andy Lester <andy@petdance.com>
Date: Wed Jul 31 17:57:56 2019 -0500
Fix typos
commit 204c9ba9651e9e05fd73936b452b9a30be456cfe
Author: Xiaobo Zhu <xiaobo.zhu@shopee.com>
Date: Tue Aug 13 22:19:25 2019 +0800
fix typos
Squashed commit of the following:
commit 1d9aaf8
Author: danmedani <danmedani@gmail.com>
Date: Sun Aug 2 11:40:26 2015 -0700
README typo fix.
Squashed commit of the following:
commit 32bfa7c
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Jul 6 21:15:08 2015 +0200
Fixed grammer
Squashed commit of the following:
commit b24f69c
Author: Sisir Koppaka <sisir.koppaka@gmail.com>
Date: Mon Mar 2 22:38:45 2015 -0500
utils/hashtable/rehashing.c: Fix typos
Squashed commit of the following:
commit 4e04082
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Mar 23 08:22:21 2015 +0000
Small config file documentation improvements
Squashed commit of the following:
commit acb8773
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:52:48 2015 -0700
Typo and grammar fixes in readme
commit 2eb75b6
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:36:18 2015 -0700
fixed redis.conf comment
Squashed commit of the following:
commit a8249a2
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri Dec 11 11:39:52 2015 +0530
Revise correction of typos.
Squashed commit of the following:
commit 3c02028
Author: zhaojun11 <zhaojun11@jd.com>
Date: Wed Jan 17 19:05:28 2018 +0800
Fix typos include two code typos in cluster.c and latency.c
Squashed commit of the following:
commit 9dba47c
Author: q191201771 <191201771@qq.com>
Date: Sat Jan 4 11:31:04 2020 +0800
fix function listCreate comment in adlist.c
Update src/server.c
commit 2c7c2cb536e78dd211b1ac6f7bda00f0f54faaeb
Author: charpty <charpty@gmail.com>
Date: Tue May 1 23:16:59 2018 +0800
server.c typo: modules system dictionary type comment
Signed-off-by: charpty <charpty@gmail.com>
commit a8395323fb63cb59cb3591cb0f0c8edb7c29a680
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun May 6 00:25:18 2018 +0300
Updates test_helper.tcl's help with undocumented options
Specifically:
* Host
* Port
* Client
commit bde6f9ced15755cd6407b4af7d601b030f36d60b
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 15:19:19 2018 +0800
fix comments in deps files
commit 3172474ba991532ab799ee1873439f3402412331
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 14:33:49 2018 +0800
fix some comments
commit 01b6f2b6858b5cf2ce4ad5092d2c746e755f53f0
Author: Thor Juhasz <thor@juhasz.pro>
Date: Sun Nov 18 14:37:41 2018 +0100
Minor fixes to comments
Found some parts a little unclear on a first read, which prompted me to have a better look at the file and fix some minor things I noticed.
Fixing minor typos and grammar. There are no changes to configuration options.
These changes are only meant to help the user better understand the explanations to the various configuration options
2020-09-10 13:43:38 +03:00
* If valueobj is non zero , the function avoids returning a shared
2018-06-18 16:54:13 +02:00
* integer , because the object is going to be used as value in the Redis key
* space ( for instance when the INCR command is used ) , so we want LFU / LRU
* values specific for each key . */
robj * createStringObjectFromLongLongWithOptions ( long long value , int valueobj ) {
2010-06-22 00:07:48 +02:00
robj * o ;
2018-06-18 16:54:13 +02:00
if ( server . maxmemory = = 0 | |
! ( server . maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS ) )
{
/* If the maxmemory policy permits, we can still return shared integers
* even if valueobj is true . */
valueobj = 0 ;
}
if ( value > = 0 & & value < OBJ_SHARED_INTEGERS & & valueobj = = 0 ) {
2010-06-22 00:07:48 +02:00
o = shared . integers [ value ] ;
} else {
if ( value > = LONG_MIN & & value < = LONG_MAX ) {
2015-07-26 15:28:00 +02:00
o = createObject ( OBJ_STRING , NULL ) ;
o - > encoding = OBJ_ENCODING_INT ;
2010-06-22 00:07:48 +02:00
o - > ptr = ( void * ) ( ( long ) value ) ;
} else {
2015-07-26 15:28:00 +02:00
o = createObject ( OBJ_STRING , sdsfromlonglong ( value ) ) ;
2010-06-22 00:07:48 +02:00
}
}
return o ;
}
2018-06-18 16:54:13 +02:00
/* Wrapper for createStringObjectFromLongLongWithOptions() always demanding
* to create a shared object if possible . */
robj * createStringObjectFromLongLong ( long long value ) {
return createStringObjectFromLongLongWithOptions ( value , 0 ) ;
}
/* Wrapper for createStringObjectFromLongLongWithOptions() avoiding a shared
* object when LFU / LRU info are needed , that is , when the object is used
* as a value in the key space , and Redis is configured to evict based on
* LFU / LRU . */
robj * createStringObjectFromLongLongForValue ( long long value ) {
return createStringObjectFromLongLongWithOptions ( value , 1 ) ;
}
2014-12-02 18:19:30 +01:00
/* Create a string object from a long double. If humanfriendly is non-zero
* it does not use exponential format and trims trailing zeroes at the end ,
2014-12-03 10:33:00 +01:00
* however this results in loss of precision . Otherwise exp format is used
* and the output of snprintf ( ) is not modified .
*
* The ' humanfriendly ' option is used for INCRBYFLOAT and HINCRBYFLOAT . */
2014-12-02 18:19:30 +01:00
robj * createStringObjectFromLongDouble ( long double value , int humanfriendly ) {
2017-01-11 19:24:19 +02:00
char buf [ MAX_LONG_DOUBLE_CHARS ] ;
2019-11-03 16:42:31 +02:00
int len = ld2string ( buf , sizeof ( buf ) , value , humanfriendly ? LD_STR_HUMAN : LD_STR_AUTO ) ;
2011-11-12 19:27:35 +01:00
return createStringObject ( buf , len ) ;
}
2012-06-05 21:50:10 +02:00
/* Duplicate a string object, with the guarantee that the returned object
* has the same encoding as the original one .
*
2018-10-16 15:48:03 +08:00
* This function also guarantees that duplicating a small integer object
2012-06-05 21:50:10 +02:00
* ( or a string object that contains a representation of a small integer )
* will always result in a fresh object that is unshared ( refcount = = 1 ) .
*
* The resulting object always has refcount set to 1. */
2016-06-22 20:57:24 +03:00
robj * dupStringObject ( const robj * o ) {
2012-06-05 21:50:10 +02:00
robj * d ;
2015-07-26 15:29:53 +02:00
serverAssert ( o - > type = = OBJ_STRING ) ;
2012-06-05 21:50:10 +02:00
switch ( o - > encoding ) {
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_RAW :
2012-06-05 21:50:10 +02:00
return createRawStringObject ( o - > ptr , sdslen ( o - > ptr ) ) ;
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_EMBSTR :
2012-06-05 21:50:10 +02:00
return createEmbeddedStringObject ( o - > ptr , sdslen ( o - > ptr ) ) ;
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_INT :
d = createObject ( OBJ_STRING , NULL ) ;
d - > encoding = OBJ_ENCODING_INT ;
2012-06-05 21:50:10 +02:00
d - > ptr = o - > ptr ;
return d ;
default :
2015-07-27 09:41:48 +02:00
serverPanic ( " Wrong encoding. " ) ;
2012-06-05 21:50:10 +02:00
break ;
}
2010-06-22 00:07:48 +02:00
}
2014-11-13 14:11:47 -05:00
robj * createQuicklistObject ( void ) {
quicklist * l = quicklistCreate ( ) ;
2015-07-26 15:28:00 +02:00
robj * o = createObject ( OBJ_LIST , l ) ;
o - > encoding = OBJ_ENCODING_QUICKLIST ;
2010-06-22 00:07:48 +02:00
return o ;
}
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-17 02:29:46 +08:00
robj * createListListpackObject ( void ) {
unsigned char * lp = lpNew ( 0 ) ;
robj * o = createObject ( OBJ_LIST , lp ) ;
o - > encoding = OBJ_ENCODING_LISTPACK ;
return o ;
}
2010-06-22 00:07:48 +02:00
robj * createSetObject ( void ) {
2021-08-05 08:25:58 +03:00
dict * d = dictCreate ( & setDictType ) ;
2015-07-26 15:28:00 +02:00
robj * o = createObject ( OBJ_SET , d ) ;
o - > encoding = OBJ_ENCODING_HT ;
2010-07-02 19:57:12 +02:00
return o ;
}
robj * createIntsetObject ( void ) {
intset * is = intsetNew ( ) ;
2015-07-26 15:28:00 +02:00
robj * o = createObject ( OBJ_SET , is ) ;
o - > encoding = OBJ_ENCODING_INTSET ;
2010-07-02 19:57:12 +02:00
return o ;
2010-06-22 00:07:48 +02:00
}
2022-11-09 18:50:07 +01:00
robj * createSetListpackObject ( void ) {
unsigned char * lp = lpNew ( 0 ) ;
robj * o = createObject ( OBJ_SET , lp ) ;
o - > encoding = OBJ_ENCODING_LISTPACK ;
return o ;
}
2010-06-22 00:07:48 +02:00
robj * createHashObject ( void ) {
2021-08-10 14:18:49 +08:00
unsigned char * zl = lpNew ( 0 ) ;
2015-07-26 15:28:00 +02:00
robj * o = createObject ( OBJ_HASH , zl ) ;
2021-08-10 14:18:49 +08:00
o - > encoding = OBJ_ENCODING_LISTPACK ;
2010-06-22 00:07:48 +02:00
return o ;
}
robj * createZsetObject ( void ) {
zset * zs = zmalloc ( sizeof ( * zs ) ) ;
2011-04-06 15:36:10 +02:00
robj * o ;
2010-06-22 00:07:48 +02:00
2021-08-05 08:25:58 +03:00
zs - > dict = dictCreate ( & zsetDictType ) ;
2010-06-22 00:07:48 +02:00
zs - > zsl = zslCreate ( ) ;
2015-07-26 15:28:00 +02:00
o = createObject ( OBJ_ZSET , zs ) ;
o - > encoding = OBJ_ENCODING_SKIPLIST ;
2011-04-06 15:36:10 +02:00
return o ;
2010-06-22 00:07:48 +02:00
}
2021-09-09 23:18:53 +08:00
robj * createZsetListpackObject ( void ) {
unsigned char * lp = lpNew ( 0 ) ;
robj * o = createObject ( OBJ_ZSET , lp ) ;
o - > encoding = OBJ_ENCODING_LISTPACK ;
2011-03-08 16:08:52 +01:00
return o ;
}
2017-08-30 12:40:27 +02:00
robj * createStreamObject ( void ) {
stream * s = streamNew ( ) ;
robj * o = createObject ( OBJ_STREAM , s ) ;
o - > encoding = OBJ_ENCODING_STREAM ;
return o ;
}
2016-05-18 11:45:40 +02:00
robj * createModuleObject ( moduleType * mt , void * value ) {
moduleValue * mv = zmalloc ( sizeof ( * mv ) ) ;
mv - > type = mt ;
mv - > value = value ;
return createObject ( OBJ_MODULE , mv ) ;
}
2010-06-22 00:07:48 +02:00
void freeStringObject ( robj * o ) {
2015-07-26 15:28:00 +02:00
if ( o - > encoding = = OBJ_ENCODING_RAW ) {
2010-06-22 00:07:48 +02:00
sdsfree ( o - > ptr ) ;
}
}
void freeListObject ( robj * o ) {
2017-01-26 21:36:26 +09:00
if ( o - > encoding = = OBJ_ENCODING_QUICKLIST ) {
2014-11-13 14:11:47 -05:00
quicklistRelease ( o - > ptr ) ;
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-17 02:29:46 +08:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
lpFree ( o - > ptr ) ;
2017-01-26 21:36:26 +09:00
} else {
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown list encoding type " ) ;
2010-06-22 00:07:48 +02:00
}
}
void freeSetObject ( robj * o ) {
2010-07-02 19:57:12 +02:00
switch ( o - > encoding ) {
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_HT :
2010-07-02 19:57:12 +02:00
dictRelease ( ( dict * ) o - > ptr ) ;
break ;
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_INTSET :
2022-11-09 18:50:07 +01:00
case OBJ_ENCODING_LISTPACK :
2010-07-02 19:57:12 +02:00
zfree ( o - > ptr ) ;
break ;
default :
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown set encoding type " ) ;
2010-07-02 19:57:12 +02:00
}
2010-06-22 00:07:48 +02:00
}
void freeZsetObject ( robj * o ) {
2011-03-08 23:56:59 +01:00
zset * zs ;
switch ( o - > encoding ) {
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_SKIPLIST :
2011-03-08 23:56:59 +01:00
zs = o - > ptr ;
dictRelease ( zs - > dict ) ;
zslFree ( zs - > zsl ) ;
zfree ( zs ) ;
break ;
2021-09-09 23:18:53 +08:00
case OBJ_ENCODING_LISTPACK :
2011-03-08 23:56:59 +01:00
zfree ( o - > ptr ) ;
break ;
default :
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown sorted set encoding " ) ;
2011-03-08 23:56:59 +01:00
}
2010-06-22 00:07:48 +02:00
}
void freeHashObject ( robj * o ) {
switch ( o - > encoding ) {
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_HT :
2010-06-22 00:07:48 +02:00
dictRelease ( ( dict * ) o - > ptr ) ;
break ;
2021-08-10 14:18:49 +08:00
case OBJ_ENCODING_LISTPACK :
lpFree ( o - > ptr ) ;
2010-06-22 00:07:48 +02:00
break ;
default :
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown hash encoding type " ) ;
2010-06-22 00:07:48 +02:00
break ;
}
}
2016-05-18 11:45:40 +02:00
void freeModuleObject ( robj * o ) {
moduleValue * mv = o - > ptr ;
mv - > type - > free ( mv - > value ) ;
zfree ( mv ) ;
}
2017-09-06 13:11:47 +02:00
void freeStreamObject ( robj * o ) {
freeStream ( o - > ptr ) ;
}
2010-06-22 00:07:48 +02:00
void incrRefCount ( robj * o ) {
2020-04-09 16:20:41 +02:00
if ( o - > refcount < OBJ_FIRST_SPECIAL_REFCOUNT ) {
o - > refcount + + ;
} else {
if ( o - > refcount = = OBJ_SHARED_REFCOUNT ) {
/* Nothing to do: this refcount is immutable. */
} else if ( o - > refcount = = OBJ_STATIC_REFCOUNT ) {
serverPanic ( " You tried to retain an object allocated in the stack " ) ;
}
}
2010-06-22 00:07:48 +02:00
}
2013-01-24 11:27:10 +01:00
void decrRefCount ( robj * o ) {
2011-06-02 17:41:42 +02:00
if ( o - > refcount = = 1 ) {
2010-06-22 00:07:48 +02:00
switch ( o - > type ) {
2015-07-26 15:28:00 +02:00
case OBJ_STRING : freeStringObject ( o ) ; break ;
case OBJ_LIST : freeListObject ( o ) ; break ;
case OBJ_SET : freeSetObject ( o ) ; break ;
case OBJ_ZSET : freeZsetObject ( o ) ; break ;
case OBJ_HASH : freeHashObject ( o ) ; break ;
2016-05-18 11:45:40 +02:00
case OBJ_MODULE : freeModuleObject ( o ) ; break ;
2017-09-06 13:11:47 +02:00
case OBJ_STREAM : freeStreamObject ( o ) ; break ;
2015-07-27 09:41:48 +02:00
default : serverPanic ( " Unknown object type " ) ; break ;
2010-06-22 00:07:48 +02:00
}
2010-11-04 10:09:30 +01:00
zfree ( o ) ;
2011-06-02 17:41:42 +02:00
} else {
2015-07-30 11:46:31 +02:00
if ( o - > refcount < = 0 ) serverPanic ( " decrRefCount against refcount <= 0 " ) ;
if ( o - > refcount ! = OBJ_SHARED_REFCOUNT ) o - > refcount - - ;
2010-06-22 00:07:48 +02:00
}
}
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
/* See dismissObject() */
void dismissSds ( sds s ) {
dismissMemory ( sdsAllocPtr ( s ) , sdsAllocSize ( s ) ) ;
}
/* See dismissObject() */
void dismissStringObject ( robj * o ) {
if ( o - > encoding = = OBJ_ENCODING_RAW ) {
dismissSds ( o - > ptr ) ;
}
}
/* See dismissObject() */
void dismissListObject ( robj * o , size_t size_hint ) {
if ( o - > encoding = = OBJ_ENCODING_QUICKLIST ) {
quicklist * ql = o - > ptr ;
serverAssert ( ql - > len ! = 0 ) ;
/* We iterate all nodes only when average node size is bigger than a
* page size , and there ' s a high chance we ' ll actually dismiss something . */
if ( size_hint / ql - > len > = server . page_size ) {
quicklistNode * node = ql - > head ;
while ( node ) {
if ( quicklistNodeIsCompressed ( node ) ) {
2021-11-03 20:47:18 +02:00
dismissMemory ( node - > entry , ( ( quicklistLZF * ) node - > entry ) - > sz ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
} else {
2021-11-03 20:47:18 +02:00
dismissMemory ( node - > entry , node - > sz ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
}
node = node - > next ;
}
}
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-17 02:29:46 +08:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
dismissMemory ( o - > ptr , lpBytes ( ( unsigned char * ) o - > ptr ) ) ;
2021-08-10 21:54:19 +08:00
} else {
serverPanic ( " Unknown list encoding type " ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
}
}
/* See dismissObject() */
void dismissSetObject ( robj * o , size_t size_hint ) {
if ( o - > encoding = = OBJ_ENCODING_HT ) {
dict * set = o - > ptr ;
serverAssert ( dictSize ( set ) ! = 0 ) ;
/* We iterate all nodes only when average member size is bigger than a
* page size , and there ' s a high chance we ' ll actually dismiss something . */
if ( size_hint / dictSize ( set ) > = server . page_size ) {
dictEntry * de ;
dictIterator * di = dictGetIterator ( set ) ;
while ( ( de = dictNext ( di ) ) ! = NULL ) {
dismissSds ( dictGetKey ( de ) ) ;
}
dictReleaseIterator ( di ) ;
}
/* Dismiss hash table memory. */
2021-08-05 09:02:30 +03:00
dismissMemory ( set - > ht_table [ 0 ] , DICTHT_SIZE ( set - > ht_size_exp [ 0 ] ) * sizeof ( dictEntry * ) ) ;
dismissMemory ( set - > ht_table [ 1 ] , DICTHT_SIZE ( set - > ht_size_exp [ 1 ] ) * sizeof ( dictEntry * ) ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
} else if ( o - > encoding = = OBJ_ENCODING_INTSET ) {
dismissMemory ( o - > ptr , intsetBlobLen ( ( intset * ) o - > ptr ) ) ;
2022-11-09 18:50:07 +01:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
dismissMemory ( o - > ptr , lpBytes ( ( unsigned char * ) o - > ptr ) ) ;
2021-08-10 21:54:19 +08:00
} else {
serverPanic ( " Unknown set encoding type " ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
}
}
/* See dismissObject() */
void dismissZsetObject ( robj * o , size_t size_hint ) {
if ( o - > encoding = = OBJ_ENCODING_SKIPLIST ) {
zset * zs = o - > ptr ;
zskiplist * zsl = zs - > zsl ;
serverAssert ( zsl - > length ! = 0 ) ;
/* We iterate all nodes only when average member size is bigger than a
* page size , and there ' s a high chance we ' ll actually dismiss something . */
if ( size_hint / zsl - > length > = server . page_size ) {
zskiplistNode * zn = zsl - > tail ;
while ( zn ! = NULL ) {
dismissSds ( zn - > ele ) ;
zn = zn - > backward ;
}
}
/* Dismiss hash table memory. */
dict * d = zs - > dict ;
2021-08-05 09:02:30 +03:00
dismissMemory ( d - > ht_table [ 0 ] , DICTHT_SIZE ( d - > ht_size_exp [ 0 ] ) * sizeof ( dictEntry * ) ) ;
dismissMemory ( d - > ht_table [ 1 ] , DICTHT_SIZE ( d - > ht_size_exp [ 1 ] ) * sizeof ( dictEntry * ) ) ;
2021-09-09 23:18:53 +08:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
dismissMemory ( o - > ptr , lpBytes ( ( unsigned char * ) o - > ptr ) ) ;
2021-08-10 21:54:19 +08:00
} else {
serverPanic ( " Unknown zset encoding type " ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
}
}
/* See dismissObject() */
void dismissHashObject ( robj * o , size_t size_hint ) {
if ( o - > encoding = = OBJ_ENCODING_HT ) {
dict * d = o - > ptr ;
serverAssert ( dictSize ( d ) ! = 0 ) ;
/* We iterate all fields only when average field/value size is bigger than
* a page size , and there ' s a high chance we ' ll actually dismiss something . */
if ( size_hint / dictSize ( d ) > = server . page_size ) {
dictEntry * de ;
dictIterator * di = dictGetIterator ( d ) ;
while ( ( de = dictNext ( di ) ) ! = NULL ) {
/* Only dismiss values memory since the field size
* usually is small . */
dismissSds ( dictGetVal ( de ) ) ;
}
dictReleaseIterator ( di ) ;
}
/* Dismiss hash table memory. */
2021-08-05 09:02:30 +03:00
dismissMemory ( d - > ht_table [ 0 ] , DICTHT_SIZE ( d - > ht_size_exp [ 0 ] ) * sizeof ( dictEntry * ) ) ;
dismissMemory ( d - > ht_table [ 1 ] , DICTHT_SIZE ( d - > ht_size_exp [ 1 ] ) * sizeof ( dictEntry * ) ) ;
2021-08-10 21:54:19 +08:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
dismissMemory ( o - > ptr , lpBytes ( ( unsigned char * ) o - > ptr ) ) ;
} else {
serverPanic ( " Unknown hash encoding type " ) ;
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
}
}
/* See dismissObject() */
void dismissStreamObject ( robj * o , size_t size_hint ) {
stream * s = o - > ptr ;
rax * rax = s - > rax ;
if ( raxSize ( rax ) = = 0 ) return ;
/* Iterate only on stream entries, although size_hint may include serialized
* consumer groups info , but usually , stream entries take up most of
* the space . */
if ( size_hint / raxSize ( rax ) > = server . page_size ) {
raxIterator ri ;
raxStart ( & ri , rax ) ;
raxSeek ( & ri , " ^ " , NULL , 0 ) ;
while ( raxNext ( & ri ) ) {
dismissMemory ( ri . data , lpBytes ( ri . data ) ) ;
}
raxStop ( & ri ) ;
}
}
/* When creating a snapshot in a fork child process, the main process and child
* process share the same physical memory pages , and if / when the parent
* modifies any keys due to write traffic , it ' ll cause CoW which consume
* physical memory . In the child process , after serializing the key and value ,
* the data is definitely not accessed again , so to avoid unnecessary CoW , we
* try to release their memory back to OS . see dismissMemory ( ) .
*
* Because of the cost of iterating all node / field / member / entry of complex data
* types , we iterate and dismiss them only when approximate average we estimate
* the size of an individual allocation is more than a page size of OS .
* ' size_hint ' is the size of serialized value . This method is not accurate , but
* it can reduce unnecessary iteration for complex data types that are probably
* not going to release any memory . */
void dismissObject ( robj * o , size_t size_hint ) {
/* madvise(MADV_DONTNEED) may not work if Transparent Huge Pages is enabled. */
if ( server . thp_enabled ) return ;
2021-08-10 16:32:27 +08:00
/* Currently we use zmadvise_dontneed only when we use jemalloc with Linux.
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
* so we avoid these pointless loops when they ' re not going to do anything . */
2021-08-10 16:32:27 +08:00
# if defined(USE_JEMALLOC) && defined(__linux__)
Use madvise(MADV_DONTNEED) to release memory to reduce COW (#8974)
## Backgroud
As we know, after `fork`, one process will copy pages when writing data to these
pages(CoW), and another process still keep old pages, they totally cost more memory.
For redis, we suffered that redis consumed much memory when the fork child is serializing
key/values, even that maybe cause OOM.
But actually we find, in redis fork child process, the child process don't need to keep some
memory and parent process may write or update that, for example, child process will never
access the key-value that is serialized but users may update it in parent process.
So we think it may reduce COW if the child process release memory that it is not needed.
## Implementation
For releasing key value in child process, we may think we call `decrRefCount` to free memory,
but i find the fork child process still use much memory when we don't write any data to redis,
and it costs much more time that slows down bgsave. Maybe because memory allocator doesn't
really release memory to OS, and it may modify some inner data for this free operation, especially
when we free small objects.
Moreover, CoW is based on pages, so it is a easy way that we only free the memory bulk that is
not less than kernel page size. madvise(MADV_DONTNEED) can quickly release specified region
pages to OS bypassing memory allocator, and allocator still consider that this memory still is used
and don't change its inner data.
There are some buffers we can release in the fork child process:
- **Serialized key-values**
the fork child process never access serialized key-values, so we try to free them.
Because we only can release big bulk memory, and it is time consumed to iterate all
items/members/fields/entries of complex data type. So we decide to iterate them and
try to release them only when their average size of item/member/field/entry is more
than page size of OS.
- **Replication backlog**
Because replication backlog is a cycle buffer, it will be changed quickly if redis has heavy
write traffic, but in fork child process, we don't need to access that.
- **Client buffers**
If clients have requests during having the fork child process, clients' buffer also be changed
frequently. The memory includes client query buffer, output buffer, and client struct used memory.
To get child process peak private dirty memory, we need to count peak memory instead
of last used memory, because the child process may continue to release memory (since
COW used to only grow till now, the last was equivalent to the peak).
Also we're adding a new `current_cow_peak` info variable (to complement the existing
`current_cow_size`)
Co-authored-by: Oran Agra <oran@redislabs.com>
2021-08-05 04:01:46 +08:00
if ( o - > refcount ! = 1 ) return ;
switch ( o - > type ) {
case OBJ_STRING : dismissStringObject ( o ) ; break ;
case OBJ_LIST : dismissListObject ( o , size_hint ) ; break ;
case OBJ_SET : dismissSetObject ( o , size_hint ) ; break ;
case OBJ_ZSET : dismissZsetObject ( o , size_hint ) ; break ;
case OBJ_HASH : dismissHashObject ( o , size_hint ) ; break ;
case OBJ_STREAM : dismissStreamObject ( o , size_hint ) ; break ;
default : break ;
}
# else
UNUSED ( o ) ; UNUSED ( size_hint ) ;
# endif
}
2013-01-24 11:27:10 +01:00
/* This variant of decrRefCount() gets its argument as void, and is useful
* as free method in data structures that expect a ' void free_object ( void * ) '
* prototype for the free method . */
void decrRefCountVoid ( void * o ) {
decrRefCount ( o ) ;
}
2015-07-26 15:20:46 +02:00
int checkType ( client * c , robj * o , int type ) {
2020-08-11 20:04:54 -07:00
/* A NULL is considered an empty key */
if ( o & & o - > type ! = type ) {
2020-12-23 19:06:25 -08:00
addReplyErrorObject ( c , shared . wrongtypeerr ) ;
2010-06-22 00:07:48 +02:00
return 1 ;
}
return 0 ;
}
2015-07-31 18:01:23 +02:00
int isSdsRepresentableAsLongLong ( sds s , long long * llval ) {
return string2ll ( s , sdslen ( s ) , llval ) ? C_OK : C_ERR ;
}
2011-04-27 13:24:52 +02:00
int isObjectRepresentableAsLongLong ( robj * o , long long * llval ) {
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , o , o - > type = = OBJ_STRING ) ;
2015-07-26 15:28:00 +02:00
if ( o - > encoding = = OBJ_ENCODING_INT ) {
2011-04-27 13:24:52 +02:00
if ( llval ) * llval = ( long ) o - > ptr ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2011-04-27 13:24:52 +02:00
} else {
2015-07-31 18:01:23 +02:00
return isSdsRepresentableAsLongLong ( o - > ptr , llval ) ;
2011-04-27 13:24:52 +02:00
}
}
2019-03-14 12:47:36 +01:00
/* Optimize the SDS string inside the string object to require little space,
* in case there is more than 10 % of free space at the end of the SDS
* string . This happens because SDS strings tend to overallocate to avoid
* wasting too much time in allocations when appending to the string . */
2019-02-12 14:21:21 +01:00
void trimStringObjectIfNeeded ( robj * o ) {
if ( o - > encoding = = OBJ_ENCODING_RAW & &
sdsavail ( o - > ptr ) > sdslen ( o - > ptr ) / 10 )
{
Optimization: sdsRemoveFreeSpace to avoid realloc on noop (#11766)
In #7875 (Redis 6.2), we changed the sds alloc to be the usable allocation
size in order to:
> reduce the need for realloc calls by making the sds implicitly take over
the internal fragmentation
This change was done most sds functions, excluding `sdsRemoveFreeSpace` and
`sdsResize`, the reason is that in some places (e.g. clientsCronResizeQueryBuffer)
we call sdsRemoveFreeSpace when we see excessive free space and want to trim it.
so if we don't trim it exactly to size, the caller may still see excessive free space and
call it again and again.
However, this resulted in some excessive calls to realloc, even when there's no need
and it's gonna be a no-op (e.g. when reducing 15 bytes allocation to 13).
It turns out that a call for realloc with jemalloc can be expensive even if it ends up
doing nothing, so this PR adds a check using `je_nallocx`, which is cheap to avoid
the call for realloc.
in addition to that this PR unifies sdsResize and sdsRemoveFreeSpace into common
code. the difference between them was that sdsResize would avoid using SDS_TYPE_5,
since it want to keep the string ready to be resized again, while sdsRemoveFreeSpace
would permit using SDS_TYPE_5 and get an optimal memory consumption.
now both methods take a `would_regrow` argument that makes it more explicit.
the only actual impact of that is that in clientsCronResizeQueryBuffer we call both sdsResize
and sdsRemoveFreeSpace for in different cases, and we now prevent the use of SDS_TYPE_5 in both.
The new test that was added to cover this concern used to pass before this PR as well,
this PR is just a performance optimization and cleanup.
Benchmark:
`redis-benchmark -c 100 -t set -d 512 -P 10 -n 100000000`
on i7-9850H with jemalloc, shows improvement from 1021k ops/sec to 1067k (average of 3 runs).
some 4.5% improvement.
Co-authored-by: Oran Agra <oran@redislabs.com>
2023-01-31 17:26:35 +02:00
o - > ptr = sdsRemoveFreeSpace ( o - > ptr , 0 ) ;
2019-02-12 14:21:21 +01:00
}
}
2010-06-22 00:07:48 +02:00
/* Try to encode a string object in order to save space */
robj * tryObjectEncoding ( robj * o ) {
long value ;
sds s = o - > ptr ;
2013-08-27 11:56:47 +02:00
size_t len ;
2010-06-22 00:07:48 +02:00
2014-04-04 10:28:34 +02:00
/* Make sure this is a string object, the only type we encode
* in this function . Other types use encoded memory efficient
* representations but are handled by the commands implementing
* the type . */
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , o , o - > type = = OBJ_STRING ) ;
2014-04-04 10:28:34 +02:00
/* We try some specialized encoding only for objects that are
* RAW or EMBSTR encoded , in other words objects that are still
* in represented by an actually array of chars . */
if ( ! sdsEncodedObject ( o ) ) return o ;
2010-06-22 00:07:48 +02:00
/* It's not safe to encode shared objects: shared objects can be shared
2014-04-04 10:28:34 +02:00
* everywhere in the " object space " of Redis and may end in places where
* they are not handled . We handle them only as values in the keyspace . */
2010-06-22 00:07:48 +02:00
if ( o - > refcount > 1 ) return o ;
2013-08-27 11:56:47 +02:00
/* Check if we can represent this string as a long integer.
2016-06-23 19:53:56 +08:00
* Note that we are sure that a string larger than 20 chars is not
2014-04-04 10:28:34 +02:00
* representable as a 32 nor 64 bit integer . */
2013-08-27 11:56:47 +02:00
len = sdslen ( s ) ;
2016-06-23 19:53:56 +08:00
if ( len < = 20 & & string2l ( s , len , & value ) ) {
2014-04-04 10:28:34 +02:00
/* This object is encodable as a long. Try to use a shared object.
* Note that we avoid using shared integers when maxmemory is used
* because every object needs to have a private LRU field for the LRU
* algorithm to work well . */
2014-07-18 10:09:51 +02:00
if ( ( server . maxmemory = = 0 | |
2016-07-21 11:14:15 +02:00
! ( server . maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS ) ) & &
2014-04-04 10:28:34 +02:00
value > = 0 & &
2015-07-27 09:41:48 +02:00
value < OBJ_SHARED_INTEGERS )
2014-04-04 10:28:34 +02:00
{
2012-06-05 21:50:10 +02:00
decrRefCount ( o ) ;
2014-04-04 10:28:34 +02:00
return shared . integers [ value ] ;
2012-06-05 21:50:10 +02:00
} else {
2019-07-22 17:45:30 +08:00
if ( o - > encoding = = OBJ_ENCODING_RAW ) {
sdsfree ( o - > ptr ) ;
o - > encoding = OBJ_ENCODING_INT ;
o - > ptr = ( void * ) value ;
return o ;
2019-07-31 12:03:10 +02:00
} else if ( o - > encoding = = OBJ_ENCODING_EMBSTR ) {
2019-07-22 17:45:30 +08:00
decrRefCount ( o ) ;
return createStringObjectFromLongLongForValue ( value ) ;
}
2012-06-05 21:50:10 +02:00
}
}
2010-06-22 00:07:48 +02:00
2014-04-04 10:28:34 +02:00
/* If the string is small and is still RAW encoded,
* try the EMBSTR encoding which is more efficient .
* In this representation the object and the SDS string are allocated
* in the same chunk of memory to save space and cache misses . */
2015-07-26 15:28:00 +02:00
if ( len < = OBJ_ENCODING_EMBSTR_SIZE_LIMIT ) {
2014-04-04 10:28:34 +02:00
robj * emb ;
2015-07-26 15:28:00 +02:00
if ( o - > encoding = = OBJ_ENCODING_EMBSTR ) return o ;
2014-04-04 10:28:34 +02:00
emb = createEmbeddedStringObject ( s , sdslen ( s ) ) ;
decrRefCount ( o ) ;
return emb ;
}
/* We can't encode the object...
2010-07-22 13:08:02 +02:00
*
2014-04-04 10:28:34 +02:00
* Do the last try , and at least optimize the SDS string inside
* the string object to require little space , in case there
* is more than 10 % of free space at the end of the SDS string .
2010-10-15 18:04:05 +02:00
*
2014-04-04 10:28:34 +02:00
* We do that only for relatively large strings as this branch
* is only entered if the length of the string is greater than
2015-07-26 15:28:00 +02:00
* OBJ_ENCODING_EMBSTR_SIZE_LIMIT . */
2019-02-12 14:21:21 +01:00
trimStringObjectIfNeeded ( o ) ;
2014-04-04 10:28:34 +02:00
/* Return the original object. */
return o ;
2010-06-22 00:07:48 +02:00
}
/* Get a decoded version of an encoded object (returned as a new object).
* If the object is already raw - encoded just increment the ref count . */
robj * getDecodedObject ( robj * o ) {
robj * dec ;
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( o ) ) {
2010-06-22 00:07:48 +02:00
incrRefCount ( o ) ;
return o ;
}
2015-07-26 15:28:00 +02:00
if ( o - > type = = OBJ_STRING & & o - > encoding = = OBJ_ENCODING_INT ) {
2010-06-22 00:07:48 +02:00
char buf [ 32 ] ;
ll2string ( buf , 32 , ( long ) o - > ptr ) ;
dec = createStringObject ( buf , strlen ( buf ) ) ;
return dec ;
} else {
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown encoding type " ) ;
2010-06-22 00:07:48 +02:00
}
}
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
/* Compare two string objects via strcmp() or strcoll() depending on flags.
2010-06-22 00:07:48 +02:00
* Note that the objects may be integer - encoded . In such a case we
* use ll2string ( ) to get a string representation of the numbers on the stack
* and compare the strings , it ' s much faster than calling getDecodedObject ( ) .
*
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
* Important note : when REDIS_COMPARE_BINARY is used a binary - safe comparison
* is used . */
# define REDIS_COMPARE_BINARY (1<<0)
# define REDIS_COMPARE_COLL (1<<1)
2022-07-19 13:59:39 +08:00
int compareStringObjectsWithFlags ( const robj * a , const robj * b , int flags ) {
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , a , a - > type = = OBJ_STRING & & b - > type = = OBJ_STRING ) ;
2010-06-22 00:07:48 +02:00
char bufa [ 128 ] , bufb [ 128 ] , * astr , * bstr ;
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
size_t alen , blen , minlen ;
2010-06-22 00:07:48 +02:00
if ( a = = b ) return 0 ;
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( a ) ) {
astr = a - > ptr ;
alen = sdslen ( astr ) ;
} else {
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
alen = ll2string ( bufa , sizeof ( bufa ) , ( long ) a - > ptr ) ;
2010-06-22 00:07:48 +02:00
astr = bufa ;
}
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( b ) ) {
bstr = b - > ptr ;
blen = sdslen ( bstr ) ;
} else {
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
blen = ll2string ( bufb , sizeof ( bufb ) , ( long ) b - > ptr ) ;
2010-06-22 00:07:48 +02:00
bstr = bufb ;
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
}
if ( flags & REDIS_COMPARE_COLL ) {
return strcoll ( astr , bstr ) ;
} else {
int cmp ;
minlen = ( alen < blen ) ? alen : blen ;
cmp = memcmp ( astr , bstr , minlen ) ;
if ( cmp = = 0 ) return alen - blen ;
return cmp ;
2010-06-22 00:07:48 +02:00
}
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
}
/* Wrapper for compareStringObjectsWithFlags() using binary comparison. */
2022-07-19 13:59:39 +08:00
int compareStringObjects ( const robj * a , const robj * b ) {
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
return compareStringObjectsWithFlags ( a , b , REDIS_COMPARE_BINARY ) ;
}
/* Wrapper for compareStringObjectsWithFlags() using collation. */
2022-07-19 13:59:39 +08:00
int collateStringObjects ( const robj * a , const robj * b ) {
Fixed compareStringObject() and introduced collateStringObject().
compareStringObject was not always giving the same result when comparing
two exact strings, but encoded as integers or as sds strings, since it
switched to strcmp() when at least one of the strings were not sds
encoded.
For instance the two strings "123" and "123\x00456", where the first
string was integer encoded, would result into the old implementation of
compareStringObject() to return 0 as if the strings were equal, while
instead the second string is "greater" than the first in a binary
comparison.
The same compasion, but with "123" encoded as sds string, would instead
return a value < 0, as it is correct. It is not impossible that the
above caused some obscure bug, since the comparison was not always
deterministic, and compareStringObject() is used in the implementation
of skiplists, hash tables, and so forth.
At the same time, collateStringObject() was introduced by this commit, so
that can be used by SORT command to return sorted strings usign
collation instead of binary comparison. See next commit.
2013-07-12 11:56:52 +02:00
return compareStringObjectsWithFlags ( a , b , REDIS_COMPARE_COLL ) ;
2010-06-22 00:07:48 +02:00
}
/* Equal string objects return 1 if the two objects are the same from the
* point of view of a string comparison , otherwise 0 is returned . Note that
* this function is faster then checking for ( compareStringObject ( a , b ) = = 0 )
* because it can perform some more optimization . */
int equalStringObjects ( robj * a , robj * b ) {
2015-07-26 15:28:00 +02:00
if ( a - > encoding = = OBJ_ENCODING_INT & &
b - > encoding = = OBJ_ENCODING_INT ) {
2012-06-05 21:50:10 +02:00
/* If both strings are integer encoded just check if the stored
* long is the same . */
2010-06-22 00:07:48 +02:00
return a - > ptr = = b - > ptr ;
} else {
return compareStringObjects ( a , b ) = = 0 ;
}
}
size_t stringObjectLen ( robj * o ) {
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , o , o - > type = = OBJ_STRING ) ;
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( o ) ) {
2010-06-22 00:07:48 +02:00
return sdslen ( o - > ptr ) ;
} else {
2015-02-27 16:08:50 +01:00
return sdigits10 ( ( long ) o - > ptr ) ;
2010-06-22 00:07:48 +02:00
}
}
2016-06-20 23:08:06 +03:00
int getDoubleFromObject ( const robj * o , double * target ) {
2010-06-22 00:07:48 +02:00
double value ;
if ( o = = NULL ) {
value = 0 ;
} else {
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , o , o - > type = = OBJ_STRING ) ;
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( o ) ) {
2019-11-03 15:02:25 +02:00
if ( ! string2d ( o - > ptr , sdslen ( o - > ptr ) , & value ) )
2015-07-26 23:17:55 +02:00
return C_ERR ;
2015-07-26 15:28:00 +02:00
} else if ( o - > encoding = = OBJ_ENCODING_INT ) {
2010-06-22 00:07:48 +02:00
value = ( long ) o - > ptr ;
} else {
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown string encoding " ) ;
2010-06-22 00:07:48 +02:00
}
}
* target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 15:20:46 +02:00
int getDoubleFromObjectOrReply ( client * c , robj * o , double * target , const char * msg ) {
2010-06-22 00:07:48 +02:00
double value ;
2015-07-26 23:17:55 +02:00
if ( getDoubleFromObject ( o , & value ) ! = C_OK ) {
2010-06-22 00:07:48 +02:00
if ( msg ! = NULL ) {
2010-09-02 19:52:24 +02:00
addReplyError ( c , ( char * ) msg ) ;
2010-06-22 00:07:48 +02:00
} else {
2011-11-12 19:27:35 +01:00
addReplyError ( c , " value is not a valid float " ) ;
}
2015-07-26 23:17:55 +02:00
return C_ERR ;
2011-11-12 19:27:35 +01:00
}
* target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2011-11-12 19:27:35 +01:00
}
int getLongDoubleFromObject ( robj * o , long double * target ) {
long double value ;
if ( o = = NULL ) {
value = 0 ;
} else {
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , o , o - > type = = OBJ_STRING ) ;
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( o ) ) {
2020-01-30 18:14:45 +05:30
if ( ! string2ld ( o - > ptr , sdslen ( o - > ptr ) , & value ) )
2015-07-26 23:17:55 +02:00
return C_ERR ;
2015-07-26 15:28:00 +02:00
} else if ( o - > encoding = = OBJ_ENCODING_INT ) {
2011-11-12 19:27:35 +01:00
value = ( long ) o - > ptr ;
} else {
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown string encoding " ) ;
2011-11-12 19:27:35 +01:00
}
}
* target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2011-11-12 19:27:35 +01:00
}
2015-07-26 15:20:46 +02:00
int getLongDoubleFromObjectOrReply ( client * c , robj * o , long double * target , const char * msg ) {
2011-11-12 19:27:35 +01:00
long double value ;
2015-07-26 23:17:55 +02:00
if ( getLongDoubleFromObject ( o , & value ) ! = C_OK ) {
2011-11-12 19:27:35 +01:00
if ( msg ! = NULL ) {
addReplyError ( c , ( char * ) msg ) ;
} else {
addReplyError ( c , " value is not a valid float " ) ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 23:17:55 +02:00
return C_ERR ;
2010-06-22 00:07:48 +02:00
}
* target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2010-06-22 00:07:48 +02:00
}
int getLongLongFromObject ( robj * o , long long * target ) {
long long value ;
if ( o = = NULL ) {
value = 0 ;
} else {
2015-07-26 15:29:53 +02:00
serverAssertWithInfo ( NULL , o , o - > type = = OBJ_STRING ) ;
2012-06-05 21:50:10 +02:00
if ( sdsEncodedObject ( o ) ) {
2016-07-06 11:43:33 +02:00
if ( string2ll ( o - > ptr , sdslen ( o - > ptr ) , & value ) = = 0 ) return C_ERR ;
2015-07-26 15:28:00 +02:00
} else if ( o - > encoding = = OBJ_ENCODING_INT ) {
2010-06-22 00:07:48 +02:00
value = ( long ) o - > ptr ;
} else {
2015-07-27 09:41:48 +02:00
serverPanic ( " Unknown string encoding " ) ;
2010-06-22 00:07:48 +02:00
}
}
2010-07-02 19:57:12 +02:00
if ( target ) * target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 15:20:46 +02:00
int getLongLongFromObjectOrReply ( client * c , robj * o , long long * target , const char * msg ) {
2010-06-22 00:07:48 +02:00
long long value ;
2015-07-26 23:17:55 +02:00
if ( getLongLongFromObject ( o , & value ) ! = C_OK ) {
2010-06-22 00:07:48 +02:00
if ( msg ! = NULL ) {
2010-09-02 19:52:24 +02:00
addReplyError ( c , ( char * ) msg ) ;
2010-06-22 00:07:48 +02:00
} else {
2010-09-02 19:52:24 +02:00
addReplyError ( c , " value is not an integer or out of range " ) ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 23:17:55 +02:00
return C_ERR ;
2010-06-22 00:07:48 +02:00
}
* target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 15:20:46 +02:00
int getLongFromObjectOrReply ( client * c , robj * o , long * target , const char * msg ) {
2010-06-22 00:07:48 +02:00
long long value ;
2015-07-26 23:17:55 +02:00
if ( getLongLongFromObjectOrReply ( c , o , & value , msg ) ! = C_OK ) return C_ERR ;
2010-06-22 00:07:48 +02:00
if ( value < LONG_MIN | | value > LONG_MAX ) {
if ( msg ! = NULL ) {
2010-09-02 19:52:24 +02:00
addReplyError ( c , ( char * ) msg ) ;
2010-06-22 00:07:48 +02:00
} else {
2010-09-02 19:52:24 +02:00
addReplyError ( c , " value is out of range " ) ;
2010-06-22 00:07:48 +02:00
}
2015-07-26 23:17:55 +02:00
return C_ERR ;
2010-06-22 00:07:48 +02:00
}
* target = value ;
2015-07-26 23:17:55 +02:00
return C_OK ;
2010-06-22 00:07:48 +02:00
}
2020-11-05 12:58:54 -05:00
int getRangeLongFromObjectOrReply ( client * c , robj * o , long min , long max , long * target , const char * msg ) {
if ( getLongFromObjectOrReply ( c , o , target , msg ) ! = C_OK ) return C_ERR ;
if ( * target < min | | * target > max ) {
if ( msg ! = NULL ) {
addReplyError ( c , ( char * ) msg ) ;
} else {
addReplyErrorFormat ( c , " value is out of range, value must between %ld and %ld " , min , max ) ;
}
return C_ERR ;
}
return C_OK ;
}
int getPositiveLongFromObjectOrReply ( client * c , robj * o , long * target , const char * msg ) {
2021-04-07 15:01:28 +08:00
if ( msg ) {
return getRangeLongFromObjectOrReply ( c , o , 0 , LONG_MAX , target , msg ) ;
} else {
return getRangeLongFromObjectOrReply ( c , o , 0 , LONG_MAX , target , " value is out of range, must be positive " ) ;
}
2020-11-05 12:58:54 -05:00
}
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-02 03:41:26 +08:00
int getIntFromObjectOrReply ( client * c , robj * o , int * target , const char * msg ) {
long value ;
if ( getRangeLongFromObjectOrReply ( c , o , INT_MIN , INT_MAX , & value , msg ) ! = C_OK )
return C_ERR ;
* target = value ;
return C_OK ;
}
2010-06-22 00:07:48 +02:00
char * strEncoding ( int encoding ) {
switch ( encoding ) {
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_RAW : return " raw " ;
case OBJ_ENCODING_INT : return " int " ;
case OBJ_ENCODING_HT : return " hashtable " ;
case OBJ_ENCODING_QUICKLIST : return " quicklist " ;
2021-08-10 14:18:49 +08:00
case OBJ_ENCODING_LISTPACK : return " listpack " ;
2015-07-26 15:28:00 +02:00
case OBJ_ENCODING_INTSET : return " intset " ;
case OBJ_ENCODING_SKIPLIST : return " skiplist " ;
case OBJ_ENCODING_EMBSTR : return " embstr " ;
2020-09-15 01:58:21 -04:00
case OBJ_ENCODING_STREAM : return " stream " ;
2010-06-22 00:07:48 +02:00
default : return " unknown " ;
}
}
2010-10-14 13:52:58 +02:00
2018-03-20 17:50:37 +01:00
/* =========================== Memory introspection ========================= */
2021-06-10 20:39:33 +08:00
/* This is a helper function with the goal of estimating the memory
2018-03-20 17:50:37 +01:00
* size of a radix tree that is used to store Stream IDs .
*
* Note : to guess the size of the radix tree is not trivial , so we
2018-06-21 17:58:29 +03:00
* approximate it considering 16 bytes of data overhead for each
2018-03-20 17:50:37 +01:00
* key ( the ID ) , and then adding the number of bare nodes , plus some
* overhead due by the data and child pointers . This secret recipe
* was obtained by checking the average radix tree created by real
* workloads , and then adjusting the constants to get numbers that
* more or less match the real memory usage .
*
* Actually the number of nodes and keys may be different depending
* on the insertion speed and thus the ability of the radix tree
* to compress prefixes . */
size_t streamRadixTreeMemoryUsage ( rax * rax ) {
2022-04-17 07:31:57 +02:00
size_t size = sizeof ( * rax ) ;
2018-03-20 17:50:37 +01:00
size = rax - > numele * sizeof ( streamID ) ;
size + = rax - > numnodes * sizeof ( raxNode ) ;
/* Add a fixed overhead due to the aux data pointer, children, ... */
size + = rax - > numnodes * sizeof ( long ) * 30 ;
return size ;
}
2016-05-09 18:01:09 +03:00
2016-09-13 10:26:36 +02:00
/* Returns the size in bytes consumed by the key's value in RAM.
* Note that the returned value is just an approximation , especially in the
* case of aggregated data types where only " sample_size " elements
* are checked and averaged to estimate the total size . */
# define OBJ_COMPUTE_SIZE_DEF_SAMPLES 5 /* Default sample size. */
2021-06-16 14:45:49 +08:00
size_t objectComputeSize ( robj * key , robj * o , size_t sample_size , int dbid ) {
2016-09-15 15:25:05 +02:00
sds ele , ele2 ;
2016-05-09 18:01:09 +03:00
dict * d ;
dictIterator * di ;
struct dictEntry * de ;
2016-09-13 10:26:36 +02:00
size_t asize = 0 , elesize = 0 , samples = 0 ;
2016-05-09 18:01:09 +03:00
if ( o - > type = = OBJ_STRING ) {
if ( o - > encoding = = OBJ_ENCODING_INT ) {
asize = sizeof ( * o ) ;
2016-09-15 15:25:05 +02:00
} else if ( o - > encoding = = OBJ_ENCODING_RAW ) {
2020-10-01 11:30:22 +03:00
asize = sdsZmallocSize ( o - > ptr ) + sizeof ( * o ) ;
2016-05-09 18:01:09 +03:00
} else if ( o - > encoding = = OBJ_ENCODING_EMBSTR ) {
2021-06-17 18:30:37 +08:00
asize = zmalloc_size ( ( void * ) o ) ;
2016-05-09 18:01:09 +03:00
} else {
serverPanic ( " Unknown string encoding " ) ;
}
} else if ( o - > type = = OBJ_LIST ) {
if ( o - > encoding = = OBJ_ENCODING_QUICKLIST ) {
quicklist * ql = o - > ptr ;
quicklistNode * node = ql - > head ;
asize = sizeof ( * o ) + sizeof ( quicklist ) ;
do {
2021-11-03 20:47:18 +02:00
elesize + = sizeof ( quicklistNode ) + zmalloc_size ( node - > entry ) ;
2016-09-13 10:26:36 +02:00
samples + + ;
} while ( ( node = node - > next ) & & samples < sample_size ) ;
2018-01-05 12:16:24 +08:00
asize + = ( double ) elesize / samples * ql - > len ;
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-17 02:29:46 +08:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
asize = sizeof ( * o ) + zmalloc_size ( o - > ptr ) ;
2016-05-09 18:01:09 +03:00
} else {
serverPanic ( " Unknown list encoding " ) ;
}
} else if ( o - > type = = OBJ_SET ) {
if ( o - > encoding = = OBJ_ENCODING_HT ) {
d = o - > ptr ;
di = dictGetIterator ( d ) ;
asize = sizeof ( * o ) + sizeof ( dict ) + ( sizeof ( struct dictEntry * ) * dictSlots ( d ) ) ;
2016-09-13 10:26:36 +02:00
while ( ( de = dictNext ( di ) ) ! = NULL & & samples < sample_size ) {
2016-05-09 18:01:09 +03:00
ele = dictGetKey ( de ) ;
2023-01-11 09:57:10 +01:00
elesize + = dictEntryMemUsage ( ) + sdsZmallocSize ( ele ) ;
2016-09-13 10:26:36 +02:00
samples + + ;
2016-05-09 18:01:09 +03:00
}
dictReleaseIterator ( di ) ;
2016-09-13 10:26:36 +02:00
if ( samples ) asize + = ( double ) elesize / samples * dictSize ( d ) ;
2016-05-09 18:01:09 +03:00
} else if ( o - > encoding = = OBJ_ENCODING_INTSET ) {
2021-06-17 18:30:37 +08:00
asize = sizeof ( * o ) + zmalloc_size ( o - > ptr ) ;
2023-01-05 08:21:57 +02:00
} else if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
asize = sizeof ( * o ) + zmalloc_size ( o - > ptr ) ;
2016-05-09 18:01:09 +03:00
} else {
serverPanic ( " Unknown set encoding " ) ;
}
} else if ( o - > type = = OBJ_ZSET ) {
2021-09-09 23:18:53 +08:00
if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
2021-06-17 18:30:37 +08:00
asize = sizeof ( * o ) + zmalloc_size ( o - > ptr ) ;
2016-05-09 18:01:09 +03:00
} else if ( o - > encoding = = OBJ_ENCODING_SKIPLIST ) {
d = ( ( zset * ) o - > ptr ) - > dict ;
2016-09-15 17:43:13 +02:00
zskiplist * zsl = ( ( zset * ) o - > ptr ) - > zsl ;
zskiplistNode * znode = zsl - > header - > level [ 0 ] . forward ;
2019-07-04 10:02:26 +03:00
asize = sizeof ( * o ) + sizeof ( zset ) + sizeof ( zskiplist ) + sizeof ( dict ) +
( sizeof ( struct dictEntry * ) * dictSlots ( d ) ) +
zmalloc_size ( zsl - > header ) ;
2016-09-15 17:43:13 +02:00
while ( znode ! = NULL & & samples < sample_size ) {
2020-10-01 11:30:22 +03:00
elesize + = sdsZmallocSize ( znode - > ele ) ;
2023-01-11 09:57:10 +01:00
elesize + = dictEntryMemUsage ( ) + zmalloc_size ( znode ) ;
2016-09-13 10:26:36 +02:00
samples + + ;
2016-09-15 17:43:13 +02:00
znode = znode - > level [ 0 ] . forward ;
2016-05-09 18:01:09 +03:00
}
2016-09-13 10:26:36 +02:00
if ( samples ) asize + = ( double ) elesize / samples * dictSize ( d ) ;
2016-05-09 18:01:09 +03:00
} else {
serverPanic ( " Unknown sorted set encoding " ) ;
}
} else if ( o - > type = = OBJ_HASH ) {
2021-08-10 14:18:49 +08:00
if ( o - > encoding = = OBJ_ENCODING_LISTPACK ) {
2021-06-17 18:30:37 +08:00
asize = sizeof ( * o ) + zmalloc_size ( o - > ptr ) ;
2016-05-09 18:01:09 +03:00
} else if ( o - > encoding = = OBJ_ENCODING_HT ) {
d = o - > ptr ;
di = dictGetIterator ( d ) ;
asize = sizeof ( * o ) + sizeof ( dict ) + ( sizeof ( struct dictEntry * ) * dictSlots ( d ) ) ;
2016-09-13 10:26:36 +02:00
while ( ( de = dictNext ( di ) ) ! = NULL & & samples < sample_size ) {
2016-05-09 18:01:09 +03:00
ele = dictGetKey ( de ) ;
2016-09-15 15:25:05 +02:00
ele2 = dictGetVal ( de ) ;
2020-10-01 11:30:22 +03:00
elesize + = sdsZmallocSize ( ele ) + sdsZmallocSize ( ele2 ) ;
2023-01-11 09:57:10 +01:00
elesize + = dictEntryMemUsage ( ) ;
2016-09-13 10:26:36 +02:00
samples + + ;
2016-05-09 18:01:09 +03:00
}
dictReleaseIterator ( di ) ;
2016-09-13 10:26:36 +02:00
if ( samples ) asize + = ( double ) elesize / samples * dictSize ( d ) ;
2016-05-09 18:01:09 +03:00
} else {
serverPanic ( " Unknown hash encoding " ) ;
}
2017-12-01 12:50:18 +01:00
} else if ( o - > type = = OBJ_STREAM ) {
stream * s = o - > ptr ;
2021-06-29 13:34:18 +02:00
asize = sizeof ( * o ) + sizeof ( * s ) ;
2018-03-20 17:50:37 +01:00
asize + = streamRadixTreeMemoryUsage ( s - > rax ) ;
2017-12-01 12:50:18 +01:00
/* Now we have to add the listpacks. The last listpack is often non
* complete , so we estimate the size of the first N listpacks , and
* use the average to compute the size of the first N - 1 listpacks , and
* finally add the real size of the last node . */
raxIterator ri ;
raxStart ( & ri , s - > rax ) ;
raxSeek ( & ri , " ^ " , NULL , 0 ) ;
size_t lpsize = 0 , samples = 0 ;
while ( samples < sample_size & & raxNext ( & ri ) ) {
unsigned char * lp = ri . data ;
lpsize + = lpBytes ( lp ) ;
samples + + ;
}
if ( s - > rax - > numele < = samples ) {
asize + = lpsize ;
} else {
if ( samples ) lpsize / = samples ; /* Compute the average. */
asize + = lpsize * ( s - > rax - > numele - 1 ) ;
/* No need to check if seek succeeded, we enter this branch only
* if there are a few elements in the radix tree . */
raxSeek ( & ri , " $ " , NULL , 0 ) ;
raxNext ( & ri ) ;
asize + = lpBytes ( ri . data ) ;
}
raxStop ( & ri ) ;
2018-03-20 17:50:37 +01:00
/* Consumer groups also have a non trivial memory overhead if there
* are many consumers and many groups , let ' s count at least the
* overhead of the pending entries in the groups and consumers
* PELs . */
if ( s - > cgroups ) {
raxStart ( & ri , s - > cgroups ) ;
raxSeek ( & ri , " ^ " , NULL , 0 ) ;
while ( raxNext ( & ri ) ) {
streamCG * cg = ri . data ;
asize + = sizeof ( * cg ) ;
asize + = streamRadixTreeMemoryUsage ( cg - > pel ) ;
asize + = sizeof ( streamNACK ) * raxSize ( cg - > pel ) ;
/* For each consumer we also need to add the basic data
* structures and the PEL memory usage . */
raxIterator cri ;
raxStart ( & cri , cg - > consumers ) ;
2018-06-21 17:58:29 +03:00
raxSeek ( & cri , " ^ " , NULL , 0 ) ;
2018-03-20 17:50:37 +01:00
while ( raxNext ( & cri ) ) {
streamConsumer * consumer = cri . data ;
asize + = sizeof ( * consumer ) ;
asize + = sdslen ( consumer - > name ) ;
asize + = streamRadixTreeMemoryUsage ( consumer - > pel ) ;
/* Don't count NACKs again, they are shared with the
* consumer group PEL . */
}
raxStop ( & cri ) ;
}
raxStop ( & ri ) ;
}
2017-01-12 09:08:43 +01:00
} else if ( o - > type = = OBJ_MODULE ) {
2021-10-17 17:31:06 +03:00
asize = moduleGetMemUsage ( key , o , sample_size , dbid ) ;
2016-05-09 18:01:09 +03:00
} else {
serverPanic ( " Unknown object type " ) ;
}
return asize ;
}
2016-09-15 09:37:55 +02:00
/* Release data obtained with getMemoryOverheadData(). */
2016-09-15 09:42:51 +02:00
void freeMemoryOverheadData ( struct redisMemOverhead * mh ) {
2016-09-15 09:37:55 +02:00
zfree ( mh - > db ) ;
zfree ( mh ) ;
}
2016-09-15 09:42:51 +02:00
/* Return a struct redisMemOverhead filled with memory overhead
* information used for the MEMORY OVERHEAD and INFO command . The returned
* structure pointer should be freed calling freeMemoryOverheadData ( ) . */
struct redisMemOverhead * getMemoryOverheadData ( void ) {
2016-09-15 09:37:55 +02:00
int j ;
size_t mem_total = 0 ;
size_t mem = 0 ;
size_t zmalloc_used = zmalloc_used_memory ( ) ;
2016-09-15 09:42:51 +02:00
struct redisMemOverhead * mh = zcalloc ( sizeof ( * mh ) ) ;
2016-09-15 09:37:55 +02:00
mh - > total_allocated = zmalloc_used ;
mh - > startup_allocated = server . initial_memory_usage ;
2016-09-16 10:43:19 +02:00
mh - > peak_allocated = server . stat_peak_memory ;
2018-02-18 17:36:21 +02:00
mh - > total_frag =
( float ) server . cron_malloc_stats . process_rss / server . cron_malloc_stats . zmalloc_used ;
mh - > total_frag_bytes =
server . cron_malloc_stats . process_rss - server . cron_malloc_stats . zmalloc_used ;
mh - > allocator_frag =
( float ) server . cron_malloc_stats . allocator_active / server . cron_malloc_stats . allocator_allocated ;
mh - > allocator_frag_bytes =
server . cron_malloc_stats . allocator_active - server . cron_malloc_stats . allocator_allocated ;
mh - > allocator_rss =
( float ) server . cron_malloc_stats . allocator_resident / server . cron_malloc_stats . allocator_active ;
mh - > allocator_rss_bytes =
server . cron_malloc_stats . allocator_resident - server . cron_malloc_stats . allocator_active ;
mh - > rss_extra =
( float ) server . cron_malloc_stats . process_rss / server . cron_malloc_stats . allocator_resident ;
mh - > rss_extra_bytes =
server . cron_malloc_stats . process_rss - server . cron_malloc_stats . allocator_resident ;
2016-09-15 09:37:55 +02:00
mem_total + = server . initial_memory_usage ;
Replication backlog and replicas use one global shared replication buffer (#9166)
## Background
For redis master, one replica uses one copy of replication buffer, that is a big waste of memory,
more replicas more waste, and allocate/free memory for every reply list also cost much.
If we set client-output-buffer-limit small and write traffic is heavy, master may disconnect with
replicas and can't finish synchronization with replica. If we set client-output-buffer-limit big,
master may be OOM when there are many replicas that separately keep much memory.
Because replication buffers of different replica client are the same, one simple idea is that
all replicas only use one replication buffer, that will effectively save memory.
Since replication backlog content is the same as replicas' output buffer, now we
can discard replication backlog memory and use global shared replication buffer
to implement replication backlog mechanism.
## Implementation
I create one global "replication buffer" which contains content of replication stream.
The structure of "replication buffer" is similar to the reply list that exists in every client.
But the node of list is `replBufBlock`, which has `id, repl_offset, refcount` fields.
```c
/* Replication buffer blocks is the list of replBufBlock.
*
* +--------------+ +--------------+ +--------------+
* | refcount = 1 | ... | refcount = 0 | ... | refcount = 2 |
* +--------------+ +--------------+ +--------------+
* | / \
* | / \
* | / \
* Repl Backlog Replia_A Replia_B
*
* Each replica or replication backlog increments only the refcount of the
* 'ref_repl_buf_node' which it points to. So when replica walks to the next
* node, it should first increase the next node's refcount, and when we trim
* the replication buffer nodes, we remove node always from the head node which
* refcount is 0. If the refcount of the head node is not 0, we must stop
* trimming and never iterate the next node. */
/* Similar with 'clientReplyBlock', it is used for shared buffers between
* all replica clients and replication backlog. */
typedef struct replBufBlock {
int refcount; /* Number of replicas or repl backlog using. */
long long id; /* The unique incremental number. */
long long repl_offset; /* Start replication offset of the block. */
size_t size, used;
char buf[];
} replBufBlock;
```
So now when we feed replication stream into replication backlog and all replicas, we only need
to feed stream into replication buffer `feedReplicationBuffer`. In this function, we set some fields of
replication backlog and replicas to references of the global replication buffer blocks. And we also
need to check replicas' output buffer limit to free if exceeding `client-output-buffer-limit`, and trim
replication backlog if exceeding `repl-backlog-size`.
When sending reply to replicas, we also need to iterate replication buffer blocks and send its
content, when totally sending one block for replica, we decrease current node count and
increase the next current node count, and then free the block which reference is 0 from the
head of replication buffer blocks.
Since now we use linked list to manage replication backlog, it may cost much time for iterating
all linked list nodes to find corresponding replication buffer node. So we create a rax tree to
store some nodes for index, but to avoid rax tree occupying too much memory, i record
one per 64 nodes for index.
Currently, to make partial resynchronization as possible as much, we always let replication
backlog as the last reference of replication buffer blocks, backlog size may exceeds our setting
if slow replicas that reference vast replication buffer blocks, and this method doesn't increase
memory usage since they share replication buffer. To avoid freezing server for freeing unreferenced
replication buffer blocks when we need to trim backlog for exceeding backlog size setting,
we trim backlog incrementally (free 64 blocks per call now), and make it faster in
`beforeSleep` (free 640 blocks).
### Other changes
- `mem_total_replication_buffers`: we add this field in INFO command, it means the total
memory of replication buffers used.
- `mem_clients_slaves`: now even replica is slow to replicate, and its output buffer memory
is not 0, but it still may be 0, since replication backlog and replicas share one global replication
buffer, only if replication buffer memory is more than the repl backlog setting size, we consider
the excess as replicas' memory. Otherwise, we think replication buffer memory is the consumption
of repl backlog.
- Key eviction
Since all replicas and replication backlog share global replication buffer, we think only the
part of exceeding backlog size the extra separate consumption of replicas.
Because we trim backlog incrementally in the background, backlog size may exceeds our
setting if slow replicas that reference vast replication buffer blocks disconnect.
To avoid massive eviction loop, we don't count the delayed freed replication backlog into
used memory even if there are no replicas, i.e. we also regard this memory as replicas's memory.
- `client-output-buffer-limit` check for replica clients
It doesn't make sense to set the replica clients output buffer limit lower than the repl-backlog-size
config (partial sync will succeed and then replica will get disconnected). Such a configuration is
ignored (the size of repl-backlog-size will be used). This doesn't have memory consumption
implications since the replica client will share the backlog buffers memory.
- Drop replication backlog after loading data if needed
We always create replication backlog if server is a master, we need it because we put DELs in
it when loading expired keys in RDB, but if RDB doesn't have replication info or there is no rdb,
it is not possible to support partial resynchronization, to avoid extra memory of replication backlog,
we drop it.
- Multi IO threads
Since all replicas and replication backlog use global replication buffer, if I/O threads are enabled,
to guarantee data accessing thread safe, we must let main thread handle sending the output buffer
to all replicas. But before, other IO threads could handle sending output buffer of all replicas.
## Other optimizations
This solution resolve some other problem:
- When replicas disconnect with master since of out of output buffer limit, releasing the output
buffer of replicas may freeze server if we set big `client-output-buffer-limit` for replicas, but now,
it doesn't cause freezing.
- This implementation may mitigate reply list copy cost time(also freezes server) when one replication
has huge reply buffer and another replica can copy buffer for full synchronization. now, we just copy
reference info, it is very light.
- If we set replication backlog size big, it also may cost much time to copy replication backlog into
replica's output buffer. But this commit eliminates this problem.
- Resizing replication backlog size doesn't empty current replication backlog content.
2021-10-25 14:24:31 +08:00
/* Replication backlog and replicas share one global replication buffer,
* only if replication buffer memory is more than the repl backlog setting ,
* we consider the excess as replicas ' memory . Otherwise , replication buffer
* memory is the consumption of repl backlog . */
if ( listLength ( server . slaves ) & &
( long long ) server . repl_buffer_mem > server . repl_backlog_size )
{
mh - > clients_slaves = server . repl_buffer_mem - server . repl_backlog_size ;
mh - > repl_backlog = server . repl_backlog_size ;
} else {
mh - > clients_slaves = 0 ;
mh - > repl_backlog = server . repl_buffer_mem ;
}
if ( server . repl_backlog ) {
/* The approximate memory of rax tree for indexed blocks. */
mh - > repl_backlog + =
server . repl_backlog - > blocks_index - > numnodes * sizeof ( raxNode ) +
raxSize ( server . repl_backlog - > blocks_index ) * sizeof ( void * ) ;
}
mem_total + = mh - > repl_backlog ;
mem_total + = mh - > clients_slaves ;
2016-09-15 09:37:55 +02:00
2020-04-07 12:07:09 +02:00
/* Computing the memory used by the clients would be O(N) if done
* here online . We use our values computed incrementally by
2022-12-06 22:26:56 -08:00
* updateClientMemoryUsage ( ) . */
2020-04-07 12:07:09 +02:00
mh - > clients_normal = server . stat_clients_type_memory [ CLIENT_TYPE_MASTER ] +
server . stat_clients_type_memory [ CLIENT_TYPE_PUBSUB ] +
server . stat_clients_type_memory [ CLIENT_TYPE_NORMAL ] ;
mem_total + = mh - > clients_normal ;
2016-09-15 09:37:55 +02:00
2021-12-16 21:56:59 -08:00
mh - > cluster_links = server . stat_cluster_links_memory ;
mem_total + = mh - > cluster_links ;
2016-09-15 09:37:55 +02:00
mem = 0 ;
if ( server . aof_state ! = AOF_OFF ) {
2020-10-01 11:30:22 +03:00
mem + = sdsZmallocSize ( server . aof_buf ) ;
2016-09-15 09:37:55 +02:00
}
mh - > aof_buffer = mem ;
mem_total + = mem ;
2021-10-05 17:03:12 +03:00
mem = evalScriptsMemory ( ) ;
2018-07-22 21:16:00 +03:00
mh - > lua_caches = mem ;
mem_total + = mem ;
2021-10-07 14:41:26 +03:00
mh - > functions_caches = functionsMemoryOverhead ( ) ;
mem_total + = mh - > functions_caches ;
2018-07-22 21:16:00 +03:00
2016-09-15 09:37:55 +02:00
for ( j = 0 ; j < server . dbnum ; j + + ) {
redisDb * db = server . db + j ;
long long keyscount = dictSize ( db - > dict ) ;
if ( keyscount = = 0 ) continue ;
2016-09-16 16:36:53 +02:00
mh - > total_keys + = keyscount ;
2016-09-15 09:37:55 +02:00
mh - > db = zrealloc ( mh - > db , sizeof ( mh - > db [ 0 ] ) * ( mh - > num_dbs + 1 ) ) ;
mh - > db [ mh - > num_dbs ] . dbid = j ;
2023-01-11 09:57:10 +01:00
mem = dictMemUsage ( db - > dict ) +
2016-09-15 09:37:55 +02:00
dictSize ( db - > dict ) * sizeof ( robj ) ;
mh - > db [ mh - > num_dbs ] . overhead_ht_main = mem ;
mem_total + = mem ;
2023-01-11 09:57:10 +01:00
mem = dictMemUsage ( db - > expires ) ;
2016-09-15 09:37:55 +02:00
mh - > db [ mh - > num_dbs ] . overhead_ht_expires = mem ;
mem_total + = mem ;
2022-01-02 00:39:59 -08:00
/* Account for the slot to keys map in cluster mode */
2022-11-20 23:23:54 +01:00
mem = dictSize ( db - > dict ) * dictEntryMetadataSize ( db - > dict ) +
dictMetadataSize ( db - > dict ) ;
2022-01-02 00:39:59 -08:00
mh - > db [ mh - > num_dbs ] . overhead_ht_slot_to_keys = mem ;
mem_total + = mem ;
2016-09-15 09:37:55 +02:00
mh - > num_dbs + + ;
}
mh - > overhead_total = mem_total ;
mh - > dataset = zmalloc_used - mem_total ;
2016-09-16 16:36:53 +02:00
mh - > peak_perc = ( float ) zmalloc_used * 100 / mh - > peak_allocated ;
2016-09-15 17:33:11 +02:00
2016-09-16 16:36:53 +02:00
/* Metrics computed after subtracting the startup memory from
* the total memory . */
2016-09-15 17:33:11 +02:00
size_t net_usage = 1 ;
if ( zmalloc_used > mh - > startup_allocated )
net_usage = zmalloc_used - mh - > startup_allocated ;
mh - > dataset_perc = ( float ) mh - > dataset * 100 / net_usage ;
2016-09-16 16:36:53 +02:00
mh - > bytes_per_key = mh - > total_keys ? ( net_usage / mh - > total_keys ) : 0 ;
2016-09-15 17:33:11 +02:00
2016-09-15 09:37:55 +02:00
return mh ;
}
2016-09-16 10:26:23 +02:00
/* Helper for "MEMORY allocator-stats", used as a callback for the jemalloc
* stats output . */
void inputCatSds ( void * result , const char * str ) {
/* result is actually a (sds *), so re-cast it here */
sds * info = ( sds * ) result ;
* info = sdscat ( * info , str ) ;
}
2016-09-16 16:36:53 +02:00
/* This implements MEMORY DOCTOR. An human readable analysis of the Redis
* memory condition . */
sds getMemoryDoctorReport ( void ) {
int empty = 0 ; /* Instance is empty or almost empty. */
int big_peak = 0 ; /* Memory peak is much larger than used mem. */
int high_frag = 0 ; /* High fragmentation. */
2018-02-18 17:36:21 +02:00
int high_alloc_frag = 0 ; /* High allocator fragmentation. */
int high_proc_rss = 0 ; /* High process rss overhead. */
int high_alloc_rss = 0 ; /* High rss overhead. */
2016-09-16 16:36:53 +02:00
int big_slave_buf = 0 ; /* Slave buffers are too big. */
int big_client_buf = 0 ; /* Client buffers are too big. */
2018-07-22 21:16:00 +03:00
int many_scripts = 0 ; /* Script cache has too many scripts. */
2016-09-16 16:36:53 +02:00
int num_reports = 0 ;
struct redisMemOverhead * mh = getMemoryOverheadData ( ) ;
if ( mh - > total_allocated < ( 1024 * 1024 * 5 ) ) {
empty = 1 ;
num_reports + + ;
} else {
/* Peak is > 150% of current used memory? */
if ( ( ( float ) mh - > peak_allocated / mh - > total_allocated ) > 1.5 ) {
big_peak = 1 ;
num_reports + + ;
}
2018-02-18 17:36:21 +02:00
/* Fragmentation is higher than 1.4 and 10MB ?*/
if ( mh - > total_frag > 1.4 & & mh - > total_frag_bytes > 10 < < 20 ) {
2016-09-16 16:36:53 +02:00
high_frag = 1 ;
num_reports + + ;
}
2018-02-18 17:36:21 +02:00
/* External fragmentation is higher than 1.1 and 10MB? */
if ( mh - > allocator_frag > 1.1 & & mh - > allocator_frag_bytes > 10 < < 20 ) {
high_alloc_frag = 1 ;
num_reports + + ;
}
2019-12-31 17:46:48 +09:00
/* Allocator rss is higher than 1.1 and 10MB ? */
2018-02-18 17:36:21 +02:00
if ( mh - > allocator_rss > 1.1 & & mh - > allocator_rss_bytes > 10 < < 20 ) {
high_alloc_rss = 1 ;
num_reports + + ;
}
2019-12-31 17:46:48 +09:00
/* Non-Allocator rss is higher than 1.1 and 10MB ? */
2018-02-18 17:36:21 +02:00
if ( mh - > rss_extra > 1.1 & & mh - > rss_extra_bytes > 10 < < 20 ) {
high_proc_rss = 1 ;
num_reports + + ;
}
2016-09-16 16:36:53 +02:00
/* Clients using more than 200k each average? */
long numslaves = listLength ( server . slaves ) ;
long numclients = listLength ( server . clients ) - numslaves ;
if ( mh - > clients_normal / numclients > ( 1024 * 200 ) ) {
big_client_buf = 1 ;
num_reports + + ;
}
/* Slaves using more than 10 MB each? */
Replication backlog and replicas use one global shared replication buffer (#9166)
## Background
For redis master, one replica uses one copy of replication buffer, that is a big waste of memory,
more replicas more waste, and allocate/free memory for every reply list also cost much.
If we set client-output-buffer-limit small and write traffic is heavy, master may disconnect with
replicas and can't finish synchronization with replica. If we set client-output-buffer-limit big,
master may be OOM when there are many replicas that separately keep much memory.
Because replication buffers of different replica client are the same, one simple idea is that
all replicas only use one replication buffer, that will effectively save memory.
Since replication backlog content is the same as replicas' output buffer, now we
can discard replication backlog memory and use global shared replication buffer
to implement replication backlog mechanism.
## Implementation
I create one global "replication buffer" which contains content of replication stream.
The structure of "replication buffer" is similar to the reply list that exists in every client.
But the node of list is `replBufBlock`, which has `id, repl_offset, refcount` fields.
```c
/* Replication buffer blocks is the list of replBufBlock.
*
* +--------------+ +--------------+ +--------------+
* | refcount = 1 | ... | refcount = 0 | ... | refcount = 2 |
* +--------------+ +--------------+ +--------------+
* | / \
* | / \
* | / \
* Repl Backlog Replia_A Replia_B
*
* Each replica or replication backlog increments only the refcount of the
* 'ref_repl_buf_node' which it points to. So when replica walks to the next
* node, it should first increase the next node's refcount, and when we trim
* the replication buffer nodes, we remove node always from the head node which
* refcount is 0. If the refcount of the head node is not 0, we must stop
* trimming and never iterate the next node. */
/* Similar with 'clientReplyBlock', it is used for shared buffers between
* all replica clients and replication backlog. */
typedef struct replBufBlock {
int refcount; /* Number of replicas or repl backlog using. */
long long id; /* The unique incremental number. */
long long repl_offset; /* Start replication offset of the block. */
size_t size, used;
char buf[];
} replBufBlock;
```
So now when we feed replication stream into replication backlog and all replicas, we only need
to feed stream into replication buffer `feedReplicationBuffer`. In this function, we set some fields of
replication backlog and replicas to references of the global replication buffer blocks. And we also
need to check replicas' output buffer limit to free if exceeding `client-output-buffer-limit`, and trim
replication backlog if exceeding `repl-backlog-size`.
When sending reply to replicas, we also need to iterate replication buffer blocks and send its
content, when totally sending one block for replica, we decrease current node count and
increase the next current node count, and then free the block which reference is 0 from the
head of replication buffer blocks.
Since now we use linked list to manage replication backlog, it may cost much time for iterating
all linked list nodes to find corresponding replication buffer node. So we create a rax tree to
store some nodes for index, but to avoid rax tree occupying too much memory, i record
one per 64 nodes for index.
Currently, to make partial resynchronization as possible as much, we always let replication
backlog as the last reference of replication buffer blocks, backlog size may exceeds our setting
if slow replicas that reference vast replication buffer blocks, and this method doesn't increase
memory usage since they share replication buffer. To avoid freezing server for freeing unreferenced
replication buffer blocks when we need to trim backlog for exceeding backlog size setting,
we trim backlog incrementally (free 64 blocks per call now), and make it faster in
`beforeSleep` (free 640 blocks).
### Other changes
- `mem_total_replication_buffers`: we add this field in INFO command, it means the total
memory of replication buffers used.
- `mem_clients_slaves`: now even replica is slow to replicate, and its output buffer memory
is not 0, but it still may be 0, since replication backlog and replicas share one global replication
buffer, only if replication buffer memory is more than the repl backlog setting size, we consider
the excess as replicas' memory. Otherwise, we think replication buffer memory is the consumption
of repl backlog.
- Key eviction
Since all replicas and replication backlog share global replication buffer, we think only the
part of exceeding backlog size the extra separate consumption of replicas.
Because we trim backlog incrementally in the background, backlog size may exceeds our
setting if slow replicas that reference vast replication buffer blocks disconnect.
To avoid massive eviction loop, we don't count the delayed freed replication backlog into
used memory even if there are no replicas, i.e. we also regard this memory as replicas's memory.
- `client-output-buffer-limit` check for replica clients
It doesn't make sense to set the replica clients output buffer limit lower than the repl-backlog-size
config (partial sync will succeed and then replica will get disconnected). Such a configuration is
ignored (the size of repl-backlog-size will be used). This doesn't have memory consumption
implications since the replica client will share the backlog buffers memory.
- Drop replication backlog after loading data if needed
We always create replication backlog if server is a master, we need it because we put DELs in
it when loading expired keys in RDB, but if RDB doesn't have replication info or there is no rdb,
it is not possible to support partial resynchronization, to avoid extra memory of replication backlog,
we drop it.
- Multi IO threads
Since all replicas and replication backlog use global replication buffer, if I/O threads are enabled,
to guarantee data accessing thread safe, we must let main thread handle sending the output buffer
to all replicas. But before, other IO threads could handle sending output buffer of all replicas.
## Other optimizations
This solution resolve some other problem:
- When replicas disconnect with master since of out of output buffer limit, releasing the output
buffer of replicas may freeze server if we set big `client-output-buffer-limit` for replicas, but now,
it doesn't cause freezing.
- This implementation may mitigate reply list copy cost time(also freezes server) when one replication
has huge reply buffer and another replica can copy buffer for full synchronization. now, we just copy
reference info, it is very light.
- If we set replication backlog size big, it also may cost much time to copy replication backlog into
replica's output buffer. But this commit eliminates this problem.
- Resizing replication backlog size doesn't empty current replication backlog content.
2021-10-25 14:24:31 +08:00
if ( numslaves > 0 & & mh - > clients_slaves > ( 1024 * 1024 * 10 ) ) {
2016-09-16 16:36:53 +02:00
big_slave_buf = 1 ;
num_reports + + ;
}
2018-07-22 21:16:00 +03:00
2018-07-23 18:44:38 +02:00
/* Too many scripts are cached? */
2021-10-05 17:03:12 +03:00
if ( dictSize ( evalScriptsDict ( ) ) > 1000 ) {
2018-07-22 21:16:00 +03:00
many_scripts = 1 ;
num_reports + + ;
}
2016-09-16 16:36:53 +02:00
}
sds s ;
if ( num_reports = = 0 ) {
s = sdsnew (
2016-09-16 16:52:00 +02:00
" Hi Sam, I can't find any memory issue in your instance. "
2016-12-06 03:11:27 +00:00
" I can only account for what occurs on this base. \n " ) ;
2016-09-16 16:36:53 +02:00
} else if ( empty = = 1 ) {
s = sdsnew (
" Hi Sam, this instance is empty or is using very little memory, "
" my issues detector can't be used in these conditions. "
" Please, leave for your mission on Earth and fill it with some data. "
" The new Sam and I will be back to our programming as soon as I "
2016-12-06 03:11:27 +00:00
" finished rebooting. \n " ) ;
2016-09-16 16:36:53 +02:00
} else {
s = sdsnew ( " Sam, I detected a few issues in this Redis instance memory implants: \n \n " ) ;
if ( big_peak ) {
s = sdscat ( s , " * Peak memory: In the past this instance used more than 150% the memory that is currently using. The allocator is normally not able to release memory after a peak, so you can expect to see a big fragmentation ratio, however this is actually harmless and is only due to the memory peak, and if the Redis instance Resident Set Size (RSS) is currently bigger than expected, the memory will be used as soon as you fill the Redis instance with more data. If the memory peak was only occasional and you want to try to reclaim memory, please try the MEMORY PURGE command, otherwise the only other option is to shutdown and restart the instance. \n \n " ) ;
}
if ( high_frag ) {
2018-02-18 17:36:21 +02:00
s = sdscatprintf ( s , " * High total RSS: This instance has a memory fragmentation and RSS overhead greater than 1.4 (this means that the Resident Set Size of the Redis process is much larger than the sum of the logical allocations Redis performed). This problem is usually due either to a large peak memory (check if there is a peak memory entry above in the report) or may result from a workload that causes the allocator to fragment memory a lot. If the problem is a large peak memory, then there is no issue. Otherwise, make sure you are using the Jemalloc allocator and not the default libc malloc. Note: The currently used allocator is \" %s \" . \n \n " , ZMALLOC_LIB ) ;
}
if ( high_alloc_frag ) {
s = sdscatprintf ( s , " * High allocator fragmentation: This instance has an allocator external fragmentation greater than 1.1. This problem is usually due either to a large peak memory (check if there is a peak memory entry above in the report) or may result from a workload that causes the allocator to fragment memory a lot. You can try enabling 'activedefrag' config option. \n \n " ) ;
}
if ( high_alloc_rss ) {
s = sdscatprintf ( s , " * High allocator RSS overhead: This instance has an RSS memory overhead is greater than 1.1 (this means that the Resident Set Size of the allocator is much larger than the sum what the allocator actually holds). This problem is usually due to a large peak memory (check if there is a peak memory entry above in the report), you can try the MEMORY PURGE command to reclaim it. \n \n " ) ;
}
if ( high_proc_rss ) {
2018-07-22 21:16:00 +03:00
s = sdscatprintf ( s , " * High process RSS overhead: This instance has non-allocator RSS memory overhead is greater than 1.1 (this means that the Resident Set Size of the Redis process is much larger than the RSS the allocator holds). This problem may be due to Lua scripts or Modules. \n \n " ) ;
2016-09-16 16:36:53 +02:00
}
if ( big_slave_buf ) {
2018-09-11 10:54:09 +02:00
s = sdscat ( s , " * Big replica buffers: The replica output buffers in this instance are greater than 10MB for each replica (on average). This likely means that there is some replica instance that is struggling receiving data, either because it is too slow or because of networking issues. As a result, data piles on the master output buffers. Please try to identify what replica is not receiving data correctly and why. You can use the INFO output in order to check the replicas delays and the CLIENT LIST command to check the output buffers of each replica. \n \n " ) ;
2016-09-16 16:36:53 +02:00
}
if ( big_client_buf ) {
s = sdscat ( s , " * Big client buffers: The clients output buffers in this instance are greater than 200K per client (on average). This may result from different causes, like Pub/Sub clients subscribed to channels bot not receiving data fast enough, so that data piles on the Redis instance output buffer, or clients sending commands with large replies or very large sequences of commands in the same pipeline. Please use the CLIENT LIST command in order to investigate the issue if it causes problems in your instance, or to understand better why certain clients are using a big amount of memory. \n \n " ) ;
}
2018-07-22 21:16:00 +03:00
if ( many_scripts ) {
2018-07-23 18:44:38 +02:00
s = sdscat ( s , " * Many scripts: There seem to be many cached scripts in this instance (more than 1000). This may be because scripts are generated and `EVAL`ed, instead of being parameterized (with KEYS and ARGV), `SCRIPT LOAD`ed and `EVALSHA`ed. Unless `SCRIPT FLUSH` is called periodically, the scripts' caches may end up consuming most of your memory. \n \n " ) ;
2018-07-22 21:16:00 +03:00
}
2016-09-16 16:36:53 +02:00
s = sdscat ( s , " I'm here to keep you safe, Sam. I want to help you. \n " ) ;
}
freeMemoryOverheadData ( mh ) ;
return s ;
}
2018-06-20 14:40:18 +07:00
/* Set the object LRU/LFU depending on server.maxmemory_policy.
* The lfu_freq arg is only relevant if policy is MAXMEMORY_FLAG_LFU .
2019-03-14 17:06:59 +01:00
* The lru_idle and lru_clock args are only relevant if policy
2018-06-20 14:40:18 +07:00
* is MAXMEMORY_FLAG_LRU .
* Either or both of them may be < 0 , in that case , nothing is set . */
2019-10-23 11:53:15 +03:00
int objectSetLRUOrLFU ( robj * val , long long lfu_freq , long long lru_idle ,
2019-11-10 09:04:39 +02:00
long long lru_clock , int lru_multiplier ) {
2018-06-20 14:40:18 +07:00
if ( server . maxmemory_policy & MAXMEMORY_FLAG_LFU ) {
if ( lfu_freq > = 0 ) {
serverAssert ( lfu_freq < = 255 ) ;
val - > lru = ( LFUGetTimeInMinutes ( ) < < 8 ) | lfu_freq ;
2019-10-23 11:53:15 +03:00
return 1 ;
2018-06-20 14:40:18 +07:00
}
} else if ( lru_idle > = 0 ) {
2019-03-14 17:06:59 +01:00
/* Provided LRU idle time is in seconds. Scale
2018-06-20 14:40:18 +07:00
* according to the LRU clock resolution this Redis
* instance was compiled with ( normally 1000 ms , so the
* below statement will expand to lru_idle * 1000 / 1000. */
2019-11-10 09:04:39 +02:00
lru_idle = lru_idle * lru_multiplier / LRU_CLOCK_RESOLUTION ;
2019-03-14 17:06:59 +01:00
long lru_abs = lru_clock - lru_idle ; /* Absolute access time. */
Fix LRU blue moon bug in RESTORE, RDB loading, module API (#9279)
The `lru_clock` and `lru` bits in `robj` save the least significant 24 bits of the unixtime (seconds since 1/1/1970),
and wrap around every 194 days.
The `objectSetLRUOrLFU` function, which is used in RESTORE with IDLETIME argument, and also in replica
or master loading an RDB that contains LRU, and by a module API had a bug that's triggered when that happens.
The scenario was that the idle time that came from the user, let's say RESTORE command is about 1000 seconds
(e.g. in the `RESTORE can set LRU` test we have), and the current `lru_clock` just wrapped around and is less than
1000 (i.e. a period of 1000 seconds once in some 6 months), the expression in that function would produce a negative
value and the code (and comment) specified that the best way to solve that is push the idle time backwards into the
past by 3 months. i.e. an idle time of 3 months instead of 1000 seconds.
instead, the right thing to do is to unwrap it, and put it near LRU_CLOCK_MAX. since now `lru_clock` is smaller than
`obj->lru` it will be unwrapped again by `estimateObjectIdleTime`.
bug was introduced by 052e03495f, but the code before it also seemed wrong.
2021-07-29 12:11:29 +03:00
/* If the LRU field underflows (since lru_clock is a wrapping clock),
* we need to make it positive again . This be handled by the unwrapping
* code in estimateObjectIdleTime . I . e . imagine a day when lru_clock
* wrap arounds ( happens once in some 6 months ) , and becomes a low
* value , like 10 , an lru_idle of 1000 should be near LRU_CLOCK_MAX . */
2019-03-14 17:06:59 +01:00
if ( lru_abs < 0 )
Fix LRU blue moon bug in RESTORE, RDB loading, module API (#9279)
The `lru_clock` and `lru` bits in `robj` save the least significant 24 bits of the unixtime (seconds since 1/1/1970),
and wrap around every 194 days.
The `objectSetLRUOrLFU` function, which is used in RESTORE with IDLETIME argument, and also in replica
or master loading an RDB that contains LRU, and by a module API had a bug that's triggered when that happens.
The scenario was that the idle time that came from the user, let's say RESTORE command is about 1000 seconds
(e.g. in the `RESTORE can set LRU` test we have), and the current `lru_clock` just wrapped around and is less than
1000 (i.e. a period of 1000 seconds once in some 6 months), the expression in that function would produce a negative
value and the code (and comment) specified that the best way to solve that is push the idle time backwards into the
past by 3 months. i.e. an idle time of 3 months instead of 1000 seconds.
instead, the right thing to do is to unwrap it, and put it near LRU_CLOCK_MAX. since now `lru_clock` is smaller than
`obj->lru` it will be unwrapped again by `estimateObjectIdleTime`.
bug was introduced by 052e03495f, but the code before it also seemed wrong.
2021-07-29 12:11:29 +03:00
lru_abs + = LRU_CLOCK_MAX ;
2019-03-14 17:06:59 +01:00
val - > lru = lru_abs ;
2019-10-23 11:53:15 +03:00
return 1 ;
2018-06-20 14:40:18 +07:00
}
2019-10-23 11:53:15 +03:00
return 0 ;
2018-06-20 14:40:18 +07:00
}
2016-09-16 10:11:52 +02:00
/* ======================= The OBJECT and MEMORY commands =================== */
/* This is a helper function for the OBJECT command. We need to lookup keys
* without any modification of LRU or other parameters . */
robj * objectCommandLookup ( client * c , robj * key ) {
2020-11-18 10:16:21 +01:00
return lookupKeyReadWithFlags ( c - > db , key , LOOKUP_NOTOUCH | LOOKUP_NONOTIFY ) ;
2016-09-16 10:11:52 +02:00
}
robj * objectCommandLookupOrReply ( client * c , robj * key , robj * reply ) {
robj * o = objectCommandLookup ( c , key ) ;
2021-08-10 10:19:21 +03:00
if ( ! o ) addReplyOrErrorObject ( c , reply ) ;
2016-09-16 10:11:52 +02:00
return o ;
}
Squash merging 125 typo/grammar/comment/doc PRs (#7773)
List of squashed commits or PRs
===============================
commit 66801ea
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Jan 13 00:54:31 2020 -0500
typo fix in acl.c
commit 46f55db
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun Sep 6 18:24:11 2020 +0300
Updates a couple of comments
Specifically:
* RM_AutoMemory completed instead of pointing to docs
* Updated link to custom type doc
commit 61a2aa0
Author: xindoo <xindoo@qq.com>
Date: Tue Sep 1 19:24:59 2020 +0800
Correct errors in code comments
commit a5871d1
Author: yz1509 <pro-756@qq.com>
Date: Tue Sep 1 18:36:06 2020 +0800
fix typos in module.c
commit 41eede7
Author: bookug <bookug@qq.com>
Date: Sat Aug 15 01:11:33 2020 +0800
docs: fix typos in comments
commit c303c84
Author: lazy-snail <ws.niu@outlook.com>
Date: Fri Aug 7 11:15:44 2020 +0800
fix spelling in redis.conf
commit 1eb76bf
Author: zhujian <zhujianxyz@gmail.com>
Date: Thu Aug 6 15:22:10 2020 +0800
add a missing 'n' in comment
commit 1530ec2
Author: Daniel Dai <764122422@qq.com>
Date: Mon Jul 27 00:46:35 2020 -0400
fix spelling in tracking.c
commit e517b31
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:32 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit c300eff
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:23 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit 4c058a8
Author: 陈浩鹏 <chenhaopeng@heytea.com>
Date: Thu Jun 25 19:00:56 2020 +0800
Grammar fix and clarification
commit 5fcaa81
Author: bodong.ybd <bodong.ybd@alibaba-inc.com>
Date: Fri Jun 19 10:09:00 2020 +0800
Fix typos
commit 4caca9a
Author: Pruthvi P <pruthvi@ixigo.com>
Date: Fri May 22 00:33:22 2020 +0530
Fix typo eviciton => eviction
commit b2a25f6
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Sun May 17 12:39:59 2020 -0400
Fix a typo.
commit 12842ae
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun May 3 17:16:59 2020 -0400
fix spelling in redis conf
commit ddba07c
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sat May 2 23:25:34 2020 +0100
Correct a "conflicts" spelling error.
commit 8fc7bf2
Author: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Date: Thu Apr 30 10:25:27 2020 +0900
docs: fix EXPIRE_FAST_CYCLE_DURATION to ACTIVE_EXPIRE_CYCLE_FAST_DURATION
commit 9b2b67a
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Fri Apr 24 11:46:22 2020 -0400
Fix a typo.
commit 0746f10
Author: devilinrust <63737265+devilinrust@users.noreply.github.com>
Date: Thu Apr 16 00:17:53 2020 +0200
Fix typos in server.c
commit 92b588d
Author: benjessop12 <56115861+benjessop12@users.noreply.github.com>
Date: Mon Apr 13 13:43:55 2020 +0100
Fix spelling mistake in lazyfree.c
commit 1da37aa
Merge: 2d4ba28 af347a8
Author: hwware <wen.hui.ware@gmail.com>
Date: Thu Mar 5 22:41:31 2020 -0500
Merge remote-tracking branch 'upstream/unstable' into expiretypofix
commit 2d4ba28
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Mar 2 00:09:40 2020 -0500
fix typo in expire.c
commit 1a746f7
Author: SennoYuki <minakami1yuki@gmail.com>
Date: Thu Feb 27 16:54:32 2020 +0800
fix typo
commit 8599b1a
Author: dongheejeong <donghee950403@gmail.com>
Date: Sun Feb 16 20:31:43 2020 +0000
Fix typo in server.c
commit f38d4e8
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun Feb 2 22:58:38 2020 -0500
fix typo in evict.c
commit fe143fc
Author: Leo Murillo <leonardo.murillo@gmail.com>
Date: Sun Feb 2 01:57:22 2020 -0600
Fix a few typos in redis.conf
commit 1ab4d21
Author: viraja1 <anchan.viraj@gmail.com>
Date: Fri Dec 27 17:15:58 2019 +0530
Fix typo in Latency API docstring
commit ca1f70e
Author: gosth <danxuedexing@qq.com>
Date: Wed Dec 18 15:18:02 2019 +0800
fix typo in sort.c
commit a57c06b
Author: ZYunH <zyunhjob@163.com>
Date: Mon Dec 16 22:28:46 2019 +0800
fix-zset-typo
commit b8c92b5
Author: git-hulk <hulk.website@gmail.com>
Date: Mon Dec 16 15:51:42 2019 +0800
FIX: typo in cluster.c, onformation->information
commit 9dd981c
Author: wujm2007 <jim.wujm@gmail.com>
Date: Mon Dec 16 09:37:52 2019 +0800
Fix typo
commit e132d7a
Author: Sebastien Williams-Wynn <s.williamswynn.mail@gmail.com>
Date: Fri Nov 15 00:14:07 2019 +0000
Minor typo change
commit 47f44d5
Author: happynote3966 <01ssrmikururudevice01@gmail.com>
Date: Mon Nov 11 22:08:48 2019 +0900
fix comment typo in redis-cli.c
commit b8bdb0d
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 18:00:17 2019 +0800
Fix a spelling mistake of comments in defragDictBucketCallback
commit 0def46a
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 13:09:27 2019 +0800
fix some spelling mistakes of comments in defrag.c
commit f3596fd
Author: Phil Rajchgot <tophil@outlook.com>
Date: Sun Oct 13 02:02:32 2019 -0400
Typo and grammar fixes
Redis and its documentation are great -- just wanted to submit a few corrections in the spirit of Hacktoberfest. Thanks for all your work on this project. I use it all the time and it works beautifully.
commit 2b928cd
Author: KangZhiDong <worldkzd@gmail.com>
Date: Sun Sep 1 07:03:11 2019 +0800
fix typos
commit 33aea14
Author: Axlgrep <axlgrep@gmail.com>
Date: Tue Aug 27 11:02:18 2019 +0800
Fixed eviction spelling issues
commit e282a80
Author: Simen Flatby <simen@oms.no>
Date: Tue Aug 20 15:25:51 2019 +0200
Update comments to reflect prop name
In the comments the prop is referenced as replica-validity-factor,
but it is really named cluster-replica-validity-factor.
commit 74d1f9a
Author: Jim Green <jimgreen2013@qq.com>
Date: Tue Aug 20 20:00:31 2019 +0800
fix comment error, the code is ok
commit eea1407
Author: Liao Tonglang <liaotonglang@gmail.com>
Date: Fri May 31 10:16:18 2019 +0800
typo fix
fix cna't to can't
commit 0da553c
Author: KAWACHI Takashi <tkawachi@gmail.com>
Date: Wed Jul 17 00:38:16 2019 +0900
Fix typo
commit 7fc8fb6
Author: Michael Prokop <mika@grml.org>
Date: Tue May 28 17:58:42 2019 +0200
Typo fixes
s/familar/familiar/
s/compatiblity/compatibility/
s/ ot / to /
s/itsef/itself/
commit 5f46c9d
Author: zhumoing <34539422+zhumoing@users.noreply.github.com>
Date: Tue May 21 21:16:50 2019 +0800
typo-fixes
typo-fixes
commit 321dfe1
Author: wxisme <850885154@qq.com>
Date: Sat Mar 16 15:10:55 2019 +0800
typo fix
commit b4fb131
Merge: 267e0e6 3df1eb8
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Fri Feb 8 22:55:45 2019 +0200
Merge branch 'unstable' of antirez/redis into unstable
commit 267e0e6
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Wed Jan 30 21:26:04 2019 +0200
Minor typo fix
commit 30544e7
Author: inshal96 <39904558+inshal96@users.noreply.github.com>
Date: Fri Jan 4 16:54:50 2019 +0500
remove an extra 'a' in the comments
commit 337969d
Author: BrotherGao <yangdongheng11@gmail.com>
Date: Sat Dec 29 12:37:29 2018 +0800
fix typo in redis.conf
commit 9f4b121
Merge: 423a030 e504583
Author: BrotherGao <yangdongheng@xiaomi.com>
Date: Sat Dec 29 11:41:12 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 423a030
Merge: 42b02b7 46a51cd
Author: 杨东衡 <yangdongheng@xiaomi.com>
Date: Tue Dec 4 23:56:11 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 42b02b7
Merge: 68c0e6e b8febe6
Author: Dongheng Yang <yangdongheng11@gmail.com>
Date: Sun Oct 28 15:54:23 2018 +0800
Merge pull request #1 from antirez/unstable
update local data
commit 714b589
Author: Christian <crifei93@gmail.com>
Date: Fri Dec 28 01:17:26 2018 +0100
fix typo "resulution"
commit e23259d
Author: garenchan <1412950785@qq.com>
Date: Wed Dec 26 09:58:35 2018 +0800
fix typo: segfauls -> segfault
commit a9359f8
Author: xjp <jianping_xie@aliyun.com>
Date: Tue Dec 18 17:31:44 2018 +0800
Fixed REDISMODULE_H spell bug
commit a12c3e4
Author: jdiaz <jrd.palacios@gmail.com>
Date: Sat Dec 15 23:39:52 2018 -0600
Fixes hyperloglog hash function comment block description
commit 770eb11
Author: 林上耀 <1210tom@163.com>
Date: Sun Nov 25 17:16:10 2018 +0800
fix typo
commit fd97fbb
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Fri Nov 23 17:14:01 2018 +0100
Correct "unsupported" typo.
commit a85522d
Author: Jungnam Lee <jungnam.lee@oracle.com>
Date: Thu Nov 8 23:01:29 2018 +0900
fix typo in test comments
commit ade8007
Author: Arun Kumar <palerdot@users.noreply.github.com>
Date: Tue Oct 23 16:56:35 2018 +0530
Fixed grammatical typo
Fixed typo for word 'dictionary'
commit 869ee39
Author: Hamid Alaei <hamid.a85@gmail.com>
Date: Sun Aug 12 16:40:02 2018 +0430
fix documentations: (ThreadSafeContextStart/Stop -> ThreadSafeContextLock/Unlock), minor typo
commit f89d158
Author: Mayank Jain <mayankjain255@gmail.com>
Date: Tue Jul 31 23:01:21 2018 +0530
Updated README.md with some spelling corrections.
Made correction in spelling of some misspelled words.
commit 892198e
Author: dsomeshwar <someshwar.dhayalan@gmail.com>
Date: Sat Jul 21 23:23:04 2018 +0530
typo fix
commit 8a4d780
Author: Itamar Haber <itamar@redislabs.com>
Date: Mon Apr 30 02:06:52 2018 +0300
Fixes some typos
commit e3acef6
Author: Noah Rosamilia <ivoahivoah@gmail.com>
Date: Sat Mar 3 23:41:21 2018 -0500
Fix typo in /deps/README.md
commit 04442fb
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:32:42 2018 +0800
Fix typo in readSyncBulkPayload() comment.
commit 9f36880
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:20:37 2018 +0800
replication.c comment: run_id -> replid.
commit f866b4a
Author: Francesco 'makevoid' Canessa <makevoid@gmail.com>
Date: Thu Feb 22 22:01:56 2018 +0000
fix comment typo in server.c
commit 0ebc69b
Author: 줍 <jubee0124@gmail.com>
Date: Mon Feb 12 16:38:48 2018 +0900
Fix typo in redis.conf
Fix `five behaviors` to `eight behaviors` in [this sentence ](antirez/redis@unstable/redis.conf#L564)
commit b50a620
Author: martinbroadhurst <martinbroadhurst@users.noreply.github.com>
Date: Thu Dec 28 12:07:30 2017 +0000
Fix typo in valgrind.sup
commit 7d8f349
Author: Peter Boughton <peter@sorcerersisle.com>
Date: Mon Nov 27 19:52:19 2017 +0000
Update CONTRIBUTING; refer doc updates to redis-doc repo.
commit 02dec7e
Author: Klauswk <klauswk1@hotmail.com>
Date: Tue Oct 24 16:18:38 2017 -0200
Fix typo in comment
commit e1efbc8
Author: chenshi <baiwfg2@gmail.com>
Date: Tue Oct 3 18:26:30 2017 +0800
Correct two spelling errors of comments
commit 93327d8
Author: spacewander <spacewanderlzx@gmail.com>
Date: Wed Sep 13 16:47:24 2017 +0800
Update the comment for OBJ_ENCODING_EMBSTR_SIZE_LIMIT's value
The value of OBJ_ENCODING_EMBSTR_SIZE_LIMIT is 44 now instead of 39.
commit 63d361f
Author: spacewander <spacewanderlzx@gmail.com>
Date: Tue Sep 12 15:06:42 2017 +0800
Fix <prevlen> related doc in ziplist.c
According to the definition of ZIP_BIG_PREVLEN and other related code,
the guard of single byte <prevlen> should be 254 instead of 255.
commit ebe228d
Author: hanael80 <hanael80@gmail.com>
Date: Tue Aug 15 09:09:40 2017 +0900
Fix typo
commit 6b696e6
Author: Matt Robenolt <matt@ydekproductions.com>
Date: Mon Aug 14 14:50:47 2017 -0700
Fix typo in LATENCY DOCTOR output
commit a2ec6ae
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 15 14:15:16 2017 +0800
Fix a typo: form => from
commit 3ab7699
Author: caosiyang <caosiyang@qiyi.com>
Date: Thu Aug 10 18:40:33 2017 +0800
Fix a typo: replicationFeedSlavesFromMaster() => replicationFeedSlavesFromMasterStream()
commit 72d43ef
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 8 15:57:25 2017 +0800
fix a typo: servewr => server
commit 707c958
Author: Bo Cai <charpty@gmail.com>
Date: Wed Jul 26 21:49:42 2017 +0800
redis-cli.c typo: conut -> count.
Signed-off-by: Bo Cai <charpty@gmail.com>
commit b9385b2
Author: JackDrogon <jack.xsuperman@gmail.com>
Date: Fri Jun 30 14:22:31 2017 +0800
Fix some spell problems
commit 20d9230
Author: akosel <aaronjkosel@gmail.com>
Date: Sun Jun 4 19:35:13 2017 -0500
Fix typo
commit b167bfc
Author: Krzysiek Witkowicz <krzysiekwitkowicz@gmail.com>
Date: Mon May 22 21:32:27 2017 +0100
Fix #4008 small typo in comment
commit 2b78ac8
Author: Jake Clarkson <jacobwclarkson@gmail.com>
Date: Wed Apr 26 15:49:50 2017 +0100
Correct typo in tests/unit/hyperloglog.tcl
commit b0f1cdb
Author: Qi Luo <qiluo-msft@users.noreply.github.com>
Date: Wed Apr 19 14:25:18 2017 -0700
Fix typo
commit a90b0f9
Author: charsyam <charsyam@naver.com>
Date: Thu Mar 16 18:19:53 2017 +0900
fix typos
fix typos
fix typos
commit 8430a79
Author: Richard Hart <richardhart92@gmail.com>
Date: Mon Mar 13 22:17:41 2017 -0400
Fixed log message typo in listenToPort.
commit 481a1c2
Author: Vinod Kumar <kumar003vinod@gmail.com>
Date: Sun Jan 15 23:04:51 2017 +0530
src/db.c: Correct "save" -> "safe" typo
commit 586b4d3
Author: wangshaonan <wshn13@gmail.com>
Date: Wed Dec 21 20:28:27 2016 +0800
Fix typo they->the in helloworld.c
commit c1c4b5e
Author: Jenner <hypxm@qq.com>
Date: Mon Dec 19 16:39:46 2016 +0800
typo error
commit 1ee1a3f
Author: tielei <43289893@qq.com>
Date: Mon Jul 18 13:52:25 2016 +0800
fix some comments
commit 11a41fb
Author: Otto Kekäläinen <otto@seravo.fi>
Date: Sun Jul 3 10:23:55 2016 +0100
Fix spelling in documentation and comments
commit 5fb5d82
Author: francischan <f1ancis621@gmail.com>
Date: Tue Jun 28 00:19:33 2016 +0800
Fix outdated comments about redis.c file.
It should now refer to server.c file.
commit 6b254bc
Author: lmatt-bit <lmatt123n@gmail.com>
Date: Thu Apr 21 21:45:58 2016 +0800
Refine the comment of dictRehashMilliseconds func
SLAVECONF->REPLCONF in comment - by andyli029
commit ee9869f
Author: clark.kang <charsyam@naver.com>
Date: Tue Mar 22 11:09:51 2016 +0900
fix typos
commit f7b3b11
Author: Harisankar H <harisankarh@gmail.com>
Date: Wed Mar 9 11:49:42 2016 +0530
Typo correction: "faield" --> "failed"
Typo correction: "faield" --> "failed"
commit 3fd40fc
Author: Itamar Haber <itamar@redislabs.com>
Date: Thu Feb 25 10:31:51 2016 +0200
Fixes a typo in comments
commit 621c160
Author: Prayag Verma <prayag.verma@gmail.com>
Date: Mon Feb 1 12:36:20 2016 +0530
Fix typo in Readme.md
Spelling mistakes -
`eviciton` > `eviction`
`familar` > `familiar`
commit d7d07d6
Author: WonCheol Lee <toctoc21c@gmail.com>
Date: Wed Dec 30 15:11:34 2015 +0900
Typo fixed
commit a4dade7
Author: Felix Bünemann <buenemann@louis.info>
Date: Mon Dec 28 11:02:55 2015 +0100
[ci skip] Improve supervised upstart config docs
This mentions that "expect stop" is required for supervised upstart
to work correctly. See http://upstart.ubuntu.com/cookbook/#expect-stop
for an explanation.
commit d9caba9
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:30:03 2015 +1100
README: Remove trailing whitespace
commit 72d42e5
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:32 2015 +1100
README: Fix typo. th => the
commit dd6e957
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:20 2015 +1100
README: Fix typo. familar => familiar
commit 3a12b23
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:28:54 2015 +1100
README: Fix typo. eviciton => eviction
commit 2d1d03b
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:21:45 2015 +1100
README: Fix typo. sever => server
commit 3973b06
Author: Itamar Haber <itamar@garantiadata.com>
Date: Sat Dec 19 17:01:20 2015 +0200
Typo fix
commit 4f2e460
Author: Steve Gao <fu@2token.com>
Date: Fri Dec 4 10:22:05 2015 +0800
Update README - fix typos
commit b21667c
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:48:37 2015 +0800
delete redundancy color judge in sdscatcolor
commit 88894c7
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:14:42 2015 +0800
the example output shoule be HelloWorld
commit 2763470
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 17:41:39 2015 +0800
modify error word keyevente
Signed-off-by: binyan <binbin.yan@nokia.com>
commit 0847b3d
Author: Bruno Martins <bscmartins@gmail.com>
Date: Wed Nov 4 11:37:01 2015 +0000
typo
commit bbb9e9e
Author: dawedawe <dawedawe@gmx.de>
Date: Fri Mar 27 00:46:41 2015 +0100
typo: zimap -> zipmap
commit 5ed297e
Author: Axel Advento <badwolf.bloodseeker.rev@gmail.com>
Date: Tue Mar 3 15:58:29 2015 +0800
Fix 'salve' typos to 'slave'
commit edec9d6
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Wed Jun 12 14:12:47 2019 +0200
Update README.md
Co-Authored-By: Qix <Qix-@users.noreply.github.com>
commit 692a7af
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Tue May 28 14:32:04 2019 +0200
grammar
commit d962b0a
Author: Nick Frost <nickfrostatx@gmail.com>
Date: Wed Jul 20 15:17:12 2016 -0700
Minor grammar fix
commit 24fff01aaccaf5956973ada8c50ceb1462e211c6 (typos)
Author: Chad Miller <chadm@squareup.com>
Date: Tue Sep 8 13:46:11 2020 -0400
Fix faulty comment about operation of unlink()
commit 3cd5c1f3326c52aa552ada7ec797c6bb16452355
Author: Kevin <kevin.xgr@gmail.com>
Date: Wed Nov 20 00:13:50 2019 +0800
Fix typo in server.c.
From a83af59 Mon Sep 17 00:00:00 2001
From: wuwo <wuwo@wacai.com>
Date: Fri, 17 Mar 2017 20:37:45 +0800
Subject: [PATCH] falure to failure
From c961896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B7=A6=E6=87=B6?= <veficos@gmail.com>
Date: Sat, 27 May 2017 15:33:04 +0800
Subject: [PATCH] fix typo
From e600ef2 Mon Sep 17 00:00:00 2001
From: "rui.zou" <rui.zou@yunify.com>
Date: Sat, 30 Sep 2017 12:38:15 +0800
Subject: [PATCH] fix a typo
From c7d07fa Mon Sep 17 00:00:00 2001
From: Alexandre Perrin <alex@kaworu.ch>
Date: Thu, 16 Aug 2018 10:35:31 +0200
Subject: [PATCH] deps README.md typo
From b25cb67 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 10:55:37 +0300
Subject: [PATCH 1/2] fix typos in header
From ad28ca6 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 11:02:36 +0300
Subject: [PATCH 2/2] fix typos
commit 34924cdedd8552466fc22c1168d49236cb7ee915
Author: Adrian Lynch <adi_ady_ade@hotmail.com>
Date: Sat Apr 4 21:59:15 2015 +0100
Typos fixed
commit fd2a1e7
Author: Jan <jsteemann@users.noreply.github.com>
Date: Sat Oct 27 19:13:01 2018 +0200
Fix typos
Fix typos
commit e14e47c1a234b53b0e103c5f6a1c61481cbcbb02
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:30:07 2019 -0500
Fix multiple misspellings of "following"
commit 79b948ce2dac6b453fe80995abbcaac04c213d5a
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:24:28 2019 -0500
Fix misspelling of create-cluster
commit 1fffde52666dc99ab35efbd31071a4c008cb5a71
Author: Andy Lester <andy@petdance.com>
Date: Wed Jul 31 17:57:56 2019 -0500
Fix typos
commit 204c9ba9651e9e05fd73936b452b9a30be456cfe
Author: Xiaobo Zhu <xiaobo.zhu@shopee.com>
Date: Tue Aug 13 22:19:25 2019 +0800
fix typos
Squashed commit of the following:
commit 1d9aaf8
Author: danmedani <danmedani@gmail.com>
Date: Sun Aug 2 11:40:26 2015 -0700
README typo fix.
Squashed commit of the following:
commit 32bfa7c
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Jul 6 21:15:08 2015 +0200
Fixed grammer
Squashed commit of the following:
commit b24f69c
Author: Sisir Koppaka <sisir.koppaka@gmail.com>
Date: Mon Mar 2 22:38:45 2015 -0500
utils/hashtable/rehashing.c: Fix typos
Squashed commit of the following:
commit 4e04082
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Mar 23 08:22:21 2015 +0000
Small config file documentation improvements
Squashed commit of the following:
commit acb8773
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:52:48 2015 -0700
Typo and grammar fixes in readme
commit 2eb75b6
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:36:18 2015 -0700
fixed redis.conf comment
Squashed commit of the following:
commit a8249a2
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri Dec 11 11:39:52 2015 +0530
Revise correction of typos.
Squashed commit of the following:
commit 3c02028
Author: zhaojun11 <zhaojun11@jd.com>
Date: Wed Jan 17 19:05:28 2018 +0800
Fix typos include two code typos in cluster.c and latency.c
Squashed commit of the following:
commit 9dba47c
Author: q191201771 <191201771@qq.com>
Date: Sat Jan 4 11:31:04 2020 +0800
fix function listCreate comment in adlist.c
Update src/server.c
commit 2c7c2cb536e78dd211b1ac6f7bda00f0f54faaeb
Author: charpty <charpty@gmail.com>
Date: Tue May 1 23:16:59 2018 +0800
server.c typo: modules system dictionary type comment
Signed-off-by: charpty <charpty@gmail.com>
commit a8395323fb63cb59cb3591cb0f0c8edb7c29a680
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun May 6 00:25:18 2018 +0300
Updates test_helper.tcl's help with undocumented options
Specifically:
* Host
* Port
* Client
commit bde6f9ced15755cd6407b4af7d601b030f36d60b
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 15:19:19 2018 +0800
fix comments in deps files
commit 3172474ba991532ab799ee1873439f3402412331
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 14:33:49 2018 +0800
fix some comments
commit 01b6f2b6858b5cf2ce4ad5092d2c746e755f53f0
Author: Thor Juhasz <thor@juhasz.pro>
Date: Sun Nov 18 14:37:41 2018 +0100
Minor fixes to comments
Found some parts a little unclear on a first read, which prompted me to have a better look at the file and fix some minor things I noticed.
Fixing minor typos and grammar. There are no changes to configuration options.
These changes are only meant to help the user better understand the explanations to the various configuration options
2020-09-10 13:43:38 +03:00
/* Object command allows to inspect the internals of a Redis Object.
2017-11-24 19:59:05 +02:00
* Usage : OBJECT < refcount | encoding | idletime | freq > < key > */
2016-09-16 10:11:52 +02:00
void objectCommand ( client * c ) {
robj * o ;
2017-11-27 17:57:44 +02:00
if ( c - > argc = = 2 & & ! strcasecmp ( c - > argv [ 1 ] - > ptr , " help " ) ) {
const char * help [ ] = {
2021-01-04 17:02:57 +02:00
" ENCODING <key> " ,
" Return the kind of internal representation used in order to store the value " ,
" associated with a <key>. " ,
" FREQ <key> " ,
" Return the access frequency index of the <key>. The returned integer is " ,
" proportional to the logarithm of the recent access frequency of the key. " ,
" IDLETIME <key> " ,
" Return the idle time of the <key>, that is the approximated number of " ,
" seconds elapsed since the last access to the key. " ,
" REFCOUNT <key> " ,
" Return the number of references of the value associated with the specified " ,
" <key>. " ,
2017-12-06 12:05:11 +01:00
NULL
2017-11-27 17:57:44 +02:00
} ;
addReplyHelp ( c , help ) ;
2017-11-24 19:59:05 +02:00
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " refcount " ) & & c - > argc = = 3 ) {
2018-11-30 09:41:54 +01:00
if ( ( o = objectCommandLookupOrReply ( c , c - > argv [ 2 ] , shared . null [ c - > resp ] ) )
2016-09-16 10:11:52 +02:00
= = NULL ) return ;
addReplyLongLong ( c , o - > refcount ) ;
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " encoding " ) & & c - > argc = = 3 ) {
2018-11-30 09:41:54 +01:00
if ( ( o = objectCommandLookupOrReply ( c , c - > argv [ 2 ] , shared . null [ c - > resp ] ) )
2016-09-16 10:11:52 +02:00
= = NULL ) return ;
addReplyBulkCString ( c , strEncoding ( o - > encoding ) ) ;
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " idletime " ) & & c - > argc = = 3 ) {
2018-11-30 09:41:54 +01:00
if ( ( o = objectCommandLookupOrReply ( c , c - > argv [ 2 ] , shared . null [ c - > resp ] ) )
2016-09-16 10:11:52 +02:00
= = NULL ) return ;
if ( server . maxmemory_policy & MAXMEMORY_FLAG_LFU ) {
addReplyError ( c , " An LFU maxmemory policy is selected, idle time not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust. " ) ;
return ;
}
addReplyLongLong ( c , estimateObjectIdleTime ( o ) / 1000 ) ;
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " freq " ) & & c - > argc = = 3 ) {
2018-11-30 09:41:54 +01:00
if ( ( o = objectCommandLookupOrReply ( c , c - > argv [ 2 ] , shared . null [ c - > resp ] ) )
2016-09-16 10:11:52 +02:00
= = NULL ) return ;
2017-11-24 19:58:37 +02:00
if ( ! ( server . maxmemory_policy & MAXMEMORY_FLAG_LFU ) ) {
2017-10-15 20:17:55 +08:00
addReplyError ( c , " An LFU maxmemory policy is not selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust. " ) ;
2016-09-16 10:11:52 +02:00
return ;
}
2017-10-15 20:17:55 +08:00
/* LFUDecrAndReturn should be called
* in case of the key has not been accessed for a long time ,
* because we update the access time only
* when the key is read or overwritten . */
addReplyLongLong ( c , LFUDecrAndReturn ( o ) ) ;
2016-09-16 10:11:52 +02:00
} else {
2018-07-02 18:49:34 +02:00
addReplySubcommandSyntaxError ( c ) ;
2016-09-16 10:11:52 +02:00
}
}
2016-09-13 10:26:36 +02:00
/* The memory command will eventually be a complete interface for the
* memory introspection capabilities of Redis .
*
* Usage : MEMORY usage < key > */
void memoryCommand ( client * c ) {
2018-11-06 18:15:51 +01:00
if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " help " ) & & c - > argc = = 2 ) {
2017-12-10 17:54:56 +02:00
const char * help [ ] = {
2021-01-04 17:02:57 +02:00
" DOCTOR " ,
" Return memory problems reports. " ,
2021-07-13 23:16:05 +08:00
" MALLOC-STATS " ,
2021-01-04 17:02:57 +02:00
" Return internal statistics report from the memory allocator. " ,
" PURGE " ,
" Attempt to purge dirty pages for reclamation by the allocator. " ,
" STATS " ,
" Return information about the memory usage of the server. " ,
" USAGE <key> [SAMPLES <count>] " ,
" Return memory in bytes used by <key> and its value. Nested values are " ,
2021-10-17 17:31:06 +03:00
" sampled up to <count> times (default: 5, 0 means sample all). " ,
2017-12-10 17:54:56 +02:00
NULL
} ;
addReplyHelp ( c , help ) ;
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " usage " ) & & c - > argc > = 3 ) {
2018-11-29 01:01:47 +08:00
dictEntry * de ;
2016-09-15 15:25:05 +02:00
long long samples = OBJ_COMPUTE_SIZE_DEF_SAMPLES ;
for ( int j = 3 ; j < c - > argc ; j + + ) {
if ( ! strcasecmp ( c - > argv [ j ] - > ptr , " samples " ) & &
j + 1 < c - > argc )
{
if ( getLongLongFromObjectOrReply ( c , c - > argv [ j + 1 ] , & samples , NULL )
= = C_ERR ) return ;
if ( samples < 0 ) {
2020-12-23 19:06:25 -08:00
addReplyErrorObject ( c , shared . syntaxerr ) ;
2016-09-15 15:25:05 +02:00
return ;
}
2020-08-02 18:59:51 +08:00
if ( samples = = 0 ) samples = LLONG_MAX ;
2016-09-15 15:25:05 +02:00
j + + ; /* skip option argument. */
} else {
2020-12-23 19:06:25 -08:00
addReplyErrorObject ( c , shared . syntaxerr ) ;
2016-09-15 15:25:05 +02:00
return ;
}
}
2018-11-29 01:01:47 +08:00
if ( ( de = dictFind ( c - > db - > dict , c - > argv [ 2 ] - > ptr ) ) = = NULL ) {
2018-11-30 09:41:54 +01:00
addReplyNull ( c ) ;
2018-11-29 01:01:47 +08:00
return ;
}
2021-06-16 14:45:49 +08:00
size_t usage = objectComputeSize ( c - > argv [ 2 ] , dictGetVal ( de ) , samples , c - > db - > id ) ;
2020-10-01 11:30:22 +03:00
usage + = sdsZmallocSize ( dictGetKey ( de ) ) ;
2023-01-11 09:57:10 +01:00
usage + = dictEntryMemUsage ( ) ;
2022-01-02 00:39:59 -08:00
usage + = dictMetadataSize ( c - > db - > dict ) ;
2016-09-13 10:26:36 +02:00
addReplyLongLong ( c , usage ) ;
2016-09-16 16:36:53 +02:00
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " stats " ) & & c - > argc = = 2 ) {
2016-09-15 09:42:51 +02:00
struct redisMemOverhead * mh = getMemoryOverheadData ( ) ;
2016-09-13 17:39:22 +02:00
2022-03-29 16:54:45 +08:00
addReplyMapLen ( c , 27 + mh - > num_dbs ) ;
2016-09-16 10:43:19 +02:00
addReplyBulkCString ( c , " peak.allocated " ) ;
addReplyLongLong ( c , mh - > peak_allocated ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " total.allocated " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > total_allocated ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " startup.allocated " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > startup_allocated ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " replication.backlog " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > repl_backlog ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " clients.slaves " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > clients_slaves ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " clients.normal " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > clients_normal ) ;
2016-09-13 17:39:22 +02:00
2022-03-29 16:54:45 +08:00
addReplyBulkCString ( c , " cluster.links " ) ;
addReplyLongLong ( c , mh - > cluster_links ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " aof.buffer " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > aof_buffer ) ;
2016-09-13 17:39:22 +02:00
2018-07-22 21:16:00 +03:00
addReplyBulkCString ( c , " lua.caches " ) ;
addReplyLongLong ( c , mh - > lua_caches ) ;
2021-10-07 14:41:26 +03:00
addReplyBulkCString ( c , " functions.caches " ) ;
addReplyLongLong ( c , mh - > functions_caches ) ;
2016-09-15 09:37:55 +02:00
for ( size_t j = 0 ; j < mh - > num_dbs ; j + + ) {
2016-09-13 17:39:22 +02:00
char dbname [ 32 ] ;
2016-09-15 09:37:55 +02:00
snprintf ( dbname , sizeof ( dbname ) , " db.%zd " , mh - > db [ j ] . dbid ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , dbname ) ;
2022-01-02 00:39:59 -08:00
addReplyMapLen ( c , 3 ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " overhead.hashtable.main " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > db [ j ] . overhead_ht_main ) ;
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " overhead.hashtable.expires " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > db [ j ] . overhead_ht_expires ) ;
2022-01-02 00:39:59 -08:00
addReplyBulkCString ( c , " overhead.hashtable.slot-to-keys " ) ;
addReplyLongLong ( c , mh - > db [ j ] . overhead_ht_slot_to_keys ) ;
2016-09-13 17:39:22 +02:00
}
2022-01-02 00:39:59 -08:00
2016-09-13 17:39:22 +02:00
addReplyBulkCString ( c , " overhead.total " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > overhead_total ) ;
2016-09-13 17:39:22 +02:00
2016-09-16 16:36:53 +02:00
addReplyBulkCString ( c , " keys.count " ) ;
addReplyLongLong ( c , mh - > total_keys ) ;
addReplyBulkCString ( c , " keys.bytes-per-key " ) ;
addReplyLongLong ( c , mh - > bytes_per_key ) ;
2016-09-15 17:33:11 +02:00
addReplyBulkCString ( c , " dataset.bytes " ) ;
2016-09-15 09:37:55 +02:00
addReplyLongLong ( c , mh - > dataset ) ;
2016-09-13 17:39:22 +02:00
2016-09-15 17:33:11 +02:00
addReplyBulkCString ( c , " dataset.percentage " ) ;
addReplyDouble ( c , mh - > dataset_perc ) ;
2016-09-16 10:43:19 +02:00
addReplyBulkCString ( c , " peak.percentage " ) ;
addReplyDouble ( c , mh - > peak_perc ) ;
2018-02-18 17:36:21 +02:00
addReplyBulkCString ( c , " allocator.allocated " ) ;
addReplyLongLong ( c , server . cron_malloc_stats . allocator_allocated ) ;
addReplyBulkCString ( c , " allocator.active " ) ;
addReplyLongLong ( c , server . cron_malloc_stats . allocator_active ) ;
addReplyBulkCString ( c , " allocator.resident " ) ;
addReplyLongLong ( c , server . cron_malloc_stats . allocator_resident ) ;
addReplyBulkCString ( c , " allocator-fragmentation.ratio " ) ;
addReplyDouble ( c , mh - > allocator_frag ) ;
addReplyBulkCString ( c , " allocator-fragmentation.bytes " ) ;
addReplyLongLong ( c , mh - > allocator_frag_bytes ) ;
addReplyBulkCString ( c , " allocator-rss.ratio " ) ;
addReplyDouble ( c , mh - > allocator_rss ) ;
addReplyBulkCString ( c , " allocator-rss.bytes " ) ;
addReplyLongLong ( c , mh - > allocator_rss_bytes ) ;
addReplyBulkCString ( c , " rss-overhead.ratio " ) ;
addReplyDouble ( c , mh - > rss_extra ) ;
addReplyBulkCString ( c , " rss-overhead.bytes " ) ;
addReplyLongLong ( c , mh - > rss_extra_bytes ) ;
addReplyBulkCString ( c , " fragmentation " ) ; /* this is the total RSS overhead, including fragmentation */
addReplyDouble ( c , mh - > total_frag ) ; /* it is kept here for backwards compatibility */
addReplyBulkCString ( c , " fragmentation.bytes " ) ;
addReplyLongLong ( c , mh - > total_frag_bytes ) ;
2016-09-16 16:36:53 +02:00
2016-09-15 09:37:55 +02:00
freeMemoryOverheadData ( mh ) ;
2016-09-16 16:36:53 +02:00
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " malloc-stats " ) & & c - > argc = = 2 ) {
2016-09-16 10:26:23 +02:00
# if defined(USE_JEMALLOC)
sds info = sdsempty ( ) ;
je_malloc_stats_print ( inputCatSds , & info , NULL ) ;
2019-09-20 01:11:20 -07:00
addReplyVerbatim ( c , info , sdslen ( info ) , " txt " ) ;
2019-09-18 18:48:14 +02:00
sdsfree ( info ) ;
2016-09-16 10:26:23 +02:00
# else
addReplyBulkCString ( c , " Stats not supported for the current allocator " ) ;
# endif
2016-09-16 16:36:53 +02:00
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " doctor " ) & & c - > argc = = 2 ) {
sds report = getMemoryDoctorReport ( ) ;
2019-09-18 18:48:14 +02:00
addReplyVerbatim ( c , report , sdslen ( report ) , " txt " ) ;
sdsfree ( report ) ;
2016-09-16 10:26:23 +02:00
} else if ( ! strcasecmp ( c - > argv [ 1 ] - > ptr , " purge " ) & & c - > argc = = 2 ) {
2019-10-04 14:22:13 +03:00
if ( jemalloc_purge ( ) = = 0 )
addReply ( c , shared . ok ) ;
else
addReplyError ( c , " Error purging dirty pages " ) ;
2016-09-13 10:26:36 +02:00
} else {
2021-01-04 17:02:57 +02:00
addReplySubcommandSyntaxError ( c ) ;
2016-09-13 10:26:36 +02:00
}
}