Skip to content

Commit 378433b

Browse files
committed
apply patches
1 parent cbe96c1 commit 378433b

File tree

12 files changed

+3049
-17
lines changed

12 files changed

+3049
-17
lines changed

extern/redis-3.2.12/redis.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ tcp-keepalive 300
125125

126126
# By default Redis does not run as a daemon. Use 'yes' if you need it.
127127
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
128-
daemonize no
128+
daemonize yes
129129

130130
# If you run Redis from upstart or systemd, Redis can interact with your
131131
# supervision tree. Options:
@@ -147,7 +147,7 @@ supervised no
147147
#
148148
# Creating a pid file is best effort: if Redis is not able to create it
149149
# nothing bad happens, the server will start and run normally.
150-
pidfile /var/run/redis_6379.pid
150+
pidfile /tmp/redis_6379.pid
151151

152152
# Specify the server verbosity level.
153153
# This can be one of:
@@ -160,7 +160,7 @@ loglevel notice
160160
# Specify the log file name. Also the empty string can be used to force
161161
# Redis to log on the standard output. Note that if you use standard
162162
# output for logging but daemonize, logs will be sent to /dev/null
163-
logfile ""
163+
logfile "/tmp/redis_6379.log"
164164

165165
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
166166
# and optionally update the other syslog parameters to suit your needs.

extern/redis-3.2.12/src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ endif
105105
ifeq ($(MALLOC),jemalloc)
106106
DEPENDENCY_TARGETS+= jemalloc
107107
FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
108-
FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a
108+
FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -lrt
109109
endif
110110

111111
REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
@@ -127,7 +127,7 @@ endif
127127

128128
REDIS_SERVER_NAME=redis-server
129129
REDIS_SENTINEL_NAME=redis-sentinel
130-
REDIS_SERVER_OBJ=adlist.o quicklist.o ae.o anet.o dict.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o geo.o
130+
REDIS_SERVER_OBJ=adlist.o quicklist.o ae.o anet.o dict.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o geo.o slots.o slots_async.o crc32.o
131131
REDIS_GEOHASH_OBJ=../deps/geohash-int/geohash.o ../deps/geohash-int/geohash_helper.o
132132
REDIS_CLI_NAME=redis-cli
133133
REDIS_CLI_OBJ=anet.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o

extern/redis-3.2.12/src/Makefile.dep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ latency.o: latency.c server.h fmacros.h config.h solarisfixes.h \
6767
lzf_c.o: lzf_c.c lzfP.h
6868
lzf_d.o: lzf_d.c lzfP.h
6969
memtest.o: memtest.c config.h
70+
crc32.o: crc32.c
71+
slots.o: slots.c server.h
7072
multi.o: multi.c server.h fmacros.h config.h solarisfixes.h \
7173
../deps/lua/src/lua.h ../deps/lua/src/luaconf.h ae.h sds.h dict.h \
7274
adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h latency.h \

extern/redis-3.2.12/src/crc32.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdint.h>
2+
3+
static const uint32_t IEEE_POLY = 0xedb88320;
4+
5+
static uint32_t crc32tab[256];
6+
7+
static void
8+
crc32_tabinit(uint32_t poly) {
9+
int i, j;
10+
for (i = 0; i < 256; i ++) {
11+
uint32_t crc = i;
12+
for (j = 0; j < 8; j ++) {
13+
if (crc & 1) {
14+
crc = (crc >> 1) ^ poly;
15+
} else {
16+
crc = (crc >> 1);
17+
}
18+
}
19+
crc32tab[i] = crc;
20+
}
21+
}
22+
23+
void
24+
crc32_init() {
25+
crc32_tabinit(IEEE_POLY);
26+
}
27+
28+
static uint32_t
29+
crc32_update(uint32_t crc, const char *buf, int len) {
30+
int i;
31+
crc = ~crc;
32+
for (i = 0; i < len; i ++) {
33+
crc = crc32tab[(uint8_t)((char)crc ^ buf[i])] ^ (crc >> 8);
34+
}
35+
return ~crc;
36+
}
37+
38+
uint32_t
39+
crc32_checksum(const char *buf, int len) {
40+
return crc32_update(0, buf, len);
41+
}

extern/redis-3.2.12/src/db.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
158158
sds copy = sdsdup(key->ptr);
159159
int retval = dictAdd(db->dict, copy, val);
160160

161+
do {
162+
uint32_t crc;
163+
int hastag;
164+
int slot = slots_num(key->ptr, &crc, &hastag);
165+
dictAdd(db->hash_slots[slot], copy, (void *)(long)crc);
166+
if (hastag) {
167+
incrRefCount(key);
168+
zslInsert(db->tagged_keys, (double)crc, key);
169+
}
170+
} while (0);
171+
161172
serverAssertWithInfo(NULL,key,retval == DICT_OK);
162173
if (val->type == OBJ_LIST) signalListAsReady(db, key);
163174
if (server.cluster_enabled) slotToKeyAdd(key);
@@ -227,6 +238,18 @@ int dbDelete(redisDb *db, robj *key) {
227238
/* Deleting an entry from the expires dict will not free the sds of
228239
* the key, because it is shared with the main dictionary. */
229240
if (dictSize(db->expires) > 0) dictDelete(db->expires,key->ptr);
241+
242+
do {
243+
uint32_t crc;
244+
int hastag;
245+
int slot = slots_num(key->ptr, &crc, &hastag);
246+
if (dictDelete(db->hash_slots[slot], key->ptr) == DICT_OK) {
247+
if (hastag) {
248+
zslDelete(db->tagged_keys, (double)crc, key);
249+
}
250+
}
251+
} while (0);
252+
230253
if (dictDelete(db->dict,key->ptr) == DICT_OK) {
231254
if (server.cluster_enabled) slotToKeyDel(key);
232255
return 1;
@@ -274,11 +297,18 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
274297
}
275298

276299
long long emptyDb(void(callback)(void*)) {
277-
int j;
300+
int i, j;
278301
long long removed = 0;
279302

280303
for (j = 0; j < server.dbnum; j++) {
281304
removed += dictSize(server.db[j].dict);
305+
for (i = 0; i < HASH_SLOTS_SIZE; i ++) {
306+
dictEmpty(server.db[j].hash_slots[i], NULL);
307+
}
308+
if (server.db[j].tagged_keys->length != 0) {
309+
zslFree(server.db[j].tagged_keys);
310+
server.db[j].tagged_keys = zslCreate();
311+
}
282312
dictEmpty(server.db[j].dict,callback);
283313
dictEmpty(server.db[j].expires,callback);
284314
}
@@ -315,8 +345,16 @@ void signalFlushedDb(int dbid) {
315345
*----------------------------------------------------------------------------*/
316346

317347
void flushdbCommand(client *c) {
348+
int i;
318349
server.dirty += dictSize(c->db->dict);
319350
signalFlushedDb(c->db->id);
351+
for (i = 0; i < HASH_SLOTS_SIZE; i ++) {
352+
dictEmpty(c->db->hash_slots[i], NULL);
353+
}
354+
if (c->db->tagged_keys->length != 0) {
355+
zslFree(c->db->tagged_keys);
356+
c->db->tagged_keys = zslCreate();
357+
}
320358
dictEmpty(c->db->dict,NULL);
321359
dictEmpty(c->db->expires,NULL);
322360
if (server.cluster_enabled) slotToKeyFlush();
@@ -724,7 +762,15 @@ void shutdownCommand(client *c) {
724762
* Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */
725763
if (server.loading || server.sentinel_mode)
726764
flags = (flags & ~SHUTDOWN_SAVE) | SHUTDOWN_NOSAVE;
727-
if (prepareForShutdown(flags) == C_OK) exit(0);
765+
if (prepareForShutdown(flags) == C_OK) {
766+
for (int j = 0; j < server.dbnum; j ++) {
767+
for (int i = 0; i < HASH_SLOTS_SIZE; i ++) {
768+
dictRelease(server.db[j].hash_slots[i]);
769+
}
770+
zslFree(server.db[j].tagged_keys);
771+
}
772+
exit(0);
773+
}
728774
addReplyError(c,"Errors trying to SHUTDOWN. Check logs.");
729775
}
730776

extern/redis-3.2.12/src/help.h

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ static char *commandGroups[] = {
1717
"scripting",
1818
"hyperloglog",
1919
"cluster",
20-
"geo"
20+
"geo",
21+
"codis",
2122
};
2223

2324
struct commandHelp {
@@ -1011,7 +1012,123 @@ struct commandHelp {
10111012
"destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]",
10121013
"Add multiple sorted sets and store the resulting sorted set in a new key",
10131014
4,
1014-
"2.0.0" }
1015+
"2.0.0" },
1016+
{"SLOTSINFO",
1017+
"-",
1018+
"", 14, "codis1.9"
1019+
},
1020+
{"SLOTSSCAN",
1021+
"slotnum cursor [COUNT count]",
1022+
"", 14, "codis3.1"
1023+
},
1024+
{"SLOTSDEL",
1025+
"slot [slot ...]",
1026+
"", 14, "codis1.9"
1027+
},
1028+
{"SLOTSMGRTSLOT",
1029+
"host port timeout slot",
1030+
"", 14, "codis1.9"
1031+
},
1032+
{"SLOTSMGRTTAGSLOT",
1033+
"host port timeout slot",
1034+
"", 14, "codis1.9"
1035+
},
1036+
{"SLOTSMGRTONE",
1037+
"host port timeout key",
1038+
"", 14, "codis1.9"
1039+
},
1040+
{"SLOTSMGRTTAGONE",
1041+
"host port timeout key",
1042+
"", 14, "codis1.9"
1043+
},
1044+
{"SLOTSHASHKEY",
1045+
"key [key...]",
1046+
"", 14, "codis1.9"
1047+
},
1048+
{"SLOTSCHECK",
1049+
"-",
1050+
"", 14, "codis1.9"
1051+
},
1052+
{"SLOTSRESTORE",
1053+
"key ttl val [key ttl val ...]",
1054+
"", 14, "codis1.9"
1055+
},
1056+
{"SLOTSMGRTSLOT-ASYNC",
1057+
"host port timeout maxbulks maxbytes slot numkeys",
1058+
"", 14, "codis3.2"
1059+
},
1060+
{"SLOTSMGRTTAGSLOT-ASYNC",
1061+
"host port timeout maxbulks maxbytes slot numkeys",
1062+
"", 14, "codis3.2"
1063+
},
1064+
{"SLOTSMGRTONE-ASYNC",
1065+
"host port timeout maxbulks maxbytes key [key...]",
1066+
"", 14, "codis3.2"
1067+
},
1068+
{"SLOTSMGRTTAGONE-ASYNC",
1069+
"host port timeout maxbulks maxbytes key [key...]",
1070+
"", 14, "codis3.2"
1071+
},
1072+
{"SLOTSMGRTONE-ASYNC-DUMP",
1073+
"timeout maxbulks key [key...]",
1074+
"", 14, "codis3.2"
1075+
},
1076+
{"SLOTSMGRTTAGONE-ASYNC-DUMP",
1077+
"timeout maxbulks key [key...]",
1078+
"", 14, "codis3.2"
1079+
},
1080+
{"SLOTSMGRT-ASYNC-FENCE",
1081+
"-",
1082+
"", 14, "codis3.2"
1083+
},
1084+
{"SLOTSMGRT-ASYNC-CANCEL",
1085+
"-",
1086+
"", 14, "codis3.2"
1087+
},
1088+
{"SLOTSMGRT-ASYNC-STATUS",
1089+
"-",
1090+
"", 14, "codis3.2"
1091+
},
1092+
{"SLOTSMGRT-EXEC-WRAPPER",
1093+
"hashkey command [arg ...]",
1094+
"", 14, "codis3.2"
1095+
},
1096+
{"SLOTSRESTORE-ASYNC-SELECT",
1097+
"db",
1098+
"", 14, "codis3.2"
1099+
},
1100+
{"SLOTSRESTORE-ASYNC DELETE",
1101+
"key",
1102+
"", 14, "codis3.2"
1103+
},
1104+
{"SLOTSRESTORE-ASYNC EXPIRE",
1105+
"key ttl",
1106+
"", 14, "codis3.2"
1107+
},
1108+
{"SLOTSRESTORE-ASYNC OBJECT",
1109+
"key ttl payload",
1110+
"", 14, "codis3.2"
1111+
},
1112+
{"SLOTSRESTORE-ASYNC LIST",
1113+
"key ttl hint [elem ...]",
1114+
"", 14, "codis3.2"
1115+
},
1116+
{"SLOTSRESTORE-ASYNC HASH",
1117+
"key ttl hint [field value ...]",
1118+
"", 14, "codis3.2"
1119+
},
1120+
{"SLOTSRESTORE-ASYNC DICT",
1121+
"key ttl hint [elem ...]",
1122+
"", 14, "codis3.2"
1123+
},
1124+
{"SLOTSRESTORE-ASYNC ZSET",
1125+
"key ttl hint [field score ...]",
1126+
"", 14, "codis3.2"
1127+
},
1128+
{"SLOTSRESTORE-ASYNC-AUTH",
1129+
"passwd",
1130+
"", 14, "codis3.2"
1131+
},
10151132
};
10161133

10171134
#endif

extern/redis-3.2.12/src/networking.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ client *createClient(int fd) {
123123
c->pubsub_channels = dictCreate(&setDictType,NULL);
124124
c->pubsub_patterns = listCreate();
125125
c->peerid = NULL;
126+
c->slotsmgrt_flags = 0;
127+
c->slotsmgrt_fenceq = NULL;
126128
listSetFreeMethod(c->pubsub_patterns,decrRefCountVoid);
127129
listSetMatchMethod(c->pubsub_patterns,listMatchObjects);
128130
if (fd != -1) listAddNodeTail(server.clients,c);
@@ -809,6 +811,8 @@ void freeClient(client *c) {
809811
replicationGetSlaveName(c));
810812
}
811813

814+
slotsmgrtAsyncUnlinkClient(c);
815+
812816
/* Free the query buffer */
813817
sdsfree(c->querybuf);
814818
c->querybuf = NULL;
@@ -1806,6 +1810,10 @@ int checkClientOutputBufferLimits(client *c) {
18061810
int soft = 0, hard = 0, class;
18071811
unsigned long used_mem = getClientOutputBufferMemoryUsage(c);
18081812

1813+
if (c->slotsmgrt_flags & CLIENT_SLOTSMGRT_ASYNC_CACHED_CLIENT) {
1814+
return 0;
1815+
}
1816+
18091817
class = getClientType(c);
18101818
/* For the purpose of output buffer limiting, masters are handled
18111819
* like normal clients. */

extern/redis-3.2.12/src/object.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ robj *createObject(int type, void *ptr) {
4848
return o;
4949
}
5050

51+
/* Set a special refcount in the object to make it "shared":
52+
* incrRefCount and decrRefCount() will test for this special refcount
53+
* and will not touch the object. This way it is free to access shared
54+
* objects such as small integers from different threads without any
55+
* mutex.
56+
*
57+
* A common patter to create shared objects:
58+
*
59+
* robj *myobject = makeObjectShared(createObject(...));
60+
*
61+
*/
62+
robj *makeObjectShared(robj *o) {
63+
serverAssert(o->refcount == 1);
64+
o->refcount = OBJ_SHARED_REFCOUNT;
65+
return o;
66+
}
67+
5168
/* Create a string object with encoding OBJ_ENCODING_RAW, that is a plain
5269
* string object where o->ptr points to a proper sds string. */
5370
robj *createRawStringObject(const char *ptr, size_t len) {
@@ -293,11 +310,10 @@ void freeHashObject(robj *o) {
293310
}
294311

295312
void incrRefCount(robj *o) {
296-
o->refcount++;
313+
if (o->refcount != OBJ_SHARED_REFCOUNT) o->refcount++;
297314
}
298315

299316
void decrRefCount(robj *o) {
300-
if (o->refcount <= 0) serverPanic("decrRefCount against refcount <= 0");
301317
if (o->refcount == 1) {
302318
switch(o->type) {
303319
case OBJ_STRING: freeStringObject(o); break;
@@ -309,7 +325,8 @@ void decrRefCount(robj *o) {
309325
}
310326
zfree(o);
311327
} else {
312-
o->refcount--;
328+
if (o->refcount <= 0) serverPanic("decrRefCount against refcount <= 0");
329+
if (o->refcount != OBJ_SHARED_REFCOUNT) o->refcount--;
313330
}
314331
}
315332

0 commit comments

Comments
 (0)