1extern crate c2rust_bitfields;
2extern crate libc;
3extern crate core;
4extern "C" {
5 pub type _IO_wide_data;
6 pub type _IO_codecvt;
7 pub type _IO_marker;
8 pub type RedisModuleCommand;
9 static mut server: redisServer;
10 static mut shared: sharedObjectsStruct;
11 fn moduleClientIsBlockedOnKeys(c: *mut client) -> libc::c_int;
12 fn mstime() -> libc::c_longlong;
13 fn getRandomHexChars(p: *mut libc::c_char, len: size_t);
14 fn addReplyDeferredLen(c: *mut client) -> *mut libc::c_void;
15 fn setDeferredArrayLen(
16 c: *mut client,
17 node: *mut libc::c_void,
18 length: libc::c_long,
19 );
20 fn setDeferredMapLen(c: *mut client, node: *mut libc::c_void, length: libc::c_long);
21 fn addReplyNull(c: *mut client);
22 fn addReplyVerbatim(
23 c: *mut client,
24 s: *const libc::c_char,
25 len: size_t,
26 ext: *const libc::c_char,
27 );
28 fn addReplyBulkCString(c: *mut client, s: *const libc::c_char);
29 fn addReplyBulkCBuffer(c: *mut client, p: *const libc::c_void, len: size_t);
30 fn addReply(c: *mut client, obj: *mut robj);
31 fn addReplySds(c: *mut client, s: sds);
32 fn addReplyBulkSds(c: *mut client, s: sds);
33 fn addReplyErrorObject(c: *mut client, err: *mut robj);
34 fn addReplyErrorSds(c: *mut client, err: sds);
35 fn addReplyError(c: *mut client, err: *const libc::c_char);
36 fn addReplyErrorArity(c: *mut client);
37 fn addReplyLongLong(c: *mut client, ll: libc::c_longlong);
38 fn addReplyArrayLen(c: *mut client, length: libc::c_long);
39 fn addReplyMapLen(c: *mut client, length: libc::c_long);
40 fn addReplyHelp(c: *mut client, help: *mut *const libc::c_char);
41 fn addReplySubcommandSyntaxError(c: *mut client);
42 fn rewriteClientCommandVector(c: *mut client, argc: libc::c_int, _: ...);
43 fn rewriteClientCommandArgument(c: *mut client, i: libc::c_int, newval: *mut robj);
44 fn replaceClientCommandVector(
45 c: *mut client,
46 argc: libc::c_int,
47 argv: *mut *mut robj,
48 );
49 fn redactClientCommandArgument(c: *mut client, argc: libc::c_int);
50 fn listenToPort(port: libc::c_int, fds: *mut socketFds) -> libc::c_int;
51 fn pauseClients(purpose: pause_purpose, end: mstime_t, type_0: pause_type);
52 fn unpauseClients(purpose: pause_purpose);
53 fn addReplyErrorFormat(c: *mut client, fmt: *const libc::c_char, _: ...);
54 fn decrRefCount(o: *mut robj);
55 fn incrRefCount(o: *mut robj);
56 fn createStringObject(ptr: *const libc::c_char, len: size_t) -> *mut robj;
57 fn getDecodedObject(o: *mut robj) -> *mut robj;
58 fn createStringObjectFromLongLong(value: libc::c_longlong) -> *mut robj;
59 fn getLongFromObjectOrReply(
60 c: *mut client,
61 o: *mut robj,
62 target: *mut libc::c_long,
63 msg: *const libc::c_char,
64 ) -> libc::c_int;
65 fn getLongLongFromObjectOrReply(
66 c: *mut client,
67 o: *mut robj,
68 target: *mut libc::c_longlong,
69 msg: *const libc::c_char,
70 ) -> libc::c_int;
71 fn getLongLongFromObject(o: *mut robj, target: *mut libc::c_longlong) -> libc::c_int;
72 fn equalStringObjects(a: *mut robj, b: *mut robj) -> libc::c_int;
73 fn replicationSetMaster(ip: *mut libc::c_char, port: libc::c_int);
74 fn replicationUnsetMaster();
75 fn replicationGetSlaveOffset() -> libc::c_longlong;
76 fn connCreateSocket() -> *mut connection;
77 fn connCreateAcceptedSocket(fd: libc::c_int) -> *mut connection;
78 fn connCreateTLS() -> *mut connection;
79 fn connCreateAcceptedTLS(
80 fd: libc::c_int,
81 require_auth: libc::c_int,
82 ) -> *mut connection;
83 fn connSetPrivateData(conn: *mut connection, data: *mut libc::c_void);
84 fn connGetPrivateData(conn: *mut connection) -> *mut libc::c_void;
85 fn connGetState(conn: *mut connection) -> libc::c_int;
86 fn connHasWriteHandler(conn: *mut connection) -> libc::c_int;
87 fn connHasReadHandler(conn: *mut connection) -> libc::c_int;
88 fn connEnableTcpNoDelay(conn: *mut connection) -> libc::c_int;
89 fn connKeepAlive(conn: *mut connection, interval: libc::c_int) -> libc::c_int;
90 fn connPeerToString(
91 conn: *mut connection,
92 ip: *mut libc::c_char,
93 ip_len: size_t,
94 port: *mut libc::c_int,
95 ) -> libc::c_int;
96 fn connSockName(
97 conn: *mut connection,
98 ip: *mut libc::c_char,
99 ip_len: size_t,
100 port: *mut libc::c_int,
101 ) -> libc::c_int;
102 fn rioInitWithBuffer(r: *mut rio, s: sds);
103 fn rioWriteBulkCount(
104 r: *mut rio,
105 prefix: libc::c_char,
106 count: libc::c_long,
107 ) -> size_t;
108 fn rioWriteBulkString(r: *mut rio, buf: *const libc::c_char, len: size_t) -> size_t;
109 fn rioWriteBulkLongLong(r: *mut rio, l: libc::c_longlong) -> size_t;
110 fn time(__timer: *mut time_t) -> time_t;
111 fn strtol(
112 _: *const libc::c_char,
113 _: *mut *mut libc::c_char,
114 _: libc::c_int,
115 ) -> libc::c_long;
116 fn strtoull(
117 _: *const libc::c_char,
118 _: *mut *mut libc::c_char,
119 _: libc::c_int,
120 ) -> libc::c_ulonglong;
121 fn random() -> libc::c_long;
122 fn exit(_: libc::c_int) -> !;
123 fn memcpy(
124 _: *mut libc::c_void,
125 _: *const libc::c_void,
126 _: libc::c_ulong,
127 ) -> *mut libc::c_void;
128 fn memmove(
129 _: *mut libc::c_void,
130 _: *const libc::c_void,
131 _: libc::c_ulong,
132 ) -> *mut libc::c_void;
133 fn memset(
134 _: *mut libc::c_void,
135 _: libc::c_int,
136 _: libc::c_ulong,
137 ) -> *mut libc::c_void;
138 fn memcmp(
139 _: *const libc::c_void,
140 _: *const libc::c_void,
141 _: libc::c_ulong,
142 ) -> libc::c_int;
143 fn strncpy(
144 _: *mut libc::c_char,
145 _: *const libc::c_char,
146 _: libc::c_ulong,
147 ) -> *mut libc::c_char;
148 fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int;
149 fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
150 fn strrchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
151 fn strlen(_: *const libc::c_char) -> libc::c_ulong;
152 fn strerror(_: libc::c_int) -> *mut libc::c_char;
153 fn strcasecmp(__s1: *const libc::c_char, __s2: *const libc::c_char) -> libc::c_int;
154 fn close(__fd: libc::c_int) -> libc::c_int;
155 fn write(__fd: libc::c_int, __buf: *const libc::c_void, __n: size_t) -> ssize_t;
156 fn fsync(__fd: libc::c_int) -> libc::c_int;
157 fn ftruncate(__fd: libc::c_int, __length: __off64_t) -> libc::c_int;
158 fn dictCreate(type_0: *mut dictType) -> *mut dict;
159 fn dictAdd(
160 d: *mut dict,
161 key: *mut libc::c_void,
162 val: *mut libc::c_void,
163 ) -> libc::c_int;
164 fn dictDelete(d: *mut dict, key: *const libc::c_void) -> libc::c_int;
165 fn dictFind(d: *mut dict, key: *const libc::c_void) -> *mut dictEntry;
166 fn dictFetchValue(d: *mut dict, key: *const libc::c_void) -> *mut libc::c_void;
167 fn dictGetIterator(d: *mut dict) -> *mut dictIterator;
168 fn dictGetSafeIterator(d: *mut dict) -> *mut dictIterator;
169 fn dictNext(iter: *mut dictIterator) -> *mut dictEntry;
170 fn dictReleaseIterator(iter: *mut dictIterator);
171 fn dictGetRandomKey(d: *mut dict) -> *mut dictEntry;
172 fn listCreate() -> *mut list;
173 fn listRelease(list: *mut list);
174 fn listAddNodeTail(list: *mut list, value: *mut libc::c_void) -> *mut list;
175 fn listDelNode(list: *mut list, node: *mut listNode);
176 fn listNext(iter: *mut listIter) -> *mut listNode;
177 fn listSearchKey(list: *mut list, key: *mut libc::c_void) -> *mut listNode;
178 fn listRewind(list: *mut list, li: *mut listIter);
179 fn zmalloc(size: size_t) -> *mut libc::c_void;
180 fn zcalloc(size: size_t) -> *mut libc::c_void;
181 fn zrealloc(ptr: *mut libc::c_void, size: size_t) -> *mut libc::c_void;
182 fn zfree(ptr: *mut libc::c_void);
183 fn zstrdup(s: *const libc::c_char) -> *mut libc::c_char;
184 fn anetTcpAccept(
185 err: *mut libc::c_char,
186 serversock: libc::c_int,
187 ip: *mut libc::c_char,
188 ip_len: size_t,
189 port: *mut libc::c_int,
190 ) -> libc::c_int;
191 fn raxNew() -> *mut rax;
192 fn raxInsert(
193 rax: *mut rax,
194 s: *mut libc::c_uchar,
195 len: size_t,
196 data: *mut libc::c_void,
197 old: *mut *mut libc::c_void,
198 ) -> libc::c_int;
199 fn raxRemove(
200 rax: *mut rax,
201 s: *mut libc::c_uchar,
202 len: size_t,
203 old: *mut *mut libc::c_void,
204 ) -> libc::c_int;
205 fn raxStart(it: *mut raxIterator, rt: *mut rax);
206 fn raxSeek(
207 it: *mut raxIterator,
208 op: *const libc::c_char,
209 ele: *mut libc::c_uchar,
210 len: size_t,
211 ) -> libc::c_int;
212 fn raxNext(it: *mut raxIterator) -> libc::c_int;
213 fn raxStop(it: *mut raxIterator);
214 fn intrev64(v: uint64_t) -> uint64_t;
215 fn crc64(crc: uint64_t, s: *const libc::c_uchar, l: uint64_t) -> uint64_t;
216 fn __errno_location() -> *mut libc::c_int;
217 fn sdsRemoveFreeSpace(s: sds) -> sds;
218 fn sdsIncrLen(s: sds, incr: ssize_t);
219 fn sdssplitargs(line: *const libc::c_char, argc: *mut libc::c_int) -> *mut sds;
220 fn sdsfreesplitres(tokens: *mut sds, count: libc::c_int);
221 fn sdsclear(s: sds);
222 fn sdsrange(s: sds, start: ssize_t, end: ssize_t);
223 fn sdscatfmt(s: sds, fmt: *const libc::c_char, _: ...) -> sds;
224 fn sdscatprintf(s: sds, fmt: *const libc::c_char, _: ...) -> sds;
225 fn sdscpy(s: sds, t: *const libc::c_char) -> sds;
226 fn sdscatsds(s: sds, t: sds) -> sds;
227 fn sdscat(s: sds, t: *const libc::c_char) -> sds;
228 fn sdscatlen(s: sds, t: *const libc::c_void, len: size_t) -> sds;
229 fn sdsgrowzero(s: sds, len: size_t) -> sds;
230 fn sdsfree(s: sds);
231 fn sdsdup(s: sds) -> sds;
232 fn sdsempty() -> sds;
233 fn sdsnew(init: *const libc::c_char) -> sds;
234 fn sdsnewlen(init: *const libc::c_void, initlen: size_t) -> sds;
235 fn fileno(__stream: *mut FILE) -> libc::c_int;
236 fn fgets(
237 __s: *mut libc::c_char,
238 __n: libc::c_int,
239 __stream: *mut FILE,
240 ) -> *mut libc::c_char;
241 fn fopen(_: *const libc::c_char, _: *const libc::c_char) -> *mut FILE;
242 fn fclose(__stream: *mut FILE) -> libc::c_int;
243 fn open(__file: *const libc::c_char, __oflag: libc::c_int, _: ...) -> libc::c_int;
244 fn rdbSaveObjectType(rdb: *mut rio, o: *mut robj) -> libc::c_int;
245 fn rdbLoadObjectType(rdb: *mut rio) -> libc::c_int;
246 fn rdbSaveObject(
247 rdb: *mut rio,
248 o: *mut robj,
249 key: *mut robj,
250 dbid: libc::c_int,
251 ) -> ssize_t;
252 fn rdbLoadObject(
253 type_0: libc::c_int,
254 rdb: *mut rio,
255 key: sds,
256 dbid: libc::c_int,
257 error: *mut libc::c_int,
258 ) -> *mut robj;
259 fn getCommandFlags(c: *mut client) -> uint64_t;
260 fn createSocketAcceptHandler(
261 sfd: *mut socketFds,
262 accept_handler: Option::<aeFileProc>,
263 ) -> libc::c_int;
264 fn _serverLog(level: libc::c_int, fmt: *const libc::c_char, _: ...);
265 fn LRU_CLOCK() -> libc::c_uint;
266 fn pubsubUnsubscribeShardChannels(channels: *mut *mut robj, count: libc::c_uint);
267 fn pubsubPublishMessage(
268 channel: *mut robj,
269 message: *mut robj,
270 sharded: libc::c_int,
271 ) -> libc::c_int;
272 fn serverPubsubSubscriptionCount() -> libc::c_int;
273 fn serverPubsubShardSubscriptionCount() -> libc::c_int;
274 fn notifyKeyspaceEvent(
275 type_0: libc::c_int,
276 event: *mut libc::c_char,
277 key: *mut robj,
278 dbid: libc::c_int,
279 );
280 fn getExpire(db: *mut redisDb, key: *mut robj) -> libc::c_longlong;
281 fn setExpire(
282 c: *mut client,
283 db: *mut redisDb,
284 key: *mut robj,
285 when: libc::c_longlong,
286 );
287 fn checkAlreadyExpired(when: libc::c_longlong) -> libc::c_int;
288 fn lookupKeyRead(db: *mut redisDb, key: *mut robj) -> *mut robj;
289 fn lookupKeyWrite(db: *mut redisDb, key: *mut robj) -> *mut robj;
290 fn lookupKeyReadWithFlags(
291 db: *mut redisDb,
292 key: *mut robj,
293 flags: libc::c_int,
294 ) -> *mut robj;
295 fn objectSetLRUOrLFU(
296 val: *mut robj,
297 lfu_freq: libc::c_longlong,
298 lru_idle: libc::c_longlong,
299 lru_clock: libc::c_longlong,
300 lru_multiplier: libc::c_int,
301 ) -> libc::c_int;
302 fn dbAdd(db: *mut redisDb, key: *mut robj, val: *mut robj);
303 fn dbDelete(db: *mut redisDb, key: *mut robj) -> libc::c_int;
304 fn emptyData(
305 dbnum: libc::c_int,
306 flags: libc::c_int,
307 callback: Option::<unsafe extern "C" fn(*mut dict) -> ()>,
308 ) -> libc::c_longlong;
309 fn signalModifiedKey(c: *mut client, db: *mut redisDb, key: *mut robj);
310 fn getKeysFromCommand(
311 cmd: *mut redisCommand,
312 argv: *mut *mut robj,
313 argc: libc::c_int,
314 result: *mut getKeysResult,
315 ) -> libc::c_int;
316 fn getKeysFreeResult(result: *mut getKeysResult);
317 fn crc16(buf: *const libc::c_char, len: libc::c_int) -> libc::c_ushort;
318 fn dictSdsHash(key: *const libc::c_void) -> uint64_t;
319 fn dictSdsCaseHash(key: *const libc::c_void) -> uint64_t;
320 fn dictSdsKeyCompare(
321 d: *mut dict,
322 key1: *const libc::c_void,
323 key2: *const libc::c_void,
324 ) -> libc::c_int;
325 fn dictSdsKeyCaseCompare(
326 d: *mut dict,
327 key1: *const libc::c_void,
328 key2: *const libc::c_void,
329 ) -> libc::c_int;
330 fn dictSdsDestructor(d: *mut dict, val: *mut libc::c_void);
331 fn execCommand(c: *mut client);
332 fn spublishCommand(c: *mut client);
333 fn ssubscribeCommand(c: *mut client);
334 fn sunsubscribeCommand(c: *mut client);
335 fn _serverAssert(
336 estr: *const libc::c_char,
337 file: *const libc::c_char,
338 line: libc::c_int,
339 );
340 fn _serverPanic(
341 file: *const libc::c_char,
342 line: libc::c_int,
343 msg: *const libc::c_char,
344 _: ...
345 );
346 fn _serverAssertWithInfo(
347 c: *const client,
348 o: *const robj,
349 estr: *const libc::c_char,
350 file: *const libc::c_char,
351 line: libc::c_int,
352 );
353 fn inet_pton(
354 __af: libc::c_int,
355 __cp: *const libc::c_char,
356 __buf: *mut libc::c_void,
357 ) -> libc::c_int;
358 fn inet_ntop(
359 __af: libc::c_int,
360 __cp: *const libc::c_void,
361 __buf: *mut libc::c_char,
362 __len: socklen_t,
363 ) -> *const libc::c_char;
364 fn __fxstat(
365 __ver: libc::c_int,
366 __fildes: libc::c_int,
367 __stat_buf: *mut stat,
368 ) -> libc::c_int;
369 fn flock(__fd: libc::c_int, __operation: libc::c_int) -> libc::c_int;
370 fn floor(_: libc::c_double) -> libc::c_double;
371 fn moduleCallClusterReceivers(
372 sender_id: *const libc::c_char,
373 module_id: uint64_t,
374 type_0: uint8_t,
375 payload: *const libc::c_uchar,
376 len: uint32_t,
377 );
378}
379pub type __uint8_t = libc::c_uchar;
380pub type __int16_t = libc::c_short;
381pub type __uint16_t = libc::c_ushort;
382pub type __int32_t = libc::c_int;
383pub type __uint32_t = libc::c_uint;
384pub type __int64_t = libc::c_long;
385pub type __uint64_t = libc::c_ulong;
386pub type __uint_least64_t = __uint64_t;
387pub type __dev_t = libc::c_ulong;
388pub type __uid_t = libc::c_uint;
389pub type __gid_t = libc::c_uint;
390pub type __ino64_t = libc::c_ulong;
391pub type __mode_t = libc::c_uint;
392pub type __nlink_t = libc::c_uint;
393pub type __off_t = libc::c_long;
394pub type __off64_t = libc::c_long;
395pub type __pid_t = libc::c_int;
396pub type __time_t = libc::c_long;
397pub type __blksize_t = libc::c_int;
398pub type __blkcnt64_t = libc::c_long;
399pub type __ssize_t = libc::c_long;
400pub type __syscall_slong_t = libc::c_long;
401pub type __socklen_t = libc::c_uint;
402pub type __sig_atomic_t = libc::c_int;
403pub type size_t = libc::c_ulong;
404#[derive(Copy, Clone)]
405#[repr(C)]
406pub struct iovec {
407 pub iov_base: *mut libc::c_void,
408 pub iov_len: size_t,
409}
410pub type mode_t = __mode_t;
411pub type off_t = __off64_t;
412pub type pid_t = __pid_t;
413#[derive(Copy, Clone)]
414#[repr(C)]
415pub struct timespec {
416 pub tv_sec: __time_t,
417 pub tv_nsec: __syscall_slong_t,
418}
419#[derive(Copy, Clone)]
420#[repr(C)]
421pub struct stat {
422 pub st_dev: __dev_t,
423 pub st_ino: __ino64_t,
424 pub st_mode: __mode_t,
425 pub st_nlink: __nlink_t,
426 pub st_uid: __uid_t,
427 pub st_gid: __gid_t,
428 pub st_rdev: __dev_t,
429 pub __pad1: __dev_t,
430 pub st_size: __off64_t,
431 pub st_blksize: __blksize_t,
432 pub __pad2: libc::c_int,
433 pub st_blocks: __blkcnt64_t,
434 pub st_atim: timespec,
435 pub st_mtim: timespec,
436 pub st_ctim: timespec,
437 pub __glibc_reserved: [libc::c_int; 2],
438}
439pub type ssize_t = __ssize_t;
440pub type time_t = __time_t;
441pub type int16_t = __int16_t;
442pub type int32_t = __int32_t;
443pub type int64_t = __int64_t;
444pub type pthread_t = libc::c_ulong;
445#[derive(Copy, Clone)]
446#[repr(C)]
447pub struct _IO_FILE {
448 pub _flags: libc::c_int,
449 pub _IO_read_ptr: *mut libc::c_char,
450 pub _IO_read_end: *mut libc::c_char,
451 pub _IO_read_base: *mut libc::c_char,
452 pub _IO_write_base: *mut libc::c_char,
453 pub _IO_write_ptr: *mut libc::c_char,
454 pub _IO_write_end: *mut libc::c_char,
455 pub _IO_buf_base: *mut libc::c_char,
456 pub _IO_buf_end: *mut libc::c_char,
457 pub _IO_save_base: *mut libc::c_char,
458 pub _IO_backup_base: *mut libc::c_char,
459 pub _IO_save_end: *mut libc::c_char,
460 pub _markers: *mut _IO_marker,
461 pub _chain: *mut _IO_FILE,
462 pub _fileno: libc::c_int,
463 pub _flags2: libc::c_int,
464 pub _old_offset: __off_t,
465 pub _cur_column: libc::c_ushort,
466 pub _vtable_offset: libc::c_schar,
467 pub _shortbuf: [libc::c_char; 1],
468 pub _lock: *mut libc::c_void,
469 pub _offset: __off64_t,
470 pub _codecvt: *mut _IO_codecvt,
471 pub _wide_data: *mut _IO_wide_data,
472 pub _freeres_list: *mut _IO_FILE,
473 pub _freeres_buf: *mut libc::c_void,
474 pub __pad5: size_t,
475 pub _mode: libc::c_int,
476 pub _unused2: [libc::c_char; 20],
477}
478pub type _IO_lock_t = ();
479pub type FILE = _IO_FILE;
480pub type uint8_t = __uint8_t;
481pub type uint16_t = __uint16_t;
482pub type uint32_t = __uint32_t;
483pub type uint64_t = __uint64_t;
484pub type uint_least64_t = __uint_least64_t;
485pub type sds = *mut libc::c_char;
486#[derive(Copy, Clone)]
487#[repr(C, packed)]
488pub struct sdshdr8 {
489 pub len: uint8_t,
490 pub alloc: uint8_t,
491 pub flags: libc::c_uchar,
492 pub buf: [libc::c_char; 0],
493}
494#[derive(Copy, Clone)]
495#[repr(C, packed)]
496pub struct sdshdr16 {
497 pub len: uint16_t,
498 pub alloc: uint16_t,
499 pub flags: libc::c_uchar,
500 pub buf: [libc::c_char; 0],
501}
502#[derive(Copy, Clone)]
503#[repr(C, packed)]
504pub struct sdshdr32 {
505 pub len: uint32_t,
506 pub alloc: uint32_t,
507 pub flags: libc::c_uchar,
508 pub buf: [libc::c_char; 0],
509}
510#[derive(Copy, Clone)]
511#[repr(C, packed)]
512pub struct sdshdr64 {
513 pub len: uint64_t,
514 pub alloc: uint64_t,
515 pub flags: libc::c_uchar,
516 pub buf: [libc::c_char; 0],
517}
518#[derive(Copy, Clone)]
519#[repr(C)]
520pub struct aeEventLoop {
521 pub maxfd: libc::c_int,
522 pub setsize: libc::c_int,
523 pub timeEventNextId: libc::c_longlong,
524 pub events: *mut aeFileEvent,
525 pub fired: *mut aeFiredEvent,
526 pub timeEventHead: *mut aeTimeEvent,
527 pub stop: libc::c_int,
528 pub apidata: *mut libc::c_void,
529 pub beforesleep: Option::<aeBeforeSleepProc>,
530 pub aftersleep: Option::<aeBeforeSleepProc>,
531 pub flags: libc::c_int,
532}
533pub type aeBeforeSleepProc = unsafe extern "C" fn(*mut aeEventLoop) -> ();
534#[derive(Copy, Clone)]
535#[repr(C)]
536pub struct aeTimeEvent {
537 pub id: libc::c_longlong,
538 pub when: monotime,
539 pub timeProc: Option::<aeTimeProc>,
540 pub finalizerProc: Option::<aeEventFinalizerProc>,
541 pub clientData: *mut libc::c_void,
542 pub prev: *mut aeTimeEvent,
543 pub next: *mut aeTimeEvent,
544 pub refcount: libc::c_int,
545}
546pub type aeEventFinalizerProc = unsafe extern "C" fn(
547 *mut aeEventLoop,
548 *mut libc::c_void,
549) -> ();
550pub type aeTimeProc = unsafe extern "C" fn(
551 *mut aeEventLoop,
552 libc::c_longlong,
553 *mut libc::c_void,
554) -> libc::c_int;
555pub type monotime = uint64_t;
556#[derive(Copy, Clone)]
557#[repr(C)]
558pub struct aeFiredEvent {
559 pub fd: libc::c_int,
560 pub mask: libc::c_int,
561}
562#[derive(Copy, Clone)]
563#[repr(C)]
564pub struct aeFileEvent {
565 pub mask: libc::c_int,
566 pub rfileProc: Option::<aeFileProc>,
567 pub wfileProc: Option::<aeFileProc>,
568 pub clientData: *mut libc::c_void,
569}
570pub type aeFileProc = unsafe extern "C" fn(
571 *mut aeEventLoop,
572 libc::c_int,
573 *mut libc::c_void,
574 libc::c_int,
575) -> ();
576#[derive(Copy, Clone)]
577#[repr(C)]
578pub struct connection {
579 pub type_0: *mut ConnectionType,
580 pub state: ConnectionState,
581 pub flags: libc::c_short,
582 pub refs: libc::c_short,
583 pub last_errno: libc::c_int,
584 pub private_data: *mut libc::c_void,
585 pub conn_handler: ConnectionCallbackFunc,
586 pub write_handler: ConnectionCallbackFunc,
587 pub read_handler: ConnectionCallbackFunc,
588 pub fd: libc::c_int,
589}
590pub type ConnectionCallbackFunc = Option::<unsafe extern "C" fn(*mut connection) -> ()>;
591pub type ConnectionState = libc::c_uint;
592pub const CONN_STATE_ERROR: ConnectionState = 5;
593pub const CONN_STATE_CLOSED: ConnectionState = 4;
594pub const CONN_STATE_CONNECTED: ConnectionState = 3;
595pub const CONN_STATE_ACCEPTING: ConnectionState = 2;
596pub const CONN_STATE_CONNECTING: ConnectionState = 1;
597pub const CONN_STATE_NONE: ConnectionState = 0;
598#[derive(Copy, Clone)]
599#[repr(C)]
600pub struct ConnectionType {
601 pub ae_handler: Option::<
602 unsafe extern "C" fn(
603 *mut aeEventLoop,
604 libc::c_int,
605 *mut libc::c_void,
606 libc::c_int,
607 ) -> (),
608 >,
609 pub connect: Option::<
610 unsafe extern "C" fn(
611 *mut connection,
612 *const libc::c_char,
613 libc::c_int,
614 *const libc::c_char,
615 ConnectionCallbackFunc,
616 ) -> libc::c_int,
617 >,
618 pub write: Option::<
619 unsafe extern "C" fn(*mut connection, *const libc::c_void, size_t) -> libc::c_int,
620 >,
621 pub writev: Option::<
622 unsafe extern "C" fn(*mut connection, *const iovec, libc::c_int) -> libc::c_int,
623 >,
624 pub read: Option::<
625 unsafe extern "C" fn(*mut connection, *mut libc::c_void, size_t) -> libc::c_int,
626 >,
627 pub close: Option::<unsafe extern "C" fn(*mut connection) -> ()>,
628 pub accept: Option::<
629 unsafe extern "C" fn(*mut connection, ConnectionCallbackFunc) -> libc::c_int,
630 >,
631 pub set_write_handler: Option::<
632 unsafe extern "C" fn(
633 *mut connection,
634 ConnectionCallbackFunc,
635 libc::c_int,
636 ) -> libc::c_int,
637 >,
638 pub set_read_handler: Option::<
639 unsafe extern "C" fn(*mut connection, ConnectionCallbackFunc) -> libc::c_int,
640 >,
641 pub get_last_error: Option::<
642 unsafe extern "C" fn(*mut connection) -> *const libc::c_char,
643 >,
644 pub blocking_connect: Option::<
645 unsafe extern "C" fn(
646 *mut connection,
647 *const libc::c_char,
648 libc::c_int,
649 libc::c_longlong,
650 ) -> libc::c_int,
651 >,
652 pub sync_write: Option::<
653 unsafe extern "C" fn(
654 *mut connection,
655 *mut libc::c_char,
656 ssize_t,
657 libc::c_longlong,
658 ) -> ssize_t,
659 >,
660 pub sync_read: Option::<
661 unsafe extern "C" fn(
662 *mut connection,
663 *mut libc::c_char,
664 ssize_t,
665 libc::c_longlong,
666 ) -> ssize_t,
667 >,
668 pub sync_readline: Option::<
669 unsafe extern "C" fn(
670 *mut connection,
671 *mut libc::c_char,
672 ssize_t,
673 libc::c_longlong,
674 ) -> ssize_t,
675 >,
676 pub get_type: Option::<unsafe extern "C" fn(*mut connection) -> libc::c_int>,
677}
678#[derive(Copy, Clone)]
679#[repr(C)]
680pub struct _rio {
681 pub read: Option::<
682 unsafe extern "C" fn(*mut _rio, *mut libc::c_void, size_t) -> size_t,
683 >,
684 pub write: Option::<
685 unsafe extern "C" fn(*mut _rio, *const libc::c_void, size_t) -> size_t,
686 >,
687 pub tell: Option::<unsafe extern "C" fn(*mut _rio) -> off_t>,
688 pub flush: Option::<unsafe extern "C" fn(*mut _rio) -> libc::c_int>,
689 pub update_cksum: Option::<
690 unsafe extern "C" fn(*mut _rio, *const libc::c_void, size_t) -> (),
691 >,
692 pub cksum: uint64_t,
693 pub flags: uint64_t,
694 pub processed_bytes: size_t,
695 pub max_processing_chunk: size_t,
696 pub io: C2RustUnnamed,
697}
698#[derive(Copy, Clone)]
699#[repr(C)]
700pub union C2RustUnnamed {
701 pub buffer: C2RustUnnamed_3,
702 pub file: C2RustUnnamed_2,
703 pub conn: C2RustUnnamed_1,
704 pub fd: C2RustUnnamed_0,
705}
706#[derive(Copy, Clone)]
707#[repr(C)]
708pub struct C2RustUnnamed_0 {
709 pub fd: libc::c_int,
710 pub pos: off_t,
711 pub buf: sds,
712}
713#[derive(Copy, Clone)]
714#[repr(C)]
715pub struct C2RustUnnamed_1 {
716 pub conn: *mut connection,
717 pub pos: off_t,
718 pub buf: sds,
719 pub read_limit: size_t,
720 pub read_so_far: size_t,
721}
722#[derive(Copy, Clone)]
723#[repr(C)]
724pub struct C2RustUnnamed_2 {
725 pub fp: *mut FILE,
726 pub buffered: off_t,
727 pub autosync: off_t,
728}
729#[derive(Copy, Clone)]
730#[repr(C)]
731pub struct C2RustUnnamed_3 {
732 pub ptr: sds,
733 pub pos: off_t,
734}
735pub type rio = _rio;
736#[derive(Copy, Clone,c2rust_bitfields::BitfieldStruct)]
737#[repr(C)]
738pub struct redisObject {
739 #[bitfield(name = "type_0", ty = "libc::c_uint", bits = "0..=3")]
740 #[bitfield(name = "encoding", ty = "libc::c_uint", bits = "4..=7")]
741 #[bitfield(name = "lru", ty = "libc::c_uint", bits = "8..=31")]
742 pub type_0_encoding_lru: [u8; 4],
743 pub refcount: libc::c_int,
744 pub ptr: *mut libc::c_void,
745}
746pub type atomic_int = libc::c_int;
747pub type atomic_uint = libc::c_uint;
748pub type atomic_llong = libc::c_longlong;
749pub type socklen_t = __socklen_t;
750pub type sa_family_t = libc::c_ushort;
751#[derive(Copy, Clone)]
752#[repr(C)]
753pub struct sockaddr_storage {
754 pub ss_family: sa_family_t,
755 pub __ss_padding: [libc::c_char; 118],
756 pub __ss_align: libc::c_ulong,
757}
758#[derive(Copy, Clone)]
759#[repr(C)]
760pub struct sockaddr_in6 {
761 pub sin6_family: sa_family_t,
762 pub sin6_port: in_port_t,
763 pub sin6_flowinfo: uint32_t,
764 pub sin6_addr: in6_addr,
765 pub sin6_scope_id: uint32_t,
766}
767#[derive(Copy, Clone)]
768#[repr(C)]
769pub struct in6_addr {
770 pub __in6_u: C2RustUnnamed_4,
771}
772#[derive(Copy, Clone)]
773#[repr(C)]
774pub union C2RustUnnamed_4 {
775 pub __u6_addr8: [uint8_t; 16],
776 pub __u6_addr16: [uint16_t; 8],
777 pub __u6_addr32: [uint32_t; 4],
778}
779pub type in_port_t = uint16_t;
780#[derive(Copy, Clone)]
781#[repr(C)]
782pub struct sockaddr_in {
783 pub sin_family: sa_family_t,
784 pub sin_port: in_port_t,
785 pub sin_addr: in_addr,
786 pub sin_zero: [libc::c_uchar; 8],
787}
788#[derive(Copy, Clone)]
789#[repr(C)]
790pub struct in_addr {
791 pub s_addr: in_addr_t,
792}
793pub type in_addr_t = uint32_t;
794pub type sig_atomic_t = __sig_atomic_t;
795#[derive(Copy, Clone)]
796#[repr(C)]
797pub struct hdr_histogram {
798 pub lowest_discernible_value: int64_t,
799 pub highest_trackable_value: int64_t,
800 pub unit_magnitude: int32_t,
801 pub significant_figures: int32_t,
802 pub sub_bucket_half_count_magnitude: int32_t,
803 pub sub_bucket_half_count: int32_t,
804 pub sub_bucket_mask: int64_t,
805 pub sub_bucket_count: int32_t,
806 pub bucket_count: int32_t,
807 pub min_value: int64_t,
808 pub max_value: int64_t,
809 pub normalizing_index_offset: int32_t,
810 pub conversion_ratio: libc::c_double,
811 pub counts_len: int32_t,
812 pub total_count: int64_t,
813 pub counts: *mut int64_t,
814}
815pub type mstime_t = libc::c_longlong;
816pub type ustime_t = libc::c_longlong;
817#[derive(Copy, Clone)]
818#[repr(C)]
819pub struct dictEntry {
820 pub key: *mut libc::c_void,
821 pub v: C2RustUnnamed_5,
822 pub next: *mut dictEntry,
823 pub metadata: [*mut libc::c_void; 0],
824}
825#[derive(Copy, Clone)]
826#[repr(C)]
827pub union C2RustUnnamed_5 {
828 pub val: *mut libc::c_void,
829 pub u64_0: uint64_t,
830 pub s64: int64_t,
831 pub d: libc::c_double,
832}
833#[derive(Copy, Clone)]
834#[repr(C)]
835pub struct dict {
836 pub type_0: *mut dictType,
837 pub ht_table: [*mut *mut dictEntry; 2],
838 pub ht_used: [libc::c_ulong; 2],
839 pub rehashidx: libc::c_long,
840 pub pauserehash: int16_t,
841 pub ht_size_exp: [libc::c_schar; 2],
842}
843#[derive(Copy, Clone)]
844#[repr(C)]
845pub struct dictType {
846 pub hashFunction: Option::<unsafe extern "C" fn(*const libc::c_void) -> uint64_t>,
847 pub keyDup: Option::<
848 unsafe extern "C" fn(*mut dict, *const libc::c_void) -> *mut libc::c_void,
849 >,
850 pub valDup: Option::<
851 unsafe extern "C" fn(*mut dict, *const libc::c_void) -> *mut libc::c_void,
852 >,
853 pub keyCompare: Option::<
854 unsafe extern "C" fn(
855 *mut dict,
856 *const libc::c_void,
857 *const libc::c_void,
858 ) -> libc::c_int,
859 >,
860 pub keyDestructor: Option::<
861 unsafe extern "C" fn(*mut dict, *mut libc::c_void) -> (),
862 >,
863 pub valDestructor: Option::<
864 unsafe extern "C" fn(*mut dict, *mut libc::c_void) -> (),
865 >,
866 pub expandAllowed: Option::<
867 unsafe extern "C" fn(size_t, libc::c_double) -> libc::c_int,
868 >,
869 pub dictEntryMetadataBytes: Option::<unsafe extern "C" fn(*mut dict) -> size_t>,
870}
871#[derive(Copy, Clone)]
872#[repr(C)]
873pub struct dictIterator {
874 pub d: *mut dict,
875 pub index: libc::c_long,
876 pub table: libc::c_int,
877 pub safe: libc::c_int,
878 pub entry: *mut dictEntry,
879 pub nextEntry: *mut dictEntry,
880 pub fingerprint: libc::c_ulonglong,
881}
882#[derive(Copy, Clone)]
883#[repr(C)]
884pub struct listNode {
885 pub prev: *mut listNode,
886 pub next: *mut listNode,
887 pub value: *mut libc::c_void,
888}
889#[derive(Copy, Clone)]
890#[repr(C)]
891pub struct listIter {
892 pub next: *mut listNode,
893 pub direction: libc::c_int,
894}
895#[derive(Copy, Clone)]
896#[repr(C)]
897pub struct list {
898 pub head: *mut listNode,
899 pub tail: *mut listNode,
900 pub dup: Option::<unsafe extern "C" fn(*mut libc::c_void) -> *mut libc::c_void>,
901 pub free: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
902 pub match_0: Option::<
903 unsafe extern "C" fn(*mut libc::c_void, *mut libc::c_void) -> libc::c_int,
904 >,
905 pub len: libc::c_ulong,
906}
907#[derive(Copy, Clone,c2rust_bitfields::BitfieldStruct)]
908#[repr(C)]
909pub struct raxNode {
910 #[bitfield(name = "iskey", ty = "uint32_t", bits = "0..=0")]
911 #[bitfield(name = "isnull", ty = "uint32_t", bits = "1..=1")]
912 #[bitfield(name = "iscompr", ty = "uint32_t", bits = "2..=2")]
913 #[bitfield(name = "size", ty = "uint32_t", bits = "3..=31")]
914 pub iskey_isnull_iscompr_size: [u8; 4],
915 pub data: [libc::c_uchar; 0],
916}
917#[derive(Copy, Clone)]
918#[repr(C)]
919pub struct rax {
920 pub head: *mut raxNode,
921 pub numele: uint64_t,
922 pub numnodes: uint64_t,
923}
924#[derive(Copy, Clone)]
925#[repr(C)]
926pub struct raxStack {
927 pub stack: *mut *mut libc::c_void,
928 pub items: size_t,
929 pub maxitems: size_t,
930 pub static_items: [*mut libc::c_void; 32],
931 pub oom: libc::c_int,
932}
933pub type raxNodeCallback = Option::<
934 unsafe extern "C" fn(*mut *mut raxNode) -> libc::c_int,
935>;
936#[derive(Copy, Clone)]
937#[repr(C)]
938pub struct raxIterator {
939 pub flags: libc::c_int,
940 pub rt: *mut rax,
941 pub key: *mut libc::c_uchar,
942 pub data: *mut libc::c_void,
943 pub key_len: size_t,
944 pub key_max: size_t,
945 pub key_static_string: [libc::c_uchar; 128],
946 pub node: *mut raxNode,
947 pub stack: raxStack,
948 pub node_cb: raxNodeCallback,
949}
950pub type C2RustUnnamed_6 = libc::c_uint;
951pub const REPL_STATE_CONNECTED: C2RustUnnamed_6 = 12;
952pub const REPL_STATE_TRANSFER: C2RustUnnamed_6 = 11;
953pub const REPL_STATE_RECEIVE_PSYNC_REPLY: C2RustUnnamed_6 = 10;
954pub const REPL_STATE_SEND_PSYNC: C2RustUnnamed_6 = 9;
955pub const REPL_STATE_RECEIVE_CAPA_REPLY: C2RustUnnamed_6 = 8;
956pub const REPL_STATE_RECEIVE_IP_REPLY: C2RustUnnamed_6 = 7;
957pub const REPL_STATE_RECEIVE_PORT_REPLY: C2RustUnnamed_6 = 6;
958pub const REPL_STATE_RECEIVE_AUTH_REPLY: C2RustUnnamed_6 = 5;
959pub const REPL_STATE_SEND_HANDSHAKE: C2RustUnnamed_6 = 4;
960pub const REPL_STATE_RECEIVE_PING_REPLY: C2RustUnnamed_6 = 3;
961pub const REPL_STATE_CONNECTING: C2RustUnnamed_6 = 2;
962pub const REPL_STATE_CONNECT: C2RustUnnamed_6 = 1;
963pub const REPL_STATE_NONE: C2RustUnnamed_6 = 0;
964pub type pause_type = libc::c_uint;
965pub const CLIENT_PAUSE_ALL: pause_type = 2;
966pub const CLIENT_PAUSE_WRITE: pause_type = 1;
967pub const CLIENT_PAUSE_OFF: pause_type = 0;
968pub type pause_purpose = libc::c_uint;
969pub const NUM_PAUSE_PURPOSES: pause_purpose = 3;
970pub const PAUSE_DURING_FAILOVER: pause_purpose = 2;
971pub const PAUSE_DURING_SHUTDOWN: pause_purpose = 1;
972pub const PAUSE_BY_CLIENT_COMMAND: pause_purpose = 0;
973#[derive(Copy, Clone)]
974#[repr(C)]
975pub struct pause_event {
976 pub type_0: pause_type,
977 pub end: mstime_t,
978}
979pub type C2RustUnnamed_7 = libc::c_uint;
980pub const CLUSTER_ENDPOINT_TYPE_UNKNOWN_ENDPOINT: C2RustUnnamed_7 = 2;
981pub const CLUSTER_ENDPOINT_TYPE_HOSTNAME: C2RustUnnamed_7 = 1;
982pub const CLUSTER_ENDPOINT_TYPE_IP: C2RustUnnamed_7 = 0;
983pub type robj = redisObject;
984pub type RedisModuleUserChangedFunc = Option::<
985 unsafe extern "C" fn(uint64_t, *mut libc::c_void) -> (),
986>;
987#[derive(Copy, Clone)]
988#[repr(C)]
989pub struct clusterSlotToKeyMapping {
990 pub by_slot: [slotToKeys; 16384],
991}
992#[derive(Copy, Clone)]
993#[repr(C)]
994pub struct slotToKeys {
995 pub count: uint64_t,
996 pub head: *mut dictEntry,
997}
998#[derive(Copy, Clone)]
999#[repr(C)]
1000pub struct redisDb {
1001 pub dict: *mut dict,
1002 pub expires: *mut dict,
1003 pub blocking_keys: *mut dict,
1004 pub ready_keys: *mut dict,
1005 pub watched_keys: *mut dict,
1006 pub id: libc::c_int,
1007 pub avg_ttl: libc::c_longlong,
1008 pub expires_cursor: libc::c_ulong,
1009 pub defrag_later: *mut list,
1010 pub slots_to_keys: *mut clusterSlotToKeyMapping,
1011}
1012#[derive(Copy, Clone)]
1013#[repr(C)]
1014pub struct multiCmd {
1015 pub argv: *mut *mut robj,
1016 pub argv_len: libc::c_int,
1017 pub argc: libc::c_int,
1018 pub cmd: *mut redisCommand,
1019}
1020#[derive(Copy, Clone)]
1021#[repr(C)]
1022pub struct redisCommand {
1023 pub declared_name: *const libc::c_char,
1024 pub summary: *const libc::c_char,
1025 pub complexity: *const libc::c_char,
1026 pub since: *const libc::c_char,
1027 pub doc_flags: libc::c_int,
1028 pub replaced_by: *const libc::c_char,
1029 pub deprecated_since: *const libc::c_char,
1030 pub group: redisCommandGroup,
1031 pub history: *mut commandHistory,
1032 pub tips: *mut *const libc::c_char,
1033 pub proc_0: Option::<redisCommandProc>,
1034 pub arity: libc::c_int,
1035 pub flags: uint64_t,
1036 pub acl_categories: uint64_t,
1037 pub key_specs_static: [keySpec; 4],
1038 pub getkeys_proc: Option::<redisGetKeysProc>,
1039 pub subcommands: *mut redisCommand,
1040 pub args: *mut redisCommandArg,
1041 pub microseconds: libc::c_longlong,
1042 pub calls: libc::c_longlong,
1043 pub rejected_calls: libc::c_longlong,
1044 pub failed_calls: libc::c_longlong,
1045 pub id: libc::c_int,
1046 pub fullname: sds,
1047 pub latency_histogram: *mut hdr_histogram,
1048 pub key_specs: *mut keySpec,
1049 pub legacy_range_key_spec: keySpec,
1050 pub num_args: libc::c_int,
1051 pub num_history: libc::c_int,
1052 pub num_tips: libc::c_int,
1053 pub key_specs_num: libc::c_int,
1054 pub key_specs_max: libc::c_int,
1055 pub subcommands_dict: *mut dict,
1056 pub parent: *mut redisCommand,
1057 pub module_cmd: *mut RedisModuleCommand,
1058}
1059#[derive(Copy, Clone)]
1060#[repr(C)]
1061pub struct keySpec {
1062 pub notes: *const libc::c_char,
1063 pub flags: uint64_t,
1064 pub begin_search_type: kspec_bs_type,
1065 pub bs: C2RustUnnamed_11,
1066 pub find_keys_type: kspec_fk_type,
1067 pub fk: C2RustUnnamed_8,
1068}
1069#[derive(Copy, Clone)]
1070#[repr(C)]
1071pub union C2RustUnnamed_8 {
1072 pub range: C2RustUnnamed_10,
1073 pub keynum: C2RustUnnamed_9,
1074}
1075#[derive(Copy, Clone)]
1076#[repr(C)]
1077pub struct C2RustUnnamed_9 {
1078 pub keynumidx: libc::c_int,
1079 pub firstkey: libc::c_int,
1080 pub keystep: libc::c_int,
1081}
1082#[derive(Copy, Clone)]
1083#[repr(C)]
1084pub struct C2RustUnnamed_10 {
1085 pub lastkey: libc::c_int,
1086 pub keystep: libc::c_int,
1087 pub limit: libc::c_int,
1088}
1089pub type kspec_fk_type = libc::c_uint;
1090pub const KSPEC_FK_KEYNUM: kspec_fk_type = 3;
1091pub const KSPEC_FK_RANGE: kspec_fk_type = 2;
1092pub const KSPEC_FK_UNKNOWN: kspec_fk_type = 1;
1093pub const KSPEC_FK_INVALID: kspec_fk_type = 0;
1094#[derive(Copy, Clone)]
1095#[repr(C)]
1096pub union C2RustUnnamed_11 {
1097 pub index: C2RustUnnamed_13,
1098 pub keyword: C2RustUnnamed_12,
1099}
1100#[derive(Copy, Clone)]
1101#[repr(C)]
1102pub struct C2RustUnnamed_12 {
1103 pub keyword: *const libc::c_char,
1104 pub startfrom: libc::c_int,
1105}
1106#[derive(Copy, Clone)]
1107#[repr(C)]
1108pub struct C2RustUnnamed_13 {
1109 pub pos: libc::c_int,
1110}
1111pub type kspec_bs_type = libc::c_uint;
1112pub const KSPEC_BS_KEYWORD: kspec_bs_type = 3;
1113pub const KSPEC_BS_INDEX: kspec_bs_type = 2;
1114pub const KSPEC_BS_UNKNOWN: kspec_bs_type = 1;
1115pub const KSPEC_BS_INVALID: kspec_bs_type = 0;
1116#[derive(Copy, Clone)]
1117#[repr(C)]
1118pub struct redisCommandArg {
1119 pub name: *const libc::c_char,
1120 pub type_0: redisCommandArgType,
1121 pub key_spec_index: libc::c_int,
1122 pub token: *const libc::c_char,
1123 pub summary: *const libc::c_char,
1124 pub since: *const libc::c_char,
1125 pub flags: libc::c_int,
1126 pub deprecated_since: *const libc::c_char,
1127 pub subargs: *mut redisCommandArg,
1128 pub num_args: libc::c_int,
1129}
1130pub type redisCommandArgType = libc::c_uint;
1131pub const ARG_TYPE_BLOCK: redisCommandArgType = 8;
1132pub const ARG_TYPE_ONEOF: redisCommandArgType = 7;
1133pub const ARG_TYPE_PURE_TOKEN: redisCommandArgType = 6;
1134pub const ARG_TYPE_UNIX_TIME: redisCommandArgType = 5;
1135pub const ARG_TYPE_PATTERN: redisCommandArgType = 4;
1136pub const ARG_TYPE_KEY: redisCommandArgType = 3;
1137pub const ARG_TYPE_DOUBLE: redisCommandArgType = 2;
1138pub const ARG_TYPE_INTEGER: redisCommandArgType = 1;
1139pub const ARG_TYPE_STRING: redisCommandArgType = 0;
1140pub type redisGetKeysProc = unsafe extern "C" fn(
1141 *mut redisCommand,
1142 *mut *mut robj,
1143 libc::c_int,
1144 *mut getKeysResult,
1145) -> libc::c_int;
1146#[derive(Copy, Clone)]
1147#[repr(C)]
1148pub struct getKeysResult {
1149 pub keysbuf: [keyReference; 256],
1150 pub keys: *mut keyReference,
1151 pub numkeys: libc::c_int,
1152 pub size: libc::c_int,
1153}
1154#[derive(Copy, Clone)]
1155#[repr(C)]
1156pub struct keyReference {
1157 pub pos: libc::c_int,
1158 pub flags: libc::c_int,
1159}
1160pub type redisCommandProc = unsafe extern "C" fn(*mut client) -> ();
1161#[derive(Copy, Clone)]
1162#[repr(C)]
1163pub struct client {
1164 pub id: uint64_t,
1165 pub flags: uint64_t,
1166 pub conn: *mut connection,
1167 pub resp: libc::c_int,
1168 pub db: *mut redisDb,
1169 pub name: *mut robj,
1170 pub querybuf: sds,
1171 pub qb_pos: size_t,
1172 pub querybuf_peak: size_t,
1173 pub argc: libc::c_int,
1174 pub argv: *mut *mut robj,
1175 pub argv_len: libc::c_int,
1176 pub original_argc: libc::c_int,
1177 pub original_argv: *mut *mut robj,
1178 pub argv_len_sum: size_t,
1179 pub cmd: *mut redisCommand,
1180 pub lastcmd: *mut redisCommand,
1181 pub realcmd: *mut redisCommand,
1182 pub user: *mut user,
1183 pub reqtype: libc::c_int,
1184 pub multibulklen: libc::c_int,
1185 pub bulklen: libc::c_long,
1186 pub reply: *mut list,
1187 pub reply_bytes: libc::c_ulonglong,
1188 pub deferred_reply_errors: *mut list,
1189 pub sentlen: size_t,
1190 pub ctime: time_t,
1191 pub duration: libc::c_long,
1192 pub slot: libc::c_int,
1193 pub cur_script: *mut dictEntry,
1194 pub lastinteraction: time_t,
1195 pub obuf_soft_limit_reached_time: time_t,
1196 pub authenticated: libc::c_int,
1197 pub replstate: libc::c_int,
1198 pub repl_start_cmd_stream_on_ack: libc::c_int,
1199 pub repldbfd: libc::c_int,
1200 pub repldboff: off_t,
1201 pub repldbsize: off_t,
1202 pub replpreamble: sds,
1203 pub read_reploff: libc::c_longlong,
1204 pub reploff: libc::c_longlong,
1205 pub repl_applied: libc::c_longlong,
1206 pub repl_ack_off: libc::c_longlong,
1207 pub repl_ack_time: libc::c_longlong,
1208 pub repl_last_partial_write: libc::c_longlong,
1209 pub psync_initial_offset: libc::c_longlong,
1210 pub replid: [libc::c_char; 41],
1211 pub slave_listening_port: libc::c_int,
1212 pub slave_addr: *mut libc::c_char,
1213 pub slave_capa: libc::c_int,
1214 pub slave_req: libc::c_int,
1215 pub mstate: multiState,
1216 pub btype: libc::c_int,
1217 pub bpop: blockingState,
1218 pub woff: libc::c_longlong,
1219 pub watched_keys: *mut list,
1220 pub pubsub_channels: *mut dict,
1221 pub pubsub_patterns: *mut list,
1222 pub pubsubshard_channels: *mut dict,
1223 pub peerid: sds,
1224 pub sockname: sds,
1225 pub client_list_node: *mut listNode,
1226 pub postponed_list_node: *mut listNode,
1227 pub pending_read_list_node: *mut listNode,
1228 pub auth_callback: RedisModuleUserChangedFunc,
1229 pub auth_callback_privdata: *mut libc::c_void,
1230 pub auth_module: *mut libc::c_void,
1231 pub client_tracking_redirection: uint64_t,
1232 pub client_tracking_prefixes: *mut rax,
1233 pub last_memory_usage: size_t,
1234 pub last_memory_type: libc::c_int,
1235 pub mem_usage_bucket_node: *mut listNode,
1236 pub mem_usage_bucket: *mut clientMemUsageBucket,
1237 pub ref_repl_buf_node: *mut listNode,
1238 pub ref_block_pos: size_t,
1239 pub buf_peak: size_t,
1240 pub buf_peak_last_reset_time: mstime_t,
1241 pub bufpos: libc::c_int,
1242 pub buf_usable_size: size_t,
1243 pub buf: *mut libc::c_char,
1244}
1245#[derive(Copy, Clone)]
1246#[repr(C)]
1247pub struct clientMemUsageBucket {
1248 pub clients: *mut list,
1249 pub mem_usage_sum: size_t,
1250}
1251#[derive(Copy, Clone)]
1252#[repr(C)]
1253pub struct blockingState {
1254 pub count: libc::c_long,
1255 pub timeout: mstime_t,
1256 pub keys: *mut dict,
1257 pub target: *mut robj,
1258 pub blockpos: blockPos,
1259 pub xread_count: size_t,
1260 pub xread_group: *mut robj,
1261 pub xread_consumer: *mut robj,
1262 pub xread_group_noack: libc::c_int,
1263 pub numreplicas: libc::c_int,
1264 pub reploffset: libc::c_longlong,
1265 pub module_blocked_handle: *mut libc::c_void,
1266}
1267#[derive(Copy, Clone)]
1268#[repr(C)]
1269pub struct blockPos {
1270 pub wherefrom: libc::c_int,
1271 pub whereto: libc::c_int,
1272}
1273#[derive(Copy, Clone)]
1274#[repr(C)]
1275pub struct multiState {
1276 pub commands: *mut multiCmd,
1277 pub count: libc::c_int,
1278 pub cmd_flags: libc::c_int,
1279 pub cmd_inv_flags: libc::c_int,
1280 pub argv_len_sums: size_t,
1281 pub alloc_count: libc::c_int,
1282}
1283#[derive(Copy, Clone)]
1284#[repr(C)]
1285pub struct user {
1286 pub name: sds,
1287 pub flags: uint32_t,
1288 pub passwords: *mut list,
1289 pub selectors: *mut list,
1290 pub acl_string: *mut robj,
1291}
1292#[derive(Copy, Clone)]
1293#[repr(C)]
1294pub struct commandHistory {
1295 pub since: *const libc::c_char,
1296 pub changes: *const libc::c_char,
1297}
1298pub type redisCommandGroup = libc::c_uint;
1299pub const COMMAND_GROUP_MODULE: redisCommandGroup = 17;
1300pub const COMMAND_GROUP_BITMAP: redisCommandGroup = 16;
1301pub const COMMAND_GROUP_STREAM: redisCommandGroup = 15;
1302pub const COMMAND_GROUP_GEO: redisCommandGroup = 14;
1303pub const COMMAND_GROUP_SENTINEL: redisCommandGroup = 13;
1304pub const COMMAND_GROUP_CLUSTER: redisCommandGroup = 12;
1305pub const COMMAND_GROUP_HYPERLOGLOG: redisCommandGroup = 11;
1306pub const COMMAND_GROUP_SCRIPTING: redisCommandGroup = 10;
1307pub const COMMAND_GROUP_SERVER: redisCommandGroup = 9;
1308pub const COMMAND_GROUP_CONNECTION: redisCommandGroup = 8;
1309pub const COMMAND_GROUP_TRANSACTIONS: redisCommandGroup = 7;
1310pub const COMMAND_GROUP_PUBSUB: redisCommandGroup = 6;
1311pub const COMMAND_GROUP_HASH: redisCommandGroup = 5;
1312pub const COMMAND_GROUP_SORTED_SET: redisCommandGroup = 4;
1313pub const COMMAND_GROUP_SET: redisCommandGroup = 3;
1314pub const COMMAND_GROUP_LIST: redisCommandGroup = 2;
1315pub const COMMAND_GROUP_STRING: redisCommandGroup = 1;
1316pub const COMMAND_GROUP_GENERIC: redisCommandGroup = 0;
1317#[derive(Copy, Clone)]
1318#[repr(C)]
1319pub struct replBacklog {
1320 pub ref_repl_buf_node: *mut listNode,
1321 pub unindexed_count: size_t,
1322 pub blocks_index: *mut rax,
1323 pub histlen: libc::c_longlong,
1324 pub offset: libc::c_longlong,
1325}
1326#[derive(Copy, Clone)]
1327#[repr(C)]
1328pub struct saveparam {
1329 pub seconds: time_t,
1330 pub changes: libc::c_int,
1331}
1332#[derive(Copy, Clone)]
1333#[repr(C)]
1334pub struct sentinelConfig {
1335 pub pre_monitor_cfg: *mut list,
1336 pub monitor_cfg: *mut list,
1337 pub post_monitor_cfg: *mut list,
1338}
1339#[derive(Copy, Clone)]
1340#[repr(C)]
1341pub struct sharedObjectsStruct {
1342 pub crlf: *mut robj,
1343 pub ok: *mut robj,
1344 pub err: *mut robj,
1345 pub emptybulk: *mut robj,
1346 pub czero: *mut robj,
1347 pub cone: *mut robj,
1348 pub pong: *mut robj,
1349 pub space: *mut robj,
1350 pub queued: *mut robj,
1351 pub null: [*mut robj; 4],
1352 pub nullarray: [*mut robj; 4],
1353 pub emptymap: [*mut robj; 4],
1354 pub emptyset: [*mut robj; 4],
1355 pub emptyarray: *mut robj,
1356 pub wrongtypeerr: *mut robj,
1357 pub nokeyerr: *mut robj,
1358 pub syntaxerr: *mut robj,
1359 pub sameobjecterr: *mut robj,
1360 pub outofrangeerr: *mut robj,
1361 pub noscripterr: *mut robj,
1362 pub loadingerr: *mut robj,
1363 pub slowevalerr: *mut robj,
1364 pub slowscripterr: *mut robj,
1365 pub slowmoduleerr: *mut robj,
1366 pub bgsaveerr: *mut robj,
1367 pub masterdownerr: *mut robj,
1368 pub roslaveerr: *mut robj,
1369 pub execaborterr: *mut robj,
1370 pub noautherr: *mut robj,
1371 pub noreplicaserr: *mut robj,
1372 pub busykeyerr: *mut robj,
1373 pub oomerr: *mut robj,
1374 pub plus: *mut robj,
1375 pub messagebulk: *mut robj,
1376 pub pmessagebulk: *mut robj,
1377 pub subscribebulk: *mut robj,
1378 pub unsubscribebulk: *mut robj,
1379 pub psubscribebulk: *mut robj,
1380 pub punsubscribebulk: *mut robj,
1381 pub del: *mut robj,
1382 pub unlink: *mut robj,
1383 pub rpop: *mut robj,
1384 pub lpop: *mut robj,
1385 pub lpush: *mut robj,
1386 pub rpoplpush: *mut robj,
1387 pub lmove: *mut robj,
1388 pub blmove: *mut robj,
1389 pub zpopmin: *mut robj,
1390 pub zpopmax: *mut robj,
1391 pub emptyscan: *mut robj,
1392 pub multi: *mut robj,
1393 pub exec: *mut robj,
1394 pub left: *mut robj,
1395 pub right: *mut robj,
1396 pub hset: *mut robj,
1397 pub srem: *mut robj,
1398 pub xgroup: *mut robj,
1399 pub xclaim: *mut robj,
1400 pub script: *mut robj,
1401 pub replconf: *mut robj,
1402 pub eval: *mut robj,
1403 pub persist: *mut robj,
1404 pub set: *mut robj,
1405 pub pexpireat: *mut robj,
1406 pub pexpire: *mut robj,
1407 pub time: *mut robj,
1408 pub pxat: *mut robj,
1409 pub absttl: *mut robj,
1410 pub retrycount: *mut robj,
1411 pub force: *mut robj,
1412 pub justid: *mut robj,
1413 pub entriesread: *mut robj,
1414 pub lastid: *mut robj,
1415 pub ping: *mut robj,
1416 pub setid: *mut robj,
1417 pub keepttl: *mut robj,
1418 pub load: *mut robj,
1419 pub createconsumer: *mut robj,
1420 pub getack: *mut robj,
1421 pub special_asterick: *mut robj,
1422 pub special_equals: *mut robj,
1423 pub default_username: *mut robj,
1424 pub redacted: *mut robj,
1425 pub ssubscribebulk: *mut robj,
1426 pub sunsubscribebulk: *mut robj,
1427 pub smessagebulk: *mut robj,
1428 pub select: [*mut robj; 10],
1429 pub integers: [*mut robj; 10000],
1430 pub mbulkhdr: [*mut robj; 32],
1431 pub bulkhdr: [*mut robj; 32],
1432 pub maphdr: [*mut robj; 32],
1433 pub sethdr: [*mut robj; 32],
1434 pub minstring: sds,
1435 pub maxstring: sds,
1436}
1437#[derive(Copy, Clone)]
1438#[repr(C)]
1439pub struct clientBufferLimitsConfig {
1440 pub hard_limit_bytes: libc::c_ulonglong,
1441 pub soft_limit_bytes: libc::c_ulonglong,
1442 pub soft_limit_seconds: time_t,
1443}
1444#[derive(Copy, Clone)]
1445#[repr(C)]
1446pub struct redisOp {
1447 pub argv: *mut *mut robj,
1448 pub argc: libc::c_int,
1449 pub dbid: libc::c_int,
1450 pub target: libc::c_int,
1451}
1452#[derive(Copy, Clone)]
1453#[repr(C)]
1454pub struct redisOpArray {
1455 pub ops: *mut redisOp,
1456 pub numops: libc::c_int,
1457 pub capacity: libc::c_int,
1458}
1459#[derive(Copy, Clone)]
1460#[repr(C)]
1461pub struct malloc_stats {
1462 pub zmalloc_used: size_t,
1463 pub process_rss: size_t,
1464 pub allocator_allocated: size_t,
1465 pub allocator_active: size_t,
1466 pub allocator_resident: size_t,
1467}
1468#[derive(Copy, Clone)]
1469#[repr(C)]
1470pub struct socketFds {
1471 pub fd: [libc::c_int; 16],
1472 pub count: libc::c_int,
1473}
1474#[derive(Copy, Clone)]
1475#[repr(C)]
1476pub struct redisTLSContextConfig {
1477 pub cert_file: *mut libc::c_char,
1478 pub key_file: *mut libc::c_char,
1479 pub key_file_pass: *mut libc::c_char,
1480 pub client_cert_file: *mut libc::c_char,
1481 pub client_key_file: *mut libc::c_char,
1482 pub client_key_file_pass: *mut libc::c_char,
1483 pub dh_params_file: *mut libc::c_char,
1484 pub ca_cert_file: *mut libc::c_char,
1485 pub ca_cert_dir: *mut libc::c_char,
1486 pub protocols: *mut libc::c_char,
1487 pub ciphers: *mut libc::c_char,
1488 pub ciphersuites: *mut libc::c_char,
1489 pub prefer_server_ciphers: libc::c_int,
1490 pub session_caching: libc::c_int,
1491 pub session_cache_size: libc::c_int,
1492 pub session_cache_timeout: libc::c_int,
1493}
1494pub type aof_file_type = libc::c_uint;
1495pub const AOF_FILE_TYPE_INCR: aof_file_type = 105;
1496pub const AOF_FILE_TYPE_HIST: aof_file_type = 104;
1497pub const AOF_FILE_TYPE_BASE: aof_file_type = 98;
1498#[derive(Copy, Clone)]
1499#[repr(C)]
1500pub struct aofInfo {
1501 pub file_name: sds,
1502 pub file_seq: libc::c_longlong,
1503 pub file_type: aof_file_type,
1504}
1505#[derive(Copy, Clone)]
1506#[repr(C)]
1507pub struct aofManifest {
1508 pub base_aof_info: *mut aofInfo,
1509 pub incr_aof_list: *mut list,
1510 pub history_aof_list: *mut list,
1511 pub curr_base_file_seq: libc::c_longlong,
1512 pub curr_incr_file_seq: libc::c_longlong,
1513 pub dirty: libc::c_int,
1514}
1515#[derive(Copy, Clone)]
1516#[repr(C)]
1517pub struct redisServer {
1518 pub pid: pid_t,
1519 pub main_thread_id: pthread_t,
1520 pub configfile: *mut libc::c_char,
1521 pub executable: *mut libc::c_char,
1522 pub exec_argv: *mut *mut libc::c_char,
1523 pub dynamic_hz: libc::c_int,
1524 pub config_hz: libc::c_int,
1525 pub umask: mode_t,
1526 pub hz: libc::c_int,
1527 pub in_fork_child: libc::c_int,
1528 pub db: *mut redisDb,
1529 pub commands: *mut dict,
1530 pub orig_commands: *mut dict,
1531 pub el: *mut aeEventLoop,
1532 pub errors: *mut rax,
1533 pub lruclock: atomic_uint,
1534 pub shutdown_asap: sig_atomic_t,
1535 pub shutdown_mstime: mstime_t,
1536 pub last_sig_received: libc::c_int,
1537 pub shutdown_flags: libc::c_int,
1538 pub activerehashing: libc::c_int,
1539 pub active_defrag_running: libc::c_int,
1540 pub pidfile: *mut libc::c_char,
1541 pub arch_bits: libc::c_int,
1542 pub cronloops: libc::c_int,
1543 pub runid: [libc::c_char; 41],
1544 pub sentinel_mode: libc::c_int,
1545 pub initial_memory_usage: size_t,
1546 pub always_show_logo: libc::c_int,
1547 pub in_exec: libc::c_int,
1548 pub busy_module_yield_flags: libc::c_int,
1549 pub busy_module_yield_reply: *const libc::c_char,
1550 pub core_propagates: libc::c_int,
1551 pub propagate_no_multi: libc::c_int,
1552 pub module_ctx_nesting: libc::c_int,
1553 pub ignore_warnings: *mut libc::c_char,
1554 pub client_pause_in_transaction: libc::c_int,
1555 pub thp_enabled: libc::c_int,
1556 pub page_size: size_t,
1557 pub moduleapi: *mut dict,
1558 pub sharedapi: *mut dict,
1559 pub module_configs_queue: *mut dict,
1560 pub loadmodule_queue: *mut list,
1561 pub module_pipe: [libc::c_int; 2],
1562 pub child_pid: pid_t,
1563 pub child_type: libc::c_int,
1564 pub port: libc::c_int,
1565 pub tls_port: libc::c_int,
1566 pub tcp_backlog: libc::c_int,
1567 pub bindaddr: [*mut libc::c_char; 16],
1568 pub bindaddr_count: libc::c_int,
1569 pub bind_source_addr: *mut libc::c_char,
1570 pub unixsocket: *mut libc::c_char,
1571 pub unixsocketperm: libc::c_uint,
1572 pub ipfd: socketFds,
1573 pub tlsfd: socketFds,
1574 pub sofd: libc::c_int,
1575 pub socket_mark_id: uint32_t,
1576 pub cfd: socketFds,
1577 pub clients: *mut list,
1578 pub clients_to_close: *mut list,
1579 pub clients_pending_write: *mut list,
1580 pub clients_pending_read: *mut list,
1581 pub slaves: *mut list,
1582 pub monitors: *mut list,
1583 pub current_client: *mut client,
1584 pub client_mem_usage_buckets: *mut clientMemUsageBucket,
1585 pub clients_timeout_table: *mut rax,
1586 pub fixed_time_expire: libc::c_long,
1587 pub in_nested_call: libc::c_int,
1588 pub clients_index: *mut rax,
1589 pub client_pause_type: pause_type,
1590 pub postponed_clients: *mut list,
1591 pub client_pause_end_time: mstime_t,
1592 pub client_pause_per_purpose: [*mut pause_event; 3],
1593 pub neterr: [libc::c_char; 256],
1594 pub migrate_cached_sockets: *mut dict,
1595 pub next_client_id: uint_least64_t,
1596 pub protected_mode: libc::c_int,
1597 pub io_threads_num: libc::c_int,
1598 pub io_threads_do_reads: libc::c_int,
1599 pub io_threads_active: libc::c_int,
1600 pub events_processed_while_blocked: libc::c_longlong,
1601 pub enable_protected_configs: libc::c_int,
1602 pub enable_debug_cmd: libc::c_int,
1603 pub enable_module_cmd: libc::c_int,
1604 pub loading: sig_atomic_t,
1605 pub async_loading: sig_atomic_t,
1606 pub loading_total_bytes: off_t,
1607 pub loading_rdb_used_mem: off_t,
1608 pub loading_loaded_bytes: off_t,
1609 pub loading_start_time: time_t,
1610 pub loading_process_events_interval_bytes: off_t,
1611 pub stat_starttime: time_t,
1612 pub stat_numcommands: libc::c_longlong,
1613 pub stat_numconnections: libc::c_longlong,
1614 pub stat_expiredkeys: libc::c_longlong,
1615 pub stat_expired_stale_perc: libc::c_double,
1616 pub stat_expired_time_cap_reached_count: libc::c_longlong,
1617 pub stat_expire_cycle_time_used: libc::c_longlong,
1618 pub stat_evictedkeys: libc::c_longlong,
1619 pub stat_evictedclients: libc::c_longlong,
1620 pub stat_total_eviction_exceeded_time: libc::c_longlong,
1621 pub stat_last_eviction_exceeded_time: monotime,
1622 pub stat_keyspace_hits: libc::c_longlong,
1623 pub stat_keyspace_misses: libc::c_longlong,
1624 pub stat_active_defrag_hits: libc::c_longlong,
1625 pub stat_active_defrag_misses: libc::c_longlong,
1626 pub stat_active_defrag_key_hits: libc::c_longlong,
1627 pub stat_active_defrag_key_misses: libc::c_longlong,
1628 pub stat_active_defrag_scanned: libc::c_longlong,
1629 pub stat_total_active_defrag_time: libc::c_longlong,
1630 pub stat_last_active_defrag_time: monotime,
1631 pub stat_peak_memory: size_t,
1632 pub stat_aof_rewrites: libc::c_longlong,
1633 pub stat_aofrw_consecutive_failures: libc::c_longlong,
1634 pub stat_rdb_saves: libc::c_longlong,
1635 pub stat_fork_time: libc::c_longlong,
1636 pub stat_fork_rate: libc::c_double,
1637 pub stat_total_forks: libc::c_longlong,
1638 pub stat_rejected_conn: libc::c_longlong,
1639 pub stat_sync_full: libc::c_longlong,
1640 pub stat_sync_partial_ok: libc::c_longlong,
1641 pub stat_sync_partial_err: libc::c_longlong,
1642 pub slowlog: *mut list,
1643 pub slowlog_entry_id: libc::c_longlong,
1644 pub slowlog_log_slower_than: libc::c_longlong,
1645 pub slowlog_max_len: libc::c_ulong,
1646 pub cron_malloc_stats: malloc_stats,
1647 pub stat_net_input_bytes: atomic_llong,
1648 pub stat_net_output_bytes: atomic_llong,
1649 pub stat_net_repl_input_bytes: atomic_llong,
1650 pub stat_net_repl_output_bytes: atomic_llong,
1651 pub stat_current_cow_peak: size_t,
1652 pub stat_current_cow_bytes: size_t,
1653 pub stat_current_cow_updated: monotime,
1654 pub stat_current_save_keys_processed: size_t,
1655 pub stat_current_save_keys_total: size_t,
1656 pub stat_rdb_cow_bytes: size_t,
1657 pub stat_aof_cow_bytes: size_t,
1658 pub stat_module_cow_bytes: size_t,
1659 pub stat_module_progress: libc::c_double,
1660 pub stat_clients_type_memory: [size_t; 4],
1661 pub stat_cluster_links_memory: size_t,
1662 pub stat_unexpected_error_replies: libc::c_longlong,
1663 pub stat_total_error_replies: libc::c_longlong,
1664 pub stat_dump_payload_sanitizations: libc::c_longlong,
1665 pub stat_io_reads_processed: libc::c_longlong,
1666 pub stat_io_writes_processed: libc::c_longlong,
1667 pub stat_total_reads_processed: atomic_llong,
1668 pub stat_total_writes_processed: atomic_llong,
1669 pub inst_metric: [C2RustUnnamed_14; 5],
1670 pub stat_reply_buffer_shrinks: libc::c_longlong,
1671 pub stat_reply_buffer_expands: libc::c_longlong,
1672 pub verbosity: libc::c_int,
1673 pub maxidletime: libc::c_int,
1674 pub tcpkeepalive: libc::c_int,
1675 pub active_expire_enabled: libc::c_int,
1676 pub active_expire_effort: libc::c_int,
1677 pub active_defrag_enabled: libc::c_int,
1678 pub sanitize_dump_payload: libc::c_int,
1679 pub skip_checksum_validation: libc::c_int,
1680 pub jemalloc_bg_thread: libc::c_int,
1681 pub active_defrag_ignore_bytes: size_t,
1682 pub active_defrag_threshold_lower: libc::c_int,
1683 pub active_defrag_threshold_upper: libc::c_int,
1684 pub active_defrag_cycle_min: libc::c_int,
1685 pub active_defrag_cycle_max: libc::c_int,
1686 pub active_defrag_max_scan_fields: libc::c_ulong,
1687 pub client_max_querybuf_len: size_t,
1688 pub dbnum: libc::c_int,
1689 pub supervised: libc::c_int,
1690 pub supervised_mode: libc::c_int,
1691 pub daemonize: libc::c_int,
1692 pub set_proc_title: libc::c_int,
1693 pub proc_title_template: *mut libc::c_char,
1694 pub client_obuf_limits: [clientBufferLimitsConfig; 3],
1695 pub pause_cron: libc::c_int,
1696 pub latency_tracking_enabled: libc::c_int,
1697 pub latency_tracking_info_percentiles: *mut libc::c_double,
1698 pub latency_tracking_info_percentiles_len: libc::c_int,
1699 pub aof_enabled: libc::c_int,
1700 pub aof_state: libc::c_int,
1701 pub aof_fsync: libc::c_int,
1702 pub aof_filename: *mut libc::c_char,
1703 pub aof_dirname: *mut libc::c_char,
1704 pub aof_no_fsync_on_rewrite: libc::c_int,
1705 pub aof_rewrite_perc: libc::c_int,
1706 pub aof_rewrite_min_size: off_t,
1707 pub aof_rewrite_base_size: off_t,
1708 pub aof_current_size: off_t,
1709 pub aof_last_incr_size: off_t,
1710 pub aof_fsync_offset: off_t,
1711 pub aof_flush_sleep: libc::c_int,
1712 pub aof_rewrite_scheduled: libc::c_int,
1713 pub aof_buf: sds,
1714 pub aof_fd: libc::c_int,
1715 pub aof_selected_db: libc::c_int,
1716 pub aof_flush_postponed_start: time_t,
1717 pub aof_last_fsync: time_t,
1718 pub aof_rewrite_time_last: time_t,
1719 pub aof_rewrite_time_start: time_t,
1720 pub aof_cur_timestamp: time_t,
1721 pub aof_timestamp_enabled: libc::c_int,
1722 pub aof_lastbgrewrite_status: libc::c_int,
1723 pub aof_delayed_fsync: libc::c_ulong,
1724 pub aof_rewrite_incremental_fsync: libc::c_int,
1725 pub rdb_save_incremental_fsync: libc::c_int,
1726 pub aof_last_write_status: libc::c_int,
1727 pub aof_last_write_errno: libc::c_int,
1728 pub aof_load_truncated: libc::c_int,
1729 pub aof_use_rdb_preamble: libc::c_int,
1730 pub aof_bio_fsync_status: atomic_int,
1731 pub aof_bio_fsync_errno: atomic_int,
1732 pub aof_manifest: *mut aofManifest,
1733 pub aof_disable_auto_gc: libc::c_int,
1734 pub dirty: libc::c_longlong,
1735 pub dirty_before_bgsave: libc::c_longlong,
1736 pub rdb_last_load_keys_expired: libc::c_longlong,
1737 pub rdb_last_load_keys_loaded: libc::c_longlong,
1738 pub saveparams: *mut saveparam,
1739 pub saveparamslen: libc::c_int,
1740 pub rdb_filename: *mut libc::c_char,
1741 pub rdb_compression: libc::c_int,
1742 pub rdb_checksum: libc::c_int,
1743 pub rdb_del_sync_files: libc::c_int,
1744 pub lastsave: time_t,
1745 pub lastbgsave_try: time_t,
1746 pub rdb_save_time_last: time_t,
1747 pub rdb_save_time_start: time_t,
1748 pub rdb_bgsave_scheduled: libc::c_int,
1749 pub rdb_child_type: libc::c_int,
1750 pub lastbgsave_status: libc::c_int,
1751 pub stop_writes_on_bgsave_err: libc::c_int,
1752 pub rdb_pipe_read: libc::c_int,
1753 pub rdb_child_exit_pipe: libc::c_int,
1754 pub rdb_pipe_conns: *mut *mut connection,
1755 pub rdb_pipe_numconns: libc::c_int,
1756 pub rdb_pipe_numconns_writing: libc::c_int,
1757 pub rdb_pipe_buff: *mut libc::c_char,
1758 pub rdb_pipe_bufflen: libc::c_int,
1759 pub rdb_key_save_delay: libc::c_int,
1760 pub key_load_delay: libc::c_int,
1761 pub child_info_pipe: [libc::c_int; 2],
1762 pub child_info_nread: libc::c_int,
1763 pub also_propagate: redisOpArray,
1764 pub replication_allowed: libc::c_int,
1765 pub logfile: *mut libc::c_char,
1766 pub syslog_enabled: libc::c_int,
1767 pub syslog_ident: *mut libc::c_char,
1768 pub syslog_facility: libc::c_int,
1769 pub crashlog_enabled: libc::c_int,
1770 pub memcheck_enabled: libc::c_int,
1771 pub use_exit_on_panic: libc::c_int,
1772 pub shutdown_timeout: libc::c_int,
1773 pub shutdown_on_sigint: libc::c_int,
1774 pub shutdown_on_sigterm: libc::c_int,
1775 pub replid: [libc::c_char; 41],
1776 pub replid2: [libc::c_char; 41],
1777 pub master_repl_offset: libc::c_longlong,
1778 pub second_replid_offset: libc::c_longlong,
1779 pub slaveseldb: libc::c_int,
1780 pub repl_ping_slave_period: libc::c_int,
1781 pub repl_backlog: *mut replBacklog,
1782 pub repl_backlog_size: libc::c_longlong,
1783 pub repl_backlog_time_limit: time_t,
1784 pub repl_no_slaves_since: time_t,
1785 pub repl_min_slaves_to_write: libc::c_int,
1786 pub repl_min_slaves_max_lag: libc::c_int,
1787 pub repl_good_slaves_count: libc::c_int,
1788 pub repl_diskless_sync: libc::c_int,
1789 pub repl_diskless_load: libc::c_int,
1790 pub repl_diskless_sync_delay: libc::c_int,
1791 pub repl_diskless_sync_max_replicas: libc::c_int,
1792 pub repl_buffer_mem: size_t,
1793 pub repl_buffer_blocks: *mut list,
1794 pub masteruser: *mut libc::c_char,
1795 pub masterauth: sds,
1796 pub masterhost: *mut libc::c_char,
1797 pub masterport: libc::c_int,
1798 pub repl_timeout: libc::c_int,
1799 pub master: *mut client,
1800 pub cached_master: *mut client,
1801 pub repl_syncio_timeout: libc::c_int,
1802 pub repl_state: libc::c_int,
1803 pub repl_transfer_size: off_t,
1804 pub repl_transfer_read: off_t,
1805 pub repl_transfer_last_fsync_off: off_t,
1806 pub repl_transfer_s: *mut connection,
1807 pub repl_transfer_fd: libc::c_int,
1808 pub repl_transfer_tmpfile: *mut libc::c_char,
1809 pub repl_transfer_lastio: time_t,
1810 pub repl_serve_stale_data: libc::c_int,
1811 pub repl_slave_ro: libc::c_int,
1812 pub repl_slave_ignore_maxmemory: libc::c_int,
1813 pub repl_down_since: time_t,
1814 pub repl_disable_tcp_nodelay: libc::c_int,
1815 pub slave_priority: libc::c_int,
1816 pub replica_announced: libc::c_int,
1817 pub slave_announce_port: libc::c_int,
1818 pub slave_announce_ip: *mut libc::c_char,
1819 pub propagation_error_behavior: libc::c_int,
1820 pub repl_ignore_disk_write_error: libc::c_int,
1821 pub master_replid: [libc::c_char; 41],
1822 pub master_initial_offset: libc::c_longlong,
1823 pub repl_slave_lazy_flush: libc::c_int,
1824 pub clients_waiting_acks: *mut list,
1825 pub get_ack_from_slaves: libc::c_int,
1826 pub maxclients: libc::c_uint,
1827 pub maxmemory: libc::c_ulonglong,
1828 pub maxmemory_clients: ssize_t,
1829 pub maxmemory_policy: libc::c_int,
1830 pub maxmemory_samples: libc::c_int,
1831 pub maxmemory_eviction_tenacity: libc::c_int,
1832 pub lfu_log_factor: libc::c_int,
1833 pub lfu_decay_time: libc::c_int,
1834 pub proto_max_bulk_len: libc::c_longlong,
1835 pub oom_score_adj_values: [libc::c_int; 3],
1836 pub oom_score_adj: libc::c_int,
1837 pub disable_thp: libc::c_int,
1838 pub blocked_clients: libc::c_uint,
1839 pub blocked_clients_by_type: [libc::c_uint; 8],
1840 pub unblocked_clients: *mut list,
1841 pub ready_keys: *mut list,
1842 pub tracking_clients: libc::c_uint,
1843 pub tracking_table_max_keys: size_t,
1844 pub tracking_pending_keys: *mut list,
1845 pub sort_desc: libc::c_int,
1846 pub sort_alpha: libc::c_int,
1847 pub sort_bypattern: libc::c_int,
1848 pub sort_store: libc::c_int,
1849 pub hash_max_listpack_entries: size_t,
1850 pub hash_max_listpack_value: size_t,
1851 pub set_max_intset_entries: size_t,
1852 pub zset_max_listpack_entries: size_t,
1853 pub zset_max_listpack_value: size_t,
1854 pub hll_sparse_max_bytes: size_t,
1855 pub stream_node_max_bytes: size_t,
1856 pub stream_node_max_entries: libc::c_longlong,
1857 pub list_max_listpack_size: libc::c_int,
1858 pub list_compress_depth: libc::c_int,
1859 pub unixtime: atomic_int,
1860 pub timezone: time_t,
1861 pub daylight_active: libc::c_int,
1862 pub mstime: mstime_t,
1863 pub ustime: ustime_t,
1864 pub blocking_op_nesting: size_t,
1865 pub blocked_last_cron: libc::c_longlong,
1866 pub pubsub_channels: *mut dict,
1867 pub pubsub_patterns: *mut dict,
1868 pub notify_keyspace_events: libc::c_int,
1869 pub pubsubshard_channels: *mut dict,
1870 pub cluster_enabled: libc::c_int,
1871 pub cluster_port: libc::c_int,
1872 pub cluster_node_timeout: mstime_t,
1873 pub cluster_configfile: *mut libc::c_char,
1874 pub cluster: *mut clusterState,
1875 pub cluster_migration_barrier: libc::c_int,
1876 pub cluster_allow_replica_migration: libc::c_int,
1877 pub cluster_slave_validity_factor: libc::c_int,
1878 pub cluster_require_full_coverage: libc::c_int,
1879 pub cluster_slave_no_failover: libc::c_int,
1880 pub cluster_announce_ip: *mut libc::c_char,
1881 pub cluster_announce_hostname: *mut libc::c_char,
1882 pub cluster_preferred_endpoint_type: libc::c_int,
1883 pub cluster_announce_port: libc::c_int,
1884 pub cluster_announce_tls_port: libc::c_int,
1885 pub cluster_announce_bus_port: libc::c_int,
1886 pub cluster_module_flags: libc::c_int,
1887 pub cluster_allow_reads_when_down: libc::c_int,
1888 pub cluster_config_file_lock_fd: libc::c_int,
1889 pub cluster_link_sendbuf_limit_bytes: libc::c_ulonglong,
1890 pub cluster_drop_packet_filter: libc::c_int,
1891 pub script_caller: *mut client,
1892 pub busy_reply_threshold: mstime_t,
1893 pub pre_command_oom_state: libc::c_int,
1894 pub script_disable_deny_script: libc::c_int,
1895 pub lazyfree_lazy_eviction: libc::c_int,
1896 pub lazyfree_lazy_expire: libc::c_int,
1897 pub lazyfree_lazy_server_del: libc::c_int,
1898 pub lazyfree_lazy_user_del: libc::c_int,
1899 pub lazyfree_lazy_user_flush: libc::c_int,
1900 pub latency_monitor_threshold: libc::c_longlong,
1901 pub latency_events: *mut dict,
1902 pub acl_filename: *mut libc::c_char,
1903 pub acllog_max_len: libc::c_ulong,
1904 pub requirepass: sds,
1905 pub acl_pubsub_default: libc::c_int,
1906 pub watchdog_period: libc::c_int,
1907 pub system_memory_size: size_t,
1908 pub tls_cluster: libc::c_int,
1909 pub tls_replication: libc::c_int,
1910 pub tls_auth_clients: libc::c_int,
1911 pub tls_ctx_config: redisTLSContextConfig,
1912 pub server_cpulist: *mut libc::c_char,
1913 pub bio_cpulist: *mut libc::c_char,
1914 pub aof_rewrite_cpulist: *mut libc::c_char,
1915 pub bgsave_cpulist: *mut libc::c_char,
1916 pub sentinel_config: *mut sentinelConfig,
1917 pub failover_end_time: mstime_t,
1918 pub force_failover: libc::c_int,
1919 pub target_replica_host: *mut libc::c_char,
1920 pub target_replica_port: libc::c_int,
1921 pub failover_state: libc::c_int,
1922 pub cluster_allow_pubsubshard_when_down: libc::c_int,
1923 pub reply_buffer_peak_reset_time: libc::c_long,
1924 pub reply_buffer_resizing_enabled: libc::c_int,
1925}
1926#[derive(Copy, Clone)]
1927#[repr(C)]
1928pub struct clusterState {
1929 pub myself: *mut clusterNode,
1930 pub currentEpoch: uint64_t,
1931 pub state: libc::c_int,
1932 pub size: libc::c_int,
1933 pub nodes: *mut dict,
1934 pub nodes_black_list: *mut dict,
1935 pub migrating_slots_to: [*mut clusterNode; 16384],
1936 pub importing_slots_from: [*mut clusterNode; 16384],
1937 pub slots: [*mut clusterNode; 16384],
1938 pub slots_to_channels: *mut rax,
1939 pub failover_auth_time: mstime_t,
1940 pub failover_auth_count: libc::c_int,
1941 pub failover_auth_sent: libc::c_int,
1942 pub failover_auth_rank: libc::c_int,
1943 pub failover_auth_epoch: uint64_t,
1944 pub cant_failover_reason: libc::c_int,
1945 pub mf_end: mstime_t,
1946 pub mf_slave: *mut clusterNode,
1947 pub mf_master_offset: libc::c_longlong,
1948 pub mf_can_start: libc::c_int,
1949 pub lastVoteEpoch: uint64_t,
1950 pub todo_before_sleep: libc::c_int,
1951 pub stats_bus_messages_sent: [libc::c_longlong; 11],
1952 pub stats_bus_messages_received: [libc::c_longlong; 11],
1953 pub stats_pfail_nodes: libc::c_longlong,
1954 pub stat_cluster_links_buffer_limit_exceeded: libc::c_ulonglong,
1955}
1956#[derive(Copy, Clone)]
1957#[repr(C)]
1958pub struct clusterNode {
1959 pub ctime: mstime_t,
1960 pub name: [libc::c_char; 40],
1961 pub flags: libc::c_int,
1962 pub configEpoch: uint64_t,
1963 pub slots: [libc::c_uchar; 2048],
1964 pub slot_info_pairs: *mut uint16_t,
1965 pub slot_info_pairs_count: libc::c_int,
1966 pub numslots: libc::c_int,
1967 pub numslaves: libc::c_int,
1968 pub slaves: *mut *mut clusterNode,
1969 pub slaveof: *mut clusterNode,
1970 pub last_in_ping_gossip: libc::c_ulonglong,
1971 pub ping_sent: mstime_t,
1972 pub pong_received: mstime_t,
1973 pub data_received: mstime_t,
1974 pub fail_time: mstime_t,
1975 pub voted_time: mstime_t,
1976 pub repl_offset_time: mstime_t,
1977 pub orphaned_time: mstime_t,
1978 pub repl_offset: libc::c_longlong,
1979 pub ip: [libc::c_char; 46],
1980 pub hostname: sds,
1981 pub port: libc::c_int,
1982 pub pport: libc::c_int,
1983 pub cport: libc::c_int,
1984 pub link: *mut clusterLink,
1985 pub inbound_link: *mut clusterLink,
1986 pub fail_reports: *mut list,
1987}
1988#[derive(Copy, Clone)]
1989#[repr(C)]
1990pub struct clusterLink {
1991 pub ctime: mstime_t,
1992 pub conn: *mut connection,
1993 pub sndbuf: sds,
1994 pub rcvbuf: *mut libc::c_char,
1995 pub rcvbuf_len: size_t,
1996 pub rcvbuf_alloc: size_t,
1997 pub node: *mut clusterNode,
1998 pub inbound: libc::c_int,
1999}
2000#[derive(Copy, Clone)]
2001#[repr(C)]
2002pub struct C2RustUnnamed_14 {
2003 pub last_sample_time: libc::c_longlong,
2004 pub last_sample_count: libc::c_longlong,
2005 pub samples: [libc::c_longlong; 16],
2006 pub idx: libc::c_int,
2007}
2008#[derive(Copy, Clone)]
2009#[repr(C)]
2010pub struct clusterNodeFailReport {
2011 pub node: *mut clusterNode,
2012 pub time: mstime_t,
2013}
2014#[derive(Copy, Clone)]
2015#[repr(C)]
2016pub struct clusterMsg {
2017 pub sig: [libc::c_char; 4],
2018 pub totlen: uint32_t,
2019 pub ver: uint16_t,
2020 pub port: uint16_t,
2021 pub type_0: uint16_t,
2022 pub count: uint16_t,
2023 pub currentEpoch: uint64_t,
2024 pub configEpoch: uint64_t,
2025 pub offset: uint64_t,
2026 pub sender: [libc::c_char; 40],
2027 pub myslots: [libc::c_uchar; 2048],
2028 pub slaveof: [libc::c_char; 40],
2029 pub myip: [libc::c_char; 46],
2030 pub extensions: uint16_t,
2031 pub notused1: [libc::c_char; 30],
2032 pub pport: uint16_t,
2033 pub cport: uint16_t,
2034 pub flags: uint16_t,
2035 pub state: libc::c_uchar,
2036 pub mflags: [libc::c_uchar; 3],
2037 pub data: clusterMsgData,
2038}
2039#[derive(Copy, Clone)]
2040#[repr(C)]
2041pub union clusterMsgData {
2042 pub ping: C2RustUnnamed_19,
2043 pub fail: C2RustUnnamed_18,
2044 pub publish: C2RustUnnamed_17,
2045 pub update: C2RustUnnamed_16,
2046 pub module: C2RustUnnamed_15,
2047}
2048#[derive(Copy, Clone)]
2049#[repr(C)]
2050pub struct C2RustUnnamed_15 {
2051 pub msg: clusterMsgModule,
2052}
2053#[derive(Copy, Clone)]
2054#[repr(C)]
2055pub struct clusterMsgModule {
2056 pub module_id: uint64_t,
2057 pub len: uint32_t,
2058 pub type_0: uint8_t,
2059 pub bulk_data: [libc::c_uchar; 3],
2060}
2061#[derive(Copy, Clone)]
2062#[repr(C)]
2063pub struct C2RustUnnamed_16 {
2064 pub nodecfg: clusterMsgDataUpdate,
2065}
2066#[derive(Copy, Clone)]
2067#[repr(C)]
2068pub struct clusterMsgDataUpdate {
2069 pub configEpoch: uint64_t,
2070 pub nodename: [libc::c_char; 40],
2071 pub slots: [libc::c_uchar; 2048],
2072}
2073#[derive(Copy, Clone)]
2074#[repr(C)]
2075pub struct C2RustUnnamed_17 {
2076 pub msg: clusterMsgDataPublish,
2077}
2078#[derive(Copy, Clone)]
2079#[repr(C)]
2080pub struct clusterMsgDataPublish {
2081 pub channel_len: uint32_t,
2082 pub message_len: uint32_t,
2083 pub bulk_data: [libc::c_uchar; 8],
2084}
2085#[derive(Copy, Clone)]
2086#[repr(C)]
2087pub struct C2RustUnnamed_18 {
2088 pub about: clusterMsgDataFail,
2089}
2090#[derive(Copy, Clone)]
2091#[repr(C)]
2092pub struct clusterMsgDataFail {
2093 pub nodename: [libc::c_char; 40],
2094}
2095#[derive(Copy, Clone)]
2096#[repr(C)]
2097pub struct C2RustUnnamed_19 {
2098 pub gossip: [clusterMsgDataGossip; 1],
2099}
2100#[derive(Copy, Clone)]
2101#[repr(C)]
2102pub struct clusterMsgDataGossip {
2103 pub nodename: [libc::c_char; 40],
2104 pub ping_sent: uint32_t,
2105 pub pong_received: uint32_t,
2106 pub ip: [libc::c_char; 46],
2107 pub port: uint16_t,
2108 pub cport: uint16_t,
2109 pub flags: uint16_t,
2110 pub pport: uint16_t,
2111 pub notused1: uint16_t,
2112}
2113#[derive(Copy, Clone)]
2114#[repr(C)]
2115pub struct clusterMsgPingExt {
2116 pub length: uint32_t,
2117 pub type_0: uint16_t,
2118 pub unused: uint16_t,
2119 pub ext: [C2RustUnnamed_20; 0],
2120}
2121#[derive(Copy, Clone)]
2122#[repr(C)]
2123pub union C2RustUnnamed_20 {
2124 pub hostname: clusterMsgPingExtHostname,
2125}
2126#[derive(Copy, Clone)]
2127#[repr(C)]
2128pub struct clusterMsgPingExtHostname {
2129 pub hostname: [libc::c_char; 1],
2130}
2131pub const CLUSTERMSG_EXT_TYPE_HOSTNAME: C2RustUnnamed_21 = 0;
2132#[derive(Copy, Clone)]
2133#[repr(C)]
2134pub struct redisNodeFlags {
2135 pub flag: uint16_t,
2136 pub name: *mut libc::c_char,
2137}
2138#[derive(Copy, Clone)]
2139#[repr(C)]
2140pub struct clusterDictEntryMetadata {
2141 pub prev: *mut dictEntry,
2142 pub next: *mut dictEntry,
2143}
2144#[derive(Copy, Clone)]
2145#[repr(C)]
2146pub struct migrateCachedSocket {
2147 pub conn: *mut connection,
2148 pub last_dbid: libc::c_long,
2149 pub last_use_time: time_t,
2150}
2151pub type C2RustUnnamed_21 = libc::c_uint;
2152#[inline]
2153unsafe extern "C" fn connAccept(
2154 mut conn: *mut connection,
2155 mut accept_handler: ConnectionCallbackFunc,
2156) -> libc::c_int {
2157 return ((*(*conn).type_0).accept)
2158 .expect("non-null function pointer")(conn, accept_handler);
2159}
2160#[inline]
2161unsafe extern "C" fn connConnect(
2162 mut conn: *mut connection,
2163 mut addr: *const libc::c_char,
2164 mut port: libc::c_int,
2165 mut src_addr: *const libc::c_char,
2166 mut connect_handler: ConnectionCallbackFunc,
2167) -> libc::c_int {
2168 return ((*(*conn).type_0).connect)
2169 .expect(
2170 "non-null function pointer",
2171 )(conn, addr, port, src_addr, connect_handler);
2172}
2173#[inline]
2174unsafe extern "C" fn connBlockingConnect(
2175 mut conn: *mut connection,
2176 mut addr: *const libc::c_char,
2177 mut port: libc::c_int,
2178 mut timeout: libc::c_longlong,
2179) -> libc::c_int {
2180 return ((*(*conn).type_0).blocking_connect)
2181 .expect("non-null function pointer")(conn, addr, port, timeout);
2182}
2183#[inline]
2184unsafe extern "C" fn connWrite(
2185 mut conn: *mut connection,
2186 mut data: *const libc::c_void,
2187 mut data_len: size_t,
2188) -> libc::c_int {
2189 return ((*(*conn).type_0).write)
2190 .expect("non-null function pointer")(conn, data, data_len);
2191}
2192#[inline]
2193unsafe extern "C" fn connRead(
2194 mut conn: *mut connection,
2195 mut buf: *mut libc::c_void,
2196 mut buf_len: size_t,
2197) -> libc::c_int {
2198 let mut ret: libc::c_int = ((*(*conn).type_0).read)
2199 .expect("non-null function pointer")(conn, buf, buf_len);
2200 return ret;
2201}
2202#[inline]
2203unsafe extern "C" fn connSetWriteHandler(
2204 mut conn: *mut connection,
2205 mut func: ConnectionCallbackFunc,
2206) -> libc::c_int {
2207 return ((*(*conn).type_0).set_write_handler)
2208 .expect("non-null function pointer")(conn, func, 0 as libc::c_int);
2209}
2210#[inline]
2211unsafe extern "C" fn connSetReadHandler(
2212 mut conn: *mut connection,
2213 mut func: ConnectionCallbackFunc,
2214) -> libc::c_int {
2215 return ((*(*conn).type_0).set_read_handler)
2216 .expect("non-null function pointer")(conn, func);
2217}
2218#[inline]
2219unsafe extern "C" fn connSetWriteHandlerWithBarrier(
2220 mut conn: *mut connection,
2221 mut func: ConnectionCallbackFunc,
2222 mut barrier: libc::c_int,
2223) -> libc::c_int {
2224 return ((*(*conn).type_0).set_write_handler)
2225 .expect("non-null function pointer")(conn, func, barrier);
2226}
2227#[inline]
2228unsafe extern "C" fn connClose(mut conn: *mut connection) {
2229 ((*(*conn).type_0).close).expect("non-null function pointer")(conn);
2230}
2231#[inline]
2232unsafe extern "C" fn connGetLastError(mut conn: *mut connection) -> *const libc::c_char {
2233 return ((*(*conn).type_0).get_last_error).expect("non-null function pointer")(conn);
2234}
2235#[inline]
2236unsafe extern "C" fn connSyncWrite(
2237 mut conn: *mut connection,
2238 mut ptr: *mut libc::c_char,
2239 mut size: ssize_t,
2240 mut timeout: libc::c_longlong,
2241) -> ssize_t {
2242 return ((*(*conn).type_0).sync_write)
2243 .expect("non-null function pointer")(conn, ptr, size, timeout);
2244}
2245#[inline]
2246unsafe extern "C" fn connSyncReadLine(
2247 mut conn: *mut connection,
2248 mut ptr: *mut libc::c_char,
2249 mut size: ssize_t,
2250 mut timeout: libc::c_longlong,
2251) -> ssize_t {
2252 return ((*(*conn).type_0).sync_readline)
2253 .expect("non-null function pointer")(conn, ptr, size, timeout);
2254}
2255#[inline]
2256unsafe extern "C" fn connGetType(mut conn: *mut connection) -> libc::c_int {
2257 return ((*(*conn).type_0).get_type).expect("non-null function pointer")(conn);
2258}
2259#[inline]
2260unsafe extern "C" fn atoi(mut __nptr: *const libc::c_char) -> libc::c_int {
2261 return strtol(
2262 __nptr,
2263 0 as *mut libc::c_void as *mut *mut libc::c_char,
2264 10 as libc::c_int,
2265 ) as libc::c_int;
2266}
2267#[inline]
2268unsafe extern "C" fn sdsalloc(s: sds) -> size_t {
2269 let mut flags: libc::c_uchar = *s.offset(-(1 as libc::c_int) as isize)
2270 as libc::c_uchar;
2271 match flags as libc::c_int & 7 as libc::c_int {
2272 0 => return (flags as libc::c_int >> 3 as libc::c_int) as size_t,
2273 1 => {
2274 return (*(s
2275 .offset(-(core::mem::size_of::<sdshdr8>() as libc::c_ulong as isize))
2276 as *mut sdshdr8))
2277 .alloc as size_t;
2278 }
2279 2 => {
2280 return (*(s
2281 .offset(-(core::mem::size_of::<sdshdr16>() as libc::c_ulong as isize))
2282 as *mut sdshdr16))
2283 .alloc as size_t;
2284 }
2285 3 => {
2286 return (*(s
2287 .offset(-(core::mem::size_of::<sdshdr32>() as libc::c_ulong as isize))
2288 as *mut sdshdr32))
2289 .alloc as size_t;
2290 }
2291 4 => {
2292 return (*(s
2293 .offset(-(core::mem::size_of::<sdshdr64>() as libc::c_ulong as isize))
2294 as *mut sdshdr64))
2295 .alloc;
2296 }
2297 _ => {}
2298 }
2299 return 0 as libc::c_int as size_t;
2300}
2301#[inline]
2302unsafe extern "C" fn sdsavail(s: sds) -> size_t {
2303 let mut flags: libc::c_uchar = *s.offset(-(1 as libc::c_int) as isize)
2304 as libc::c_uchar;
2305 match flags as libc::c_int & 7 as libc::c_int {
2306 0 => return 0 as libc::c_int as size_t,
2307 1 => {
2308 let mut sh: *mut sdshdr8 = s
2309 .offset(-(core::mem::size_of::<sdshdr8>() as libc::c_ulong as isize))
2310 as *mut libc::c_void as *mut sdshdr8;
2311 return ((*sh).alloc as libc::c_int - (*sh).len as libc::c_int) as size_t;
2312 }
2313 2 => {
2314 let mut sh_0: *mut sdshdr16 = s
2315 .offset(-(core::mem::size_of::<sdshdr16>() as libc::c_ulong as isize))
2316 as *mut libc::c_void as *mut sdshdr16;
2317 return ((*sh_0).alloc as libc::c_int - (*sh_0).len as libc::c_int) as size_t;
2318 }
2319 3 => {
2320 let mut sh_1: *mut sdshdr32 = s
2321 .offset(-(core::mem::size_of::<sdshdr32>() as libc::c_ulong as isize))
2322 as *mut libc::c_void as *mut sdshdr32;
2323 return ((*sh_1).alloc).wrapping_sub((*sh_1).len) as size_t;
2324 }
2325 4 => {
2326 let mut sh_2: *mut sdshdr64 = s
2327 .offset(-(core::mem::size_of::<sdshdr64>() as libc::c_ulong as isize))
2328 as *mut libc::c_void as *mut sdshdr64;
2329 return ((*sh_2).alloc).wrapping_sub((*sh_2).len);
2330 }
2331 _ => {}
2332 }
2333 return 0 as libc::c_int as size_t;
2334}
2335#[inline]
2336unsafe extern "C" fn sdslen(s: sds) -> size_t {
2337 let mut flags: libc::c_uchar = *s.offset(-(1 as libc::c_int) as isize)
2338 as libc::c_uchar;
2339 match flags as libc::c_int & 7 as libc::c_int {
2340 0 => return (flags as libc::c_int >> 3 as libc::c_int) as size_t,
2341 1 => {
2342 return (*(s
2343 .offset(-(core::mem::size_of::<sdshdr8>() as libc::c_ulong as isize))
2344 as *mut sdshdr8))
2345 .len as size_t;
2346 }
2347 2 => {
2348 return (*(s
2349 .offset(-(core::mem::size_of::<sdshdr16>() as libc::c_ulong as isize))
2350 as *mut sdshdr16))
2351 .len as size_t;
2352 }
2353 3 => {
2354 return (*(s
2355 .offset(-(core::mem::size_of::<sdshdr32>() as libc::c_ulong as isize))
2356 as *mut sdshdr32))
2357 .len as size_t;
2358 }
2359 4 => {
2360 return (*(s
2361 .offset(-(core::mem::size_of::<sdshdr64>() as libc::c_ulong as isize))
2362 as *mut sdshdr64))
2363 .len;
2364 }
2365 _ => {}
2366 }
2367 return 0 as libc::c_int as size_t;
2368}
2369#[inline]
2370unsafe extern "C" fn __bswap_32(mut __bsx: __uint32_t) -> __uint32_t {
2371 return (__bsx & 0xff000000 as libc::c_uint) >> 24 as libc::c_int
2372 | (__bsx & 0xff0000 as libc::c_uint) >> 8 as libc::c_int
2373 | (__bsx & 0xff00 as libc::c_uint) << 8 as libc::c_int
2374 | (__bsx & 0xff as libc::c_uint) << 24 as libc::c_int;
2375}
2376#[inline]
2377unsafe extern "C" fn __bswap_16(mut __bsx: __uint16_t) -> __uint16_t {
2378 return (__bsx as libc::c_int >> 8 as libc::c_int & 0xff as libc::c_int
2379 | (__bsx as libc::c_int & 0xff as libc::c_int) << 8 as libc::c_int)
2380 as __uint16_t;
2381}
2382#[inline]
2383unsafe extern "C" fn fstat(
2384 mut __fd: libc::c_int,
2385 mut __statbuf: *mut stat,
2386) -> libc::c_int {
2387 return __fxstat(0 as libc::c_int, __fd, __statbuf);
2388}
2389#[no_mangle]
2390pub static mut myself: *mut clusterNode = 0 as *const clusterNode as *mut clusterNode;
2391#[no_mangle]
2392pub static mut clusterNodesDictType: dictType = unsafe {
2393 {
2394 let mut init = dictType {
2395 hashFunction: Some(
2396 dictSdsHash as unsafe extern "C" fn(*const libc::c_void) -> uint64_t,
2397 ),
2398 keyDup: None,
2399 valDup: None,
2400 keyCompare: Some(
2401 dictSdsKeyCompare
2402 as unsafe extern "C" fn(
2403 *mut dict,
2404 *const libc::c_void,
2405 *const libc::c_void,
2406 ) -> libc::c_int,
2407 ),
2408 keyDestructor: Some(
2409 dictSdsDestructor
2410 as unsafe extern "C" fn(*mut dict, *mut libc::c_void) -> (),
2411 ),
2412 valDestructor: None,
2413 expandAllowed: None,
2414 dictEntryMetadataBytes: None,
2415 };
2416 init
2417 }
2418};
2419#[no_mangle]
2420pub static mut clusterNodesBlackListDictType: dictType = unsafe {
2421 {
2422 let mut init = dictType {
2423 hashFunction: Some(
2424 dictSdsCaseHash as unsafe extern "C" fn(*const libc::c_void) -> uint64_t,
2425 ),
2426 keyDup: None,
2427 valDup: None,
2428 keyCompare: Some(
2429 dictSdsKeyCaseCompare
2430 as unsafe extern "C" fn(
2431 *mut dict,
2432 *const libc::c_void,
2433 *const libc::c_void,
2434 ) -> libc::c_int,
2435 ),
2436 keyDestructor: Some(
2437 dictSdsDestructor
2438 as unsafe extern "C" fn(*mut dict, *mut libc::c_void) -> (),
2439 ),
2440 valDestructor: None,
2441 expandAllowed: None,
2442 dictEntryMetadataBytes: None,
2443 };
2444 init
2445 }
2446};
2447#[no_mangle]
2448pub unsafe extern "C" fn clusterLoadConfig(
2449 mut filename: *mut libc::c_char,
2450) -> libc::c_int {
2451 let mut current_block: u64;
2452 let mut fp: *mut FILE = fopen(filename, b"r\0" as *const u8 as *const libc::c_char);
2453 let mut sb: stat = stat {
2454 st_dev: 0,
2455 st_ino: 0,
2456 st_mode: 0,
2457 st_nlink: 0,
2458 st_uid: 0,
2459 st_gid: 0,
2460 st_rdev: 0,
2461 __pad1: 0,
2462 st_size: 0,
2463 st_blksize: 0,
2464 __pad2: 0,
2465 st_blocks: 0,
2466 st_atim: timespec { tv_sec: 0, tv_nsec: 0 },
2467 st_mtim: timespec { tv_sec: 0, tv_nsec: 0 },
2468 st_ctim: timespec { tv_sec: 0, tv_nsec: 0 },
2469 __glibc_reserved: [0; 2],
2470 };
2471 let mut line: *mut libc::c_char = 0 as *mut libc::c_char;
2472 let mut maxline: libc::c_int = 0;
2473 let mut j: libc::c_int = 0;
2474 if fp.is_null() {
2475 if *__errno_location() == 2 as libc::c_int {
2476 return -(1 as libc::c_int)
2477 } else {
2478 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
2479 _serverLog(
2480 3 as libc::c_int,
2481 b"Loading the cluster node config from %s: %s\0" as *const u8
2482 as *const libc::c_char,
2483 filename,
2484 strerror(*__errno_location()),
2485 );
2486 }
2487 exit(1 as libc::c_int);
2488 }
2489 }
2490 if fstat(fileno(fp), &mut sb) == -(1 as libc::c_int) {
2491 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
2492 _serverLog(
2493 3 as libc::c_int,
2494 b"Unable to obtain the cluster node config file stat %s: %s\0"
2495 as *const u8 as *const libc::c_char,
2496 filename,
2497 strerror(*__errno_location()),
2498 );
2499 }
2500 exit(1 as libc::c_int);
2501 }
2502 if sb.st_size == 0 as libc::c_int as libc::c_long {
2503 fclose(fp);
2504 return -(1 as libc::c_int);
2505 }
2506 maxline = 1024 as libc::c_int + 16384 as libc::c_int * 128 as libc::c_int;
2507 line = zmalloc(maxline as size_t) as *mut libc::c_char;
2508 's_95: loop {
2509 if (fgets(line, maxline, fp)).is_null() {
2510 current_block = 5431927413890720344;
2511 break;
2512 }
2513 let mut argc: libc::c_int = 0;
2514 let mut argv: *mut sds = 0 as *mut sds;
2515 let mut n: *mut clusterNode = 0 as *mut clusterNode;
2516 let mut master: *mut clusterNode = 0 as *mut clusterNode;
2517 let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
2518 let mut s: *mut libc::c_char = 0 as *mut libc::c_char;
2519 if *line.offset(0 as libc::c_int as isize) as libc::c_int == '\n' as i32
2520 || *line.offset(0 as libc::c_int as isize) as libc::c_int == '\0' as i32
2521 {
2522 continue;
2523 }
2524 argv = sdssplitargs(line, &mut argc);
2525 if argv.is_null() {
2526 current_block = 8085191762609820871;
2527 break;
2528 }
2529 if strcasecmp(
2530 *argv.offset(0 as libc::c_int as isize) as *const libc::c_char,
2531 b"vars\0" as *const u8 as *const libc::c_char,
2532 ) == 0 as libc::c_int
2533 {
2534 if argc % 2 as libc::c_int == 0 {
2535 current_block = 8085191762609820871;
2536 break;
2537 }
2538 j = 1 as libc::c_int;
2539 while j < argc {
2540 if strcasecmp(
2541 *argv.offset(j as isize) as *const libc::c_char,
2542 b"currentEpoch\0" as *const u8 as *const libc::c_char,
2543 ) == 0 as libc::c_int
2544 {
2545 (*server.cluster)
2546 .currentEpoch = strtoull(
2547 *argv.offset((j + 1 as libc::c_int) as isize)
2548 as *const libc::c_char,
2549 0 as *mut *mut libc::c_char,
2550 10 as libc::c_int,
2551 ) as uint64_t;
2552 } else if strcasecmp(
2553 *argv.offset(j as isize) as *const libc::c_char,
2554 b"lastVoteEpoch\0" as *const u8 as *const libc::c_char,
2555 ) == 0 as libc::c_int
2556 {
2557 (*server.cluster)
2558 .lastVoteEpoch = strtoull(
2559 *argv.offset((j + 1 as libc::c_int) as isize)
2560 as *const libc::c_char,
2561 0 as *mut *mut libc::c_char,
2562 10 as libc::c_int,
2563 ) as uint64_t;
2564 } else if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity)
2565 {
2566 _serverLog(
2567 3 as libc::c_int,
2568 b"Skipping unknown cluster config variable '%s'\0" as *const u8
2569 as *const libc::c_char,
2570 *argv.offset(j as isize),
2571 );
2572 }
2573 j += 2 as libc::c_int;
2574 }
2575 sdsfreesplitres(argv, argc);
2576 } else if argc < 8 as libc::c_int {
2577 sdsfreesplitres(argv, argc);
2578 current_block = 8085191762609820871;
2579 break;
2580 } else if verifyClusterNodeId(
2581 *argv.offset(0 as libc::c_int as isize) as *const libc::c_char,
2582 sdslen(*argv.offset(0 as libc::c_int as isize)) as libc::c_int,
2583 ) == -(1 as libc::c_int)
2584 {
2585 sdsfreesplitres(argv, argc);
2586 current_block = 8085191762609820871;
2587 break;
2588 } else {
2589 n = clusterLookupNode(
2590 *argv.offset(0 as libc::c_int as isize) as *const libc::c_char,
2591 sdslen(*argv.offset(0 as libc::c_int as isize)) as libc::c_int,
2592 );
2593 if n.is_null() {
2594 n = createClusterNode(
2595 *argv.offset(0 as libc::c_int as isize),
2596 0 as libc::c_int,
2597 );
2598 clusterAddNode(n);
2599 }
2600 let mut hostname: *mut libc::c_char = strchr(
2601 *argv.offset(1 as libc::c_int as isize) as *const libc::c_char,
2602 ',' as i32,
2603 );
2604 if !hostname.is_null() {
2605 *hostname = '\0' as i32 as libc::c_char;
2606 hostname = hostname.offset(1);
2607 (*n).hostname = sdscpy((*n).hostname, hostname);
2608 } else if sdslen((*n).hostname) != 0 as libc::c_int as libc::c_ulong {
2609 sdsclear((*n).hostname);
2610 }
2611 p = strrchr(
2612 *argv.offset(1 as libc::c_int as isize) as *const libc::c_char,
2613 ':' as i32,
2614 );
2615 if p.is_null() {
2616 sdsfreesplitres(argv, argc);
2617 current_block = 8085191762609820871;
2618 break;
2619 } else {
2620 *p = '\0' as i32 as libc::c_char;
2621 memcpy(
2622 ((*n).ip).as_mut_ptr() as *mut libc::c_void,
2623 *argv.offset(1 as libc::c_int as isize) as *const libc::c_void,
2624 (strlen(
2625 *argv.offset(1 as libc::c_int as isize) as *const libc::c_char,
2626 ))
2627 .wrapping_add(1 as libc::c_int as libc::c_ulong),
2628 );
2629 let mut port: *mut libc::c_char = p.offset(1 as libc::c_int as isize);
2630 let mut busp: *mut libc::c_char = strchr(port, '@' as i32);
2631 if !busp.is_null() {
2632 *busp = '\0' as i32 as libc::c_char;
2633 busp = busp.offset(1);
2634 }
2635 (*n).port = atoi(port);
2636 (*n)
2637 .cport = if !busp.is_null() {
2638 atoi(busp)
2639 } else {
2640 (*n).port + 10000 as libc::c_int
2641 };
2642 s = *argv.offset(2 as libc::c_int as isize);
2643 p = s;
2644 while !p.is_null() {
2645 p = strchr(s, ',' as i32);
2646 if !p.is_null() {
2647 *p = '\0' as i32 as libc::c_char;
2648 }
2649 if strcasecmp(s, b"myself\0" as *const u8 as *const libc::c_char)
2650 == 0
2651 {
2652 if ((*server.cluster).myself).is_null() {} else {
2653 _serverAssert(
2654 b"server.cluster->myself == NULL\0" as *const u8
2655 as *const libc::c_char,
2656 b"cluster.c\0" as *const u8 as *const libc::c_char,
2657 265 as libc::c_int,
2658 );
2659 unreachable!();
2660 };
2661 (*server.cluster).myself = n;
2662 myself = (*server.cluster).myself;
2663 (*n).flags |= 16 as libc::c_int;
2664 } else if strcasecmp(
2665 s,
2666 b"master\0" as *const u8 as *const libc::c_char,
2667 ) == 0
2668 {
2669 (*n).flags |= 1 as libc::c_int;
2670 } else if strcasecmp(
2671 s,
2672 b"slave\0" as *const u8 as *const libc::c_char,
2673 ) == 0
2674 {
2675 (*n).flags |= 2 as libc::c_int;
2676 } else if strcasecmp(
2677 s,
2678 b"fail?\0" as *const u8 as *const libc::c_char,
2679 ) == 0
2680 {
2681 (*n).flags |= 4 as libc::c_int;
2682 } else if strcasecmp(
2683 s,
2684 b"fail\0" as *const u8 as *const libc::c_char,
2685 ) == 0
2686 {
2687 (*n).flags |= 8 as libc::c_int;
2688 (*n).fail_time = mstime();
2689 } else if strcasecmp(
2690 s,
2691 b"handshake\0" as *const u8 as *const libc::c_char,
2692 ) == 0
2693 {
2694 (*n).flags |= 32 as libc::c_int;
2695 } else if strcasecmp(
2696 s,
2697 b"noaddr\0" as *const u8 as *const libc::c_char,
2698 ) == 0
2699 {
2700 (*n).flags |= 64 as libc::c_int;
2701 } else if strcasecmp(
2702 s,
2703 b"nofailover\0" as *const u8 as *const libc::c_char,
2704 ) == 0
2705 {
2706 (*n).flags |= 512 as libc::c_int;
2707 } else if !(strcasecmp(
2708 s,
2709 b"noflags\0" as *const u8 as *const libc::c_char,
2710 ) == 0)
2711 {
2712 _serverPanic(
2713 b"cluster.c\0" as *const u8 as *const libc::c_char,
2714 286 as libc::c_int,
2715 b"Unknown flag in redis cluster config file\0" as *const u8
2716 as *const libc::c_char,
2717 );
2718 unreachable!();
2719 }
2720 if !p.is_null() {
2721 s = p.offset(1 as libc::c_int as isize);
2722 }
2723 }
2724 if *(*argv.offset(3 as libc::c_int as isize))
2725 .offset(0 as libc::c_int as isize) as libc::c_int != '-' as i32
2726 {
2727 if verifyClusterNodeId(
2728 *argv.offset(3 as libc::c_int as isize) as *const libc::c_char,
2729 sdslen(*argv.offset(3 as libc::c_int as isize)) as libc::c_int,
2730 ) == -(1 as libc::c_int)
2731 {
2732 sdsfreesplitres(argv, argc);
2733 current_block = 8085191762609820871;
2734 break;
2735 } else {
2736 master = clusterLookupNode(
2737 *argv.offset(3 as libc::c_int as isize)
2738 as *const libc::c_char,
2739 sdslen(*argv.offset(3 as libc::c_int as isize))
2740 as libc::c_int,
2741 );
2742 if master.is_null() {
2743 master = createClusterNode(
2744 *argv.offset(3 as libc::c_int as isize),
2745 0 as libc::c_int,
2746 );
2747 clusterAddNode(master);
2748 }
2749 (*n).slaveof = master;
2750 clusterNodeAddSlave(master, n);
2751 }
2752 }
2753 if atoi(*argv.offset(4 as libc::c_int as isize) as *const libc::c_char)
2754 != 0
2755 {
2756 (*n).ping_sent = mstime();
2757 }
2758 if atoi(*argv.offset(5 as libc::c_int as isize) as *const libc::c_char)
2759 != 0
2760 {
2761 (*n).pong_received = mstime();
2762 }
2763 (*n)
2764 .configEpoch = (if (*n).flags & 2 as libc::c_int != 0
2765 && !((*n).slaveof).is_null()
2766 {
2767 0 as libc::c_int as libc::c_ulonglong
2768 } else {
2769 strtoull(
2770 *argv.offset(6 as libc::c_int as isize) as *const libc::c_char,
2771 0 as *mut *mut libc::c_char,
2772 10 as libc::c_int,
2773 )
2774 }) as uint64_t;
2775 j = 8 as libc::c_int;
2776 while j < argc {
2777 let mut start: libc::c_int = 0;
2778 let mut stop: libc::c_int = 0;
2779 if *(*argv.offset(j as isize)).offset(0 as libc::c_int as isize)
2780 as libc::c_int == '[' as i32
2781 {
2782 let mut slot: libc::c_int = 0;
2783 let mut direction: libc::c_char = 0;
2784 let mut cn: *mut clusterNode = 0 as *mut clusterNode;
2785 p = strchr(
2786 *argv.offset(j as isize) as *const libc::c_char,
2787 '-' as i32,
2788 );
2789 if !p.is_null() {} else {
2790 _serverAssert(
2791 b"p != NULL\0" as *const u8 as *const libc::c_char,
2792 b"cluster.c\0" as *const u8 as *const libc::c_char,
2793 327 as libc::c_int,
2794 );
2795 unreachable!();
2796 };
2797 *p = '\0' as i32 as libc::c_char;
2798 direction = *p.offset(1 as libc::c_int as isize);
2799 slot = atoi(
2800 (*argv.offset(j as isize)).offset(1 as libc::c_int as isize)
2801 as *const libc::c_char,
2802 );
2803 if slot < 0 as libc::c_int || slot >= 16384 as libc::c_int {
2804 sdsfreesplitres(argv, argc);
2805 current_block = 8085191762609820871;
2806 break 's_95;
2807 } else {
2808 p = p.offset(3 as libc::c_int as isize);
2809 let mut pr: *mut libc::c_char = strchr(p, ']' as i32);
2810 let mut node_len: size_t = pr.offset_from(p) as libc::c_long
2811 as size_t;
2812 if pr.is_null()
2813 || verifyClusterNodeId(p, node_len as libc::c_int)
2814 == -(1 as libc::c_int)
2815 {
2816 sdsfreesplitres(argv, argc);
2817 current_block = 8085191762609820871;
2818 break 's_95;
2819 } else {
2820 cn = clusterLookupNode(p, 40 as libc::c_int);
2821 if cn.is_null() {
2822 cn = createClusterNode(p, 0 as libc::c_int);
2823 clusterAddNode(cn);
2824 }
2825 if direction as libc::c_int == '>' as i32 {
2826 (*server.cluster).migrating_slots_to[slot as usize] = cn;
2827 } else {
2828 (*server.cluster).importing_slots_from[slot as usize] = cn;
2829 }
2830 }
2831 }
2832 } else {
2833 p = strchr(
2834 *argv.offset(j as isize) as *const libc::c_char,
2835 '-' as i32,
2836 );
2837 if !p.is_null() {
2838 *p = '\0' as i32 as libc::c_char;
2839 start = atoi(
2840 *argv.offset(j as isize) as *const libc::c_char,
2841 );
2842 stop = atoi(p.offset(1 as libc::c_int as isize));
2843 } else {
2844 stop = atoi(*argv.offset(j as isize) as *const libc::c_char);
2845 start = stop;
2846 }
2847 if start < 0 as libc::c_int || start >= 16384 as libc::c_int
2848 || stop < 0 as libc::c_int || stop >= 16384 as libc::c_int
2849 {
2850 sdsfreesplitres(argv, argc);
2851 current_block = 8085191762609820871;
2852 break 's_95;
2853 } else {
2854 while start <= stop {
2855 let fresh0 = start;
2856 start = start + 1;
2857 clusterAddSlot(n, fresh0);
2858 }
2859 }
2860 }
2861 j += 1;
2862 }
2863 sdsfreesplitres(argv, argc);
2864 }
2865 }
2866 }
2867 match current_block {
2868 5431927413890720344 => {
2869 if !((*server.cluster).myself).is_null() {
2870 zfree(line as *mut libc::c_void);
2871 fclose(fp);
2872 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
2873 _serverLog(
2874 2 as libc::c_int,
2875 b"Node configuration loaded, I'm %.40s\0" as *const u8
2876 as *const libc::c_char,
2877 ((*myself).name).as_mut_ptr(),
2878 );
2879 }
2880 if clusterGetMaxEpoch() > (*server.cluster).currentEpoch {
2881 (*server.cluster).currentEpoch = clusterGetMaxEpoch();
2882 }
2883 return 0 as libc::c_int;
2884 }
2885 }
2886 _ => {}
2887 }
2888 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
2889 _serverLog(
2890 3 as libc::c_int,
2891 b"Unrecoverable error: corrupted cluster config file.\0" as *const u8
2892 as *const libc::c_char,
2893 );
2894 }
2895 zfree(line as *mut libc::c_void);
2896 if !fp.is_null() {
2897 fclose(fp);
2898 }
2899 exit(1 as libc::c_int);
2900}
2901#[no_mangle]
2902pub unsafe extern "C" fn clusterSaveConfig(mut do_fsync: libc::c_int) -> libc::c_int {
2903 let mut current_block: u64;
2904 let mut ci: sds = 0 as *mut libc::c_char;
2905 let mut content_size: size_t = 0;
2906 let mut sb: stat = stat {
2907 st_dev: 0,
2908 st_ino: 0,
2909 st_mode: 0,
2910 st_nlink: 0,
2911 st_uid: 0,
2912 st_gid: 0,
2913 st_rdev: 0,
2914 __pad1: 0,
2915 st_size: 0,
2916 st_blksize: 0,
2917 __pad2: 0,
2918 st_blocks: 0,
2919 st_atim: timespec { tv_sec: 0, tv_nsec: 0 },
2920 st_mtim: timespec { tv_sec: 0, tv_nsec: 0 },
2921 st_ctim: timespec { tv_sec: 0, tv_nsec: 0 },
2922 __glibc_reserved: [0; 2],
2923 };
2924 let mut fd: libc::c_int = 0;
2925 (*server.cluster).todo_before_sleep &= !((1 as libc::c_int) << 2 as libc::c_int);
2926 ci = clusterGenNodesDescription(32 as libc::c_int, 0 as libc::c_int);
2927 ci = sdscatprintf(
2928 ci,
2929 b"vars currentEpoch %llu lastVoteEpoch %llu\n\0" as *const u8
2930 as *const libc::c_char,
2931 (*server.cluster).currentEpoch as libc::c_ulonglong,
2932 (*server.cluster).lastVoteEpoch as libc::c_ulonglong,
2933 );
2934 content_size = sdslen(ci);
2935 fd = open(
2936 server.cluster_configfile,
2937 0o1 as libc::c_int | 0o100 as libc::c_int,
2938 0o644 as libc::c_int,
2939 );
2940 if !(fd == -(1 as libc::c_int)) {
2941 if !(fstat(fd, &mut sb) == -(1 as libc::c_int)) {
2942 if sb.st_size > content_size as off_t {
2943 ci = sdsgrowzero(ci, sb.st_size as size_t);
2944 memset(
2945 ci.offset(content_size as isize) as *mut libc::c_void,
2946 '\n' as i32,
2947 (sb.st_size as libc::c_ulong).wrapping_sub(content_size),
2948 );
2949 }
2950 if !(write(fd, ci as *const libc::c_void, sdslen(ci))
2951 != sdslen(ci) as ssize_t)
2952 {
2953 if do_fsync != 0 {
2954 (*server.cluster).todo_before_sleep
2955 &= !((1 as libc::c_int) << 3 as libc::c_int);
2956 if fsync(fd) == -(1 as libc::c_int) {
2957 current_block = 4890479531577211101;
2958 } else {
2959 current_block = 2979737022853876585;
2960 }
2961 } else {
2962 current_block = 2979737022853876585;
2963 }
2964 match current_block {
2965 4890479531577211101 => {}
2966 _ => {
2967 content_size != sdslen(ci)
2968 && ftruncate(fd, content_size as __off64_t)
2969 == -(1 as libc::c_int);
2970 close(fd);
2971 sdsfree(ci);
2972 return 0 as libc::c_int;
2973 }
2974 }
2975 }
2976 }
2977 }
2978 if fd != -(1 as libc::c_int) {
2979 close(fd);
2980 }
2981 sdsfree(ci);
2982 return -(1 as libc::c_int);
2983}
2984#[no_mangle]
2985pub unsafe extern "C" fn clusterSaveConfigOrDie(mut do_fsync: libc::c_int) {
2986 if clusterSaveConfig(do_fsync) == -(1 as libc::c_int) {
2987 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
2988 _serverLog(
2989 3 as libc::c_int,
2990 b"Fatal: can't update cluster config file.\0" as *const u8
2991 as *const libc::c_char,
2992 );
2993 }
2994 exit(1 as libc::c_int);
2995 }
2996}
2997#[no_mangle]
2998pub unsafe extern "C" fn clusterLockConfig(
2999 mut filename: *mut libc::c_char,
3000) -> libc::c_int {
3001 let mut fd: libc::c_int = open(
3002 filename,
3003 0o1 as libc::c_int | 0o100 as libc::c_int | 0o2000000 as libc::c_int,
3004 0o644 as libc::c_int,
3005 );
3006 if fd == -(1 as libc::c_int) {
3007 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3008 _serverLog(
3009 3 as libc::c_int,
3010 b"Can't open %s in order to acquire a lock: %s\0" as *const u8
3011 as *const libc::c_char,
3012 filename,
3013 strerror(*__errno_location()),
3014 );
3015 }
3016 return -(1 as libc::c_int);
3017 }
3018 if flock(fd, 2 as libc::c_int | 4 as libc::c_int) == -(1 as libc::c_int) {
3019 if *__errno_location() == 11 as libc::c_int {
3020 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3021 _serverLog(
3022 3 as libc::c_int,
3023 b"Sorry, the cluster configuration file %s is already used by a different Redis Cluster node. Please make sure that different nodes use different cluster configuration files.\0"
3024 as *const u8 as *const libc::c_char,
3025 filename,
3026 );
3027 }
3028 } else if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3029 _serverLog(
3030 3 as libc::c_int,
3031 b"Impossible to lock %s: %s\0" as *const u8 as *const libc::c_char,
3032 filename,
3033 strerror(*__errno_location()),
3034 );
3035 }
3036 close(fd);
3037 return -(1 as libc::c_int);
3038 }
3039 server.cluster_config_file_lock_fd = fd;
3040 return 0 as libc::c_int;
3041}
3042#[no_mangle]
3043pub unsafe extern "C" fn deriveAnnouncedPorts(
3044 mut announced_port: *mut libc::c_int,
3045 mut announced_pport: *mut libc::c_int,
3046 mut announced_cport: *mut libc::c_int,
3047) {
3048 let mut port: libc::c_int = if server.tls_cluster != 0 {
3049 server.tls_port
3050 } else {
3051 server.port
3052 };
3053 *announced_port = port;
3054 *announced_pport = if server.tls_cluster != 0 {
3055 server.port
3056 } else {
3057 0 as libc::c_int
3058 };
3059 *announced_cport = if server.cluster_port != 0 {
3060 server.cluster_port
3061 } else {
3062 port + 10000 as libc::c_int
3063 };
3064 if server.tls_cluster != 0 && server.cluster_announce_tls_port != 0 {
3065 *announced_port = server.cluster_announce_tls_port;
3066 *announced_pport = server.cluster_announce_port;
3067 } else if server.cluster_announce_port != 0 {
3068 *announced_port = server.cluster_announce_port;
3069 }
3070 if server.cluster_announce_bus_port != 0 {
3071 *announced_cport = server.cluster_announce_bus_port;
3072 }
3073}
3074#[no_mangle]
3075pub unsafe extern "C" fn clusterUpdateMyselfFlags() {
3076 if myself.is_null() {
3077 return;
3078 }
3079 let mut oldflags: libc::c_int = (*myself).flags;
3080 let mut nofailover: libc::c_int = if server.cluster_slave_no_failover != 0 {
3081 512 as libc::c_int
3082 } else {
3083 0 as libc::c_int
3084 };
3085 (*myself).flags &= !(512 as libc::c_int);
3086 (*myself).flags |= nofailover;
3087 if (*myself).flags != oldflags {
3088 clusterDoBeforeSleep(
3089 (1 as libc::c_int) << 2 as libc::c_int
3090 | (1 as libc::c_int) << 1 as libc::c_int,
3091 );
3092 }
3093}
3094#[no_mangle]
3095pub unsafe extern "C" fn clusterUpdateMyselfAnnouncedPorts() {
3096 if myself.is_null() {
3097 return;
3098 }
3099 deriveAnnouncedPorts(
3100 &mut (*myself).port,
3101 &mut (*myself).pport,
3102 &mut (*myself).cport,
3103 );
3104}
3105#[no_mangle]
3106pub unsafe extern "C" fn clusterUpdateMyselfIp() {
3107 if myself.is_null() {
3108 return;
3109 }
3110 static mut prev_ip: *mut libc::c_char = 0 as *const libc::c_char
3111 as *mut libc::c_char;
3112 let mut curr_ip: *mut libc::c_char = server.cluster_announce_ip;
3113 let mut changed: libc::c_int = 0 as libc::c_int;
3114 if prev_ip.is_null() && !curr_ip.is_null() {
3115 changed = 1 as libc::c_int;
3116 } else if !prev_ip.is_null() && curr_ip.is_null() {
3117 changed = 1 as libc::c_int;
3118 } else if !prev_ip.is_null() && !curr_ip.is_null() && strcmp(prev_ip, curr_ip) != 0 {
3119 changed = 1 as libc::c_int;
3120 }
3121 if changed != 0 {
3122 if !prev_ip.is_null() {
3123 zfree(prev_ip as *mut libc::c_void);
3124 }
3125 prev_ip = curr_ip;
3126 if !curr_ip.is_null() {
3127 prev_ip = zstrdup(prev_ip);
3128 strncpy(
3129 ((*myself).ip).as_mut_ptr(),
3130 server.cluster_announce_ip,
3131 (46 as libc::c_int - 1 as libc::c_int) as libc::c_ulong,
3132 );
3133 (*myself)
3134 .ip[(46 as libc::c_int - 1 as libc::c_int)
3135 as usize] = '\0' as i32 as libc::c_char;
3136 } else {
3137 (*myself).ip[0 as libc::c_int as usize] = '\0' as i32 as libc::c_char;
3138 }
3139 }
3140}
3141unsafe extern "C" fn updateAnnouncedHostname(
3142 mut node: *mut clusterNode,
3143 mut new: *mut libc::c_char,
3144) {
3145 if !new.is_null() && strcmp(new, (*node).hostname as *const libc::c_char) == 0 {
3146 return;
3147 }
3148 if !new.is_null() {
3149 (*node).hostname = sdscpy((*node).hostname, new);
3150 } else if sdslen((*node).hostname) != 0 as libc::c_int as libc::c_ulong {
3151 sdsclear((*node).hostname);
3152 }
3153}
3154#[no_mangle]
3155pub unsafe extern "C" fn clusterUpdateMyselfHostname() {
3156 if myself.is_null() {
3157 return;
3158 }
3159 updateAnnouncedHostname(myself, server.cluster_announce_hostname);
3160}
3161#[no_mangle]
3162pub unsafe extern "C" fn clusterInit() {
3163 let mut saveconf: libc::c_int = 0 as libc::c_int;
3164 server
3165 .cluster = zmalloc(core::mem::size_of::<clusterState>() as libc::c_ulong)
3166 as *mut clusterState;
3167 (*server.cluster).myself = 0 as *mut clusterNode;
3168 (*server.cluster).currentEpoch = 0 as libc::c_int as uint64_t;
3169 (*server.cluster).state = 1 as libc::c_int;
3170 (*server.cluster).size = 1 as libc::c_int;
3171 (*server.cluster).todo_before_sleep = 0 as libc::c_int;
3172 (*server.cluster).nodes = dictCreate(&mut clusterNodesDictType);
3173 (*server.cluster).nodes_black_list = dictCreate(&mut clusterNodesBlackListDictType);
3174 (*server.cluster).failover_auth_time = 0 as libc::c_int as mstime_t;
3175 (*server.cluster).failover_auth_count = 0 as libc::c_int;
3176 (*server.cluster).failover_auth_rank = 0 as libc::c_int;
3177 (*server.cluster).failover_auth_epoch = 0 as libc::c_int as uint64_t;
3178 (*server.cluster).cant_failover_reason = 0 as libc::c_int;
3179 (*server.cluster).lastVoteEpoch = 0 as libc::c_int as uint64_t;
3180 let mut i: libc::c_int = 0 as libc::c_int;
3181 while i < 11 as libc::c_int {
3182 (*server.cluster)
3183 .stats_bus_messages_sent[i as usize] = 0 as libc::c_int as libc::c_longlong;
3184 (*server.cluster)
3185 .stats_bus_messages_received[i
3186 as usize] = 0 as libc::c_int as libc::c_longlong;
3187 i += 1;
3188 }
3189 (*server.cluster).stats_pfail_nodes = 0 as libc::c_int as libc::c_longlong;
3190 (*server.cluster)
3191 .stat_cluster_links_buffer_limit_exceeded = 0 as libc::c_int
3192 as libc::c_ulonglong;
3193 memset(
3194 ((*server.cluster).slots).as_mut_ptr() as *mut libc::c_void,
3195 0 as libc::c_int,
3196 core::mem::size_of::<[*mut clusterNode; 16384]>() as libc::c_ulong,
3197 );
3198 clusterCloseAllSlots();
3199 server.cluster_config_file_lock_fd = -(1 as libc::c_int);
3200 if clusterLockConfig(server.cluster_configfile) == -(1 as libc::c_int) {
3201 exit(1 as libc::c_int);
3202 }
3203 if clusterLoadConfig(server.cluster_configfile) == -(1 as libc::c_int) {
3204 (*server.cluster)
3205 .myself = createClusterNode(
3206 0 as *mut libc::c_char,
3207 16 as libc::c_int | 1 as libc::c_int,
3208 );
3209 myself = (*server.cluster).myself;
3210 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3211 _serverLog(
3212 2 as libc::c_int,
3213 b"No cluster configuration found, I'm %.40s\0" as *const u8
3214 as *const libc::c_char,
3215 ((*myself).name).as_mut_ptr(),
3216 );
3217 }
3218 clusterAddNode(myself);
3219 saveconf = 1 as libc::c_int;
3220 }
3221 if saveconf != 0 {
3222 clusterSaveConfigOrDie(1 as libc::c_int);
3223 }
3224 server.cfd.count = 0 as libc::c_int;
3225 let mut port: libc::c_int = if server.tls_cluster != 0 {
3226 server.tls_port
3227 } else {
3228 server.port
3229 };
3230 if server.cluster_port == 0 && port > 65535 as libc::c_int - 10000 as libc::c_int {
3231 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3232 _serverLog(
3233 3 as libc::c_int,
3234 b"Redis port number too high. Cluster communication port is 10,000 port numbers higher than your Redis port. Your Redis port number must be 55535 or less.\0"
3235 as *const u8 as *const libc::c_char,
3236 );
3237 }
3238 exit(1 as libc::c_int);
3239 }
3240 if server.bindaddr_count == 0 {
3241 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3242 _serverLog(
3243 3 as libc::c_int,
3244 b"No bind address is configured, but it is required for the Cluster bus.\0"
3245 as *const u8 as *const libc::c_char,
3246 );
3247 }
3248 exit(1 as libc::c_int);
3249 }
3250 let mut cport: libc::c_int = if server.cluster_port != 0 {
3251 server.cluster_port
3252 } else {
3253 port + 10000 as libc::c_int
3254 };
3255 if listenToPort(cport, &mut server.cfd) == -(1 as libc::c_int) {
3256 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3257 _serverLog(
3258 3 as libc::c_int,
3259 b"Failed listening on port %u (cluster), aborting.\0" as *const u8
3260 as *const libc::c_char,
3261 cport,
3262 );
3263 }
3264 exit(1 as libc::c_int);
3265 }
3266 if createSocketAcceptHandler(
3267 &mut server.cfd,
3268 Some(
3269 clusterAcceptHandler
3270 as unsafe extern "C" fn(
3271 *mut aeEventLoop,
3272 libc::c_int,
3273 *mut libc::c_void,
3274 libc::c_int,
3275 ) -> (),
3276 ),
3277 ) != 0 as libc::c_int
3278 {
3279 _serverPanic(
3280 b"cluster.c\0" as *const u8 as *const libc::c_char,
3281 691 as libc::c_int,
3282 b"Unrecoverable error creating Redis Cluster socket accept handler.\0"
3283 as *const u8 as *const libc::c_char,
3284 );
3285 unreachable!();
3286 }
3287 slotToKeyInit(server.db);
3288 (*server.cluster).slots_to_channels = raxNew();
3289 deriveAnnouncedPorts(
3290 &mut (*myself).port,
3291 &mut (*myself).pport,
3292 &mut (*myself).cport,
3293 );
3294 (*server.cluster).mf_end = 0 as libc::c_int as mstime_t;
3295 (*server.cluster).mf_slave = 0 as *mut clusterNode;
3296 resetManualFailover();
3297 clusterUpdateMyselfFlags();
3298 clusterUpdateMyselfIp();
3299 clusterUpdateMyselfHostname();
3300}
3301#[no_mangle]
3302pub unsafe extern "C" fn clusterReset(mut hard: libc::c_int) {
3303 let mut di: *mut dictIterator = 0 as *mut dictIterator;
3304 let mut de: *mut dictEntry = 0 as *mut dictEntry;
3305 let mut j: libc::c_int = 0;
3306 if (*myself).flags & 2 as libc::c_int != 0 {
3307 clusterSetNodeAsMaster(myself);
3308 replicationUnsetMaster();
3309 emptyData(-(1 as libc::c_int), 0 as libc::c_int, None);
3310 }
3311 clusterCloseAllSlots();
3312 resetManualFailover();
3313 j = 0 as libc::c_int;
3314 while j < 16384 as libc::c_int {
3315 clusterDelSlot(j);
3316 j += 1;
3317 }
3318 di = dictGetSafeIterator((*server.cluster).nodes);
3319 loop {
3320 de = dictNext(di);
3321 if de.is_null() {
3322 break;
3323 }
3324 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
3325 if node == myself {
3326 continue;
3327 }
3328 clusterDelNode(node);
3329 }
3330 dictReleaseIterator(di);
3331 if hard != 0 {
3332 let mut oldname: sds = 0 as *mut libc::c_char;
3333 (*server.cluster).currentEpoch = 0 as libc::c_int as uint64_t;
3334 (*server.cluster).lastVoteEpoch = 0 as libc::c_int as uint64_t;
3335 (*myself).configEpoch = 0 as libc::c_int as uint64_t;
3336 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3337 _serverLog(
3338 3 as libc::c_int,
3339 b"configEpoch set to 0 via CLUSTER RESET HARD\0" as *const u8
3340 as *const libc::c_char,
3341 );
3342 }
3343 oldname = sdsnewlen(
3344 ((*myself).name).as_mut_ptr() as *const libc::c_void,
3345 40 as libc::c_int as size_t,
3346 );
3347 dictDelete((*server.cluster).nodes, oldname as *const libc::c_void);
3348 sdsfree(oldname);
3349 getRandomHexChars(((*myself).name).as_mut_ptr(), 40 as libc::c_int as size_t);
3350 clusterAddNode(myself);
3351 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3352 _serverLog(
3353 2 as libc::c_int,
3354 b"Node hard reset, now I'm %.40s\0" as *const u8 as *const libc::c_char,
3355 ((*myself).name).as_mut_ptr(),
3356 );
3357 }
3358 }
3359 clusterDoBeforeSleep(
3360 (1 as libc::c_int) << 2 as libc::c_int | (1 as libc::c_int) << 1 as libc::c_int
3361 | (1 as libc::c_int) << 3 as libc::c_int,
3362 );
3363}
3364#[no_mangle]
3365pub unsafe extern "C" fn createClusterLink(
3366 mut node: *mut clusterNode,
3367) -> *mut clusterLink {
3368 let mut link: *mut clusterLink = zmalloc(
3369 core::mem::size_of::<clusterLink>() as libc::c_ulong,
3370 ) as *mut clusterLink;
3371 (*link).ctime = mstime();
3372 (*link).sndbuf = sdsempty();
3373 (*link).rcvbuf_alloc = 1024 as libc::c_int as size_t;
3374 (*link).rcvbuf = zmalloc((*link).rcvbuf_alloc) as *mut libc::c_char;
3375 (*link).rcvbuf_len = 0 as libc::c_int as size_t;
3376 (*link).conn = 0 as *mut connection;
3377 (*link).node = node;
3378 (*link)
3379 .inbound = (node == 0 as *mut libc::c_void as *mut clusterNode) as libc::c_int;
3380 if (*link).inbound == 0 {
3381 (*node).link = link;
3382 }
3383 return link;
3384}
3385#[no_mangle]
3386pub unsafe extern "C" fn freeClusterLink(mut link: *mut clusterLink) {
3387 if !((*link).conn).is_null() {
3388 connClose((*link).conn);
3389 (*link).conn = 0 as *mut connection;
3390 }
3391 sdsfree((*link).sndbuf);
3392 zfree((*link).rcvbuf as *mut libc::c_void);
3393 if !((*link).node).is_null() {
3394 if (*(*link).node).link == link {
3395 if (*link).inbound == 0 {} else {
3396 _serverAssert(
3397 b"!link->inbound\0" as *const u8 as *const libc::c_char,
3398 b"cluster.c\0" as *const u8 as *const libc::c_char,
3399 807 as libc::c_int,
3400 );
3401 unreachable!();
3402 };
3403 (*(*link).node).link = 0 as *mut clusterLink;
3404 } else if (*(*link).node).inbound_link == link {
3405 if (*link).inbound != 0 {} else {
3406 _serverAssert(
3407 b"link->inbound\0" as *const u8 as *const libc::c_char,
3408 b"cluster.c\0" as *const u8 as *const libc::c_char,
3409 810 as libc::c_int,
3410 );
3411 unreachable!();
3412 };
3413 (*(*link).node).inbound_link = 0 as *mut clusterLink;
3414 }
3415 }
3416 zfree(link as *mut libc::c_void);
3417}
3418#[no_mangle]
3419pub unsafe extern "C" fn setClusterNodeToInboundClusterLink(
3420 mut node: *mut clusterNode,
3421 mut link: *mut clusterLink,
3422) {
3423 if ((*link).node).is_null() {} else {
3424 _serverAssert(
3425 b"!link->node\0" as *const u8 as *const libc::c_char,
3426 b"cluster.c\0" as *const u8 as *const libc::c_char,
3427 818 as libc::c_int,
3428 );
3429 unreachable!();
3430 };
3431 if (*link).inbound != 0 {} else {
3432 _serverAssert(
3433 b"link->inbound\0" as *const u8 as *const libc::c_char,
3434 b"cluster.c\0" as *const u8 as *const libc::c_char,
3435 819 as libc::c_int,
3436 );
3437 unreachable!();
3438 };
3439 if !((*node).inbound_link).is_null() {
3440 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3441 _serverLog(
3442 0 as libc::c_int,
3443 b"Replacing inbound link fd %d from node %.40s with fd %d\0" as *const u8
3444 as *const libc::c_char,
3445 (*(*(*node).inbound_link).conn).fd,
3446 ((*node).name).as_mut_ptr(),
3447 (*(*link).conn).fd,
3448 );
3449 }
3450 freeClusterLink((*node).inbound_link);
3451 }
3452 if ((*node).inbound_link).is_null() {} else {
3453 _serverAssert(
3454 b"!node->inbound_link\0" as *const u8 as *const libc::c_char,
3455 b"cluster.c\0" as *const u8 as *const libc::c_char,
3456 832 as libc::c_int,
3457 );
3458 unreachable!();
3459 };
3460 (*node).inbound_link = link;
3461 (*link).node = node;
3462}
3463unsafe extern "C" fn clusterConnAcceptHandler(mut conn: *mut connection) {
3464 let mut link: *mut clusterLink = 0 as *mut clusterLink;
3465 if connGetState(conn) != CONN_STATE_CONNECTED as libc::c_int {
3466 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3467 _serverLog(
3468 1 as libc::c_int,
3469 b"Error accepting cluster node connection: %s\0" as *const u8
3470 as *const libc::c_char,
3471 connGetLastError(conn),
3472 );
3473 }
3474 connClose(conn);
3475 return;
3476 }
3477 link = createClusterLink(0 as *mut clusterNode);
3478 (*link).conn = conn;
3479 connSetPrivateData(conn, link as *mut libc::c_void);
3480 connSetReadHandler(
3481 conn,
3482 Some(clusterReadHandler as unsafe extern "C" fn(*mut connection) -> ()),
3483 );
3484}
3485#[no_mangle]
3486pub unsafe extern "C" fn clusterAcceptHandler(
3487 mut el: *mut aeEventLoop,
3488 mut fd: libc::c_int,
3489 mut privdata: *mut libc::c_void,
3490 mut mask: libc::c_int,
3491) {
3492 let mut cport: libc::c_int = 0;
3493 let mut cfd: libc::c_int = 0;
3494 let mut max: libc::c_int = 1000 as libc::c_int;
3495 let mut cip: [libc::c_char; 46] = [0; 46];
3496 if (server.masterhost).is_null() && server.loading != 0 {
3497 return;
3498 }
3499 loop {
3500 let fresh1 = max;
3501 max = max - 1;
3502 if !(fresh1 != 0) {
3503 break;
3504 }
3505 cfd = anetTcpAccept(
3506 (server.neterr).as_mut_ptr(),
3507 fd,
3508 cip.as_mut_ptr(),
3509 core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
3510 &mut cport,
3511 );
3512 if cfd == -(1 as libc::c_int) {
3513 if *__errno_location() != 11 as libc::c_int {
3514 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3515 _serverLog(
3516 1 as libc::c_int,
3517 b"Error accepting cluster node: %s\0" as *const u8
3518 as *const libc::c_char,
3519 (server.neterr).as_mut_ptr(),
3520 );
3521 }
3522 }
3523 return;
3524 }
3525 let mut conn: *mut connection = if server.tls_cluster != 0 {
3526 connCreateAcceptedTLS(cfd, 1 as libc::c_int)
3527 } else {
3528 connCreateAcceptedSocket(cfd)
3529 };
3530 if connGetState(conn) != CONN_STATE_ACCEPTING as libc::c_int {
3531 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3532 _serverLog(
3533 1 as libc::c_int,
3534 b"Error creating an accepting connection for cluster node: %s\0"
3535 as *const u8 as *const libc::c_char,
3536 connGetLastError(conn),
3537 );
3538 }
3539 connClose(conn);
3540 return;
3541 }
3542 connEnableTcpNoDelay(conn);
3543 connKeepAlive(
3544 conn,
3545 (server.cluster_node_timeout * 2 as libc::c_int as libc::c_longlong)
3546 as libc::c_int,
3547 );
3548 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3549 _serverLog(
3550 1 as libc::c_int,
3551 b"Accepting cluster node connection from %s:%d\0" as *const u8
3552 as *const libc::c_char,
3553 cip.as_mut_ptr(),
3554 cport,
3555 );
3556 }
3557 if connAccept(
3558 conn,
3559 Some(clusterConnAcceptHandler as unsafe extern "C" fn(*mut connection) -> ()),
3560 ) == -(1 as libc::c_int)
3561 {
3562 if connGetState(conn) == CONN_STATE_ERROR as libc::c_int {
3563 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
3564 _serverLog(
3565 1 as libc::c_int,
3566 b"Error accepting cluster node connection: %s\0" as *const u8
3567 as *const libc::c_char,
3568 connGetLastError(conn),
3569 );
3570 }
3571 }
3572 connClose(conn);
3573 return;
3574 }
3575 };
3576}
3577#[no_mangle]
3578pub unsafe extern "C" fn getClusterConnectionsCount() -> libc::c_ulong {
3579 return if server.cluster_enabled != 0 {
3580 ((*(*server.cluster).nodes).ht_used[0 as libc::c_int as usize])
3581 .wrapping_add((*(*server.cluster).nodes).ht_used[1 as libc::c_int as usize])
3582 .wrapping_sub(1 as libc::c_int as libc::c_ulong)
3583 .wrapping_mul(2 as libc::c_int as libc::c_ulong)
3584 } else {
3585 0 as libc::c_int as libc::c_ulong
3586 };
3587}
3588#[no_mangle]
3589pub unsafe extern "C" fn keyHashSlot(
3590 mut key: *mut libc::c_char,
3591 mut keylen: libc::c_int,
3592) -> libc::c_uint {
3593 let mut s: libc::c_int = 0;
3594 let mut e: libc::c_int = 0;
3595 s = 0 as libc::c_int;
3596 while s < keylen {
3597 if *key.offset(s as isize) as libc::c_int == '{' as i32 {
3598 break;
3599 }
3600 s += 1;
3601 }
3602 if s == keylen {
3603 return (crc16(key, keylen) as libc::c_int & 0x3fff as libc::c_int)
3604 as libc::c_uint;
3605 }
3606 e = s + 1 as libc::c_int;
3607 while e < keylen {
3608 if *key.offset(e as isize) as libc::c_int == '}' as i32 {
3609 break;
3610 }
3611 e += 1;
3612 }
3613 if e == keylen || e == s + 1 as libc::c_int {
3614 return (crc16(key, keylen) as libc::c_int & 0x3fff as libc::c_int)
3615 as libc::c_uint;
3616 }
3617 return (crc16(
3618 key.offset(s as isize).offset(1 as libc::c_int as isize),
3619 e - s - 1 as libc::c_int,
3620 ) as libc::c_int & 0x3fff as libc::c_int) as libc::c_uint;
3621}
3622#[no_mangle]
3623pub unsafe extern "C" fn createClusterNode(
3624 mut nodename: *mut libc::c_char,
3625 mut flags: libc::c_int,
3626) -> *mut clusterNode {
3627 let mut node: *mut clusterNode = zmalloc(
3628 core::mem::size_of::<clusterNode>() as libc::c_ulong,
3629 ) as *mut clusterNode;
3630 if !nodename.is_null() {
3631 memcpy(
3632 ((*node).name).as_mut_ptr() as *mut libc::c_void,
3633 nodename as *const libc::c_void,
3634 40 as libc::c_int as libc::c_ulong,
3635 );
3636 } else {
3637 getRandomHexChars(((*node).name).as_mut_ptr(), 40 as libc::c_int as size_t);
3638 }
3639 (*node).ctime = mstime();
3640 (*node).configEpoch = 0 as libc::c_int as uint64_t;
3641 (*node).flags = flags;
3642 memset(
3643 ((*node).slots).as_mut_ptr() as *mut libc::c_void,
3644 0 as libc::c_int,
3645 core::mem::size_of::<[libc::c_uchar; 2048]>() as libc::c_ulong,
3646 );
3647 (*node).slot_info_pairs = 0 as *mut uint16_t;
3648 (*node).slot_info_pairs_count = 0 as libc::c_int;
3649 (*node).numslots = 0 as libc::c_int;
3650 (*node).numslaves = 0 as libc::c_int;
3651 (*node).slaves = 0 as *mut *mut clusterNode;
3652 (*node).slaveof = 0 as *mut clusterNode;
3653 (*node).last_in_ping_gossip = 0 as libc::c_int as libc::c_ulonglong;
3654 (*node).pong_received = 0 as libc::c_int as mstime_t;
3655 (*node).ping_sent = (*node).pong_received;
3656 (*node).data_received = 0 as libc::c_int as mstime_t;
3657 (*node).fail_time = 0 as libc::c_int as mstime_t;
3658 (*node).link = 0 as *mut clusterLink;
3659 (*node).inbound_link = 0 as *mut clusterLink;
3660 memset(
3661 ((*node).ip).as_mut_ptr() as *mut libc::c_void,
3662 0 as libc::c_int,
3663 core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
3664 );
3665 (*node).hostname = sdsempty();
3666 (*node).port = 0 as libc::c_int;
3667 (*node).cport = 0 as libc::c_int;
3668 (*node).pport = 0 as libc::c_int;
3669 (*node).fail_reports = listCreate();
3670 (*node).voted_time = 0 as libc::c_int as mstime_t;
3671 (*node).orphaned_time = 0 as libc::c_int as mstime_t;
3672 (*node).repl_offset_time = 0 as libc::c_int as mstime_t;
3673 (*node).repl_offset = 0 as libc::c_int as libc::c_longlong;
3674 (*(*node).fail_reports)
3675 .free = Some(zfree as unsafe extern "C" fn(*mut libc::c_void) -> ());
3676 return node;
3677}
3678#[no_mangle]
3679pub unsafe extern "C" fn clusterNodeAddFailureReport(
3680 mut failing: *mut clusterNode,
3681 mut sender: *mut clusterNode,
3682) -> libc::c_int {
3683 let mut l: *mut list = (*failing).fail_reports;
3684 let mut ln: *mut listNode = 0 as *mut listNode;
3685 let mut li: listIter = listIter {
3686 next: 0 as *mut listNode,
3687 direction: 0,
3688 };
3689 let mut fr: *mut clusterNodeFailReport = 0 as *mut clusterNodeFailReport;
3690 listRewind(l, &mut li);
3691 loop {
3692 ln = listNext(&mut li);
3693 if ln.is_null() {
3694 break;
3695 }
3696 fr = (*ln).value as *mut clusterNodeFailReport;
3697 if (*fr).node == sender {
3698 (*fr).time = mstime();
3699 return 0 as libc::c_int;
3700 }
3701 }
3702 fr = zmalloc(core::mem::size_of::<clusterNodeFailReport>() as libc::c_ulong)
3703 as *mut clusterNodeFailReport;
3704 (*fr).node = sender;
3705 (*fr).time = mstime();
3706 listAddNodeTail(l, fr as *mut libc::c_void);
3707 return 1 as libc::c_int;
3708}
3709#[no_mangle]
3710pub unsafe extern "C" fn clusterNodeCleanupFailureReports(mut node: *mut clusterNode) {
3711 let mut l: *mut list = (*node).fail_reports;
3712 let mut ln: *mut listNode = 0 as *mut listNode;
3713 let mut li: listIter = listIter {
3714 next: 0 as *mut listNode,
3715 direction: 0,
3716 };
3717 let mut fr: *mut clusterNodeFailReport = 0 as *mut clusterNodeFailReport;
3718 let mut maxtime: mstime_t = server.cluster_node_timeout
3719 * 2 as libc::c_int as libc::c_longlong;
3720 let mut now: mstime_t = mstime();
3721 listRewind(l, &mut li);
3722 loop {
3723 ln = listNext(&mut li);
3724 if ln.is_null() {
3725 break;
3726 }
3727 fr = (*ln).value as *mut clusterNodeFailReport;
3728 if now - (*fr).time > maxtime {
3729 listDelNode(l, ln);
3730 }
3731 };
3732}
3733#[no_mangle]
3734pub unsafe extern "C" fn clusterNodeDelFailureReport(
3735 mut node: *mut clusterNode,
3736 mut sender: *mut clusterNode,
3737) -> libc::c_int {
3738 let mut l: *mut list = (*node).fail_reports;
3739 let mut ln: *mut listNode = 0 as *mut listNode;
3740 let mut li: listIter = listIter {
3741 next: 0 as *mut listNode,
3742 direction: 0,
3743 };
3744 let mut fr: *mut clusterNodeFailReport = 0 as *mut clusterNodeFailReport;
3745 listRewind(l, &mut li);
3746 loop {
3747 ln = listNext(&mut li);
3748 if ln.is_null() {
3749 break;
3750 }
3751 fr = (*ln).value as *mut clusterNodeFailReport;
3752 if (*fr).node == sender {
3753 break;
3754 }
3755 }
3756 if ln.is_null() {
3757 return 0 as libc::c_int;
3758 }
3759 listDelNode(l, ln);
3760 clusterNodeCleanupFailureReports(node);
3761 return 1 as libc::c_int;
3762}
3763#[no_mangle]
3764pub unsafe extern "C" fn clusterNodeFailureReportsCount(
3765 mut node: *mut clusterNode,
3766) -> libc::c_int {
3767 clusterNodeCleanupFailureReports(node);
3768 return (*(*node).fail_reports).len as libc::c_int;
3769}
3770#[no_mangle]
3771pub unsafe extern "C" fn clusterNodeRemoveSlave(
3772 mut master: *mut clusterNode,
3773 mut slave: *mut clusterNode,
3774) -> libc::c_int {
3775 let mut j: libc::c_int = 0;
3776 j = 0 as libc::c_int;
3777 while j < (*master).numslaves {
3778 if *((*master).slaves).offset(j as isize) == slave {
3779 if (j + 1 as libc::c_int) < (*master).numslaves {
3780 let mut remaining_slaves: libc::c_int = (*master).numslaves - j
3781 - 1 as libc::c_int;
3782 memmove(
3783 ((*master).slaves).offset(j as isize) as *mut libc::c_void,
3784 ((*master).slaves).offset((j + 1 as libc::c_int) as isize)
3785 as *const libc::c_void,
3786 (core::mem::size_of::<*mut clusterNode>() as libc::c_ulong)
3787 .wrapping_mul(remaining_slaves as libc::c_ulong),
3788 );
3789 }
3790 (*master).numslaves -= 1;
3791 if (*master).numslaves == 0 as libc::c_int {
3792 (*master).flags &= !(256 as libc::c_int);
3793 }
3794 return 0 as libc::c_int;
3795 }
3796 j += 1;
3797 }
3798 return -(1 as libc::c_int);
3799}
3800#[no_mangle]
3801pub unsafe extern "C" fn clusterNodeAddSlave(
3802 mut master: *mut clusterNode,
3803 mut slave: *mut clusterNode,
3804) -> libc::c_int {
3805 let mut j: libc::c_int = 0;
3806 j = 0 as libc::c_int;
3807 while j < (*master).numslaves {
3808 if *((*master).slaves).offset(j as isize) == slave {
3809 return -(1 as libc::c_int);
3810 }
3811 j += 1;
3812 }
3813 (*master)
3814 .slaves = zrealloc(
3815 (*master).slaves as *mut libc::c_void,
3816 (core::mem::size_of::<*mut clusterNode>() as libc::c_ulong)
3817 .wrapping_mul(((*master).numslaves + 1 as libc::c_int) as libc::c_ulong),
3818 ) as *mut *mut clusterNode;
3819 let ref mut fresh2 = *((*master).slaves).offset((*master).numslaves as isize);
3820 *fresh2 = slave;
3821 (*master).numslaves += 1;
3822 (*master).flags |= 256 as libc::c_int;
3823 return 0 as libc::c_int;
3824}
3825#[no_mangle]
3826pub unsafe extern "C" fn clusterCountNonFailingSlaves(
3827 mut n: *mut clusterNode,
3828) -> libc::c_int {
3829 let mut j: libc::c_int = 0;
3830 let mut okslaves: libc::c_int = 0 as libc::c_int;
3831 j = 0 as libc::c_int;
3832 while j < (*n).numslaves {
3833 if (**((*n).slaves).offset(j as isize)).flags & 8 as libc::c_int == 0 {
3834 okslaves += 1;
3835 }
3836 j += 1;
3837 }
3838 return okslaves;
3839}
3840#[no_mangle]
3841pub unsafe extern "C" fn freeClusterNode(mut n: *mut clusterNode) {
3842 let mut nodename: sds = 0 as *mut libc::c_char;
3843 let mut j: libc::c_int = 0;
3844 j = 0 as libc::c_int;
3845 while j < (*n).numslaves {
3846 let ref mut fresh3 = (**((*n).slaves).offset(j as isize)).slaveof;
3847 *fresh3 = 0 as *mut clusterNode;
3848 j += 1;
3849 }
3850 if (*n).flags & 2 as libc::c_int != 0 && !((*n).slaveof).is_null() {
3851 clusterNodeRemoveSlave((*n).slaveof, n);
3852 }
3853 nodename = sdsnewlen(
3854 ((*n).name).as_mut_ptr() as *const libc::c_void,
3855 40 as libc::c_int as size_t,
3856 );
3857 if dictDelete((*server.cluster).nodes, nodename as *const libc::c_void)
3858 == 0 as libc::c_int
3859 {} else {
3860 _serverAssert(
3861 b"dictDelete(server.cluster->nodes,nodename) == DICT_OK\0" as *const u8
3862 as *const libc::c_char,
3863 b"cluster.c\0" as *const u8 as *const libc::c_char,
3864 1153 as libc::c_int,
3865 );
3866 unreachable!();
3867 };
3868 sdsfree(nodename);
3869 sdsfree((*n).hostname);
3870 if !((*n).link).is_null() {
3871 freeClusterLink((*n).link);
3872 }
3873 if !((*n).inbound_link).is_null() {
3874 freeClusterLink((*n).inbound_link);
3875 }
3876 listRelease((*n).fail_reports);
3877 zfree((*n).slaves as *mut libc::c_void);
3878 zfree(n as *mut libc::c_void);
3879}
3880#[no_mangle]
3881pub unsafe extern "C" fn clusterAddNode(mut node: *mut clusterNode) {
3882 let mut retval: libc::c_int = 0;
3883 retval = dictAdd(
3884 (*server.cluster).nodes,
3885 sdsnewlen(
3886 ((*node).name).as_mut_ptr() as *const libc::c_void,
3887 40 as libc::c_int as size_t,
3888 ) as *mut libc::c_void,
3889 node as *mut libc::c_void,
3890 );
3891 if retval == 0 as libc::c_int {} else {
3892 _serverAssert(
3893 b"retval == DICT_OK\0" as *const u8 as *const libc::c_char,
3894 b"cluster.c\0" as *const u8 as *const libc::c_char,
3895 1171 as libc::c_int,
3896 );
3897 unreachable!();
3898 };
3899}
3900#[no_mangle]
3901pub unsafe extern "C" fn clusterDelNode(mut delnode: *mut clusterNode) {
3902 let mut j: libc::c_int = 0;
3903 let mut di: *mut dictIterator = 0 as *mut dictIterator;
3904 let mut de: *mut dictEntry = 0 as *mut dictEntry;
3905 j = 0 as libc::c_int;
3906 while j < 16384 as libc::c_int {
3907 if (*server.cluster).importing_slots_from[j as usize] == delnode {
3908 (*server.cluster).importing_slots_from[j as usize] = 0 as *mut clusterNode;
3909 }
3910 if (*server.cluster).migrating_slots_to[j as usize] == delnode {
3911 (*server.cluster).migrating_slots_to[j as usize] = 0 as *mut clusterNode;
3912 }
3913 if (*server.cluster).slots[j as usize] == delnode {
3914 clusterDelSlot(j);
3915 }
3916 j += 1;
3917 }
3918 di = dictGetSafeIterator((*server.cluster).nodes);
3919 loop {
3920 de = dictNext(di);
3921 if de.is_null() {
3922 break;
3923 }
3924 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
3925 if node == delnode {
3926 continue;
3927 }
3928 clusterNodeDelFailureReport(node, delnode);
3929 }
3930 dictReleaseIterator(di);
3931 freeClusterNode(delnode);
3932}
3933#[no_mangle]
3934pub unsafe extern "C" fn verifyClusterNodeId(
3935 mut name: *const libc::c_char,
3936 mut length: libc::c_int,
3937) -> libc::c_int {
3938 if length != 40 as libc::c_int {
3939 return -(1 as libc::c_int);
3940 }
3941 let mut i: libc::c_int = 0 as libc::c_int;
3942 while i < length {
3943 if !(*name.offset(i as isize) as libc::c_int >= 'a' as i32
3944 && *name.offset(i as isize) as libc::c_int <= 'z' as i32)
3945 {
3946 if !(*name.offset(i as isize) as libc::c_int >= '0' as i32
3947 && *name.offset(i as isize) as libc::c_int <= '9' as i32)
3948 {
3949 return -(1 as libc::c_int);
3950 }
3951 }
3952 i += 1;
3953 }
3954 return 0 as libc::c_int;
3955}
3956#[no_mangle]
3957pub unsafe extern "C" fn clusterLookupNode(
3958 mut name: *const libc::c_char,
3959 mut length: libc::c_int,
3960) -> *mut clusterNode {
3961 if verifyClusterNodeId(name, length) != 0 as libc::c_int {
3962 return 0 as *mut clusterNode;
3963 }
3964 let mut s: sds = sdsnewlen(name as *const libc::c_void, length as size_t);
3965 let mut de: *mut dictEntry = dictFind(
3966 (*server.cluster).nodes,
3967 s as *const libc::c_void,
3968 );
3969 sdsfree(s);
3970 if de.is_null() {
3971 return 0 as *mut clusterNode;
3972 }
3973 return (*de).v.val as *mut clusterNode;
3974}
3975#[no_mangle]
3976pub unsafe extern "C" fn clusterGetNodesServingMySlots(
3977 mut node: *mut clusterNode,
3978) -> *mut list {
3979 let mut nodes_for_slot: *mut list = listCreate();
3980 let mut my_primary: *mut clusterNode = if (*node).flags & 1 as libc::c_int != 0 {
3981 node
3982 } else {
3983 (*node).slaveof
3984 };
3985 if !my_primary.is_null() {} else {
3986 _serverAssert(
3987 b"my_primary\0" as *const u8 as *const libc::c_char,
3988 b"cluster.c\0" as *const u8 as *const libc::c_char,
3989 1243 as libc::c_int,
3990 );
3991 unreachable!();
3992 };
3993 listAddNodeTail(nodes_for_slot, my_primary as *mut libc::c_void);
3994 let mut i: libc::c_int = 0 as libc::c_int;
3995 while i < (*my_primary).numslaves {
3996 listAddNodeTail(
3997 nodes_for_slot,
3998 *((*my_primary).slaves).offset(i as isize) as *mut libc::c_void,
3999 );
4000 i += 1;
4001 }
4002 return nodes_for_slot;
4003}
4004#[no_mangle]
4005pub unsafe extern "C" fn clusterRenameNode(
4006 mut node: *mut clusterNode,
4007 mut newname: *mut libc::c_char,
4008) {
4009 let mut retval: libc::c_int = 0;
4010 let mut s: sds = sdsnewlen(
4011 ((*node).name).as_mut_ptr() as *const libc::c_void,
4012 40 as libc::c_int as size_t,
4013 );
4014 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4015 _serverLog(
4016 0 as libc::c_int,
4017 b"Renaming node %.40s into %.40s\0" as *const u8 as *const libc::c_char,
4018 ((*node).name).as_mut_ptr(),
4019 newname,
4020 );
4021 }
4022 retval = dictDelete((*server.cluster).nodes, s as *const libc::c_void);
4023 sdsfree(s);
4024 if retval == 0 as libc::c_int {} else {
4025 _serverAssert(
4026 b"retval == DICT_OK\0" as *const u8 as *const libc::c_char,
4027 b"cluster.c\0" as *const u8 as *const libc::c_char,
4028 1263 as libc::c_int,
4029 );
4030 unreachable!();
4031 };
4032 memcpy(
4033 ((*node).name).as_mut_ptr() as *mut libc::c_void,
4034 newname as *const libc::c_void,
4035 40 as libc::c_int as libc::c_ulong,
4036 );
4037 clusterAddNode(node);
4038}
4039#[no_mangle]
4040pub unsafe extern "C" fn clusterGetMaxEpoch() -> uint64_t {
4041 let mut max: uint64_t = 0 as libc::c_int as uint64_t;
4042 let mut di: *mut dictIterator = 0 as *mut dictIterator;
4043 let mut de: *mut dictEntry = 0 as *mut dictEntry;
4044 di = dictGetSafeIterator((*server.cluster).nodes);
4045 loop {
4046 de = dictNext(di);
4047 if de.is_null() {
4048 break;
4049 }
4050 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
4051 if (*node).configEpoch > max {
4052 max = (*node).configEpoch;
4053 }
4054 }
4055 dictReleaseIterator(di);
4056 if max < (*server.cluster).currentEpoch {
4057 max = (*server.cluster).currentEpoch;
4058 }
4059 return max;
4060}
4061#[no_mangle]
4062pub unsafe extern "C" fn clusterBumpConfigEpochWithoutConsensus() -> libc::c_int {
4063 let mut maxEpoch: uint64_t = clusterGetMaxEpoch();
4064 if (*myself).configEpoch == 0 as libc::c_int as libc::c_ulong
4065 || (*myself).configEpoch != maxEpoch
4066 {
4067 (*server.cluster)
4068 .currentEpoch = ((*server.cluster).currentEpoch).wrapping_add(1);
4069 (*myself).configEpoch = (*server.cluster).currentEpoch;
4070 clusterDoBeforeSleep(
4071 (1 as libc::c_int) << 2 as libc::c_int
4072 | (1 as libc::c_int) << 3 as libc::c_int,
4073 );
4074 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4075 _serverLog(
4076 3 as libc::c_int,
4077 b"New configEpoch set to %llu\0" as *const u8 as *const libc::c_char,
4078 (*myself).configEpoch as libc::c_ulonglong,
4079 );
4080 }
4081 return 0 as libc::c_int;
4082 } else {
4083 return -(1 as libc::c_int)
4084 };
4085}
4086#[no_mangle]
4087pub unsafe extern "C" fn clusterHandleConfigEpochCollision(
4088 mut sender: *mut clusterNode,
4089) {
4090 if (*sender).configEpoch != (*myself).configEpoch
4091 || (*sender).flags & 1 as libc::c_int == 0
4092 || (*myself).flags & 1 as libc::c_int == 0
4093 {
4094 return;
4095 }
4096 if memcmp(
4097 ((*sender).name).as_mut_ptr() as *const libc::c_void,
4098 ((*myself).name).as_mut_ptr() as *const libc::c_void,
4099 40 as libc::c_int as libc::c_ulong,
4100 ) <= 0 as libc::c_int
4101 {
4102 return;
4103 }
4104 (*server.cluster).currentEpoch = ((*server.cluster).currentEpoch).wrapping_add(1);
4105 (*myself).configEpoch = (*server.cluster).currentEpoch;
4106 clusterSaveConfigOrDie(1 as libc::c_int);
4107 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4108 _serverLog(
4109 1 as libc::c_int,
4110 b"WARNING: configEpoch collision with node %.40s. configEpoch set to %llu\0"
4111 as *const u8 as *const libc::c_char,
4112 ((*sender).name).as_mut_ptr(),
4113 (*myself).configEpoch as libc::c_ulonglong,
4114 );
4115 }
4116}
4117#[no_mangle]
4118pub unsafe extern "C" fn clusterBlacklistCleanup() {
4119 let mut di: *mut dictIterator = 0 as *mut dictIterator;
4120 let mut de: *mut dictEntry = 0 as *mut dictEntry;
4121 di = dictGetSafeIterator((*server.cluster).nodes_black_list);
4122 loop {
4123 de = dictNext(di);
4124 if de.is_null() {
4125 break;
4126 }
4127 let mut expire: int64_t = (*de).v.u64_0 as int64_t;
4128 if expire < server.unixtime as libc::c_long {
4129 dictDelete((*server.cluster).nodes_black_list, (*de).key);
4130 }
4131 }
4132 dictReleaseIterator(di);
4133}
4134#[no_mangle]
4135pub unsafe extern "C" fn clusterBlacklistAddNode(mut node: *mut clusterNode) {
4136 let mut de: *mut dictEntry = 0 as *mut dictEntry;
4137 let mut id: sds = sdsnewlen(
4138 ((*node).name).as_mut_ptr() as *const libc::c_void,
4139 40 as libc::c_int as size_t,
4140 );
4141 clusterBlacklistCleanup();
4142 if dictAdd(
4143 (*server.cluster).nodes_black_list,
4144 id as *mut libc::c_void,
4145 0 as *mut libc::c_void,
4146 ) == 0 as libc::c_int
4147 {
4148 id = sdsdup(id);
4149 }
4150 de = dictFind((*server.cluster).nodes_black_list, id as *const libc::c_void);
4151 (*de)
4152 .v
4153 .u64_0 = (time(0 as *mut time_t) + 60 as libc::c_int as libc::c_long)
4154 as uint64_t;
4155 sdsfree(id);
4156}
4157#[no_mangle]
4158pub unsafe extern "C" fn clusterBlacklistExists(
4159 mut nodeid: *mut libc::c_char,
4160) -> libc::c_int {
4161 let mut id: sds = sdsnewlen(
4162 nodeid as *const libc::c_void,
4163 40 as libc::c_int as size_t,
4164 );
4165 let mut retval: libc::c_int = 0;
4166 clusterBlacklistCleanup();
4167 retval = (dictFind((*server.cluster).nodes_black_list, id as *const libc::c_void)
4168 != 0 as *mut libc::c_void as *mut dictEntry) as libc::c_int;
4169 sdsfree(id);
4170 return retval;
4171}
4172#[no_mangle]
4173pub unsafe extern "C" fn markNodeAsFailingIfNeeded(mut node: *mut clusterNode) {
4174 let mut failures: libc::c_int = 0;
4175 let mut needed_quorum: libc::c_int = (*server.cluster).size / 2 as libc::c_int
4176 + 1 as libc::c_int;
4177 if (*node).flags & 4 as libc::c_int == 0 {
4178 return;
4179 }
4180 if (*node).flags & 8 as libc::c_int != 0 {
4181 return;
4182 }
4183 failures = clusterNodeFailureReportsCount(node);
4184 if (*myself).flags & 1 as libc::c_int != 0 {
4185 failures += 1;
4186 }
4187 if failures < needed_quorum {
4188 return;
4189 }
4190 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4191 _serverLog(
4192 2 as libc::c_int,
4193 b"Marking node %.40s as failing (quorum reached).\0" as *const u8
4194 as *const libc::c_char,
4195 ((*node).name).as_mut_ptr(),
4196 );
4197 }
4198 (*node).flags &= !(4 as libc::c_int);
4199 (*node).flags |= 8 as libc::c_int;
4200 (*node).fail_time = mstime();
4201 clusterSendFail(((*node).name).as_mut_ptr());
4202 clusterDoBeforeSleep(
4203 (1 as libc::c_int) << 1 as libc::c_int | (1 as libc::c_int) << 2 as libc::c_int,
4204 );
4205}
4206#[no_mangle]
4207pub unsafe extern "C" fn clearNodeFailureIfNeeded(mut node: *mut clusterNode) {
4208 let mut now: mstime_t = mstime();
4209 if (*node).flags & 8 as libc::c_int != 0 {} else {
4210 _serverAssert(
4211 b"nodeFailed(node)\0" as *const u8 as *const libc::c_char,
4212 b"cluster.c\0" as *const u8 as *const libc::c_char,
4213 1534 as libc::c_int,
4214 );
4215 unreachable!();
4216 };
4217 if (*node).flags & 2 as libc::c_int != 0 || (*node).numslots == 0 as libc::c_int {
4218 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4219 _serverLog(
4220 2 as libc::c_int,
4221 b"Clear FAIL state for node %.40s: %s is reachable again.\0" as *const u8
4222 as *const libc::c_char,
4223 ((*node).name).as_mut_ptr(),
4224 if (*node).flags & 2 as libc::c_int != 0 {
4225 b"replica\0" as *const u8 as *const libc::c_char
4226 } else {
4227 b"master without slots\0" as *const u8 as *const libc::c_char
4228 },
4229 );
4230 }
4231 (*node).flags &= !(8 as libc::c_int);
4232 clusterDoBeforeSleep(
4233 (1 as libc::c_int) << 1 as libc::c_int
4234 | (1 as libc::c_int) << 2 as libc::c_int,
4235 );
4236 }
4237 if (*node).flags & 1 as libc::c_int != 0 && (*node).numslots > 0 as libc::c_int
4238 && now - (*node).fail_time
4239 > server.cluster_node_timeout * 2 as libc::c_int as libc::c_longlong
4240 {
4241 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4242 _serverLog(
4243 2 as libc::c_int,
4244 b"Clear FAIL state for node %.40s: is reachable again and nobody is serving its slots after some time.\0"
4245 as *const u8 as *const libc::c_char,
4246 ((*node).name).as_mut_ptr(),
4247 );
4248 }
4249 (*node).flags &= !(8 as libc::c_int);
4250 clusterDoBeforeSleep(
4251 (1 as libc::c_int) << 1 as libc::c_int
4252 | (1 as libc::c_int) << 2 as libc::c_int,
4253 );
4254 }
4255}
4256#[no_mangle]
4257pub unsafe extern "C" fn clusterHandshakeInProgress(
4258 mut ip: *mut libc::c_char,
4259 mut port: libc::c_int,
4260 mut cport: libc::c_int,
4261) -> libc::c_int {
4262 let mut di: *mut dictIterator = 0 as *mut dictIterator;
4263 let mut de: *mut dictEntry = 0 as *mut dictEntry;
4264 di = dictGetSafeIterator((*server.cluster).nodes);
4265 loop {
4266 de = dictNext(di);
4267 if de.is_null() {
4268 break;
4269 }
4270 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
4271 if (*node).flags & 32 as libc::c_int == 0 {
4272 continue;
4273 }
4274 if strcasecmp(((*node).ip).as_mut_ptr(), ip) == 0 && (*node).port == port
4275 && (*node).cport == cport
4276 {
4277 break;
4278 }
4279 }
4280 dictReleaseIterator(di);
4281 return (de != 0 as *mut libc::c_void as *mut dictEntry) as libc::c_int;
4282}
4283#[no_mangle]
4284pub unsafe extern "C" fn clusterStartHandshake(
4285 mut ip: *mut libc::c_char,
4286 mut port: libc::c_int,
4287 mut cport: libc::c_int,
4288) -> libc::c_int {
4289 let mut n: *mut clusterNode = 0 as *mut clusterNode;
4290 let mut norm_ip: [libc::c_char; 46] = [0; 46];
4291 let mut sa: sockaddr_storage = sockaddr_storage {
4292 ss_family: 0,
4293 __ss_padding: [0; 118],
4294 __ss_align: 0,
4295 };
4296 if inet_pton(
4297 2 as libc::c_int,
4298 ip,
4299 &mut (*(&mut sa as *mut sockaddr_storage as *mut sockaddr_in)).sin_addr
4300 as *mut in_addr as *mut libc::c_void,
4301 ) != 0
4302 {
4303 sa.ss_family = 2 as libc::c_int as sa_family_t;
4304 } else if inet_pton(
4305 10 as libc::c_int,
4306 ip,
4307 &mut (*(&mut sa as *mut sockaddr_storage as *mut sockaddr_in6)).sin6_addr
4308 as *mut in6_addr as *mut libc::c_void,
4309 ) != 0
4310 {
4311 sa.ss_family = 10 as libc::c_int as sa_family_t;
4312 } else {
4313 *__errno_location() = 22 as libc::c_int;
4314 return 0 as libc::c_int;
4315 }
4316 if port <= 0 as libc::c_int || port > 65535 as libc::c_int
4317 || cport <= 0 as libc::c_int || cport > 65535 as libc::c_int
4318 {
4319 *__errno_location() = 22 as libc::c_int;
4320 return 0 as libc::c_int;
4321 }
4322 memset(
4323 norm_ip.as_mut_ptr() as *mut libc::c_void,
4324 0 as libc::c_int,
4325 46 as libc::c_int as libc::c_ulong,
4326 );
4327 if sa.ss_family as libc::c_int == 2 as libc::c_int {
4328 inet_ntop(
4329 2 as libc::c_int,
4330 &mut (*(&mut sa as *mut sockaddr_storage as *mut sockaddr_in)).sin_addr
4331 as *mut in_addr as *mut libc::c_void,
4332 norm_ip.as_mut_ptr(),
4333 46 as libc::c_int as socklen_t,
4334 );
4335 } else {
4336 inet_ntop(
4337 10 as libc::c_int,
4338 &mut (*(&mut sa as *mut sockaddr_storage as *mut sockaddr_in6)).sin6_addr
4339 as *mut in6_addr as *mut libc::c_void,
4340 norm_ip.as_mut_ptr(),
4341 46 as libc::c_int as socklen_t,
4342 );
4343 }
4344 if clusterHandshakeInProgress(norm_ip.as_mut_ptr(), port, cport) != 0 {
4345 *__errno_location() = 11 as libc::c_int;
4346 return 0 as libc::c_int;
4347 }
4348 n = createClusterNode(
4349 0 as *mut libc::c_char,
4350 32 as libc::c_int | 128 as libc::c_int,
4351 );
4352 memcpy(
4353 ((*n).ip).as_mut_ptr() as *mut libc::c_void,
4354 norm_ip.as_mut_ptr() as *const libc::c_void,
4355 core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
4356 );
4357 (*n).port = port;
4358 (*n).cport = cport;
4359 clusterAddNode(n);
4360 return 1 as libc::c_int;
4361}
4362#[no_mangle]
4363pub unsafe extern "C" fn clusterProcessGossipSection(
4364 mut hdr: *mut clusterMsg,
4365 mut link: *mut clusterLink,
4366) {
4367 let mut count: uint16_t = __bswap_16((*hdr).count);
4368 let mut g: *mut clusterMsgDataGossip = ((*hdr).data.ping.gossip).as_mut_ptr();
4369 let mut sender: *mut clusterNode = if !((*link).node).is_null() {
4370 (*link).node
4371 } else {
4372 clusterLookupNode(((*hdr).sender).as_mut_ptr(), 40 as libc::c_int)
4373 };
4374 loop {
4375 let fresh4 = count;
4376 count = count.wrapping_sub(1);
4377 if !(fresh4 != 0) {
4378 break;
4379 }
4380 let mut flags: uint16_t = __bswap_16((*g).flags);
4381 let mut node: *mut clusterNode = 0 as *mut clusterNode;
4382 let mut ci: sds = 0 as *mut libc::c_char;
4383 if server.verbosity == 0 as libc::c_int {
4384 ci = representClusterNodeFlags(sdsempty(), flags);
4385 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4386 _serverLog(
4387 0 as libc::c_int,
4388 b"GOSSIP %.40s %s:%d@%d %s\0" as *const u8 as *const libc::c_char,
4389 ((*g).nodename).as_mut_ptr(),
4390 ((*g).ip).as_mut_ptr(),
4391 __bswap_16((*g).port) as libc::c_int,
4392 __bswap_16((*g).cport) as libc::c_int,
4393 ci,
4394 );
4395 }
4396 sdsfree(ci);
4397 }
4398 node = clusterLookupNode(((*g).nodename).as_mut_ptr(), 40 as libc::c_int);
4399 if !node.is_null() {
4400 if !sender.is_null() && (*sender).flags & 1 as libc::c_int != 0
4401 && node != myself
4402 {
4403 if flags as libc::c_int & (8 as libc::c_int | 4 as libc::c_int) != 0 {
4404 if clusterNodeAddFailureReport(node, sender) != 0 {
4405 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity)
4406 {
4407 _serverLog(
4408 1 as libc::c_int,
4409 b"Node %.40s reported node %.40s as not reachable.\0"
4410 as *const u8 as *const libc::c_char,
4411 ((*sender).name).as_mut_ptr(),
4412 ((*node).name).as_mut_ptr(),
4413 );
4414 }
4415 }
4416 markNodeAsFailingIfNeeded(node);
4417 } else if clusterNodeDelFailureReport(node, sender) != 0 {
4418 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4419 _serverLog(
4420 1 as libc::c_int,
4421 b"Node %.40s reported node %.40s is back online.\0"
4422 as *const u8 as *const libc::c_char,
4423 ((*sender).name).as_mut_ptr(),
4424 ((*node).name).as_mut_ptr(),
4425 );
4426 }
4427 }
4428 }
4429 if flags as libc::c_int & (8 as libc::c_int | 4 as libc::c_int) == 0
4430 && (*node).ping_sent == 0 as libc::c_int as libc::c_longlong
4431 && clusterNodeFailureReportsCount(node) == 0 as libc::c_int
4432 {
4433 let mut pongtime: mstime_t = __bswap_32((*g).pong_received) as mstime_t;
4434 pongtime *= 1000 as libc::c_int as libc::c_longlong;
4435 if pongtime <= server.mstime + 500 as libc::c_int as libc::c_longlong
4436 && pongtime > (*node).pong_received
4437 {
4438 (*node).pong_received = pongtime;
4439 }
4440 }
4441 if (*node).flags & (8 as libc::c_int | 4 as libc::c_int) != 0
4442 && flags as libc::c_int & 64 as libc::c_int == 0
4443 && flags as libc::c_int & (8 as libc::c_int | 4 as libc::c_int) == 0
4444 && (strcasecmp(((*node).ip).as_mut_ptr(), ((*g).ip).as_mut_ptr()) != 0
4445 || (*node).port != __bswap_16((*g).port) as libc::c_int
4446 || (*node).cport != __bswap_16((*g).cport) as libc::c_int)
4447 {
4448 if !((*node).link).is_null() {
4449 freeClusterLink((*node).link);
4450 }
4451 memcpy(
4452 ((*node).ip).as_mut_ptr() as *mut libc::c_void,
4453 ((*g).ip).as_mut_ptr() as *const libc::c_void,
4454 46 as libc::c_int as libc::c_ulong,
4455 );
4456 (*node).port = __bswap_16((*g).port) as libc::c_int;
4457 (*node).pport = __bswap_16((*g).pport) as libc::c_int;
4458 (*node).cport = __bswap_16((*g).cport) as libc::c_int;
4459 (*node).flags &= !(64 as libc::c_int);
4460 }
4461 } else if !sender.is_null() && flags as libc::c_int & 64 as libc::c_int == 0
4462 && clusterBlacklistExists(((*g).nodename).as_mut_ptr()) == 0
4463 {
4464 let mut node_0: *mut clusterNode = 0 as *mut clusterNode;
4465 node_0 = createClusterNode(
4466 ((*g).nodename).as_mut_ptr(),
4467 flags as libc::c_int,
4468 );
4469 memcpy(
4470 ((*node_0).ip).as_mut_ptr() as *mut libc::c_void,
4471 ((*g).ip).as_mut_ptr() as *const libc::c_void,
4472 46 as libc::c_int as libc::c_ulong,
4473 );
4474 (*node_0).port = __bswap_16((*g).port) as libc::c_int;
4475 (*node_0).pport = __bswap_16((*g).pport) as libc::c_int;
4476 (*node_0).cport = __bswap_16((*g).cport) as libc::c_int;
4477 clusterAddNode(node_0);
4478 }
4479 g = g.offset(1);
4480 };
4481}
4482#[no_mangle]
4483pub unsafe extern "C" fn nodeIp2String(
4484 mut buf: *mut libc::c_char,
4485 mut link: *mut clusterLink,
4486 mut announced_ip: *mut libc::c_char,
4487) -> libc::c_int {
4488 if *announced_ip.offset(0 as libc::c_int as isize) as libc::c_int != '\0' as i32 {
4489 memcpy(
4490 buf as *mut libc::c_void,
4491 announced_ip as *const libc::c_void,
4492 46 as libc::c_int as libc::c_ulong,
4493 );
4494 *buf
4495 .offset(
4496 (46 as libc::c_int - 1 as libc::c_int) as isize,
4497 ) = '\0' as i32 as libc::c_char;
4498 return 0 as libc::c_int;
4499 } else {
4500 if connPeerToString(
4501 (*link).conn,
4502 buf,
4503 46 as libc::c_int as size_t,
4504 0 as *mut libc::c_int,
4505 ) == -(1 as libc::c_int)
4506 {
4507 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4508 _serverLog(
4509 2 as libc::c_int,
4510 b"Error converting peer IP to string: %s\0" as *const u8
4511 as *const libc::c_char,
4512 if !((*link).conn).is_null() {
4513 connGetLastError((*link).conn)
4514 } else {
4515 b"no link\0" as *const u8 as *const libc::c_char
4516 },
4517 );
4518 }
4519 return -(1 as libc::c_int);
4520 }
4521 return 0 as libc::c_int;
4522 };
4523}
4524#[no_mangle]
4525pub unsafe extern "C" fn nodeUpdateAddressIfNeeded(
4526 mut node: *mut clusterNode,
4527 mut link: *mut clusterLink,
4528 mut hdr: *mut clusterMsg,
4529) -> libc::c_int {
4530 let mut ip: [libc::c_char; 46] = [
4531 0 as libc::c_int as libc::c_char,
4532 0,
4533 0,
4534 0,
4535 0,
4536 0,
4537 0,
4538 0,
4539 0,
4540 0,
4541 0,
4542 0,
4543 0,
4544 0,
4545 0,
4546 0,
4547 0,
4548 0,
4549 0,
4550 0,
4551 0,
4552 0,
4553 0,
4554 0,
4555 0,
4556 0,
4557 0,
4558 0,
4559 0,
4560 0,
4561 0,
4562 0,
4563 0,
4564 0,
4565 0,
4566 0,
4567 0,
4568 0,
4569 0,
4570 0,
4571 0,
4572 0,
4573 0,
4574 0,
4575 0,
4576 0,
4577 ];
4578 let mut port: libc::c_int = __bswap_16((*hdr).port) as libc::c_int;
4579 let mut pport: libc::c_int = __bswap_16((*hdr).pport) as libc::c_int;
4580 let mut cport: libc::c_int = __bswap_16((*hdr).cport) as libc::c_int;
4581 if link == (*node).link {
4582 return 0 as libc::c_int;
4583 }
4584 if nodeIp2String(ip.as_mut_ptr(), link, ((*hdr).myip).as_mut_ptr())
4585 == -(1 as libc::c_int)
4586 {
4587 return 0 as libc::c_int;
4588 }
4589 if (*node).port == port && (*node).cport == cport && (*node).pport == pport
4590 && strcmp(ip.as_mut_ptr(), ((*node).ip).as_mut_ptr()) == 0 as libc::c_int
4591 {
4592 return 0 as libc::c_int;
4593 }
4594 memcpy(
4595 ((*node).ip).as_mut_ptr() as *mut libc::c_void,
4596 ip.as_mut_ptr() as *const libc::c_void,
4597 core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
4598 );
4599 (*node).port = port;
4600 (*node).pport = pport;
4601 (*node).cport = cport;
4602 if !((*node).link).is_null() {
4603 freeClusterLink((*node).link);
4604 }
4605 (*node).flags &= !(64 as libc::c_int);
4606 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4607 _serverLog(
4608 3 as libc::c_int,
4609 b"Address updated for node %.40s, now %s:%d\0" as *const u8
4610 as *const libc::c_char,
4611 ((*node).name).as_mut_ptr(),
4612 ((*node).ip).as_mut_ptr(),
4613 (*node).port,
4614 );
4615 }
4616 if (*myself).flags & 2 as libc::c_int != 0 && (*myself).slaveof == node {
4617 replicationSetMaster(((*node).ip).as_mut_ptr(), (*node).port);
4618 }
4619 return 1 as libc::c_int;
4620}
4621#[no_mangle]
4622pub unsafe extern "C" fn clusterSetNodeAsMaster(mut n: *mut clusterNode) {
4623 if (*n).flags & 1 as libc::c_int != 0 {
4624 return;
4625 }
4626 if !((*n).slaveof).is_null() {
4627 clusterNodeRemoveSlave((*n).slaveof, n);
4628 if n != myself {
4629 (*n).flags |= 256 as libc::c_int;
4630 }
4631 }
4632 (*n).flags &= !(2 as libc::c_int);
4633 (*n).flags |= 1 as libc::c_int;
4634 (*n).slaveof = 0 as *mut clusterNode;
4635 clusterDoBeforeSleep(
4636 (1 as libc::c_int) << 2 as libc::c_int | (1 as libc::c_int) << 1 as libc::c_int,
4637 );
4638}
4639#[no_mangle]
4640pub unsafe extern "C" fn clusterUpdateSlotsConfigWith(
4641 mut sender: *mut clusterNode,
4642 mut senderConfigEpoch: uint64_t,
4643 mut slots: *mut libc::c_uchar,
4644) {
4645 let mut j: libc::c_int = 0;
4646 let mut curmaster: *mut clusterNode = 0 as *mut clusterNode;
4647 let mut newmaster: *mut clusterNode = 0 as *mut clusterNode;
4648 let mut dirty_slots: [uint16_t; 16384] = [0; 16384];
4649 let mut dirty_slots_count: libc::c_int = 0 as libc::c_int;
4650 let mut sender_slots: libc::c_int = 0 as libc::c_int;
4651 let mut migrated_our_slots: libc::c_int = 0 as libc::c_int;
4652 curmaster = if (*myself).flags & 1 as libc::c_int != 0 {
4653 myself
4654 } else {
4655 (*myself).slaveof
4656 };
4657 if sender == myself {
4658 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4659 _serverLog(
4660 3 as libc::c_int,
4661 b"Discarding UPDATE message about myself.\0" as *const u8
4662 as *const libc::c_char,
4663 );
4664 }
4665 return;
4666 }
4667 j = 0 as libc::c_int;
4668 while j < 16384 as libc::c_int {
4669 if bitmapTestBit(slots, j) != 0 {
4670 sender_slots += 1;
4671 if !((*server.cluster).slots[j as usize] == sender) {
4672 if ((*server.cluster).importing_slots_from[j as usize]).is_null() {
4673 if ((*server.cluster).slots[j as usize]).is_null()
4674 || (*(*server.cluster).slots[j as usize]).configEpoch
4675 < senderConfigEpoch
4676 {
4677 if (*server.cluster).slots[j as usize] == myself
4678 && countKeysInSlot(j as libc::c_uint) != 0
4679 && sender != myself
4680 {
4681 dirty_slots[dirty_slots_count as usize] = j as uint16_t;
4682 dirty_slots_count += 1;
4683 }
4684 if (*server.cluster).slots[j as usize] == curmaster {
4685 newmaster = sender;
4686 migrated_our_slots += 1;
4687 }
4688 clusterDelSlot(j);
4689 clusterAddSlot(sender, j);
4690 clusterDoBeforeSleep(
4691 (1 as libc::c_int) << 2 as libc::c_int
4692 | (1 as libc::c_int) << 1 as libc::c_int
4693 | (1 as libc::c_int) << 3 as libc::c_int,
4694 );
4695 }
4696 }
4697 }
4698 }
4699 j += 1;
4700 }
4701 if server.cluster_module_flags & (1 as libc::c_int) << 2 as libc::c_int != 0 {
4702 return;
4703 }
4704 if !newmaster.is_null() && (*curmaster).numslots == 0 as libc::c_int
4705 && (server.cluster_allow_replica_migration != 0
4706 || sender_slots == migrated_our_slots)
4707 {
4708 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4709 _serverLog(
4710 3 as libc::c_int,
4711 b"Configuration change detected. Reconfiguring myself as a replica of %.40s\0"
4712 as *const u8 as *const libc::c_char,
4713 ((*sender).name).as_mut_ptr(),
4714 );
4715 }
4716 clusterSetMaster(sender);
4717 clusterDoBeforeSleep(
4718 (1 as libc::c_int) << 2 as libc::c_int
4719 | (1 as libc::c_int) << 1 as libc::c_int
4720 | (1 as libc::c_int) << 3 as libc::c_int,
4721 );
4722 } else if !((*myself).slaveof).is_null() && !((*(*myself).slaveof).slaveof).is_null()
4723 && (*(*myself).slaveof).slaveof != myself
4724 {
4725 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4726 _serverLog(
4727 3 as libc::c_int,
4728 b"I'm a sub-replica! Reconfiguring myself as a replica of grandmaster %.40s\0"
4729 as *const u8 as *const libc::c_char,
4730 ((*(*(*myself).slaveof).slaveof).name).as_mut_ptr(),
4731 );
4732 }
4733 clusterSetMaster((*(*myself).slaveof).slaveof);
4734 clusterDoBeforeSleep(
4735 (1 as libc::c_int) << 2 as libc::c_int
4736 | (1 as libc::c_int) << 1 as libc::c_int
4737 | (1 as libc::c_int) << 3 as libc::c_int,
4738 );
4739 } else if dirty_slots_count != 0 {
4740 j = 0 as libc::c_int;
4741 while j < dirty_slots_count {
4742 delKeysInSlot(dirty_slots[j as usize] as libc::c_uint);
4743 j += 1;
4744 }
4745 }
4746}
4747unsafe extern "C" fn getPingExtLength(mut ext: *mut clusterMsgPingExt) -> uint32_t {
4748 return __bswap_32((*ext).length);
4749}
4750unsafe extern "C" fn getInitialPingExt(
4751 mut hdr: *mut clusterMsg,
4752 mut count: uint16_t,
4753) -> *mut clusterMsgPingExt {
4754 let mut initial: *mut clusterMsgPingExt = &mut *((*hdr).data.ping.gossip)
4755 .as_mut_ptr()
4756 .offset(count as isize) as *mut clusterMsgDataGossip as *mut clusterMsgPingExt;
4757 return initial;
4758}
4759unsafe extern "C" fn getNextPingExt(
4760 mut ext: *mut clusterMsgPingExt,
4761) -> *mut clusterMsgPingExt {
4762 let mut next: *mut clusterMsgPingExt = (ext as *mut libc::c_char)
4763 .offset(getPingExtLength(ext) as isize) as *mut clusterMsgPingExt;
4764 return next;
4765}
4766#[no_mangle]
4767pub unsafe extern "C" fn getHostnamePingExtSize() -> libc::c_int {
4768 if sdslen((*myself).hostname) == 0 as libc::c_int as libc::c_ulong {
4769 return 0 as libc::c_int;
4770 }
4771 let mut totlen: libc::c_int = (core::mem::size_of::<clusterMsgPingExt>()
4772 as libc::c_ulong)
4773 .wrapping_add(
4774 (sdslen((*myself).hostname))
4775 .wrapping_add(1 as libc::c_int as libc::c_ulong)
4776 .wrapping_add(7 as libc::c_int as libc::c_ulong)
4777 .wrapping_div(8 as libc::c_int as libc::c_ulong)
4778 .wrapping_mul(8 as libc::c_int as libc::c_ulong),
4779 ) as libc::c_int;
4780 return totlen;
4781}
4782#[no_mangle]
4783pub unsafe extern "C" fn writeHostnamePingExt(
4784 mut cursor: *mut *mut clusterMsgPingExt,
4785) -> libc::c_int {
4786 if sdslen((*myself).hostname) == 0 as libc::c_int as libc::c_ulong {
4787 return 0 as libc::c_int;
4788 }
4789 let mut ext: *mut clusterMsgPingExtHostname = &mut (*((**cursor).ext)
4790 .as_mut_ptr()
4791 .offset(0 as libc::c_int as isize))
4792 .hostname;
4793 memcpy(
4794 ((*ext).hostname).as_mut_ptr() as *mut libc::c_void,
4795 (*myself).hostname as *const libc::c_void,
4796 sdslen((*myself).hostname),
4797 );
4798 let mut extension_size: uint32_t = getHostnamePingExtSize() as uint32_t;
4799 (**cursor)
4800 .type_0 = __bswap_16(CLUSTERMSG_EXT_TYPE_HOSTNAME as libc::c_int as __uint16_t);
4801 (**cursor).length = __bswap_32(extension_size);
4802 *cursor = ((*ext).hostname)
4803 .as_mut_ptr()
4804 .offset(
4805 (sdslen((*myself).hostname))
4806 .wrapping_add(1 as libc::c_int as libc::c_ulong)
4807 .wrapping_add(7 as libc::c_int as libc::c_ulong)
4808 .wrapping_div(8 as libc::c_int as libc::c_ulong)
4809 .wrapping_mul(8 as libc::c_int as libc::c_ulong) as isize,
4810 ) as *mut clusterMsgPingExt;
4811 return extension_size as libc::c_int;
4812}
4813#[no_mangle]
4814pub unsafe extern "C" fn clusterProcessPingExtensions(
4815 mut hdr: *mut clusterMsg,
4816 mut link: *mut clusterLink,
4817) {
4818 let mut sender: *mut clusterNode = if !((*link).node).is_null() {
4819 (*link).node
4820 } else {
4821 clusterLookupNode(((*hdr).sender).as_mut_ptr(), 40 as libc::c_int)
4822 };
4823 let mut ext_hostname: *mut libc::c_char = 0 as *mut libc::c_char;
4824 let mut extensions: uint16_t = __bswap_16((*hdr).extensions);
4825 let mut ext: *mut clusterMsgPingExt = getInitialPingExt(
4826 hdr,
4827 __bswap_16((*hdr).count),
4828 );
4829 loop {
4830 let fresh5 = extensions;
4831 extensions = extensions.wrapping_sub(1);
4832 if !(fresh5 != 0) {
4833 break;
4834 }
4835 let mut type_0: uint16_t = __bswap_16((*ext).type_0);
4836 if type_0 as libc::c_int == CLUSTERMSG_EXT_TYPE_HOSTNAME as libc::c_int {
4837 let mut hostname_ext: *mut clusterMsgPingExtHostname = &mut (*((*ext).ext)
4838 .as_mut_ptr()
4839 .offset(0 as libc::c_int as isize))
4840 .hostname as *mut clusterMsgPingExtHostname;
4841 ext_hostname = ((*hostname_ext).hostname).as_mut_ptr();
4842 } else if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4843 _serverLog(
4844 3 as libc::c_int,
4845 b"Received unknown extension type %d\0" as *const u8
4846 as *const libc::c_char,
4847 type_0 as libc::c_int,
4848 );
4849 }
4850 ext = getNextPingExt(ext);
4851 }
4852 updateAnnouncedHostname(sender, ext_hostname);
4853}
4854unsafe extern "C" fn getNodeFromLinkAndMsg(
4855 mut link: *mut clusterLink,
4856 mut hdr: *mut clusterMsg,
4857) -> *mut clusterNode {
4858 let mut sender: *mut clusterNode = 0 as *mut clusterNode;
4859 if !((*link).node).is_null() && (*(*link).node).flags & 32 as libc::c_int == 0 {
4860 sender = (*link).node;
4861 } else {
4862 sender = clusterLookupNode(((*hdr).sender).as_mut_ptr(), 40 as libc::c_int);
4863 if !sender.is_null() && ((*link).node).is_null() {
4864 setClusterNodeToInboundClusterLink(sender, link);
4865 }
4866 }
4867 return sender;
4868}
4869#[no_mangle]
4870pub unsafe extern "C" fn clusterProcessPacket(
4871 mut link: *mut clusterLink,
4872) -> libc::c_int {
4873 let mut hdr: *mut clusterMsg = (*link).rcvbuf as *mut clusterMsg;
4874 let mut totlen: uint32_t = __bswap_32((*hdr).totlen);
4875 let mut type_0: uint16_t = __bswap_16((*hdr).type_0);
4876 let mut now: mstime_t = mstime();
4877 if (type_0 as libc::c_int) < 11 as libc::c_int {
4878 (*server.cluster).stats_bus_messages_received[type_0 as usize] += 1;
4879 }
4880 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4881 _serverLog(
4882 0 as libc::c_int,
4883 b"--- Processing packet of type %s, %lu bytes\0" as *const u8
4884 as *const libc::c_char,
4885 clusterGetMessageTypeString(type_0 as libc::c_int),
4886 totlen as libc::c_ulong,
4887 );
4888 }
4889 if totlen < 16 as libc::c_int as libc::c_uint {
4890 return 1 as libc::c_int;
4891 }
4892 if totlen as libc::c_ulong > (*link).rcvbuf_len {
4893 return 1 as libc::c_int;
4894 }
4895 if __bswap_16((*hdr).ver) as libc::c_int != 1 as libc::c_int {
4896 return 1 as libc::c_int;
4897 }
4898 if type_0 as libc::c_int == server.cluster_drop_packet_filter {
4899 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4900 _serverLog(
4901 3 as libc::c_int,
4902 b"Dropping packet that matches debug drop filter\0" as *const u8
4903 as *const libc::c_char,
4904 );
4905 }
4906 return 1 as libc::c_int;
4907 }
4908 let mut flags: uint16_t = __bswap_16((*hdr).flags);
4909 let mut extensions: uint16_t = __bswap_16((*hdr).extensions);
4910 let mut senderCurrentEpoch: uint64_t = 0 as libc::c_int as uint64_t;
4911 let mut senderConfigEpoch: uint64_t = 0 as libc::c_int as uint64_t;
4912 let mut explen: uint32_t = 0;
4913 let mut sender: *mut clusterNode = 0 as *mut clusterNode;
4914 if type_0 as libc::c_int == 0 as libc::c_int
4915 || type_0 as libc::c_int == 1 as libc::c_int
4916 || type_0 as libc::c_int == 2 as libc::c_int
4917 {
4918 let mut count: uint16_t = __bswap_16((*hdr).count);
4919 explen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
4920 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
4921 as uint32_t;
4922 explen = (explen as libc::c_ulong)
4923 .wrapping_add(
4924 (core::mem::size_of::<clusterMsgDataGossip>() as libc::c_ulong)
4925 .wrapping_mul(count as libc::c_ulong),
4926 ) as uint32_t as uint32_t;
4927 if (*hdr).mflags[0 as libc::c_int as usize] as libc::c_int
4928 & (1 as libc::c_int) << 2 as libc::c_int != 0
4929 {
4930 let mut ext: *mut clusterMsgPingExt = getInitialPingExt(hdr, count);
4931 loop {
4932 let fresh6 = extensions;
4933 extensions = extensions.wrapping_sub(1);
4934 if !(fresh6 != 0) {
4935 break;
4936 }
4937 let mut extlen: uint16_t = getPingExtLength(ext) as uint16_t;
4938 if extlen as libc::c_int % 8 as libc::c_int != 0 as libc::c_int {
4939 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4940 _serverLog(
4941 3 as libc::c_int,
4942 b"Received a %s packet without proper padding (%d bytes)\0"
4943 as *const u8 as *const libc::c_char,
4944 clusterGetMessageTypeString(type_0 as libc::c_int),
4945 extlen as libc::c_int,
4946 );
4947 }
4948 return 1 as libc::c_int;
4949 }
4950 if totlen.wrapping_sub(explen) < extlen as libc::c_uint {
4951 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
4952 _serverLog(
4953 3 as libc::c_int,
4954 b"Received invalid %s packet with extension data that exceeds total packet length (%lld)\0"
4955 as *const u8 as *const libc::c_char,
4956 clusterGetMessageTypeString(type_0 as libc::c_int),
4957 totlen as libc::c_ulonglong,
4958 );
4959 }
4960 return 1 as libc::c_int;
4961 }
4962 explen = (explen as libc::c_uint).wrapping_add(extlen as libc::c_uint)
4963 as uint32_t as uint32_t;
4964 ext = getNextPingExt(ext);
4965 }
4966 }
4967 } else if type_0 as libc::c_int == 3 as libc::c_int {
4968 explen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
4969 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
4970 as uint32_t;
4971 explen = (explen as libc::c_ulong)
4972 .wrapping_add(core::mem::size_of::<clusterMsgDataFail>() as libc::c_ulong)
4973 as uint32_t as uint32_t;
4974 } else if type_0 as libc::c_int == 4 as libc::c_int
4975 || type_0 as libc::c_int == 10 as libc::c_int
4976 {
4977 explen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
4978 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
4979 as uint32_t;
4980 explen = (explen as libc::c_ulong)
4981 .wrapping_add(
4982 (core::mem::size_of::<clusterMsgDataPublish>() as libc::c_ulong)
4983 .wrapping_sub(8 as libc::c_int as libc::c_ulong)
4984 .wrapping_add(
4985 __bswap_32((*hdr).data.publish.msg.channel_len) as libc::c_ulong,
4986 )
4987 .wrapping_add(
4988 __bswap_32((*hdr).data.publish.msg.message_len) as libc::c_ulong,
4989 ),
4990 ) as uint32_t as uint32_t;
4991 } else if type_0 as libc::c_int == 5 as libc::c_int
4992 || type_0 as libc::c_int == 6 as libc::c_int
4993 || type_0 as libc::c_int == 8 as libc::c_int
4994 {
4995 explen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
4996 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
4997 as uint32_t;
4998 } else if type_0 as libc::c_int == 7 as libc::c_int {
4999 explen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
5000 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
5001 as uint32_t;
5002 explen = (explen as libc::c_ulong)
5003 .wrapping_add(
5004 core::mem::size_of::<clusterMsgDataUpdate>() as libc::c_ulong,
5005 ) as uint32_t as uint32_t;
5006 } else if type_0 as libc::c_int == 9 as libc::c_int {
5007 explen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
5008 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
5009 as uint32_t;
5010 explen = (explen as libc::c_ulong)
5011 .wrapping_add(
5012 (core::mem::size_of::<clusterMsgModule>() as libc::c_ulong)
5013 .wrapping_sub(3 as libc::c_int as libc::c_ulong)
5014 .wrapping_add(
5015 __bswap_32((*hdr).data.module.msg.len) as libc::c_ulong,
5016 ),
5017 ) as uint32_t as uint32_t;
5018 } else {
5019 explen = totlen;
5020 }
5021 if totlen != explen {
5022 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5023 _serverLog(
5024 3 as libc::c_int,
5025 b"Received invalid %s packet of length %lld but expected length %lld\0"
5026 as *const u8 as *const libc::c_char,
5027 clusterGetMessageTypeString(type_0 as libc::c_int),
5028 totlen as libc::c_ulonglong,
5029 explen as libc::c_ulonglong,
5030 );
5031 }
5032 return 1 as libc::c_int;
5033 }
5034 sender = getNodeFromLinkAndMsg(link, hdr);
5035 if !sender.is_null() {
5036 (*sender).data_received = now;
5037 }
5038 if !sender.is_null() && (*sender).flags & 32 as libc::c_int == 0 {
5039 senderCurrentEpoch = intrev64((*hdr).currentEpoch);
5040 senderConfigEpoch = intrev64((*hdr).configEpoch);
5041 if senderCurrentEpoch > (*server.cluster).currentEpoch {
5042 (*server.cluster).currentEpoch = senderCurrentEpoch;
5043 }
5044 if senderConfigEpoch > (*sender).configEpoch {
5045 (*sender).configEpoch = senderConfigEpoch;
5046 clusterDoBeforeSleep(
5047 (1 as libc::c_int) << 2 as libc::c_int
5048 | (1 as libc::c_int) << 3 as libc::c_int,
5049 );
5050 }
5051 (*sender).repl_offset = intrev64((*hdr).offset) as libc::c_longlong;
5052 (*sender).repl_offset_time = now;
5053 if (*server.cluster).mf_end != 0 && (*myself).flags & 2 as libc::c_int != 0
5054 && (*myself).slaveof == sender
5055 && (*hdr).mflags[0 as libc::c_int as usize] as libc::c_int
5056 & (1 as libc::c_int) << 0 as libc::c_int != 0
5057 && (*server.cluster).mf_master_offset
5058 == -(1 as libc::c_int) as libc::c_longlong
5059 {
5060 (*server.cluster).mf_master_offset = (*sender).repl_offset;
5061 clusterDoBeforeSleep((1 as libc::c_int) << 4 as libc::c_int);
5062 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5063 _serverLog(
5064 3 as libc::c_int,
5065 b"Received replication offset for paused master manual failover: %lld\0"
5066 as *const u8 as *const libc::c_char,
5067 (*server.cluster).mf_master_offset,
5068 );
5069 }
5070 }
5071 }
5072 if type_0 as libc::c_int == 0 as libc::c_int
5073 || type_0 as libc::c_int == 2 as libc::c_int
5074 {
5075 if (type_0 as libc::c_int == 2 as libc::c_int
5076 || (*myself).ip[0 as libc::c_int as usize] as libc::c_int == '\0' as i32)
5077 && (server.cluster_announce_ip).is_null()
5078 {
5079 let mut ip: [libc::c_char; 46] = [0; 46];
5080 if connSockName(
5081 (*link).conn,
5082 ip.as_mut_ptr(),
5083 core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
5084 0 as *mut libc::c_int,
5085 ) != -(1 as libc::c_int)
5086 && strcmp(ip.as_mut_ptr(), ((*myself).ip).as_mut_ptr()) != 0
5087 {
5088 memcpy(
5089 ((*myself).ip).as_mut_ptr() as *mut libc::c_void,
5090 ip.as_mut_ptr() as *const libc::c_void,
5091 46 as libc::c_int as libc::c_ulong,
5092 );
5093 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5094 _serverLog(
5095 3 as libc::c_int,
5096 b"IP address for this node updated to %s\0" as *const u8
5097 as *const libc::c_char,
5098 ((*myself).ip).as_mut_ptr(),
5099 );
5100 }
5101 clusterDoBeforeSleep((1 as libc::c_int) << 2 as libc::c_int);
5102 }
5103 }
5104 if sender.is_null() && type_0 as libc::c_int == 2 as libc::c_int {
5105 let mut node: *mut clusterNode = 0 as *mut clusterNode;
5106 node = createClusterNode(0 as *mut libc::c_char, 32 as libc::c_int);
5107 if nodeIp2String(((*node).ip).as_mut_ptr(), link, ((*hdr).myip).as_mut_ptr())
5108 == 0 as libc::c_int
5109 {} else {
5110 _serverAssert(
5111 b"nodeIp2String(node->ip,link,hdr->myip) == C_OK\0" as *const u8
5112 as *const libc::c_char,
5113 b"cluster.c\0" as *const u8 as *const libc::c_char,
5114 2269 as libc::c_int,
5115 );
5116 unreachable!();
5117 };
5118 (*node).port = __bswap_16((*hdr).port) as libc::c_int;
5119 (*node).pport = __bswap_16((*hdr).pport) as libc::c_int;
5120 (*node).cport = __bswap_16((*hdr).cport) as libc::c_int;
5121 clusterAddNode(node);
5122 clusterDoBeforeSleep((1 as libc::c_int) << 2 as libc::c_int);
5123 }
5124 if sender.is_null() && type_0 as libc::c_int == 2 as libc::c_int {
5125 clusterProcessGossipSection(hdr, link);
5126 }
5127 clusterSendPing(link, 1 as libc::c_int);
5128 }
5129 if type_0 as libc::c_int == 0 as libc::c_int
5130 || type_0 as libc::c_int == 1 as libc::c_int
5131 || type_0 as libc::c_int == 2 as libc::c_int
5132 {
5133 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5134 _serverLog(
5135 0 as libc::c_int,
5136 b"%s packet received: %.40s\0" as *const u8 as *const libc::c_char,
5137 clusterGetMessageTypeString(type_0 as libc::c_int),
5138 if !((*link).node).is_null() {
5139 ((*(*link).node).name).as_mut_ptr() as *const libc::c_char
5140 } else {
5141 b"NULL\0" as *const u8 as *const libc::c_char
5142 },
5143 );
5144 }
5145 if (*link).inbound == 0 {
5146 if (*(*link).node).flags & 32 as libc::c_int != 0 {
5147 if !sender.is_null() {
5148 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5149 _serverLog(
5150 1 as libc::c_int,
5151 b"Handshake: we already know node %.40s, updating the address if needed.\0"
5152 as *const u8 as *const libc::c_char,
5153 ((*sender).name).as_mut_ptr(),
5154 );
5155 }
5156 if nodeUpdateAddressIfNeeded(sender, link, hdr) != 0 {
5157 clusterDoBeforeSleep(
5158 (1 as libc::c_int) << 2 as libc::c_int
5159 | (1 as libc::c_int) << 1 as libc::c_int,
5160 );
5161 }
5162 clusterDelNode((*link).node);
5163 return 0 as libc::c_int;
5164 }
5165 clusterRenameNode((*link).node, ((*hdr).sender).as_mut_ptr());
5166 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5167 _serverLog(
5168 0 as libc::c_int,
5169 b"Handshake with node %.40s completed.\0" as *const u8
5170 as *const libc::c_char,
5171 ((*(*link).node).name).as_mut_ptr(),
5172 );
5173 }
5174 (*(*link).node).flags &= !(32 as libc::c_int);
5175 (*(*link).node).flags
5176 |= flags as libc::c_int & (1 as libc::c_int | 2 as libc::c_int);
5177 clusterDoBeforeSleep((1 as libc::c_int) << 2 as libc::c_int);
5178 } else if memcmp(
5179 ((*(*link).node).name).as_mut_ptr() as *const libc::c_void,
5180 ((*hdr).sender).as_mut_ptr() as *const libc::c_void,
5181 40 as libc::c_int as libc::c_ulong,
5182 ) != 0 as libc::c_int
5183 {
5184 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5185 _serverLog(
5186 0 as libc::c_int,
5187 b"PONG contains mismatching sender ID. About node %.40s added %d ms ago, having flags %d\0"
5188 as *const u8 as *const libc::c_char,
5189 ((*(*link).node).name).as_mut_ptr(),
5190 (now - (*(*link).node).ctime) as libc::c_int,
5191 (*(*link).node).flags,
5192 );
5193 }
5194 (*(*link).node).flags |= 64 as libc::c_int;
5195 (*(*link).node)
5196 .ip[0 as libc::c_int as usize] = '\0' as i32 as libc::c_char;
5197 (*(*link).node).port = 0 as libc::c_int;
5198 (*(*link).node).pport = 0 as libc::c_int;
5199 (*(*link).node).cport = 0 as libc::c_int;
5200 freeClusterLink(link);
5201 clusterDoBeforeSleep((1 as libc::c_int) << 2 as libc::c_int);
5202 return 0 as libc::c_int;
5203 }
5204 }
5205 if !sender.is_null() {
5206 let mut nofailover: libc::c_int = flags as libc::c_int & 512 as libc::c_int;
5207 (*sender).flags &= !(512 as libc::c_int);
5208 (*sender).flags |= nofailover;
5209 }
5210 if !sender.is_null() && type_0 as libc::c_int == 0 as libc::c_int
5211 && (*sender).flags & 32 as libc::c_int == 0
5212 && nodeUpdateAddressIfNeeded(sender, link, hdr) != 0
5213 {
5214 clusterDoBeforeSleep(
5215 (1 as libc::c_int) << 2 as libc::c_int
5216 | (1 as libc::c_int) << 1 as libc::c_int,
5217 );
5218 }
5219 if (*link).inbound == 0 && type_0 as libc::c_int == 1 as libc::c_int {
5220 (*(*link).node).pong_received = now;
5221 (*(*link).node).ping_sent = 0 as libc::c_int as mstime_t;
5222 if (*(*link).node).flags & 4 as libc::c_int != 0 {
5223 (*(*link).node).flags &= !(4 as libc::c_int);
5224 clusterDoBeforeSleep(
5225 (1 as libc::c_int) << 2 as libc::c_int
5226 | (1 as libc::c_int) << 1 as libc::c_int,
5227 );
5228 } else if (*(*link).node).flags & 8 as libc::c_int != 0 {
5229 clearNodeFailureIfNeeded((*link).node);
5230 }
5231 }
5232 if !sender.is_null() {
5233 if memcmp(
5234 ((*hdr).slaveof).as_mut_ptr() as *const libc::c_void,
5235 b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
5236 as *const u8 as *const libc::c_char as *const libc::c_void,
5237 core::mem::size_of::<[libc::c_char; 40]>() as libc::c_ulong,
5238 ) == 0
5239 {
5240 clusterSetNodeAsMaster(sender);
5241 } else {
5242 let mut master: *mut clusterNode = clusterLookupNode(
5243 ((*hdr).slaveof).as_mut_ptr(),
5244 40 as libc::c_int,
5245 );
5246 if (*sender).flags & 1 as libc::c_int != 0 {
5247 clusterDelNodeSlots(sender);
5248 (*sender).flags &= !(1 as libc::c_int | 256 as libc::c_int);
5249 (*sender).flags |= 2 as libc::c_int;
5250 clusterDoBeforeSleep(
5251 (1 as libc::c_int) << 2 as libc::c_int
5252 | (1 as libc::c_int) << 1 as libc::c_int,
5253 );
5254 }
5255 if !master.is_null() && (*sender).slaveof != master {
5256 if !((*sender).slaveof).is_null() {
5257 clusterNodeRemoveSlave((*sender).slaveof, sender);
5258 }
5259 clusterNodeAddSlave(master, sender);
5260 (*sender).slaveof = master;
5261 clusterDoBeforeSleep((1 as libc::c_int) << 2 as libc::c_int);
5262 }
5263 }
5264 }
5265 let mut sender_master: *mut clusterNode = 0 as *mut clusterNode;
5266 let mut dirty_slots: libc::c_int = 0 as libc::c_int;
5267 if !sender.is_null() {
5268 sender_master = if (*sender).flags & 1 as libc::c_int != 0 {
5269 sender
5270 } else {
5271 (*sender).slaveof
5272 };
5273 if !sender_master.is_null() {
5274 dirty_slots = (memcmp(
5275 ((*sender_master).slots).as_mut_ptr() as *const libc::c_void,
5276 ((*hdr).myslots).as_mut_ptr() as *const libc::c_void,
5277 core::mem::size_of::<[libc::c_uchar; 2048]>() as libc::c_ulong,
5278 ) != 0 as libc::c_int) as libc::c_int;
5279 }
5280 }
5281 if !sender.is_null() && (*sender).flags & 1 as libc::c_int != 0
5282 && dirty_slots != 0
5283 {
5284 clusterUpdateSlotsConfigWith(
5285 sender,
5286 senderConfigEpoch,
5287 ((*hdr).myslots).as_mut_ptr(),
5288 );
5289 }
5290 if !sender.is_null() && dirty_slots != 0 {
5291 let mut j: libc::c_int = 0;
5292 j = 0 as libc::c_int;
5293 while j < 16384 as libc::c_int {
5294 if bitmapTestBit(((*hdr).myslots).as_mut_ptr(), j) != 0 {
5295 if !((*server.cluster).slots[j as usize] == sender
5296 || ((*server.cluster).slots[j as usize]).is_null())
5297 {
5298 if (*(*server.cluster).slots[j as usize]).configEpoch
5299 > senderConfigEpoch
5300 {
5301 if !((1 as libc::c_int & 0xff as libc::c_int)
5302 < server.verbosity)
5303 {
5304 _serverLog(
5305 1 as libc::c_int,
5306 b"Node %.40s has old slots configuration, sending an UPDATE message about %.40s\0"
5307 as *const u8 as *const libc::c_char,
5308 ((*sender).name).as_mut_ptr(),
5309 ((*(*server.cluster).slots[j as usize]).name).as_mut_ptr(),
5310 );
5311 }
5312 clusterSendUpdate(
5313 (*sender).link,
5314 (*server.cluster).slots[j as usize],
5315 );
5316 break;
5317 }
5318 }
5319 }
5320 j += 1;
5321 }
5322 }
5323 if !sender.is_null() && (*myself).flags & 1 as libc::c_int != 0
5324 && (*sender).flags & 1 as libc::c_int != 0
5325 && senderConfigEpoch == (*myself).configEpoch
5326 {
5327 clusterHandleConfigEpochCollision(sender);
5328 }
5329 if !sender.is_null() {
5330 clusterProcessGossipSection(hdr, link);
5331 clusterProcessPingExtensions(hdr, link);
5332 }
5333 } else if type_0 as libc::c_int == 3 as libc::c_int {
5334 let mut failing: *mut clusterNode = 0 as *mut clusterNode;
5335 if !sender.is_null() {
5336 failing = clusterLookupNode(
5337 ((*hdr).data.fail.about.nodename).as_mut_ptr(),
5338 40 as libc::c_int,
5339 );
5340 if !failing.is_null()
5341 && (*failing).flags & (8 as libc::c_int | 16 as libc::c_int) == 0
5342 {
5343 if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5344 _serverLog(
5345 2 as libc::c_int,
5346 b"FAIL message received from %.40s about %.40s\0" as *const u8
5347 as *const libc::c_char,
5348 ((*hdr).sender).as_mut_ptr(),
5349 ((*hdr).data.fail.about.nodename).as_mut_ptr(),
5350 );
5351 }
5352 (*failing).flags |= 8 as libc::c_int;
5353 (*failing).fail_time = now;
5354 (*failing).flags &= !(4 as libc::c_int);
5355 clusterDoBeforeSleep(
5356 (1 as libc::c_int) << 2 as libc::c_int
5357 | (1 as libc::c_int) << 1 as libc::c_int,
5358 );
5359 }
5360 } else if !((2 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5361 _serverLog(
5362 2 as libc::c_int,
5363 b"Ignoring FAIL message from unknown node %.40s about %.40s\0"
5364 as *const u8 as *const libc::c_char,
5365 ((*hdr).sender).as_mut_ptr(),
5366 ((*hdr).data.fail.about.nodename).as_mut_ptr(),
5367 );
5368 }
5369 } else if type_0 as libc::c_int == 4 as libc::c_int
5370 || type_0 as libc::c_int == 10 as libc::c_int
5371 {
5372 if sender.is_null() {
5373 return 1 as libc::c_int;
5374 }
5375 let mut channel: *mut robj = 0 as *mut robj;
5376 let mut message: *mut robj = 0 as *mut robj;
5377 let mut channel_len: uint32_t = 0;
5378 let mut message_len: uint32_t = 0;
5379 if type_0 as libc::c_int == 4 as libc::c_int
5380 && serverPubsubSubscriptionCount() > 0 as libc::c_int
5381 || type_0 as libc::c_int == 10 as libc::c_int
5382 && serverPubsubShardSubscriptionCount() > 0 as libc::c_int
5383 {
5384 channel_len = __bswap_32((*hdr).data.publish.msg.channel_len);
5385 message_len = __bswap_32((*hdr).data.publish.msg.message_len);
5386 channel = createStringObject(
5387 ((*hdr).data.publish.msg.bulk_data).as_mut_ptr() as *mut libc::c_char,
5388 channel_len as size_t,
5389 );
5390 message = createStringObject(
5391 (((*hdr).data.publish.msg.bulk_data).as_mut_ptr() as *mut libc::c_char)
5392 .offset(channel_len as isize),
5393 message_len as size_t,
5394 );
5395 pubsubPublishMessage(
5396 channel,
5397 message,
5398 (type_0 as libc::c_int == 10 as libc::c_int) as libc::c_int,
5399 );
5400 decrRefCount(channel);
5401 decrRefCount(message);
5402 }
5403 } else if type_0 as libc::c_int == 5 as libc::c_int {
5404 if sender.is_null() {
5405 return 1 as libc::c_int;
5406 }
5407 clusterSendFailoverAuthIfNeeded(sender, hdr);
5408 } else if type_0 as libc::c_int == 6 as libc::c_int {
5409 if sender.is_null() {
5410 return 1 as libc::c_int;
5411 }
5412 if (*sender).flags & 1 as libc::c_int != 0
5413 && (*sender).numslots > 0 as libc::c_int
5414 && senderCurrentEpoch >= (*server.cluster).failover_auth_epoch
5415 {
5416 (*server.cluster).failover_auth_count += 1;
5417 clusterDoBeforeSleep((1 as libc::c_int) << 0 as libc::c_int);
5418 }
5419 } else if type_0 as libc::c_int == 8 as libc::c_int {
5420 if sender.is_null() || (*sender).slaveof != myself {
5421 return 1 as libc::c_int;
5422 }
5423 resetManualFailover();
5424 (*server.cluster).mf_end = now + 5000 as libc::c_int as libc::c_longlong;
5425 (*server.cluster).mf_slave = sender;
5426 pauseClients(
5427 PAUSE_DURING_FAILOVER,
5428 now + (5000 as libc::c_int * 2 as libc::c_int) as libc::c_longlong,
5429 CLIENT_PAUSE_WRITE,
5430 );
5431 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5432 _serverLog(
5433 3 as libc::c_int,
5434 b"Manual failover requested by replica %.40s.\0" as *const u8
5435 as *const libc::c_char,
5436 ((*sender).name).as_mut_ptr(),
5437 );
5438 }
5439 clusterSendPing(link, 0 as libc::c_int);
5440 } else if type_0 as libc::c_int == 7 as libc::c_int {
5441 let mut n: *mut clusterNode = 0 as *mut clusterNode;
5442 let mut reportedConfigEpoch: uint64_t = intrev64(
5443 (*hdr).data.update.nodecfg.configEpoch,
5444 );
5445 if sender.is_null() {
5446 return 1 as libc::c_int;
5447 }
5448 n = clusterLookupNode(
5449 ((*hdr).data.update.nodecfg.nodename).as_mut_ptr(),
5450 40 as libc::c_int,
5451 );
5452 if n.is_null() {
5453 return 1 as libc::c_int;
5454 }
5455 if (*n).configEpoch >= reportedConfigEpoch {
5456 return 1 as libc::c_int;
5457 }
5458 if (*n).flags & 2 as libc::c_int != 0 {
5459 clusterSetNodeAsMaster(n);
5460 }
5461 (*n).configEpoch = reportedConfigEpoch;
5462 clusterDoBeforeSleep(
5463 (1 as libc::c_int) << 2 as libc::c_int
5464 | (1 as libc::c_int) << 3 as libc::c_int,
5465 );
5466 clusterUpdateSlotsConfigWith(
5467 n,
5468 reportedConfigEpoch,
5469 ((*hdr).data.update.nodecfg.slots).as_mut_ptr(),
5470 );
5471 } else if type_0 as libc::c_int == 9 as libc::c_int {
5472 if sender.is_null() {
5473 return 1 as libc::c_int;
5474 }
5475 let mut module_id: uint64_t = (*hdr).data.module.msg.module_id;
5476 let mut len: uint32_t = __bswap_32((*hdr).data.module.msg.len);
5477 let mut type_1: uint8_t = (*hdr).data.module.msg.type_0;
5478 let mut payload: *mut libc::c_uchar = ((*hdr).data.module.msg.bulk_data)
5479 .as_mut_ptr();
5480 moduleCallClusterReceivers(
5481 ((*sender).name).as_mut_ptr(),
5482 module_id,
5483 type_1,
5484 payload,
5485 len,
5486 );
5487 } else if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5488 _serverLog(
5489 3 as libc::c_int,
5490 b"Received unknown packet type: %d\0" as *const u8 as *const libc::c_char,
5491 type_0 as libc::c_int,
5492 );
5493 }
5494 return 1 as libc::c_int;
5495}
5496#[no_mangle]
5497pub unsafe extern "C" fn handleLinkIOError(mut link: *mut clusterLink) {
5498 freeClusterLink(link);
5499}
5500#[no_mangle]
5501pub unsafe extern "C" fn clusterWriteHandler(mut conn: *mut connection) {
5502 let mut link: *mut clusterLink = connGetPrivateData(conn) as *mut clusterLink;
5503 let mut nwritten: ssize_t = 0;
5504 nwritten = connWrite(
5505 conn,
5506 (*link).sndbuf as *const libc::c_void,
5507 sdslen((*link).sndbuf),
5508 ) as ssize_t;
5509 if nwritten <= 0 as libc::c_int as libc::c_long {
5510 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5511 _serverLog(
5512 0 as libc::c_int,
5513 b"I/O error writing to node link: %s\0" as *const u8
5514 as *const libc::c_char,
5515 if nwritten == -(1 as libc::c_int) as libc::c_long {
5516 connGetLastError(conn)
5517 } else {
5518 b"short write\0" as *const u8 as *const libc::c_char
5519 },
5520 );
5521 }
5522 handleLinkIOError(link);
5523 return;
5524 }
5525 sdsrange((*link).sndbuf, nwritten, -(1 as libc::c_int) as ssize_t);
5526 if sdslen((*link).sndbuf) == 0 as libc::c_int as libc::c_ulong {
5527 connSetWriteHandler((*link).conn, None);
5528 }
5529}
5530#[no_mangle]
5531pub unsafe extern "C" fn clusterLinkConnectHandler(mut conn: *mut connection) {
5532 let mut link: *mut clusterLink = connGetPrivateData(conn) as *mut clusterLink;
5533 let mut node: *mut clusterNode = (*link).node;
5534 if connGetState(conn) != CONN_STATE_CONNECTED as libc::c_int {
5535 if !((1 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5536 _serverLog(
5537 1 as libc::c_int,
5538 b"Connection with Node %.40s at %s:%d failed: %s\0" as *const u8
5539 as *const libc::c_char,
5540 ((*node).name).as_mut_ptr(),
5541 ((*node).ip).as_mut_ptr(),
5542 (*node).cport,
5543 connGetLastError(conn),
5544 );
5545 }
5546 freeClusterLink(link);
5547 return;
5548 }
5549 connSetReadHandler(
5550 conn,
5551 Some(clusterReadHandler as unsafe extern "C" fn(*mut connection) -> ()),
5552 );
5553 let mut old_ping_sent: mstime_t = (*node).ping_sent;
5554 clusterSendPing(
5555 link,
5556 if (*node).flags & 128 as libc::c_int != 0 {
5557 2 as libc::c_int
5558 } else {
5559 0 as libc::c_int
5560 },
5561 );
5562 if old_ping_sent != 0 {
5563 (*node).ping_sent = old_ping_sent;
5564 }
5565 (*node).flags &= !(128 as libc::c_int);
5566 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5567 _serverLog(
5568 0 as libc::c_int,
5569 b"Connecting with Node %.40s at %s:%d\0" as *const u8 as *const libc::c_char,
5570 ((*node).name).as_mut_ptr(),
5571 ((*node).ip).as_mut_ptr(),
5572 (*node).cport,
5573 );
5574 }
5575}
5576#[no_mangle]
5577pub unsafe extern "C" fn clusterReadHandler(mut conn: *mut connection) {
5578 let mut buf: [clusterMsg; 1] = [clusterMsg {
5579 sig: [0; 4],
5580 totlen: 0,
5581 ver: 0,
5582 port: 0,
5583 type_0: 0,
5584 count: 0,
5585 currentEpoch: 0,
5586 configEpoch: 0,
5587 offset: 0,
5588 sender: [0; 40],
5589 myslots: [0; 2048],
5590 slaveof: [0; 40],
5591 myip: [0; 46],
5592 extensions: 0,
5593 notused1: [0; 30],
5594 pport: 0,
5595 cport: 0,
5596 flags: 0,
5597 state: 0,
5598 mflags: [0; 3],
5599 data: clusterMsgData {
5600 ping: C2RustUnnamed_19 {
5601 gossip: [clusterMsgDataGossip {
5602 nodename: [0; 40],
5603 ping_sent: 0,
5604 pong_received: 0,
5605 ip: [0; 46],
5606 port: 0,
5607 cport: 0,
5608 flags: 0,
5609 pport: 0,
5610 notused1: 0,
5611 }; 1],
5612 },
5613 },
5614 }; 1];
5615 let mut nread: ssize_t = 0;
5616 let mut hdr: *mut clusterMsg = 0 as *mut clusterMsg;
5617 let mut link: *mut clusterLink = connGetPrivateData(conn) as *mut clusterLink;
5618 let mut readlen: libc::c_uint = 0;
5619 let mut rcvbuflen: libc::c_uint = 0;
5620 loop {
5621 rcvbuflen = (*link).rcvbuf_len as libc::c_uint;
5622 if rcvbuflen < 8 as libc::c_int as libc::c_uint {
5623 readlen = (8 as libc::c_int as libc::c_uint).wrapping_sub(rcvbuflen);
5624 } else {
5625 hdr = (*link).rcvbuf as *mut clusterMsg;
5626 if rcvbuflen == 8 as libc::c_int as libc::c_uint {
5627 if memcmp(
5628 ((*hdr).sig).as_mut_ptr() as *const libc::c_void,
5629 b"RCmb\0" as *const u8 as *const libc::c_char as *const libc::c_void,
5630 4 as libc::c_int as libc::c_ulong,
5631 ) != 0 as libc::c_int
5632 || (__bswap_32((*hdr).totlen) as libc::c_ulong)
5633 < (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
5634 .wrapping_sub(
5635 core::mem::size_of::<clusterMsgData>() as libc::c_ulong,
5636 )
5637 {
5638 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5639 _serverLog(
5640 3 as libc::c_int,
5641 b"Bad message length or signature received from Cluster bus.\0"
5642 as *const u8 as *const libc::c_char,
5643 );
5644 }
5645 handleLinkIOError(link);
5646 return;
5647 }
5648 }
5649 readlen = (__bswap_32((*hdr).totlen)).wrapping_sub(rcvbuflen);
5650 if readlen as libc::c_ulong
5651 > core::mem::size_of::<[clusterMsg; 1]>() as libc::c_ulong
5652 {
5653 readlen = core::mem::size_of::<[clusterMsg; 1]>() as libc::c_ulong
5654 as libc::c_uint;
5655 }
5656 }
5657 nread = connRead(conn, buf.as_mut_ptr() as *mut libc::c_void, readlen as size_t)
5658 as ssize_t;
5659 if nread == -(1 as libc::c_int) as libc::c_long
5660 && connGetState(conn) == CONN_STATE_CONNECTED as libc::c_int
5661 {
5662 return;
5663 }
5664 if nread <= 0 as libc::c_int as libc::c_long {
5665 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
5666 _serverLog(
5667 0 as libc::c_int,
5668 b"I/O error reading from node link: %s\0" as *const u8
5669 as *const libc::c_char,
5670 if nread == 0 as libc::c_int as libc::c_long {
5671 b"connection closed\0" as *const u8 as *const libc::c_char
5672 } else {
5673 connGetLastError(conn)
5674 },
5675 );
5676 }
5677 handleLinkIOError(link);
5678 return;
5679 } else {
5680 let mut unused: size_t = ((*link).rcvbuf_alloc)
5681 .wrapping_sub((*link).rcvbuf_len);
5682 if nread as size_t > unused {
5683 let mut required: size_t = ((*link).rcvbuf_len)
5684 .wrapping_add(nread as libc::c_ulong);
5685 (*link)
5686 .rcvbuf_alloc = if required
5687 < ((1 as libc::c_int) << 20 as libc::c_int) as libc::c_ulong
5688 {
5689 required.wrapping_mul(2 as libc::c_int as libc::c_ulong)
5690 } else {
5691 required
5692 .wrapping_add(
5693 ((1 as libc::c_int) << 20 as libc::c_int) as libc::c_ulong,
5694 )
5695 };
5696 (*link)
5697 .rcvbuf = zrealloc(
5698 (*link).rcvbuf as *mut libc::c_void,
5699 (*link).rcvbuf_alloc,
5700 ) as *mut libc::c_char;
5701 }
5702 memcpy(
5703 ((*link).rcvbuf).offset((*link).rcvbuf_len as isize)
5704 as *mut libc::c_void,
5705 buf.as_mut_ptr() as *const libc::c_void,
5706 nread as libc::c_ulong,
5707 );
5708 (*link)
5709 .rcvbuf_len = ((*link).rcvbuf_len as libc::c_ulong)
5710 .wrapping_add(nread as libc::c_ulong) as size_t as size_t;
5711 hdr = (*link).rcvbuf as *mut clusterMsg;
5712 rcvbuflen = (rcvbuflen as libc::c_long + nread) as libc::c_uint;
5713 }
5714 if rcvbuflen >= 8 as libc::c_int as libc::c_uint
5715 && rcvbuflen == __bswap_32((*hdr).totlen)
5716 {
5717 if clusterProcessPacket(link) != 0 {
5718 if (*link).rcvbuf_alloc > 1024 as libc::c_int as libc::c_ulong {
5719 zfree((*link).rcvbuf as *mut libc::c_void);
5720 (*link).rcvbuf_alloc = 1024 as libc::c_int as size_t;
5721 (*link).rcvbuf = zmalloc((*link).rcvbuf_alloc) as *mut libc::c_char;
5722 }
5723 (*link).rcvbuf_len = 0 as libc::c_int as size_t;
5724 } else {
5725 return
5726 }
5727 }
5728 };
5729}
5730#[no_mangle]
5731pub unsafe extern "C" fn clusterSendMessage(
5732 mut link: *mut clusterLink,
5733 mut msg: *mut libc::c_uchar,
5734 mut msglen: size_t,
5735) {
5736 if sdslen((*link).sndbuf) == 0 as libc::c_int as libc::c_ulong
5737 && msglen != 0 as libc::c_int as libc::c_ulong
5738 {
5739 connSetWriteHandlerWithBarrier(
5740 (*link).conn,
5741 Some(clusterWriteHandler as unsafe extern "C" fn(*mut connection) -> ()),
5742 1 as libc::c_int,
5743 );
5744 }
5745 (*link).sndbuf = sdscatlen((*link).sndbuf, msg as *const libc::c_void, msglen);
5746 let mut hdr: *mut clusterMsg = msg as *mut clusterMsg;
5747 let mut type_0: uint16_t = __bswap_16((*hdr).type_0);
5748 if (type_0 as libc::c_int) < 11 as libc::c_int {
5749 (*server.cluster).stats_bus_messages_sent[type_0 as usize] += 1;
5750 }
5751}
5752#[no_mangle]
5753pub unsafe extern "C" fn clusterBroadcastMessage(
5754 mut buf: *mut libc::c_void,
5755 mut len: size_t,
5756) {
5757 let mut di: *mut dictIterator = 0 as *mut dictIterator;
5758 let mut de: *mut dictEntry = 0 as *mut dictEntry;
5759 di = dictGetSafeIterator((*server.cluster).nodes);
5760 loop {
5761 de = dictNext(di);
5762 if de.is_null() {
5763 break;
5764 }
5765 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
5766 if ((*node).link).is_null() {
5767 continue;
5768 }
5769 if (*node).flags & (16 as libc::c_int | 32 as libc::c_int) != 0 {
5770 continue;
5771 }
5772 clusterSendMessage((*node).link, buf as *mut libc::c_uchar, len);
5773 }
5774 dictReleaseIterator(di);
5775}
5776#[no_mangle]
5777pub unsafe extern "C" fn clusterBuildMessageHdr(
5778 mut hdr: *mut clusterMsg,
5779 mut type_0: libc::c_int,
5780) {
5781 let mut totlen: libc::c_int = 0 as libc::c_int;
5782 let mut offset: uint64_t = 0;
5783 let mut master: *mut clusterNode = 0 as *mut clusterNode;
5784 master = if (*myself).flags & 2 as libc::c_int != 0 && !((*myself).slaveof).is_null()
5785 {
5786 (*myself).slaveof
5787 } else {
5788 myself
5789 };
5790 memset(
5791 hdr as *mut libc::c_void,
5792 0 as libc::c_int,
5793 core::mem::size_of::<clusterMsg>() as libc::c_ulong,
5794 );
5795 (*hdr).ver = __bswap_16(1 as libc::c_int as __uint16_t);
5796 (*hdr).sig[0 as libc::c_int as usize] = 'R' as i32 as libc::c_char;
5797 (*hdr).sig[1 as libc::c_int as usize] = 'C' as i32 as libc::c_char;
5798 (*hdr).sig[2 as libc::c_int as usize] = 'm' as i32 as libc::c_char;
5799 (*hdr).sig[3 as libc::c_int as usize] = 'b' as i32 as libc::c_char;
5800 (*hdr).type_0 = __bswap_16(type_0 as __uint16_t);
5801 memcpy(
5802 ((*hdr).sender).as_mut_ptr() as *mut libc::c_void,
5803 ((*myself).name).as_mut_ptr() as *const libc::c_void,
5804 40 as libc::c_int as libc::c_ulong,
5805 );
5806 memset(
5807 ((*hdr).myip).as_mut_ptr() as *mut libc::c_void,
5808 0 as libc::c_int,
5809 46 as libc::c_int as libc::c_ulong,
5810 );
5811 if !(server.cluster_announce_ip).is_null() {
5812 strncpy(
5813 ((*hdr).myip).as_mut_ptr(),
5814 server.cluster_announce_ip,
5815 (46 as libc::c_int - 1 as libc::c_int) as libc::c_ulong,
5816 );
5817 (*hdr)
5818 .myip[(46 as libc::c_int - 1 as libc::c_int)
5819 as usize] = '\0' as i32 as libc::c_char;
5820 }
5821 let mut announced_port: libc::c_int = 0;
5822 let mut announced_pport: libc::c_int = 0;
5823 let mut announced_cport: libc::c_int = 0;
5824 deriveAnnouncedPorts(
5825 &mut announced_port,
5826 &mut announced_pport,
5827 &mut announced_cport,
5828 );
5829 memcpy(
5830 ((*hdr).myslots).as_mut_ptr() as *mut libc::c_void,
5831 ((*master).slots).as_mut_ptr() as *const libc::c_void,
5832 core::mem::size_of::<[libc::c_uchar; 2048]>() as libc::c_ulong,
5833 );
5834 memset(
5835 ((*hdr).slaveof).as_mut_ptr() as *mut libc::c_void,
5836 0 as libc::c_int,
5837 40 as libc::c_int as libc::c_ulong,
5838 );
5839 if !((*myself).slaveof).is_null() {
5840 memcpy(
5841 ((*hdr).slaveof).as_mut_ptr() as *mut libc::c_void,
5842 ((*(*myself).slaveof).name).as_mut_ptr() as *const libc::c_void,
5843 40 as libc::c_int as libc::c_ulong,
5844 );
5845 }
5846 (*hdr).port = __bswap_16(announced_port as __uint16_t);
5847 (*hdr).pport = __bswap_16(announced_pport as __uint16_t);
5848 (*hdr).cport = __bswap_16(announced_cport as __uint16_t);
5849 (*hdr).flags = __bswap_16((*myself).flags as __uint16_t);
5850 (*hdr).state = (*server.cluster).state as libc::c_uchar;
5851 (*hdr).currentEpoch = intrev64((*server.cluster).currentEpoch);
5852 (*hdr).configEpoch = intrev64((*master).configEpoch);
5853 if (*myself).flags & 2 as libc::c_int != 0 {
5854 offset = replicationGetSlaveOffset() as uint64_t;
5855 } else {
5856 offset = server.master_repl_offset as uint64_t;
5857 }
5858 (*hdr).offset = intrev64(offset);
5859 if (*myself).flags & 1 as libc::c_int != 0 && (*server.cluster).mf_end != 0 {
5860 (*hdr)
5861 .mflags[0 as libc::c_int
5862 as usize] = ((*hdr).mflags[0 as libc::c_int as usize] as libc::c_int
5863 | (1 as libc::c_int) << 0 as libc::c_int) as libc::c_uchar;
5864 }
5865 if type_0 == 3 as libc::c_int {
5866 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
5867 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
5868 as libc::c_int;
5869 totlen = (totlen as libc::c_ulong)
5870 .wrapping_add(core::mem::size_of::<clusterMsgDataFail>() as libc::c_ulong)
5871 as libc::c_int as libc::c_int;
5872 } else if type_0 == 7 as libc::c_int {
5873 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
5874 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
5875 as libc::c_int;
5876 totlen = (totlen as libc::c_ulong)
5877 .wrapping_add(
5878 core::mem::size_of::<clusterMsgDataUpdate>() as libc::c_ulong,
5879 ) as libc::c_int as libc::c_int;
5880 }
5881 (*hdr).totlen = __bswap_32(totlen as __uint32_t);
5882}
5883#[no_mangle]
5884pub unsafe extern "C" fn clusterSetGossipEntry(
5885 mut hdr: *mut clusterMsg,
5886 mut i: libc::c_int,
5887 mut n: *mut clusterNode,
5888) {
5889 let mut gossip: *mut clusterMsgDataGossip = 0 as *mut clusterMsgDataGossip;
5890 gossip = &mut *((*hdr).data.ping.gossip).as_mut_ptr().offset(i as isize)
5891 as *mut clusterMsgDataGossip;
5892 memcpy(
5893 ((*gossip).nodename).as_mut_ptr() as *mut libc::c_void,
5894 ((*n).name).as_mut_ptr() as *const libc::c_void,
5895 40 as libc::c_int as libc::c_ulong,
5896 );
5897 (*gossip)
5898 .ping_sent = __bswap_32(
5899 ((*n).ping_sent / 1000 as libc::c_int as libc::c_longlong) as __uint32_t,
5900 );
5901 (*gossip)
5902 .pong_received = __bswap_32(
5903 ((*n).pong_received / 1000 as libc::c_int as libc::c_longlong) as __uint32_t,
5904 );
5905 memcpy(
5906 ((*gossip).ip).as_mut_ptr() as *mut libc::c_void,
5907 ((*n).ip).as_mut_ptr() as *const libc::c_void,
5908 core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
5909 );
5910 (*gossip).port = __bswap_16((*n).port as __uint16_t);
5911 (*gossip).cport = __bswap_16((*n).cport as __uint16_t);
5912 (*gossip).flags = __bswap_16((*n).flags as __uint16_t);
5913 (*gossip).pport = __bswap_16((*n).pport as __uint16_t);
5914 (*gossip).notused1 = 0 as libc::c_int as uint16_t;
5915}
5916#[no_mangle]
5917pub unsafe extern "C" fn clusterSendPing(
5918 mut link: *mut clusterLink,
5919 mut type_0: libc::c_int,
5920) {
5921 static mut cluster_pings_sent: libc::c_ulonglong = 0 as libc::c_int
5922 as libc::c_ulonglong;
5923 cluster_pings_sent = cluster_pings_sent.wrapping_add(1);
5924 let mut buf: *mut libc::c_uchar = 0 as *mut libc::c_uchar;
5925 let mut hdr: *mut clusterMsg = 0 as *mut clusterMsg;
5926 let mut gossipcount: libc::c_int = 0 as libc::c_int;
5927 let mut wanted: libc::c_int = 0;
5928 let mut estlen: libc::c_int = 0;
5929 let mut freshnodes: libc::c_int = ((*(*server.cluster).nodes)
5930 .ht_used[0 as libc::c_int as usize])
5931 .wrapping_add((*(*server.cluster).nodes).ht_used[1 as libc::c_int as usize])
5932 .wrapping_sub(2 as libc::c_int as libc::c_ulong) as libc::c_int;
5933 wanted = floor(
5934 ((*(*server.cluster).nodes).ht_used[0 as libc::c_int as usize])
5935 .wrapping_add((*(*server.cluster).nodes).ht_used[1 as libc::c_int as usize])
5936 .wrapping_div(10 as libc::c_int as libc::c_ulong) as libc::c_double,
5937 ) as libc::c_int;
5938 if wanted < 3 as libc::c_int {
5939 wanted = 3 as libc::c_int;
5940 }
5941 if wanted > freshnodes {
5942 wanted = freshnodes;
5943 }
5944 let mut pfail_wanted: libc::c_int = (*server.cluster).stats_pfail_nodes
5945 as libc::c_int;
5946 estlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
5947 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
5948 as libc::c_int;
5949 estlen = (estlen as libc::c_ulong)
5950 .wrapping_add(
5951 (core::mem::size_of::<clusterMsgDataGossip>() as libc::c_ulong)
5952 .wrapping_mul((wanted + pfail_wanted) as libc::c_ulong),
5953 ) as libc::c_int as libc::c_int;
5954 estlen += getHostnamePingExtSize();
5955 if estlen < core::mem::size_of::<clusterMsg>() as libc::c_ulong as libc::c_int {
5956 estlen = core::mem::size_of::<clusterMsg>() as libc::c_ulong as libc::c_int;
5957 }
5958 buf = zcalloc(estlen as size_t) as *mut libc::c_uchar;
5959 hdr = buf as *mut clusterMsg;
5960 if (*link).inbound == 0 && type_0 == 0 as libc::c_int {
5961 (*(*link).node).ping_sent = mstime();
5962 }
5963 clusterBuildMessageHdr(hdr, type_0);
5964 let mut maxiterations: libc::c_int = wanted * 3 as libc::c_int;
5965 while freshnodes > 0 as libc::c_int && gossipcount < wanted
5966 && {
5967 let fresh7 = maxiterations;
5968 maxiterations = maxiterations - 1;
5969 fresh7 != 0
5970 }
5971 {
5972 let mut de: *mut dictEntry = dictGetRandomKey((*server.cluster).nodes);
5973 let mut this: *mut clusterNode = (*de).v.val as *mut clusterNode;
5974 if this == myself {
5975 continue;
5976 }
5977 if (*this).flags & 4 as libc::c_int != 0 {
5978 continue;
5979 }
5980 if (*this).flags & (32 as libc::c_int | 64 as libc::c_int) != 0
5981 || ((*this).link).is_null() && (*this).numslots == 0 as libc::c_int
5982 {
5983 freshnodes -= 1;
5984 } else {
5985 if (*this).last_in_ping_gossip == cluster_pings_sent {
5986 continue;
5987 }
5988 clusterSetGossipEntry(hdr, gossipcount, this);
5989 (*this).last_in_ping_gossip = cluster_pings_sent;
5990 freshnodes -= 1;
5991 gossipcount += 1;
5992 }
5993 }
5994 if pfail_wanted != 0 {
5995 let mut di: *mut dictIterator = 0 as *mut dictIterator;
5996 let mut de_0: *mut dictEntry = 0 as *mut dictEntry;
5997 di = dictGetSafeIterator((*server.cluster).nodes);
5998 loop {
5999 de_0 = dictNext(di);
6000 if !(!de_0.is_null() && pfail_wanted > 0 as libc::c_int) {
6001 break;
6002 }
6003 let mut node: *mut clusterNode = (*de_0).v.val as *mut clusterNode;
6004 if (*node).flags & 32 as libc::c_int != 0 {
6005 continue;
6006 }
6007 if (*node).flags & 64 as libc::c_int != 0 {
6008 continue;
6009 }
6010 if (*node).flags & 4 as libc::c_int == 0 {
6011 continue;
6012 }
6013 clusterSetGossipEntry(hdr, gossipcount, node);
6014 gossipcount += 1;
6015 pfail_wanted -= 1;
6016 }
6017 dictReleaseIterator(di);
6018 }
6019 let mut totlen: libc::c_int = 0 as libc::c_int;
6020 let mut extensions: libc::c_int = 0 as libc::c_int;
6021 let mut cursor: *mut clusterMsgPingExt = getInitialPingExt(
6022 hdr,
6023 gossipcount as uint16_t,
6024 );
6025 if sdslen((*myself).hostname) != 0 as libc::c_int as libc::c_ulong {
6026 (*hdr)
6027 .mflags[0 as libc::c_int
6028 as usize] = ((*hdr).mflags[0 as libc::c_int as usize] as libc::c_int
6029 | (1 as libc::c_int) << 2 as libc::c_int) as libc::c_uchar;
6030 totlen += writeHostnamePingExt(&mut cursor);
6031 extensions += 1;
6032 }
6033 totlen = (totlen as libc::c_ulong)
6034 .wrapping_add(
6035 (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
6036 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong),
6037 ) as libc::c_int as libc::c_int;
6038 totlen = (totlen as libc::c_ulong)
6039 .wrapping_add(
6040 (core::mem::size_of::<clusterMsgDataGossip>() as libc::c_ulong)
6041 .wrapping_mul(gossipcount as libc::c_ulong),
6042 ) as libc::c_int as libc::c_int;
6043 (*hdr).count = __bswap_16(gossipcount as __uint16_t);
6044 (*hdr).extensions = __bswap_16(extensions as __uint16_t);
6045 (*hdr).totlen = __bswap_32(totlen as __uint32_t);
6046 clusterSendMessage(link, buf, totlen as size_t);
6047 zfree(buf as *mut libc::c_void);
6048}
6049#[no_mangle]
6050pub unsafe extern "C" fn clusterBroadcastPong(mut target: libc::c_int) {
6051 let mut di: *mut dictIterator = 0 as *mut dictIterator;
6052 let mut de: *mut dictEntry = 0 as *mut dictEntry;
6053 di = dictGetSafeIterator((*server.cluster).nodes);
6054 loop {
6055 de = dictNext(di);
6056 if de.is_null() {
6057 break;
6058 }
6059 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
6060 if ((*node).link).is_null() {
6061 continue;
6062 }
6063 if node == myself || (*node).flags & 32 as libc::c_int != 0 {
6064 continue;
6065 }
6066 if target == 1 as libc::c_int {
6067 let mut local_slave: libc::c_int = ((*node).flags & 2 as libc::c_int != 0
6068 && !((*node).slaveof).is_null()
6069 && ((*node).slaveof == myself || (*node).slaveof == (*myself).slaveof))
6070 as libc::c_int;
6071 if local_slave == 0 {
6072 continue;
6073 }
6074 }
6075 clusterSendPing((*node).link, 1 as libc::c_int);
6076 }
6077 dictReleaseIterator(di);
6078}
6079#[no_mangle]
6080pub unsafe extern "C" fn clusterSendPublish(
6081 mut link: *mut clusterLink,
6082 mut channel: *mut robj,
6083 mut message: *mut robj,
6084 mut type_0: uint16_t,
6085) {
6086 let mut payload: *mut libc::c_uchar = 0 as *mut libc::c_uchar;
6087 let mut buf: [clusterMsg; 1] = [clusterMsg {
6088 sig: [0; 4],
6089 totlen: 0,
6090 ver: 0,
6091 port: 0,
6092 type_0: 0,
6093 count: 0,
6094 currentEpoch: 0,
6095 configEpoch: 0,
6096 offset: 0,
6097 sender: [0; 40],
6098 myslots: [0; 2048],
6099 slaveof: [0; 40],
6100 myip: [0; 46],
6101 extensions: 0,
6102 notused1: [0; 30],
6103 pport: 0,
6104 cport: 0,
6105 flags: 0,
6106 state: 0,
6107 mflags: [0; 3],
6108 data: clusterMsgData {
6109 ping: C2RustUnnamed_19 {
6110 gossip: [clusterMsgDataGossip {
6111 nodename: [0; 40],
6112 ping_sent: 0,
6113 pong_received: 0,
6114 ip: [0; 46],
6115 port: 0,
6116 cport: 0,
6117 flags: 0,
6118 pport: 0,
6119 notused1: 0,
6120 }; 1],
6121 },
6122 },
6123 }; 1];
6124 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6125 let mut totlen: uint32_t = 0;
6126 let mut channel_len: uint32_t = 0;
6127 let mut message_len: uint32_t = 0;
6128 channel = getDecodedObject(channel);
6129 message = getDecodedObject(message);
6130 channel_len = sdslen((*channel).ptr as sds) as uint32_t;
6131 message_len = sdslen((*message).ptr as sds) as uint32_t;
6132 clusterBuildMessageHdr(hdr, type_0 as libc::c_int);
6133 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
6134 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
6135 as uint32_t;
6136 totlen = (totlen as libc::c_ulong)
6137 .wrapping_add(
6138 (core::mem::size_of::<clusterMsgDataPublish>() as libc::c_ulong)
6139 .wrapping_sub(8 as libc::c_int as libc::c_ulong)
6140 .wrapping_add(channel_len as libc::c_ulong)
6141 .wrapping_add(message_len as libc::c_ulong),
6142 ) as uint32_t as uint32_t;
6143 (*hdr).data.publish.msg.channel_len = __bswap_32(channel_len);
6144 (*hdr).data.publish.msg.message_len = __bswap_32(message_len);
6145 (*hdr).totlen = __bswap_32(totlen);
6146 if (totlen as libc::c_ulong)
6147 < core::mem::size_of::<[clusterMsg; 1]>() as libc::c_ulong
6148 {
6149 payload = buf.as_mut_ptr() as *mut libc::c_uchar;
6150 } else {
6151 payload = zmalloc(totlen as size_t) as *mut libc::c_uchar;
6152 memcpy(
6153 payload as *mut libc::c_void,
6154 hdr as *const libc::c_void,
6155 core::mem::size_of::<clusterMsg>() as libc::c_ulong,
6156 );
6157 hdr = payload as *mut clusterMsg;
6158 }
6159 memcpy(
6160 ((*hdr).data.publish.msg.bulk_data).as_mut_ptr() as *mut libc::c_void,
6161 (*channel).ptr,
6162 sdslen((*channel).ptr as sds),
6163 );
6164 memcpy(
6165 ((*hdr).data.publish.msg.bulk_data)
6166 .as_mut_ptr()
6167 .offset(sdslen((*channel).ptr as sds) as isize) as *mut libc::c_void,
6168 (*message).ptr,
6169 sdslen((*message).ptr as sds),
6170 );
6171 if !link.is_null() {
6172 clusterSendMessage(link, payload, totlen as size_t);
6173 } else {
6174 clusterBroadcastMessage(payload as *mut libc::c_void, totlen as size_t);
6175 }
6176 decrRefCount(channel);
6177 decrRefCount(message);
6178 if payload != buf.as_mut_ptr() as *mut libc::c_uchar {
6179 zfree(payload as *mut libc::c_void);
6180 }
6181}
6182#[no_mangle]
6183pub unsafe extern "C" fn clusterSendFail(mut nodename: *mut libc::c_char) {
6184 let mut buf: [clusterMsg; 1] = [clusterMsg {
6185 sig: [0; 4],
6186 totlen: 0,
6187 ver: 0,
6188 port: 0,
6189 type_0: 0,
6190 count: 0,
6191 currentEpoch: 0,
6192 configEpoch: 0,
6193 offset: 0,
6194 sender: [0; 40],
6195 myslots: [0; 2048],
6196 slaveof: [0; 40],
6197 myip: [0; 46],
6198 extensions: 0,
6199 notused1: [0; 30],
6200 pport: 0,
6201 cport: 0,
6202 flags: 0,
6203 state: 0,
6204 mflags: [0; 3],
6205 data: clusterMsgData {
6206 ping: C2RustUnnamed_19 {
6207 gossip: [clusterMsgDataGossip {
6208 nodename: [0; 40],
6209 ping_sent: 0,
6210 pong_received: 0,
6211 ip: [0; 46],
6212 port: 0,
6213 cport: 0,
6214 flags: 0,
6215 pport: 0,
6216 notused1: 0,
6217 }; 1],
6218 },
6219 },
6220 }; 1];
6221 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6222 clusterBuildMessageHdr(hdr, 3 as libc::c_int);
6223 memcpy(
6224 ((*hdr).data.fail.about.nodename).as_mut_ptr() as *mut libc::c_void,
6225 nodename as *const libc::c_void,
6226 40 as libc::c_int as libc::c_ulong,
6227 );
6228 clusterBroadcastMessage(
6229 buf.as_mut_ptr() as *mut libc::c_void,
6230 __bswap_32((*hdr).totlen) as size_t,
6231 );
6232}
6233#[no_mangle]
6234pub unsafe extern "C" fn clusterSendUpdate(
6235 mut link: *mut clusterLink,
6236 mut node: *mut clusterNode,
6237) {
6238 let mut buf: [clusterMsg; 1] = [clusterMsg {
6239 sig: [0; 4],
6240 totlen: 0,
6241 ver: 0,
6242 port: 0,
6243 type_0: 0,
6244 count: 0,
6245 currentEpoch: 0,
6246 configEpoch: 0,
6247 offset: 0,
6248 sender: [0; 40],
6249 myslots: [0; 2048],
6250 slaveof: [0; 40],
6251 myip: [0; 46],
6252 extensions: 0,
6253 notused1: [0; 30],
6254 pport: 0,
6255 cport: 0,
6256 flags: 0,
6257 state: 0,
6258 mflags: [0; 3],
6259 data: clusterMsgData {
6260 ping: C2RustUnnamed_19 {
6261 gossip: [clusterMsgDataGossip {
6262 nodename: [0; 40],
6263 ping_sent: 0,
6264 pong_received: 0,
6265 ip: [0; 46],
6266 port: 0,
6267 cport: 0,
6268 flags: 0,
6269 pport: 0,
6270 notused1: 0,
6271 }; 1],
6272 },
6273 },
6274 }; 1];
6275 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6276 if link.is_null() {
6277 return;
6278 }
6279 clusterBuildMessageHdr(hdr, 7 as libc::c_int);
6280 memcpy(
6281 ((*hdr).data.update.nodecfg.nodename).as_mut_ptr() as *mut libc::c_void,
6282 ((*node).name).as_mut_ptr() as *const libc::c_void,
6283 40 as libc::c_int as libc::c_ulong,
6284 );
6285 (*hdr).data.update.nodecfg.configEpoch = intrev64((*node).configEpoch);
6286 memcpy(
6287 ((*hdr).data.update.nodecfg.slots).as_mut_ptr() as *mut libc::c_void,
6288 ((*node).slots).as_mut_ptr() as *const libc::c_void,
6289 core::mem::size_of::<[libc::c_uchar; 2048]>() as libc::c_ulong,
6290 );
6291 clusterSendMessage(
6292 link,
6293 buf.as_mut_ptr() as *mut libc::c_uchar,
6294 __bswap_32((*hdr).totlen) as size_t,
6295 );
6296}
6297#[no_mangle]
6298pub unsafe extern "C" fn clusterSendModule(
6299 mut link: *mut clusterLink,
6300 mut module_id: uint64_t,
6301 mut type_0: uint8_t,
6302 mut payload: *const libc::c_char,
6303 mut len: uint32_t,
6304) {
6305 let mut heapbuf: *mut libc::c_uchar = 0 as *mut libc::c_uchar;
6306 let mut buf: [clusterMsg; 1] = [clusterMsg {
6307 sig: [0; 4],
6308 totlen: 0,
6309 ver: 0,
6310 port: 0,
6311 type_0: 0,
6312 count: 0,
6313 currentEpoch: 0,
6314 configEpoch: 0,
6315 offset: 0,
6316 sender: [0; 40],
6317 myslots: [0; 2048],
6318 slaveof: [0; 40],
6319 myip: [0; 46],
6320 extensions: 0,
6321 notused1: [0; 30],
6322 pport: 0,
6323 cport: 0,
6324 flags: 0,
6325 state: 0,
6326 mflags: [0; 3],
6327 data: clusterMsgData {
6328 ping: C2RustUnnamed_19 {
6329 gossip: [clusterMsgDataGossip {
6330 nodename: [0; 40],
6331 ping_sent: 0,
6332 pong_received: 0,
6333 ip: [0; 46],
6334 port: 0,
6335 cport: 0,
6336 flags: 0,
6337 pport: 0,
6338 notused1: 0,
6339 }; 1],
6340 },
6341 },
6342 }; 1];
6343 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6344 let mut totlen: uint32_t = 0;
6345 clusterBuildMessageHdr(hdr, 9 as libc::c_int);
6346 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
6347 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
6348 as uint32_t;
6349 totlen = (totlen as libc::c_ulong)
6350 .wrapping_add(
6351 (core::mem::size_of::<clusterMsgModule>() as libc::c_ulong)
6352 .wrapping_sub(3 as libc::c_int as libc::c_ulong)
6353 .wrapping_add(len as libc::c_ulong),
6354 ) as uint32_t as uint32_t;
6355 (*hdr).data.module.msg.module_id = module_id;
6356 (*hdr).data.module.msg.type_0 = type_0;
6357 (*hdr).data.module.msg.len = __bswap_32(len);
6358 (*hdr).totlen = __bswap_32(totlen);
6359 if (totlen as libc::c_ulong)
6360 < core::mem::size_of::<[clusterMsg; 1]>() as libc::c_ulong
6361 {
6362 heapbuf = buf.as_mut_ptr() as *mut libc::c_uchar;
6363 } else {
6364 heapbuf = zmalloc(totlen as size_t) as *mut libc::c_uchar;
6365 memcpy(
6366 heapbuf as *mut libc::c_void,
6367 hdr as *const libc::c_void,
6368 core::mem::size_of::<clusterMsg>() as libc::c_ulong,
6369 );
6370 hdr = heapbuf as *mut clusterMsg;
6371 }
6372 memcpy(
6373 ((*hdr).data.module.msg.bulk_data).as_mut_ptr() as *mut libc::c_void,
6374 payload as *const libc::c_void,
6375 len as libc::c_ulong,
6376 );
6377 if !link.is_null() {
6378 clusterSendMessage(link, heapbuf, totlen as size_t);
6379 } else {
6380 clusterBroadcastMessage(heapbuf as *mut libc::c_void, totlen as size_t);
6381 }
6382 if heapbuf != buf.as_mut_ptr() as *mut libc::c_uchar {
6383 zfree(heapbuf as *mut libc::c_void);
6384 }
6385}
6386#[no_mangle]
6387pub unsafe extern "C" fn clusterSendModuleMessageToTarget(
6388 mut target: *const libc::c_char,
6389 mut module_id: uint64_t,
6390 mut type_0: uint8_t,
6391 mut payload: *const libc::c_char,
6392 mut len: uint32_t,
6393) -> libc::c_int {
6394 let mut node: *mut clusterNode = 0 as *mut clusterNode;
6395 if !target.is_null() {
6396 node = clusterLookupNode(target, strlen(target) as libc::c_int);
6397 if node.is_null() || ((*node).link).is_null() {
6398 return -(1 as libc::c_int);
6399 }
6400 }
6401 clusterSendModule(
6402 if !target.is_null() { (*node).link } else { 0 as *mut clusterLink },
6403 module_id,
6404 type_0,
6405 payload,
6406 len,
6407 );
6408 return 0 as libc::c_int;
6409}
6410#[no_mangle]
6411pub unsafe extern "C" fn clusterPropagatePublish(
6412 mut channel: *mut robj,
6413 mut message: *mut robj,
6414 mut sharded: libc::c_int,
6415) {
6416 if sharded == 0 {
6417 clusterSendPublish(
6418 0 as *mut clusterLink,
6419 channel,
6420 message,
6421 4 as libc::c_int as uint16_t,
6422 );
6423 return;
6424 }
6425 let mut nodes_for_slot: *mut list = clusterGetNodesServingMySlots(
6426 (*server.cluster).myself,
6427 );
6428 if (*nodes_for_slot).len != 0 as libc::c_int as libc::c_ulong {
6429 let mut li: listIter = listIter {
6430 next: 0 as *mut listNode,
6431 direction: 0,
6432 };
6433 let mut ln: *mut listNode = 0 as *mut listNode;
6434 listRewind(nodes_for_slot, &mut li);
6435 loop {
6436 ln = listNext(&mut li);
6437 if ln.is_null() {
6438 break;
6439 }
6440 let mut node: *mut clusterNode = (*ln).value as *mut clusterNode;
6441 if node != myself {
6442 clusterSendPublish(
6443 (*node).link,
6444 channel,
6445 message,
6446 10 as libc::c_int as uint16_t,
6447 );
6448 }
6449 }
6450 }
6451 listRelease(nodes_for_slot);
6452}
6453#[no_mangle]
6454pub unsafe extern "C" fn clusterRequestFailoverAuth() {
6455 let mut buf: [clusterMsg; 1] = [clusterMsg {
6456 sig: [0; 4],
6457 totlen: 0,
6458 ver: 0,
6459 port: 0,
6460 type_0: 0,
6461 count: 0,
6462 currentEpoch: 0,
6463 configEpoch: 0,
6464 offset: 0,
6465 sender: [0; 40],
6466 myslots: [0; 2048],
6467 slaveof: [0; 40],
6468 myip: [0; 46],
6469 extensions: 0,
6470 notused1: [0; 30],
6471 pport: 0,
6472 cport: 0,
6473 flags: 0,
6474 state: 0,
6475 mflags: [0; 3],
6476 data: clusterMsgData {
6477 ping: C2RustUnnamed_19 {
6478 gossip: [clusterMsgDataGossip {
6479 nodename: [0; 40],
6480 ping_sent: 0,
6481 pong_received: 0,
6482 ip: [0; 46],
6483 port: 0,
6484 cport: 0,
6485 flags: 0,
6486 pport: 0,
6487 notused1: 0,
6488 }; 1],
6489 },
6490 },
6491 }; 1];
6492 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6493 let mut totlen: uint32_t = 0;
6494 clusterBuildMessageHdr(hdr, 5 as libc::c_int);
6495 if (*server.cluster).mf_end != 0 {
6496 (*hdr)
6497 .mflags[0 as libc::c_int
6498 as usize] = ((*hdr).mflags[0 as libc::c_int as usize] as libc::c_int
6499 | (1 as libc::c_int) << 1 as libc::c_int) as libc::c_uchar;
6500 }
6501 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
6502 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
6503 as uint32_t;
6504 (*hdr).totlen = __bswap_32(totlen);
6505 clusterBroadcastMessage(buf.as_mut_ptr() as *mut libc::c_void, totlen as size_t);
6506}
6507#[no_mangle]
6508pub unsafe extern "C" fn clusterSendFailoverAuth(mut node: *mut clusterNode) {
6509 let mut buf: [clusterMsg; 1] = [clusterMsg {
6510 sig: [0; 4],
6511 totlen: 0,
6512 ver: 0,
6513 port: 0,
6514 type_0: 0,
6515 count: 0,
6516 currentEpoch: 0,
6517 configEpoch: 0,
6518 offset: 0,
6519 sender: [0; 40],
6520 myslots: [0; 2048],
6521 slaveof: [0; 40],
6522 myip: [0; 46],
6523 extensions: 0,
6524 notused1: [0; 30],
6525 pport: 0,
6526 cport: 0,
6527 flags: 0,
6528 state: 0,
6529 mflags: [0; 3],
6530 data: clusterMsgData {
6531 ping: C2RustUnnamed_19 {
6532 gossip: [clusterMsgDataGossip {
6533 nodename: [0; 40],
6534 ping_sent: 0,
6535 pong_received: 0,
6536 ip: [0; 46],
6537 port: 0,
6538 cport: 0,
6539 flags: 0,
6540 pport: 0,
6541 notused1: 0,
6542 }; 1],
6543 },
6544 },
6545 }; 1];
6546 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6547 let mut totlen: uint32_t = 0;
6548 if ((*node).link).is_null() {
6549 return;
6550 }
6551 clusterBuildMessageHdr(hdr, 6 as libc::c_int);
6552 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
6553 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
6554 as uint32_t;
6555 (*hdr).totlen = __bswap_32(totlen);
6556 clusterSendMessage(
6557 (*node).link,
6558 buf.as_mut_ptr() as *mut libc::c_uchar,
6559 totlen as size_t,
6560 );
6561}
6562#[no_mangle]
6563pub unsafe extern "C" fn clusterSendMFStart(mut node: *mut clusterNode) {
6564 let mut buf: [clusterMsg; 1] = [clusterMsg {
6565 sig: [0; 4],
6566 totlen: 0,
6567 ver: 0,
6568 port: 0,
6569 type_0: 0,
6570 count: 0,
6571 currentEpoch: 0,
6572 configEpoch: 0,
6573 offset: 0,
6574 sender: [0; 40],
6575 myslots: [0; 2048],
6576 slaveof: [0; 40],
6577 myip: [0; 46],
6578 extensions: 0,
6579 notused1: [0; 30],
6580 pport: 0,
6581 cport: 0,
6582 flags: 0,
6583 state: 0,
6584 mflags: [0; 3],
6585 data: clusterMsgData {
6586 ping: C2RustUnnamed_19 {
6587 gossip: [clusterMsgDataGossip {
6588 nodename: [0; 40],
6589 ping_sent: 0,
6590 pong_received: 0,
6591 ip: [0; 46],
6592 port: 0,
6593 cport: 0,
6594 flags: 0,
6595 pport: 0,
6596 notused1: 0,
6597 }; 1],
6598 },
6599 },
6600 }; 1];
6601 let mut hdr: *mut clusterMsg = buf.as_mut_ptr();
6602 let mut totlen: uint32_t = 0;
6603 if ((*node).link).is_null() {
6604 return;
6605 }
6606 clusterBuildMessageHdr(hdr, 8 as libc::c_int);
6607 totlen = (core::mem::size_of::<clusterMsg>() as libc::c_ulong)
6608 .wrapping_sub(core::mem::size_of::<clusterMsgData>() as libc::c_ulong)
6609 as uint32_t;
6610 (*hdr).totlen = __bswap_32(totlen);
6611 clusterSendMessage(
6612 (*node).link,
6613 buf.as_mut_ptr() as *mut libc::c_uchar,
6614 totlen as size_t,
6615 );
6616}
6617#[no_mangle]
6618pub unsafe extern "C" fn clusterSendFailoverAuthIfNeeded(
6619 mut node: *mut clusterNode,
6620 mut request: *mut clusterMsg,
6621) {
6622 let mut master: *mut clusterNode = (*node).slaveof;
6623 let mut requestCurrentEpoch: uint64_t = intrev64((*request).currentEpoch);
6624 let mut requestConfigEpoch: uint64_t = intrev64((*request).configEpoch);
6625 let mut claimed_slots: *mut libc::c_uchar = ((*request).myslots).as_mut_ptr();
6626 let mut force_ack: libc::c_int = (*request).mflags[0 as libc::c_int as usize]
6627 as libc::c_int & (1 as libc::c_int) << 1 as libc::c_int;
6628 let mut j: libc::c_int = 0;
6629 if (*myself).flags & 2 as libc::c_int != 0 || (*myself).numslots == 0 as libc::c_int
6630 {
6631 return;
6632 }
6633 if requestCurrentEpoch < (*server.cluster).currentEpoch {
6634 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6635 _serverLog(
6636 3 as libc::c_int,
6637 b"Failover auth denied to %.40s: reqEpoch (%llu) < curEpoch(%llu)\0"
6638 as *const u8 as *const libc::c_char,
6639 ((*node).name).as_mut_ptr(),
6640 requestCurrentEpoch as libc::c_ulonglong,
6641 (*server.cluster).currentEpoch as libc::c_ulonglong,
6642 );
6643 }
6644 return;
6645 }
6646 if (*server.cluster).lastVoteEpoch == (*server.cluster).currentEpoch {
6647 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6648 _serverLog(
6649 3 as libc::c_int,
6650 b"Failover auth denied to %.40s: already voted for epoch %llu\0"
6651 as *const u8 as *const libc::c_char,
6652 ((*node).name).as_mut_ptr(),
6653 (*server.cluster).currentEpoch as libc::c_ulonglong,
6654 );
6655 }
6656 return;
6657 }
6658 if (*node).flags & 1 as libc::c_int != 0 || master.is_null()
6659 || (*master).flags & 8 as libc::c_int == 0 && force_ack == 0
6660 {
6661 if (*node).flags & 1 as libc::c_int != 0 {
6662 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6663 _serverLog(
6664 3 as libc::c_int,
6665 b"Failover auth denied to %.40s: it is a master node\0" as *const u8
6666 as *const libc::c_char,
6667 ((*node).name).as_mut_ptr(),
6668 );
6669 }
6670 } else if master.is_null() {
6671 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6672 _serverLog(
6673 3 as libc::c_int,
6674 b"Failover auth denied to %.40s: I don't know its master\0"
6675 as *const u8 as *const libc::c_char,
6676 ((*node).name).as_mut_ptr(),
6677 );
6678 }
6679 } else if (*master).flags & 8 as libc::c_int == 0 {
6680 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6681 _serverLog(
6682 3 as libc::c_int,
6683 b"Failover auth denied to %.40s: its master is up\0" as *const u8
6684 as *const libc::c_char,
6685 ((*node).name).as_mut_ptr(),
6686 );
6687 }
6688 }
6689 return;
6690 }
6691 if mstime() - (*(*node).slaveof).voted_time
6692 < server.cluster_node_timeout * 2 as libc::c_int as libc::c_longlong
6693 {
6694 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6695 _serverLog(
6696 3 as libc::c_int,
6697 b"Failover auth denied to %.40s: can't vote about this master before %lld milliseconds\0"
6698 as *const u8 as *const libc::c_char,
6699 ((*node).name).as_mut_ptr(),
6700 server.cluster_node_timeout * 2 as libc::c_int as libc::c_longlong
6701 - (mstime() - (*(*node).slaveof).voted_time),
6702 );
6703 }
6704 return;
6705 }
6706 j = 0 as libc::c_int;
6707 while j < 16384 as libc::c_int {
6708 if !(bitmapTestBit(claimed_slots, j) == 0 as libc::c_int) {
6709 if !(((*server.cluster).slots[j as usize]).is_null()
6710 || (*(*server.cluster).slots[j as usize]).configEpoch
6711 <= requestConfigEpoch)
6712 {
6713 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6714 _serverLog(
6715 3 as libc::c_int,
6716 b"Failover auth denied to %.40s: slot %d epoch (%llu) > reqEpoch (%llu)\0"
6717 as *const u8 as *const libc::c_char,
6718 ((*node).name).as_mut_ptr(),
6719 j,
6720 (*(*server.cluster).slots[j as usize]).configEpoch
6721 as libc::c_ulonglong,
6722 requestConfigEpoch as libc::c_ulonglong,
6723 );
6724 }
6725 return;
6726 }
6727 }
6728 j += 1;
6729 }
6730 (*server.cluster).lastVoteEpoch = (*server.cluster).currentEpoch;
6731 (*(*node).slaveof).voted_time = mstime();
6732 clusterDoBeforeSleep(
6733 (1 as libc::c_int) << 2 as libc::c_int | (1 as libc::c_int) << 3 as libc::c_int,
6734 );
6735 clusterSendFailoverAuth(node);
6736 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6737 _serverLog(
6738 3 as libc::c_int,
6739 b"Failover auth granted to %.40s for epoch %llu\0" as *const u8
6740 as *const libc::c_char,
6741 ((*node).name).as_mut_ptr(),
6742 (*server.cluster).currentEpoch as libc::c_ulonglong,
6743 );
6744 }
6745}
6746#[no_mangle]
6747pub unsafe extern "C" fn clusterGetSlaveRank() -> libc::c_int {
6748 let mut myoffset: libc::c_longlong = 0;
6749 let mut j: libc::c_int = 0;
6750 let mut rank: libc::c_int = 0 as libc::c_int;
6751 let mut master: *mut clusterNode = 0 as *mut clusterNode;
6752 if (*myself).flags & 2 as libc::c_int != 0 {} else {
6753 _serverAssert(
6754 b"nodeIsSlave(myself)\0" as *const u8 as *const libc::c_char,
6755 b"cluster.c\0" as *const u8 as *const libc::c_char,
6756 3424 as libc::c_int,
6757 );
6758 unreachable!();
6759 };
6760 master = (*myself).slaveof;
6761 if master.is_null() {
6762 return 0 as libc::c_int;
6763 }
6764 myoffset = replicationGetSlaveOffset();
6765 j = 0 as libc::c_int;
6766 while j < (*master).numslaves {
6767 if *((*master).slaves).offset(j as isize) != myself
6768 && (**((*master).slaves).offset(j as isize)).flags & 512 as libc::c_int == 0
6769 && (**((*master).slaves).offset(j as isize)).repl_offset > myoffset
6770 {
6771 rank += 1;
6772 }
6773 j += 1;
6774 }
6775 return rank;
6776}
6777#[no_mangle]
6778pub unsafe extern "C" fn clusterLogCantFailover(mut reason: libc::c_int) {
6779 let mut msg: *mut libc::c_char = 0 as *mut libc::c_char;
6780 static mut lastlog_time: time_t = 0 as libc::c_int as time_t;
6781 let mut nolog_fail_time: mstime_t = server.cluster_node_timeout
6782 + 5000 as libc::c_int as libc::c_longlong;
6783 if reason == (*server.cluster).cant_failover_reason
6784 && time(0 as *mut time_t) - lastlog_time
6785 < (60 as libc::c_int * 5 as libc::c_int) as libc::c_long
6786 {
6787 return;
6788 }
6789 (*server.cluster).cant_failover_reason = reason;
6790 if !((*myself).slaveof).is_null()
6791 && (*(*myself).slaveof).flags & 8 as libc::c_int != 0
6792 && mstime() - (*(*myself).slaveof).fail_time < nolog_fail_time
6793 {
6794 return;
6795 }
6796 match reason {
6797 1 => {
6798 msg = b"Disconnected from master for longer than allowed. Please check the 'cluster-replica-validity-factor' configuration option.\0"
6799 as *const u8 as *const libc::c_char as *mut libc::c_char;
6800 }
6801 2 => {
6802 msg = b"Waiting the delay before I can start a new failover.\0" as *const u8
6803 as *const libc::c_char as *mut libc::c_char;
6804 }
6805 3 => {
6806 msg = b"Failover attempt expired.\0" as *const u8 as *const libc::c_char
6807 as *mut libc::c_char;
6808 }
6809 4 => {
6810 msg = b"Waiting for votes, but majority still not reached.\0" as *const u8
6811 as *const libc::c_char as *mut libc::c_char;
6812 }
6813 _ => {
6814 msg = b"Unknown reason code.\0" as *const u8 as *const libc::c_char
6815 as *mut libc::c_char;
6816 }
6817 }
6818 lastlog_time = time(0 as *mut time_t);
6819 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6820 _serverLog(
6821 3 as libc::c_int,
6822 b"Currently unable to failover: %s\0" as *const u8 as *const libc::c_char,
6823 msg,
6824 );
6825 }
6826}
6827#[no_mangle]
6828pub unsafe extern "C" fn clusterFailoverReplaceYourMaster() {
6829 let mut j: libc::c_int = 0;
6830 let mut oldmaster: *mut clusterNode = (*myself).slaveof;
6831 if (*myself).flags & 1 as libc::c_int != 0 || oldmaster.is_null() {
6832 return;
6833 }
6834 clusterSetNodeAsMaster(myself);
6835 replicationUnsetMaster();
6836 j = 0 as libc::c_int;
6837 while j < 16384 as libc::c_int {
6838 if clusterNodeGetSlotBit(oldmaster, j) != 0 {
6839 clusterDelSlot(j);
6840 clusterAddSlot(myself, j);
6841 }
6842 j += 1;
6843 }
6844 clusterUpdateState();
6845 clusterSaveConfigOrDie(1 as libc::c_int);
6846 clusterBroadcastPong(0 as libc::c_int);
6847 resetManualFailover();
6848}
6849#[no_mangle]
6850pub unsafe extern "C" fn clusterHandleSlaveFailover() {
6851 let mut data_age: mstime_t = 0;
6852 let mut auth_age: mstime_t = mstime() - (*server.cluster).failover_auth_time;
6853 let mut needed_quorum: libc::c_int = (*server.cluster).size / 2 as libc::c_int
6854 + 1 as libc::c_int;
6855 let mut manual_failover: libc::c_int = ((*server.cluster).mf_end
6856 != 0 as libc::c_int as libc::c_longlong && (*server.cluster).mf_can_start != 0)
6857 as libc::c_int;
6858 let mut auth_timeout: mstime_t = 0;
6859 let mut auth_retry_time: mstime_t = 0;
6860 (*server.cluster).todo_before_sleep &= !((1 as libc::c_int) << 0 as libc::c_int);
6861 auth_timeout = server.cluster_node_timeout * 2 as libc::c_int as libc::c_longlong;
6862 if auth_timeout < 2000 as libc::c_int as libc::c_longlong {
6863 auth_timeout = 2000 as libc::c_int as mstime_t;
6864 }
6865 auth_retry_time = auth_timeout * 2 as libc::c_int as libc::c_longlong;
6866 if (*myself).flags & 1 as libc::c_int != 0 || ((*myself).slaveof).is_null()
6867 || (*(*myself).slaveof).flags & 8 as libc::c_int == 0 && manual_failover == 0
6868 || server.cluster_slave_no_failover != 0 && manual_failover == 0
6869 || (*(*myself).slaveof).numslots == 0 as libc::c_int
6870 {
6871 (*server.cluster).cant_failover_reason = 0 as libc::c_int;
6872 return;
6873 }
6874 if server.repl_state == REPL_STATE_CONNECTED as libc::c_int {
6875 data_age = (server.unixtime as libc::c_long - (*server.master).lastinteraction)
6876 as mstime_t * 1000 as libc::c_int as libc::c_longlong;
6877 } else {
6878 data_age = (server.unixtime as libc::c_long - server.repl_down_since) as mstime_t
6879 * 1000 as libc::c_int as libc::c_longlong;
6880 }
6881 if data_age > server.cluster_node_timeout {
6882 data_age -= server.cluster_node_timeout;
6883 }
6884 if server.cluster_slave_validity_factor != 0
6885 && data_age
6886 > server.repl_ping_slave_period as mstime_t
6887 * 1000 as libc::c_int as libc::c_longlong
6888 + server.cluster_node_timeout
6889 * server.cluster_slave_validity_factor as libc::c_longlong
6890 {
6891 if manual_failover == 0 {
6892 clusterLogCantFailover(1 as libc::c_int);
6893 return;
6894 }
6895 }
6896 if auth_age > auth_retry_time {
6897 (*server.cluster)
6898 .failover_auth_time = mstime() + 500 as libc::c_int as libc::c_longlong
6899 + (random() % 500 as libc::c_int as libc::c_long) as libc::c_longlong;
6900 (*server.cluster).failover_auth_count = 0 as libc::c_int;
6901 (*server.cluster).failover_auth_sent = 0 as libc::c_int;
6902 (*server.cluster).failover_auth_rank = clusterGetSlaveRank();
6903 (*server.cluster).failover_auth_time
6904 += ((*server.cluster).failover_auth_rank * 1000 as libc::c_int)
6905 as libc::c_longlong;
6906 if (*server.cluster).mf_end != 0 {
6907 (*server.cluster).failover_auth_time = mstime();
6908 (*server.cluster).failover_auth_rank = 0 as libc::c_int;
6909 clusterDoBeforeSleep((1 as libc::c_int) << 0 as libc::c_int);
6910 }
6911 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6912 _serverLog(
6913 3 as libc::c_int,
6914 b"Start of election delayed for %lld milliseconds (rank #%d, offset %lld).\0"
6915 as *const u8 as *const libc::c_char,
6916 (*server.cluster).failover_auth_time - mstime(),
6917 (*server.cluster).failover_auth_rank,
6918 replicationGetSlaveOffset(),
6919 );
6920 }
6921 clusterBroadcastPong(1 as libc::c_int);
6922 return;
6923 }
6924 if (*server.cluster).failover_auth_sent == 0 as libc::c_int
6925 && (*server.cluster).mf_end == 0 as libc::c_int as libc::c_longlong
6926 {
6927 let mut newrank: libc::c_int = clusterGetSlaveRank();
6928 if newrank > (*server.cluster).failover_auth_rank {
6929 let mut added_delay: libc::c_longlong = ((newrank
6930 - (*server.cluster).failover_auth_rank) * 1000 as libc::c_int)
6931 as libc::c_longlong;
6932 (*server.cluster).failover_auth_time += added_delay;
6933 (*server.cluster).failover_auth_rank = newrank;
6934 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6935 _serverLog(
6936 3 as libc::c_int,
6937 b"Replica rank updated to #%d, added %lld milliseconds of delay.\0"
6938 as *const u8 as *const libc::c_char,
6939 newrank,
6940 added_delay,
6941 );
6942 }
6943 }
6944 }
6945 if mstime() < (*server.cluster).failover_auth_time {
6946 clusterLogCantFailover(2 as libc::c_int);
6947 return;
6948 }
6949 if auth_age > auth_timeout {
6950 clusterLogCantFailover(3 as libc::c_int);
6951 return;
6952 }
6953 if (*server.cluster).failover_auth_sent == 0 as libc::c_int {
6954 (*server.cluster)
6955 .currentEpoch = ((*server.cluster).currentEpoch).wrapping_add(1);
6956 (*server.cluster).failover_auth_epoch = (*server.cluster).currentEpoch;
6957 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6958 _serverLog(
6959 3 as libc::c_int,
6960 b"Starting a failover election for epoch %llu.\0" as *const u8
6961 as *const libc::c_char,
6962 (*server.cluster).currentEpoch as libc::c_ulonglong,
6963 );
6964 }
6965 clusterRequestFailoverAuth();
6966 (*server.cluster).failover_auth_sent = 1 as libc::c_int;
6967 clusterDoBeforeSleep(
6968 (1 as libc::c_int) << 2 as libc::c_int
6969 | (1 as libc::c_int) << 1 as libc::c_int
6970 | (1 as libc::c_int) << 3 as libc::c_int,
6971 );
6972 return;
6973 }
6974 if (*server.cluster).failover_auth_count >= needed_quorum {
6975 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6976 _serverLog(
6977 3 as libc::c_int,
6978 b"Failover election won: I'm the new master.\0" as *const u8
6979 as *const libc::c_char,
6980 );
6981 }
6982 if (*myself).configEpoch < (*server.cluster).failover_auth_epoch {
6983 (*myself).configEpoch = (*server.cluster).failover_auth_epoch;
6984 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
6985 _serverLog(
6986 3 as libc::c_int,
6987 b"configEpoch set to %llu after successful failover\0" as *const u8
6988 as *const libc::c_char,
6989 (*myself).configEpoch as libc::c_ulonglong,
6990 );
6991 }
6992 }
6993 clusterFailoverReplaceYourMaster();
6994 } else {
6995 clusterLogCantFailover(4 as libc::c_int);
6996 };
6997}
6998#[no_mangle]
6999pub unsafe extern "C" fn clusterHandleSlaveMigration(mut max_slaves: libc::c_int) {
7000 let mut j: libc::c_int = 0;
7001 let mut okslaves: libc::c_int = 0 as libc::c_int;
7002 let mut mymaster: *mut clusterNode = (*myself).slaveof;
7003 let mut target: *mut clusterNode = 0 as *mut clusterNode;
7004 let mut candidate: *mut clusterNode = 0 as *mut clusterNode;
7005 let mut di: *mut dictIterator = 0 as *mut dictIterator;
7006 let mut de: *mut dictEntry = 0 as *mut dictEntry;
7007 if (*server.cluster).state != 0 as libc::c_int {
7008 return;
7009 }
7010 if mymaster.is_null() {
7011 return;
7012 }
7013 j = 0 as libc::c_int;
7014 while j < (*mymaster).numslaves {
7015 if (**((*mymaster).slaves).offset(j as isize)).flags & 8 as libc::c_int == 0
7016 && (**((*mymaster).slaves).offset(j as isize)).flags & 4 as libc::c_int == 0
7017 {
7018 okslaves += 1;
7019 }
7020 j += 1;
7021 }
7022 if okslaves <= server.cluster_migration_barrier {
7023 return;
7024 }
7025 candidate = myself;
7026 di = dictGetSafeIterator((*server.cluster).nodes);
7027 loop {
7028 de = dictNext(di);
7029 if de.is_null() {
7030 break;
7031 }
7032 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
7033 let mut okslaves_0: libc::c_int = 0 as libc::c_int;
7034 let mut is_orphaned: libc::c_int = 1 as libc::c_int;
7035 if (*node).flags & 2 as libc::c_int != 0 || (*node).flags & 8 as libc::c_int != 0
7036 {
7037 is_orphaned = 0 as libc::c_int;
7038 }
7039 if (*node).flags & 256 as libc::c_int == 0 {
7040 is_orphaned = 0 as libc::c_int;
7041 }
7042 if (*node).flags & 1 as libc::c_int != 0 {
7043 okslaves_0 = clusterCountNonFailingSlaves(node);
7044 }
7045 if okslaves_0 > 0 as libc::c_int {
7046 is_orphaned = 0 as libc::c_int;
7047 }
7048 if is_orphaned != 0 {
7049 if target.is_null() && (*node).numslots > 0 as libc::c_int {
7050 target = node;
7051 }
7052 if (*node).orphaned_time == 0 {
7053 (*node).orphaned_time = mstime();
7054 }
7055 } else {
7056 (*node).orphaned_time = 0 as libc::c_int as mstime_t;
7057 }
7058 if okslaves_0 == max_slaves {
7059 j = 0 as libc::c_int;
7060 while j < (*node).numslaves {
7061 if memcmp(
7062 ((**((*node).slaves).offset(j as isize)).name).as_mut_ptr()
7063 as *const libc::c_void,
7064 ((*candidate).name).as_mut_ptr() as *const libc::c_void,
7065 40 as libc::c_int as libc::c_ulong,
7066 ) < 0 as libc::c_int
7067 {
7068 candidate = *((*node).slaves).offset(j as isize);
7069 }
7070 j += 1;
7071 }
7072 }
7073 }
7074 dictReleaseIterator(di);
7075 if !target.is_null() && candidate == myself
7076 && mstime() - (*target).orphaned_time > 5000 as libc::c_int as libc::c_longlong
7077 && server.cluster_module_flags & (1 as libc::c_int) << 1 as libc::c_int == 0
7078 {
7079 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7080 _serverLog(
7081 3 as libc::c_int,
7082 b"Migrating to orphaned master %.40s\0" as *const u8
7083 as *const libc::c_char,
7084 ((*target).name).as_mut_ptr(),
7085 );
7086 }
7087 clusterSetMaster(target);
7088 }
7089}
7090#[no_mangle]
7091pub unsafe extern "C" fn resetManualFailover() {
7092 if !((*server.cluster).mf_slave).is_null() {
7093 unpauseClients(PAUSE_DURING_FAILOVER);
7094 }
7095 (*server.cluster).mf_end = 0 as libc::c_int as mstime_t;
7096 (*server.cluster).mf_can_start = 0 as libc::c_int;
7097 (*server.cluster).mf_slave = 0 as *mut clusterNode;
7098 (*server.cluster).mf_master_offset = -(1 as libc::c_int) as libc::c_longlong;
7099}
7100#[no_mangle]
7101pub unsafe extern "C" fn manualFailoverCheckTimeout() {
7102 if (*server.cluster).mf_end != 0 && (*server.cluster).mf_end < mstime() {
7103 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7104 _serverLog(
7105 3 as libc::c_int,
7106 b"Manual failover timed out.\0" as *const u8 as *const libc::c_char,
7107 );
7108 }
7109 resetManualFailover();
7110 }
7111}
7112#[no_mangle]
7113pub unsafe extern "C" fn clusterHandleManualFailover() {
7114 if (*server.cluster).mf_end == 0 as libc::c_int as libc::c_longlong {
7115 return;
7116 }
7117 if (*server.cluster).mf_can_start != 0 {
7118 return;
7119 }
7120 if (*server.cluster).mf_master_offset == -(1 as libc::c_int) as libc::c_longlong {
7121 return;
7122 }
7123 if (*server.cluster).mf_master_offset == replicationGetSlaveOffset() {
7124 (*server.cluster).mf_can_start = 1 as libc::c_int;
7125 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7126 _serverLog(
7127 3 as libc::c_int,
7128 b"All master replication stream processed, manual failover can start.\0"
7129 as *const u8 as *const libc::c_char,
7130 );
7131 }
7132 clusterDoBeforeSleep((1 as libc::c_int) << 0 as libc::c_int);
7133 return;
7134 }
7135 clusterDoBeforeSleep((1 as libc::c_int) << 4 as libc::c_int);
7136}
7137unsafe extern "C" fn clusterNodeCronHandleReconnect(
7138 mut node: *mut clusterNode,
7139 mut handshake_timeout: mstime_t,
7140 mut now: mstime_t,
7141) -> libc::c_int {
7142 if (*node).flags & (16 as libc::c_int | 64 as libc::c_int) != 0 {
7143 return 1 as libc::c_int;
7144 }
7145 if (*node).flags & 4 as libc::c_int != 0 {
7146 (*server.cluster).stats_pfail_nodes += 1;
7147 }
7148 if (*node).flags & 32 as libc::c_int != 0 && now - (*node).ctime > handshake_timeout
7149 {
7150 clusterDelNode(node);
7151 return 1 as libc::c_int;
7152 }
7153 if ((*node).link).is_null() {
7154 let mut link: *mut clusterLink = createClusterLink(node);
7155 (*link)
7156 .conn = if server.tls_cluster != 0 {
7157 connCreateTLS()
7158 } else {
7159 connCreateSocket()
7160 };
7161 connSetPrivateData((*link).conn, link as *mut libc::c_void);
7162 if connConnect(
7163 (*link).conn,
7164 ((*node).ip).as_mut_ptr(),
7165 (*node).cport,
7166 server.bind_source_addr,
7167 Some(
7168 clusterLinkConnectHandler as unsafe extern "C" fn(*mut connection) -> (),
7169 ),
7170 ) == -(1 as libc::c_int)
7171 {
7172 if (*node).ping_sent == 0 as libc::c_int as libc::c_longlong {
7173 (*node).ping_sent = mstime();
7174 }
7175 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7176 _serverLog(
7177 0 as libc::c_int,
7178 b"Unable to connect to Cluster Node [%s]:%d -> %s\0" as *const u8
7179 as *const libc::c_char,
7180 ((*node).ip).as_mut_ptr(),
7181 (*node).cport,
7182 (server.neterr).as_mut_ptr(),
7183 );
7184 }
7185 freeClusterLink(link);
7186 return 0 as libc::c_int;
7187 }
7188 }
7189 return 0 as libc::c_int;
7190}
7191unsafe extern "C" fn resizeClusterLinkBuffer(mut link: *mut clusterLink) {
7192 if !link.is_null()
7193 && (sdsavail((*link).sndbuf)).wrapping_div(4 as libc::c_int as libc::c_ulong)
7194 > sdslen((*link).sndbuf)
7195 {
7196 (*link).sndbuf = sdsRemoveFreeSpace((*link).sndbuf);
7197 }
7198}
7199unsafe extern "C" fn clusterNodeCronResizeBuffers(mut node: *mut clusterNode) {
7200 resizeClusterLinkBuffer((*node).link);
7201 resizeClusterLinkBuffer((*node).inbound_link);
7202}
7203unsafe extern "C" fn freeClusterLinkOnBufferLimitReached(mut link: *mut clusterLink) {
7204 if link.is_null()
7205 || server.cluster_link_sendbuf_limit_bytes
7206 == 0 as libc::c_int as libc::c_ulonglong
7207 {
7208 return;
7209 }
7210 let mut mem_link: libc::c_ulonglong = sdsalloc((*link).sndbuf) as libc::c_ulonglong;
7211 if mem_link > server.cluster_link_sendbuf_limit_bytes {
7212 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7213 _serverLog(
7214 3 as libc::c_int,
7215 b"Freeing cluster link(%s node %.40s, used memory: %llu) due to exceeding send buffer memory limit.\0"
7216 as *const u8 as *const libc::c_char,
7217 if (*link).inbound != 0 {
7218 b"from\0" as *const u8 as *const libc::c_char
7219 } else {
7220 b"to\0" as *const u8 as *const libc::c_char
7221 },
7222 if !((*link).node).is_null() {
7223 ((*(*link).node).name).as_mut_ptr() as *const libc::c_char
7224 } else {
7225 b"\0" as *const u8 as *const libc::c_char
7226 },
7227 mem_link,
7228 );
7229 }
7230 freeClusterLink(link);
7231 (*server.cluster)
7232 .stat_cluster_links_buffer_limit_exceeded = ((*server.cluster)
7233 .stat_cluster_links_buffer_limit_exceeded)
7234 .wrapping_add(1);
7235 }
7236}
7237unsafe extern "C" fn clusterNodeCronFreeLinkOnBufferLimitReached(
7238 mut node: *mut clusterNode,
7239) {
7240 freeClusterLinkOnBufferLimitReached((*node).link);
7241 freeClusterLinkOnBufferLimitReached((*node).inbound_link);
7242}
7243unsafe extern "C" fn getClusterLinkMemUsage(mut link: *mut clusterLink) -> size_t {
7244 if !link.is_null() {
7245 return (core::mem::size_of::<clusterLink>() as libc::c_ulong)
7246 .wrapping_add(sdsalloc((*link).sndbuf))
7247 .wrapping_add((*link).rcvbuf_alloc)
7248 } else {
7249 return 0 as libc::c_int as size_t
7250 };
7251}
7252unsafe extern "C" fn clusterNodeCronUpdateClusterLinksMemUsage(
7253 mut node: *mut clusterNode,
7254) {
7255 server
7256 .stat_cluster_links_memory = (server.stat_cluster_links_memory as libc::c_ulong)
7257 .wrapping_add(getClusterLinkMemUsage((*node).link)) as size_t as size_t;
7258 server
7259 .stat_cluster_links_memory = (server.stat_cluster_links_memory as libc::c_ulong)
7260 .wrapping_add(getClusterLinkMemUsage((*node).inbound_link)) as size_t as size_t;
7261}
7262#[no_mangle]
7263pub unsafe extern "C" fn clusterCron() {
7264 let mut di: *mut dictIterator = 0 as *mut dictIterator;
7265 let mut de: *mut dictEntry = 0 as *mut dictEntry;
7266 let mut update_state: libc::c_int = 0 as libc::c_int;
7267 let mut orphaned_masters: libc::c_int = 0;
7268 let mut max_slaves: libc::c_int = 0;
7269 let mut this_slaves: libc::c_int = 0;
7270 let mut min_pong: mstime_t = 0 as libc::c_int as mstime_t;
7271 let mut now: mstime_t = mstime();
7272 let mut min_pong_node: *mut clusterNode = 0 as *mut clusterNode;
7273 static mut iteration: libc::c_ulonglong = 0 as libc::c_int as libc::c_ulonglong;
7274 let mut handshake_timeout: mstime_t = 0;
7275 iteration = iteration.wrapping_add(1);
7276 clusterUpdateMyselfHostname();
7277 handshake_timeout = server.cluster_node_timeout;
7278 if handshake_timeout < 1000 as libc::c_int as libc::c_longlong {
7279 handshake_timeout = 1000 as libc::c_int as mstime_t;
7280 }
7281 (*server.cluster).stats_pfail_nodes = 0 as libc::c_int as libc::c_longlong;
7282 server.stat_cluster_links_memory = 0 as libc::c_int as size_t;
7283 di = dictGetSafeIterator((*server.cluster).nodes);
7284 loop {
7285 de = dictNext(di);
7286 if de.is_null() {
7287 break;
7288 }
7289 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
7290 clusterNodeCronResizeBuffers(node);
7291 clusterNodeCronFreeLinkOnBufferLimitReached(node);
7292 clusterNodeCronUpdateClusterLinksMemUsage(node);
7293 clusterNodeCronHandleReconnect(node, handshake_timeout, now) != 0;
7294 }
7295 dictReleaseIterator(di);
7296 if iteration.wrapping_rem(10 as libc::c_int as libc::c_ulonglong) == 0 {
7297 let mut j: libc::c_int = 0;
7298 j = 0 as libc::c_int;
7299 while j < 5 as libc::c_int {
7300 de = dictGetRandomKey((*server.cluster).nodes);
7301 let mut this: *mut clusterNode = (*de).v.val as *mut clusterNode;
7302 if !(((*this).link).is_null()
7303 || (*this).ping_sent != 0 as libc::c_int as libc::c_longlong)
7304 {
7305 if !((*this).flags & (16 as libc::c_int | 32 as libc::c_int) != 0) {
7306 if min_pong_node.is_null() || min_pong > (*this).pong_received {
7307 min_pong_node = this;
7308 min_pong = (*this).pong_received;
7309 }
7310 }
7311 }
7312 j += 1;
7313 }
7314 if !min_pong_node.is_null() {
7315 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7316 _serverLog(
7317 0 as libc::c_int,
7318 b"Pinging node %.40s\0" as *const u8 as *const libc::c_char,
7319 ((*min_pong_node).name).as_mut_ptr(),
7320 );
7321 }
7322 clusterSendPing((*min_pong_node).link, 0 as libc::c_int);
7323 }
7324 }
7325 orphaned_masters = 0 as libc::c_int;
7326 max_slaves = 0 as libc::c_int;
7327 this_slaves = 0 as libc::c_int;
7328 di = dictGetSafeIterator((*server.cluster).nodes);
7329 loop {
7330 de = dictNext(di);
7331 if de.is_null() {
7332 break;
7333 }
7334 let mut node_0: *mut clusterNode = (*de).v.val as *mut clusterNode;
7335 now = mstime();
7336 if (*node_0).flags & (16 as libc::c_int | 64 as libc::c_int | 32 as libc::c_int)
7337 != 0
7338 {
7339 continue;
7340 }
7341 if (*myself).flags & 2 as libc::c_int != 0
7342 && (*node_0).flags & 1 as libc::c_int != 0
7343 && (*node_0).flags & 8 as libc::c_int == 0
7344 {
7345 let mut okslaves: libc::c_int = clusterCountNonFailingSlaves(node_0);
7346 if okslaves == 0 as libc::c_int && (*node_0).numslots > 0 as libc::c_int
7347 && (*node_0).flags & 256 as libc::c_int != 0
7348 {
7349 orphaned_masters += 1;
7350 }
7351 if okslaves > max_slaves {
7352 max_slaves = okslaves;
7353 }
7354 if (*myself).slaveof == node_0 {
7355 this_slaves = okslaves;
7356 }
7357 }
7358 let mut ping_delay: mstime_t = now - (*node_0).ping_sent;
7359 let mut data_delay: mstime_t = now - (*node_0).data_received;
7360 if !((*node_0).link).is_null()
7361 && now - (*(*node_0).link).ctime > server.cluster_node_timeout
7362 && (*node_0).ping_sent != 0
7363 && ping_delay
7364 > server.cluster_node_timeout / 2 as libc::c_int as libc::c_longlong
7365 && data_delay
7366 > server.cluster_node_timeout / 2 as libc::c_int as libc::c_longlong
7367 {
7368 freeClusterLink((*node_0).link);
7369 }
7370 if !((*node_0).link).is_null()
7371 && (*node_0).ping_sent == 0 as libc::c_int as libc::c_longlong
7372 && now - (*node_0).pong_received
7373 > server.cluster_node_timeout / 2 as libc::c_int as libc::c_longlong
7374 {
7375 clusterSendPing((*node_0).link, 0 as libc::c_int);
7376 } else if (*server.cluster).mf_end != 0
7377 && (*myself).flags & 1 as libc::c_int != 0
7378 && (*server.cluster).mf_slave == node_0 && !((*node_0).link).is_null()
7379 {
7380 clusterSendPing((*node_0).link, 0 as libc::c_int);
7381 } else {
7382 if (*node_0).ping_sent == 0 as libc::c_int as libc::c_longlong {
7383 continue;
7384 }
7385 let mut node_delay: mstime_t = if ping_delay < data_delay {
7386 ping_delay
7387 } else {
7388 data_delay
7389 };
7390 if node_delay > server.cluster_node_timeout {
7391 if (*node_0).flags & (4 as libc::c_int | 8 as libc::c_int) == 0 {
7392 if !((0 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7393 _serverLog(
7394 0 as libc::c_int,
7395 b"*** NODE %.40s possibly failing\0" as *const u8
7396 as *const libc::c_char,
7397 ((*node_0).name).as_mut_ptr(),
7398 );
7399 }
7400 (*node_0).flags |= 4 as libc::c_int;
7401 update_state = 1 as libc::c_int;
7402 }
7403 }
7404 }
7405 }
7406 dictReleaseIterator(di);
7407 if (*myself).flags & 2 as libc::c_int != 0 && (server.masterhost).is_null()
7408 && !((*myself).slaveof).is_null()
7409 && (*(*myself).slaveof).flags & 64 as libc::c_int == 0
7410 {
7411 replicationSetMaster(
7412 ((*(*myself).slaveof).ip).as_mut_ptr(),
7413 (*(*myself).slaveof).port,
7414 );
7415 }
7416 manualFailoverCheckTimeout();
7417 if (*myself).flags & 2 as libc::c_int != 0 {
7418 clusterHandleManualFailover();
7419 if server.cluster_module_flags & (1 as libc::c_int) << 1 as libc::c_int == 0 {
7420 clusterHandleSlaveFailover();
7421 }
7422 if orphaned_masters != 0 && max_slaves >= 2 as libc::c_int
7423 && this_slaves == max_slaves && server.cluster_allow_replica_migration != 0
7424 {
7425 clusterHandleSlaveMigration(max_slaves);
7426 }
7427 }
7428 if update_state != 0 || (*server.cluster).state == 1 as libc::c_int {
7429 clusterUpdateState();
7430 }
7431}
7432#[no_mangle]
7433pub unsafe extern "C" fn clusterBeforeSleep() {
7434 let mut flags: libc::c_int = (*server.cluster).todo_before_sleep;
7435 (*server.cluster).todo_before_sleep = 0 as libc::c_int;
7436 if flags & (1 as libc::c_int) << 4 as libc::c_int != 0 {
7437 if (*myself).flags & 2 as libc::c_int != 0 {
7438 clusterHandleManualFailover();
7439 if server.cluster_module_flags & (1 as libc::c_int) << 1 as libc::c_int == 0
7440 {
7441 clusterHandleSlaveFailover();
7442 }
7443 }
7444 } else if flags & (1 as libc::c_int) << 0 as libc::c_int != 0 {
7445 clusterHandleSlaveFailover();
7446 }
7447 if flags & (1 as libc::c_int) << 1 as libc::c_int != 0 {
7448 clusterUpdateState();
7449 }
7450 if flags & (1 as libc::c_int) << 2 as libc::c_int != 0 {
7451 let mut fsync_0: libc::c_int = flags & (1 as libc::c_int) << 3 as libc::c_int;
7452 clusterSaveConfigOrDie(fsync_0);
7453 }
7454}
7455#[no_mangle]
7456pub unsafe extern "C" fn clusterDoBeforeSleep(mut flags: libc::c_int) {
7457 (*server.cluster).todo_before_sleep |= flags;
7458}
7459#[no_mangle]
7460pub unsafe extern "C" fn bitmapTestBit(
7461 mut bitmap: *mut libc::c_uchar,
7462 mut pos: libc::c_int,
7463) -> libc::c_int {
7464 let mut byte: off_t = (pos / 8 as libc::c_int) as off_t;
7465 let mut bit: libc::c_int = pos & 7 as libc::c_int;
7466 return (*bitmap.offset(byte as isize) as libc::c_int & (1 as libc::c_int) << bit
7467 != 0 as libc::c_int) as libc::c_int;
7468}
7469#[no_mangle]
7470pub unsafe extern "C" fn bitmapSetBit(
7471 mut bitmap: *mut libc::c_uchar,
7472 mut pos: libc::c_int,
7473) {
7474 let mut byte: off_t = (pos / 8 as libc::c_int) as off_t;
7475 let mut bit: libc::c_int = pos & 7 as libc::c_int;
7476 let ref mut fresh8 = *bitmap.offset(byte as isize);
7477 *fresh8 = (*fresh8 as libc::c_int | (1 as libc::c_int) << bit) as libc::c_uchar;
7478}
7479#[no_mangle]
7480pub unsafe extern "C" fn bitmapClearBit(
7481 mut bitmap: *mut libc::c_uchar,
7482 mut pos: libc::c_int,
7483) {
7484 let mut byte: off_t = (pos / 8 as libc::c_int) as off_t;
7485 let mut bit: libc::c_int = pos & 7 as libc::c_int;
7486 let ref mut fresh9 = *bitmap.offset(byte as isize);
7487 *fresh9 = (*fresh9 as libc::c_int & !((1 as libc::c_int) << bit)) as libc::c_uchar;
7488}
7489#[no_mangle]
7490pub unsafe extern "C" fn clusterMastersHaveSlaves() -> libc::c_int {
7491 let mut di: *mut dictIterator = dictGetSafeIterator((*server.cluster).nodes);
7492 let mut de: *mut dictEntry = 0 as *mut dictEntry;
7493 let mut slaves: libc::c_int = 0 as libc::c_int;
7494 loop {
7495 de = dictNext(di);
7496 if de.is_null() {
7497 break;
7498 }
7499 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
7500 if (*node).flags & 2 as libc::c_int != 0 {
7501 continue;
7502 }
7503 slaves += (*node).numslaves;
7504 }
7505 dictReleaseIterator(di);
7506 return (slaves != 0 as libc::c_int) as libc::c_int;
7507}
7508#[no_mangle]
7509pub unsafe extern "C" fn clusterNodeSetSlotBit(
7510 mut n: *mut clusterNode,
7511 mut slot: libc::c_int,
7512) -> libc::c_int {
7513 let mut old: libc::c_int = bitmapTestBit(((*n).slots).as_mut_ptr(), slot);
7514 bitmapSetBit(((*n).slots).as_mut_ptr(), slot);
7515 if old == 0 {
7516 (*n).numslots += 1;
7517 if (*n).numslots == 1 as libc::c_int && clusterMastersHaveSlaves() != 0 {
7518 (*n).flags |= 256 as libc::c_int;
7519 }
7520 }
7521 return old;
7522}
7523#[no_mangle]
7524pub unsafe extern "C" fn clusterNodeClearSlotBit(
7525 mut n: *mut clusterNode,
7526 mut slot: libc::c_int,
7527) -> libc::c_int {
7528 let mut old: libc::c_int = bitmapTestBit(((*n).slots).as_mut_ptr(), slot);
7529 bitmapClearBit(((*n).slots).as_mut_ptr(), slot);
7530 if old != 0 {
7531 (*n).numslots -= 1;
7532 }
7533 return old;
7534}
7535#[no_mangle]
7536pub unsafe extern "C" fn clusterNodeGetSlotBit(
7537 mut n: *mut clusterNode,
7538 mut slot: libc::c_int,
7539) -> libc::c_int {
7540 return bitmapTestBit(((*n).slots).as_mut_ptr(), slot);
7541}
7542#[no_mangle]
7543pub unsafe extern "C" fn clusterAddSlot(
7544 mut n: *mut clusterNode,
7545 mut slot: libc::c_int,
7546) -> libc::c_int {
7547 if !((*server.cluster).slots[slot as usize]).is_null() {
7548 return -(1 as libc::c_int);
7549 }
7550 clusterNodeSetSlotBit(n, slot);
7551 (*server.cluster).slots[slot as usize] = n;
7552 return 0 as libc::c_int;
7553}
7554#[no_mangle]
7555pub unsafe extern "C" fn clusterDelSlot(mut slot: libc::c_int) -> libc::c_int {
7556 let mut n: *mut clusterNode = (*server.cluster).slots[slot as usize];
7557 if n.is_null() {
7558 return -(1 as libc::c_int);
7559 }
7560 let mut nodes_for_slot: *mut list = clusterGetNodesServingMySlots(n);
7561 let mut ln: *mut listNode = listSearchKey(
7562 nodes_for_slot,
7563 myself as *mut libc::c_void,
7564 );
7565 if !ln.is_null() {
7566 removeChannelsInSlot(slot as libc::c_uint);
7567 }
7568 listRelease(nodes_for_slot);
7569 if clusterNodeClearSlotBit(n, slot) == 1 as libc::c_int {} else {
7570 _serverAssert(
7571 b"clusterNodeClearSlotBit(n,slot) == 1\0" as *const u8
7572 as *const libc::c_char,
7573 b"cluster.c\0" as *const u8 as *const libc::c_char,
7574 4358 as libc::c_int,
7575 );
7576 unreachable!();
7577 };
7578 (*server.cluster).slots[slot as usize] = 0 as *mut clusterNode;
7579 return 0 as libc::c_int;
7580}
7581#[no_mangle]
7582pub unsafe extern "C" fn clusterDelNodeSlots(mut node: *mut clusterNode) -> libc::c_int {
7583 let mut deleted: libc::c_int = 0 as libc::c_int;
7584 let mut j: libc::c_int = 0;
7585 j = 0 as libc::c_int;
7586 while j < 16384 as libc::c_int {
7587 if clusterNodeGetSlotBit(node, j) != 0 {
7588 clusterDelSlot(j);
7589 deleted += 1;
7590 }
7591 j += 1;
7592 }
7593 return deleted;
7594}
7595#[no_mangle]
7596pub unsafe extern "C" fn clusterCloseAllSlots() {
7597 memset(
7598 ((*server.cluster).migrating_slots_to).as_mut_ptr() as *mut libc::c_void,
7599 0 as libc::c_int,
7600 core::mem::size_of::<[*mut clusterNode; 16384]>() as libc::c_ulong,
7601 );
7602 memset(
7603 ((*server.cluster).importing_slots_from).as_mut_ptr() as *mut libc::c_void,
7604 0 as libc::c_int,
7605 core::mem::size_of::<[*mut clusterNode; 16384]>() as libc::c_ulong,
7606 );
7607}
7608#[no_mangle]
7609pub unsafe extern "C" fn clusterUpdateState() {
7610 let mut j: libc::c_int = 0;
7611 let mut new_state: libc::c_int = 0;
7612 let mut reachable_masters: libc::c_int = 0 as libc::c_int;
7613 static mut among_minority_time: mstime_t = 0;
7614 static mut first_call_time: mstime_t = 0 as libc::c_int as mstime_t;
7615 (*server.cluster).todo_before_sleep &= !((1 as libc::c_int) << 1 as libc::c_int);
7616 if first_call_time == 0 as libc::c_int as libc::c_longlong {
7617 first_call_time = mstime();
7618 }
7619 if (*myself).flags & 1 as libc::c_int != 0
7620 && (*server.cluster).state == 1 as libc::c_int
7621 && mstime() - first_call_time < 2000 as libc::c_int as libc::c_longlong
7622 {
7623 return;
7624 }
7625 new_state = 0 as libc::c_int;
7626 if server.cluster_require_full_coverage != 0 {
7627 j = 0 as libc::c_int;
7628 while j < 16384 as libc::c_int {
7629 if ((*server.cluster).slots[j as usize]).is_null()
7630 || (*(*server.cluster).slots[j as usize]).flags & 8 as libc::c_int != 0
7631 {
7632 new_state = 1 as libc::c_int;
7633 break;
7634 } else {
7635 j += 1;
7636 }
7637 }
7638 }
7639 let mut di: *mut dictIterator = 0 as *mut dictIterator;
7640 let mut de: *mut dictEntry = 0 as *mut dictEntry;
7641 (*server.cluster).size = 0 as libc::c_int;
7642 di = dictGetSafeIterator((*server.cluster).nodes);
7643 loop {
7644 de = dictNext(di);
7645 if de.is_null() {
7646 break;
7647 }
7648 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
7649 if (*node).flags & 1 as libc::c_int != 0 && (*node).numslots != 0 {
7650 (*server.cluster).size += 1;
7651 if (*node).flags & (8 as libc::c_int | 4 as libc::c_int) == 0 as libc::c_int
7652 {
7653 reachable_masters += 1;
7654 }
7655 }
7656 }
7657 dictReleaseIterator(di);
7658 let mut needed_quorum: libc::c_int = (*server.cluster).size / 2 as libc::c_int
7659 + 1 as libc::c_int;
7660 if reachable_masters < needed_quorum {
7661 new_state = 1 as libc::c_int;
7662 among_minority_time = mstime();
7663 }
7664 if new_state != (*server.cluster).state {
7665 let mut rejoin_delay: mstime_t = server.cluster_node_timeout;
7666 if rejoin_delay > 5000 as libc::c_int as libc::c_longlong {
7667 rejoin_delay = 5000 as libc::c_int as mstime_t;
7668 }
7669 if rejoin_delay < 500 as libc::c_int as libc::c_longlong {
7670 rejoin_delay = 500 as libc::c_int as mstime_t;
7671 }
7672 if new_state == 0 as libc::c_int && (*myself).flags & 1 as libc::c_int != 0
7673 && mstime() - among_minority_time < rejoin_delay
7674 {
7675 return;
7676 }
7677 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7678 _serverLog(
7679 3 as libc::c_int,
7680 b"Cluster state changed: %s\0" as *const u8 as *const libc::c_char,
7681 if new_state == 0 as libc::c_int {
7682 b"ok\0" as *const u8 as *const libc::c_char
7683 } else {
7684 b"fail\0" as *const u8 as *const libc::c_char
7685 },
7686 );
7687 }
7688 (*server.cluster).state = new_state;
7689 }
7690}
7691#[no_mangle]
7692pub unsafe extern "C" fn verifyClusterConfigWithData() -> libc::c_int {
7693 let mut j: libc::c_int = 0;
7694 let mut update_config: libc::c_int = 0 as libc::c_int;
7695 if server.cluster_module_flags & (1 as libc::c_int) << 2 as libc::c_int != 0 {
7696 return 0 as libc::c_int;
7697 }
7698 if (*myself).flags & 2 as libc::c_int != 0 {
7699 return 0 as libc::c_int;
7700 }
7701 j = 1 as libc::c_int;
7702 while j < server.dbnum {
7703 if ((*(*(server.db).offset(j as isize)).dict).ht_used[0 as libc::c_int as usize])
7704 .wrapping_add(
7705 (*(*(server.db).offset(j as isize)).dict)
7706 .ht_used[1 as libc::c_int as usize],
7707 ) != 0
7708 {
7709 return -(1 as libc::c_int);
7710 }
7711 j += 1;
7712 }
7713 j = 0 as libc::c_int;
7714 while j < 16384 as libc::c_int {
7715 if !(countKeysInSlot(j as libc::c_uint) == 0) {
7716 if !((*server.cluster).slots[j as usize] == myself
7717 || !((*server.cluster).importing_slots_from[j as usize]).is_null())
7718 {
7719 update_config += 1;
7720 if ((*server.cluster).slots[j as usize]).is_null() {
7721 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7722 _serverLog(
7723 3 as libc::c_int,
7724 b"I have keys for unassigned slot %d. Taking responsibility for it.\0"
7725 as *const u8 as *const libc::c_char,
7726 j,
7727 );
7728 }
7729 clusterAddSlot(myself, j);
7730 } else {
7731 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
7732 _serverLog(
7733 3 as libc::c_int,
7734 b"I have keys for slot %d, but the slot is assigned to another node. Setting it to importing state.\0"
7735 as *const u8 as *const libc::c_char,
7736 j,
7737 );
7738 }
7739 (*server.cluster)
7740 .importing_slots_from[j
7741 as usize] = (*server.cluster).slots[j as usize];
7742 }
7743 }
7744 }
7745 j += 1;
7746 }
7747 if update_config != 0 {
7748 clusterSaveConfigOrDie(1 as libc::c_int);
7749 }
7750 return 0 as libc::c_int;
7751}
7752#[no_mangle]
7753pub unsafe extern "C" fn clusterSetMaster(mut n: *mut clusterNode) {
7754 if n != myself {} else {
7755 _serverAssert(
7756 b"n != myself\0" as *const u8 as *const libc::c_char,
7757 b"cluster.c\0" as *const u8 as *const libc::c_char,
7758 4572 as libc::c_int,
7759 );
7760 unreachable!();
7761 };
7762 if (*myself).numslots == 0 as libc::c_int {} else {
7763 _serverAssert(
7764 b"myself->numslots == 0\0" as *const u8 as *const libc::c_char,
7765 b"cluster.c\0" as *const u8 as *const libc::c_char,
7766 4573 as libc::c_int,
7767 );
7768 unreachable!();
7769 };
7770 if (*myself).flags & 1 as libc::c_int != 0 {
7771 (*myself).flags &= !(1 as libc::c_int | 256 as libc::c_int);
7772 (*myself).flags |= 2 as libc::c_int;
7773 clusterCloseAllSlots();
7774 } else if !((*myself).slaveof).is_null() {
7775 clusterNodeRemoveSlave((*myself).slaveof, myself);
7776 }
7777 (*myself).slaveof = n;
7778 clusterNodeAddSlave(n, myself);
7779 replicationSetMaster(((*n).ip).as_mut_ptr(), (*n).port);
7780 resetManualFailover();
7781}
7782static mut redisNodeFlagsTable: [redisNodeFlags; 8] = [
7783 {
7784 let mut init = redisNodeFlags {
7785 flag: 16 as libc::c_int as uint16_t,
7786 name: b"myself,\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
7787 };
7788 init
7789 },
7790 {
7791 let mut init = redisNodeFlags {
7792 flag: 1 as libc::c_int as uint16_t,
7793 name: b"master,\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
7794 };
7795 init
7796 },
7797 {
7798 let mut init = redisNodeFlags {
7799 flag: 2 as libc::c_int as uint16_t,
7800 name: b"slave,\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
7801 };
7802 init
7803 },
7804 {
7805 let mut init = redisNodeFlags {
7806 flag: 4 as libc::c_int as uint16_t,
7807 name: b"fail?,\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
7808 };
7809 init
7810 },
7811 {
7812 let mut init = redisNodeFlags {
7813 flag: 8 as libc::c_int as uint16_t,
7814 name: b"fail,\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
7815 };
7816 init
7817 },
7818 {
7819 let mut init = redisNodeFlags {
7820 flag: 32 as libc::c_int as uint16_t,
7821 name: b"handshake,\0" as *const u8 as *const libc::c_char
7822 as *mut libc::c_char,
7823 };
7824 init
7825 },
7826 {
7827 let mut init = redisNodeFlags {
7828 flag: 64 as libc::c_int as uint16_t,
7829 name: b"noaddr,\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
7830 };
7831 init
7832 },
7833 {
7834 let mut init = redisNodeFlags {
7835 flag: 512 as libc::c_int as uint16_t,
7836 name: b"nofailover,\0" as *const u8 as *const libc::c_char
7837 as *mut libc::c_char,
7838 };
7839 init
7840 },
7841];
7842#[no_mangle]
7843pub unsafe extern "C" fn representClusterNodeFlags(
7844 mut ci: sds,
7845 mut flags: uint16_t,
7846) -> sds {
7847 let mut orig_len: size_t = sdslen(ci);
7848 let mut i: libc::c_int = 0;
7849 let mut size: libc::c_int = (core::mem::size_of::<[redisNodeFlags; 8]>()
7850 as libc::c_ulong)
7851 .wrapping_div(core::mem::size_of::<redisNodeFlags>() as libc::c_ulong)
7852 as libc::c_int;
7853 i = 0 as libc::c_int;
7854 while i < size {
7855 let mut nodeflag: *mut redisNodeFlags = redisNodeFlagsTable
7856 .as_mut_ptr()
7857 .offset(i as isize);
7858 if flags as libc::c_int & (*nodeflag).flag as libc::c_int != 0 {
7859 ci = sdscat(ci, (*nodeflag).name);
7860 }
7861 i += 1;
7862 }
7863 if sdslen(ci) == orig_len {
7864 ci = sdscat(ci, b"noflags,\0" as *const u8 as *const libc::c_char);
7865 }
7866 sdsIncrLen(ci, -(1 as libc::c_int) as ssize_t);
7867 return ci;
7868}
7869#[no_mangle]
7870pub unsafe extern "C" fn representSlotInfo(
7871 mut ci: sds,
7872 mut slot_info_pairs: *mut uint16_t,
7873 mut slot_info_pairs_count: libc::c_int,
7874) -> sds {
7875 let mut i: libc::c_int = 0 as libc::c_int;
7876 while i < slot_info_pairs_count {
7877 let mut start: libc::c_ulong = *slot_info_pairs.offset(i as isize)
7878 as libc::c_ulong;
7879 let mut end: libc::c_ulong = *slot_info_pairs
7880 .offset((i + 1 as libc::c_int) as isize) as libc::c_ulong;
7881 if start == end {
7882 ci = sdscatfmt(ci, b" %i\0" as *const u8 as *const libc::c_char, start);
7883 } else {
7884 ci = sdscatfmt(
7885 ci,
7886 b" %i-%i\0" as *const u8 as *const libc::c_char,
7887 start,
7888 end,
7889 );
7890 }
7891 i += 2 as libc::c_int;
7892 }
7893 return ci;
7894}
7895#[no_mangle]
7896pub unsafe extern "C" fn clusterGenNodeDescription(
7897 mut node: *mut clusterNode,
7898 mut use_pport: libc::c_int,
7899) -> sds {
7900 let mut j: libc::c_int = 0;
7901 let mut start: libc::c_int = 0;
7902 let mut ci: sds = 0 as *mut libc::c_char;
7903 let mut port: libc::c_int = if use_pport != 0 && (*node).pport != 0 {
7904 (*node).pport
7905 } else {
7906 (*node).port
7907 };
7908 ci = sdscatlen(
7909 sdsempty(),
7910 ((*node).name).as_mut_ptr() as *const libc::c_void,
7911 40 as libc::c_int as size_t,
7912 );
7913 if sdslen((*node).hostname) != 0 as libc::c_int as libc::c_ulong {
7914 ci = sdscatfmt(
7915 ci,
7916 b" %s:%i@%i,%s \0" as *const u8 as *const libc::c_char,
7917 ((*node).ip).as_mut_ptr(),
7918 port,
7919 (*node).cport,
7920 (*node).hostname,
7921 );
7922 } else {
7923 ci = sdscatfmt(
7924 ci,
7925 b" %s:%i@%i \0" as *const u8 as *const libc::c_char,
7926 ((*node).ip).as_mut_ptr(),
7927 port,
7928 (*node).cport,
7929 );
7930 }
7931 ci = representClusterNodeFlags(ci, (*node).flags as uint16_t);
7932 ci = sdscatlen(
7933 ci,
7934 b" \0" as *const u8 as *const libc::c_char as *const libc::c_void,
7935 1 as libc::c_int as size_t,
7936 );
7937 if !((*node).slaveof).is_null() {
7938 ci = sdscatlen(
7939 ci,
7940 ((*(*node).slaveof).name).as_mut_ptr() as *const libc::c_void,
7941 40 as libc::c_int as size_t,
7942 );
7943 } else {
7944 ci = sdscatlen(
7945 ci,
7946 b"-\0" as *const u8 as *const libc::c_char as *const libc::c_void,
7947 1 as libc::c_int as size_t,
7948 );
7949 }
7950 let mut nodeEpoch: libc::c_ulonglong = (*node).configEpoch as libc::c_ulonglong;
7951 if (*node).flags & 2 as libc::c_int != 0 && !((*node).slaveof).is_null() {
7952 nodeEpoch = (*(*node).slaveof).configEpoch as libc::c_ulonglong;
7953 }
7954 ci = sdscatfmt(
7955 ci,
7956 b" %I %I %U %s\0" as *const u8 as *const libc::c_char,
7957 (*node).ping_sent,
7958 (*node).pong_received,
7959 nodeEpoch,
7960 if !((*node).link).is_null() || (*node).flags & 16 as libc::c_int != 0 {
7961 b"connected\0" as *const u8 as *const libc::c_char
7962 } else {
7963 b"disconnected\0" as *const u8 as *const libc::c_char
7964 },
7965 );
7966 if !((*node).slot_info_pairs).is_null() {
7967 ci = representSlotInfo(
7968 ci,
7969 (*node).slot_info_pairs,
7970 (*node).slot_info_pairs_count,
7971 );
7972 } else if (*node).numslots > 0 as libc::c_int {
7973 start = -(1 as libc::c_int);
7974 j = 0 as libc::c_int;
7975 while j < 16384 as libc::c_int {
7976 let mut bit: libc::c_int = 0;
7977 bit = clusterNodeGetSlotBit(node, j);
7978 if bit != 0 as libc::c_int {
7979 if start == -(1 as libc::c_int) {
7980 start = j;
7981 }
7982 }
7983 if start != -(1 as libc::c_int)
7984 && (bit == 0 || j == 16384 as libc::c_int - 1 as libc::c_int)
7985 {
7986 if bit != 0 && j == 16384 as libc::c_int - 1 as libc::c_int {
7987 j += 1;
7988 }
7989 if start == j - 1 as libc::c_int {
7990 ci = sdscatfmt(
7991 ci,
7992 b" %i\0" as *const u8 as *const libc::c_char,
7993 start,
7994 );
7995 } else {
7996 ci = sdscatfmt(
7997 ci,
7998 b" %i-%i\0" as *const u8 as *const libc::c_char,
7999 start,
8000 j - 1 as libc::c_int,
8001 );
8002 }
8003 start = -(1 as libc::c_int);
8004 }
8005 j += 1;
8006 }
8007 }
8008 if (*node).flags & 16 as libc::c_int != 0 {
8009 j = 0 as libc::c_int;
8010 while j < 16384 as libc::c_int {
8011 if !((*server.cluster).migrating_slots_to[j as usize]).is_null() {
8012 ci = sdscatprintf(
8013 ci,
8014 b" [%d->-%.40s]\0" as *const u8 as *const libc::c_char,
8015 j,
8016 ((*(*server.cluster).migrating_slots_to[j as usize]).name)
8017 .as_mut_ptr(),
8018 );
8019 } else if !((*server.cluster).importing_slots_from[j as usize]).is_null() {
8020 ci = sdscatprintf(
8021 ci,
8022 b" [%d-<-%.40s]\0" as *const u8 as *const libc::c_char,
8023 j,
8024 ((*(*server.cluster).importing_slots_from[j as usize]).name)
8025 .as_mut_ptr(),
8026 );
8027 }
8028 j += 1;
8029 }
8030 }
8031 return ci;
8032}
8033#[no_mangle]
8034pub unsafe extern "C" fn clusterGenNodesSlotsInfo(mut filter: libc::c_int) {
8035 let mut n: *mut clusterNode = 0 as *mut clusterNode;
8036 let mut start: libc::c_int = -(1 as libc::c_int);
8037 let mut i: libc::c_int = 0 as libc::c_int;
8038 while i <= 16384 as libc::c_int {
8039 if n.is_null() {
8040 if i == 16384 as libc::c_int {
8041 break;
8042 }
8043 n = (*server.cluster).slots[i as usize];
8044 start = i;
8045 } else if i == 16384 as libc::c_int || n != (*server.cluster).slots[i as usize] {
8046 if (*n).flags & filter == 0 {
8047 if ((*n).slot_info_pairs).is_null() {
8048 (*n)
8049 .slot_info_pairs = zmalloc(
8050 ((2 as libc::c_int * (*n).numslots) as libc::c_ulong)
8051 .wrapping_mul(
8052 core::mem::size_of::<uint16_t>() as libc::c_ulong,
8053 ),
8054 ) as *mut uint16_t;
8055 }
8056 if ((*n).slot_info_pairs_count + 1 as libc::c_int)
8057 < 2 as libc::c_int * (*n).numslots
8058 {} else {
8059 _serverAssert(
8060 b"(n->slot_info_pairs_count + 1) < (2 * n->numslots)\0"
8061 as *const u8 as *const libc::c_char,
8062 b"cluster.c\0" as *const u8 as *const libc::c_char,
8063 4752 as libc::c_int,
8064 );
8065 unreachable!();
8066 };
8067 let fresh10 = (*n).slot_info_pairs_count;
8068 (*n).slot_info_pairs_count = (*n).slot_info_pairs_count + 1;
8069 *((*n).slot_info_pairs).offset(fresh10 as isize) = start as uint16_t;
8070 let fresh11 = (*n).slot_info_pairs_count;
8071 (*n).slot_info_pairs_count = (*n).slot_info_pairs_count + 1;
8072 *((*n).slot_info_pairs)
8073 .offset(fresh11 as isize) = (i - 1 as libc::c_int) as uint16_t;
8074 }
8075 if i == 16384 as libc::c_int {
8076 break;
8077 }
8078 n = (*server.cluster).slots[i as usize];
8079 start = i;
8080 }
8081 i += 1;
8082 }
8083}
8084#[no_mangle]
8085pub unsafe extern "C" fn clusterFreeNodesSlotsInfo(mut n: *mut clusterNode) {
8086 zfree((*n).slot_info_pairs as *mut libc::c_void);
8087 (*n).slot_info_pairs = 0 as *mut uint16_t;
8088 (*n).slot_info_pairs_count = 0 as libc::c_int;
8089}
8090#[no_mangle]
8091pub unsafe extern "C" fn clusterGenNodesDescription(
8092 mut filter: libc::c_int,
8093 mut use_pport: libc::c_int,
8094) -> sds {
8095 let mut ci: sds = sdsempty();
8096 let mut ni: sds = 0 as *mut libc::c_char;
8097 let mut di: *mut dictIterator = 0 as *mut dictIterator;
8098 let mut de: *mut dictEntry = 0 as *mut dictEntry;
8099 clusterGenNodesSlotsInfo(filter);
8100 di = dictGetSafeIterator((*server.cluster).nodes);
8101 loop {
8102 de = dictNext(di);
8103 if de.is_null() {
8104 break;
8105 }
8106 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
8107 if (*node).flags & filter != 0 {
8108 continue;
8109 }
8110 ni = clusterGenNodeDescription(node, use_pport);
8111 ci = sdscatsds(ci, ni);
8112 sdsfree(ni);
8113 ci = sdscatlen(
8114 ci,
8115 b"\n\0" as *const u8 as *const libc::c_char as *const libc::c_void,
8116 1 as libc::c_int as size_t,
8117 );
8118 clusterFreeNodesSlotsInfo(node);
8119 }
8120 dictReleaseIterator(di);
8121 return ci;
8122}
8123#[no_mangle]
8124pub unsafe extern "C" fn addReplyClusterLinkDescription(
8125 mut c: *mut client,
8126 mut link: *mut clusterLink,
8127) {
8128 addReplyMapLen(c, 6 as libc::c_int as libc::c_long);
8129 addReplyBulkCString(c, b"direction\0" as *const u8 as *const libc::c_char);
8130 addReplyBulkCString(
8131 c,
8132 if (*link).inbound != 0 {
8133 b"from\0" as *const u8 as *const libc::c_char
8134 } else {
8135 b"to\0" as *const u8 as *const libc::c_char
8136 },
8137 );
8138 if !((*link).node).is_null() {} else {
8139 _serverAssert(
8140 b"link->node\0" as *const u8 as *const libc::c_char,
8141 b"cluster.c\0" as *const u8 as *const libc::c_char,
8142 4820 as libc::c_int,
8143 );
8144 unreachable!();
8145 };
8146 let mut node_name: sds = sdsnewlen(
8147 ((*(*link).node).name).as_mut_ptr() as *const libc::c_void,
8148 40 as libc::c_int as size_t,
8149 );
8150 addReplyBulkCString(c, b"node\0" as *const u8 as *const libc::c_char);
8151 addReplyBulkCString(c, node_name as *const libc::c_char);
8152 sdsfree(node_name);
8153 addReplyBulkCString(c, b"create-time\0" as *const u8 as *const libc::c_char);
8154 addReplyLongLong(c, (*link).ctime);
8155 let mut events: [libc::c_char; 3] = [0; 3];
8156 let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
8157 p = events.as_mut_ptr();
8158 if !((*link).conn).is_null() {
8159 if connHasReadHandler((*link).conn) != 0 {
8160 let fresh12 = p;
8161 p = p.offset(1);
8162 *fresh12 = 'r' as i32 as libc::c_char;
8163 }
8164 if connHasWriteHandler((*link).conn) != 0 {
8165 let fresh13 = p;
8166 p = p.offset(1);
8167 *fresh13 = 'w' as i32 as libc::c_char;
8168 }
8169 }
8170 *p = '\0' as i32 as libc::c_char;
8171 addReplyBulkCString(c, b"events\0" as *const u8 as *const libc::c_char);
8172 addReplyBulkCString(c, events.as_mut_ptr());
8173 addReplyBulkCString(
8174 c,
8175 b"send-buffer-allocated\0" as *const u8 as *const libc::c_char,
8176 );
8177 addReplyLongLong(c, sdsalloc((*link).sndbuf) as libc::c_longlong);
8178 addReplyBulkCString(c, b"send-buffer-used\0" as *const u8 as *const libc::c_char);
8179 addReplyLongLong(c, sdslen((*link).sndbuf) as libc::c_longlong);
8180}
8181#[no_mangle]
8182pub unsafe extern "C" fn addReplyClusterLinksDescription(mut c: *mut client) {
8183 let mut di: *mut dictIterator = 0 as *mut dictIterator;
8184 let mut de: *mut dictEntry = 0 as *mut dictEntry;
8185 let mut arraylen_ptr: *mut libc::c_void = 0 as *mut libc::c_void;
8186 let mut num_links: libc::c_int = 0 as libc::c_int;
8187 arraylen_ptr = addReplyDeferredLen(c);
8188 di = dictGetSafeIterator((*server.cluster).nodes);
8189 loop {
8190 de = dictNext(di);
8191 if de.is_null() {
8192 break;
8193 }
8194 let mut node: *mut clusterNode = (*de).v.val as *mut clusterNode;
8195 if !((*node).link).is_null() {
8196 num_links += 1;
8197 addReplyClusterLinkDescription(c, (*node).link);
8198 }
8199 if !((*node).inbound_link).is_null() {
8200 num_links += 1;
8201 addReplyClusterLinkDescription(c, (*node).inbound_link);
8202 }
8203 }
8204 dictReleaseIterator(di);
8205 setDeferredArrayLen(c, arraylen_ptr, num_links as libc::c_long);
8206}
8207#[no_mangle]
8208pub unsafe extern "C" fn getPreferredEndpoint(
8209 mut n: *mut clusterNode,
8210) -> *const libc::c_char {
8211 match server.cluster_preferred_endpoint_type {
8212 0 => return ((*n).ip).as_mut_ptr(),
8213 1 => {
8214 return if sdslen((*n).hostname) != 0 as libc::c_int as libc::c_ulong {
8215 (*n).hostname as *const libc::c_char
8216 } else {
8217 b"?\0" as *const u8 as *const libc::c_char
8218 };
8219 }
8220 2 => return b"\0" as *const u8 as *const libc::c_char,
8221 _ => {}
8222 }
8223 return b"unknown\0" as *const u8 as *const libc::c_char;
8224}
8225#[no_mangle]
8226pub unsafe extern "C" fn clusterGetMessageTypeString(
8227 mut type_0: libc::c_int,
8228) -> *const libc::c_char {
8229 match type_0 {
8230 0 => return b"ping\0" as *const u8 as *const libc::c_char,
8231 1 => return b"pong\0" as *const u8 as *const libc::c_char,
8232 2 => return b"meet\0" as *const u8 as *const libc::c_char,
8233 3 => return b"fail\0" as *const u8 as *const libc::c_char,
8234 4 => return b"publish\0" as *const u8 as *const libc::c_char,
8235 10 => return b"publishshard\0" as *const u8 as *const libc::c_char,
8236 5 => return b"auth-req\0" as *const u8 as *const libc::c_char,
8237 6 => return b"auth-ack\0" as *const u8 as *const libc::c_char,
8238 7 => return b"update\0" as *const u8 as *const libc::c_char,
8239 8 => return b"mfstart\0" as *const u8 as *const libc::c_char,
8240 9 => return b"module\0" as *const u8 as *const libc::c_char,
8241 _ => {}
8242 }
8243 return b"unknown\0" as *const u8 as *const libc::c_char;
8244}
8245#[no_mangle]
8246pub unsafe extern "C" fn getSlotOrReply(
8247 mut c: *mut client,
8248 mut o: *mut robj,
8249) -> libc::c_int {
8250 let mut slot: libc::c_longlong = 0;
8251 if getLongLongFromObject(o, &mut slot) != 0 as libc::c_int
8252 || slot < 0 as libc::c_int as libc::c_longlong
8253 || slot >= 16384 as libc::c_int as libc::c_longlong
8254 {
8255 addReplyError(
8256 c,
8257 b"Invalid or out of range slot\0" as *const u8 as *const libc::c_char,
8258 );
8259 return -(1 as libc::c_int);
8260 }
8261 return slot as libc::c_int;
8262}
8263unsafe extern "C" fn isReplicaAvailable(mut node: *mut clusterNode) -> libc::c_int {
8264 if (*node).flags & 8 as libc::c_int != 0 {
8265 return 0 as libc::c_int;
8266 }
8267 let mut repl_offset: libc::c_longlong = (*node).repl_offset;
8268 if (*node).flags & 16 as libc::c_int != 0 {
8269 repl_offset = replicationGetSlaveOffset();
8270 }
8271 return (repl_offset != 0 as libc::c_int as libc::c_longlong) as libc::c_int;
8272}
8273#[no_mangle]
8274pub unsafe extern "C" fn checkSlotAssignmentsOrReply(
8275 mut c: *mut client,
8276 mut slots: *mut libc::c_uchar,
8277 mut del: libc::c_int,
8278 mut start_slot: libc::c_int,
8279 mut end_slot: libc::c_int,
8280) -> libc::c_int {
8281 let mut slot: libc::c_int = 0;
8282 slot = start_slot;
8283 while slot <= end_slot {
8284 if del != 0 && ((*server.cluster).slots[slot as usize]).is_null() {
8285 addReplyErrorFormat(
8286 c,
8287 b"Slot %d is already unassigned\0" as *const u8 as *const libc::c_char,
8288 slot,
8289 );
8290 return -(1 as libc::c_int);
8291 } else {
8292 if del == 0 && !((*server.cluster).slots[slot as usize]).is_null() {
8293 addReplyErrorFormat(
8294 c,
8295 b"Slot %d is already busy\0" as *const u8 as *const libc::c_char,
8296 slot,
8297 );
8298 return -(1 as libc::c_int);
8299 }
8300 }
8301 let ref mut fresh14 = *slots.offset(slot as isize);
8302 let fresh15 = *fresh14;
8303 *fresh14 = (*fresh14).wrapping_add(1);
8304 if fresh15 as libc::c_int == 1 as libc::c_int {
8305 addReplyErrorFormat(
8306 c,
8307 b"Slot %d specified multiple times\0" as *const u8
8308 as *const libc::c_char,
8309 slot,
8310 );
8311 return -(1 as libc::c_int);
8312 }
8313 slot += 1;
8314 }
8315 return 0 as libc::c_int;
8316}
8317#[no_mangle]
8318pub unsafe extern "C" fn clusterUpdateSlots(
8319 mut c: *mut client,
8320 mut slots: *mut libc::c_uchar,
8321 mut del: libc::c_int,
8322) {
8323 let mut j: libc::c_int = 0;
8324 j = 0 as libc::c_int;
8325 while j < 16384 as libc::c_int {
8326 if *slots.offset(j as isize) != 0 {
8327 let mut retval: libc::c_int = 0;
8328 if !((*server.cluster).importing_slots_from[j as usize]).is_null() {
8329 (*server.cluster)
8330 .importing_slots_from[j as usize] = 0 as *mut clusterNode;
8331 }
8332 retval = if del != 0 {
8333 clusterDelSlot(j)
8334 } else {
8335 clusterAddSlot(myself, j)
8336 };
8337 if retval == 0 as libc::c_int {} else {
8338 _serverAssertWithInfo(
8339 c,
8340 0 as *const robj,
8341 b"retval == C_OK\0" as *const u8 as *const libc::c_char,
8342 b"cluster.c\0" as *const u8 as *const libc::c_char,
8343 4964 as libc::c_int,
8344 );
8345 unreachable!();
8346 };
8347 }
8348 j += 1;
8349 }
8350}
8351#[no_mangle]
8352pub unsafe extern "C" fn addNodeToNodeReply(
8353 mut c: *mut client,
8354 mut node: *mut clusterNode,
8355) {
8356 addReplyArrayLen(c, 4 as libc::c_int as libc::c_long);
8357 if server.cluster_preferred_endpoint_type == CLUSTER_ENDPOINT_TYPE_IP as libc::c_int
8358 {
8359 addReplyBulkCString(c, ((*node).ip).as_mut_ptr());
8360 } else if server.cluster_preferred_endpoint_type
8361 == CLUSTER_ENDPOINT_TYPE_HOSTNAME as libc::c_int
8362 {
8363 if sdslen((*node).hostname) != 0 as libc::c_int as libc::c_ulong {
8364 addReplyBulkCBuffer(
8365 c,
8366 (*node).hostname as *const libc::c_void,
8367 sdslen((*node).hostname),
8368 );
8369 } else {
8370 addReplyBulkCString(c, b"?\0" as *const u8 as *const libc::c_char);
8371 }
8372 } else if server.cluster_preferred_endpoint_type
8373 == CLUSTER_ENDPOINT_TYPE_UNKNOWN_ENDPOINT as libc::c_int
8374 {
8375 addReplyNull(c);
8376 } else {
8377 _serverPanic(
8378 b"cluster.c\0" as *const u8 as *const libc::c_char,
8379 4982 as libc::c_int,
8380 b"Unrecognized preferred endpoint type\0" as *const u8 as *const libc::c_char,
8381 );
8382 unreachable!();
8383 }
8384 let mut use_pport: libc::c_int = (server.tls_cluster != 0 && !((*c).conn).is_null()
8385 && connGetType((*c).conn) != 2 as libc::c_int) as libc::c_int;
8386 addReplyLongLong(
8387 c,
8388 (if use_pport != 0 && (*node).pport != 0 { (*node).pport } else { (*node).port })
8389 as libc::c_longlong,
8390 );
8391 addReplyBulkCBuffer(
8392 c,
8393 ((*node).name).as_mut_ptr() as *const libc::c_void,
8394 40 as libc::c_int as size_t,
8395 );
8396 let mut deflen: *mut libc::c_void = addReplyDeferredLen(c);
8397 let mut length: libc::c_int = 0 as libc::c_int;
8398 if server.cluster_preferred_endpoint_type != CLUSTER_ENDPOINT_TYPE_IP as libc::c_int
8399 {
8400 addReplyBulkCString(c, b"ip\0" as *const u8 as *const libc::c_char);
8401 addReplyBulkCString(c, ((*node).ip).as_mut_ptr());
8402 length += 1;
8403 }
8404 if server.cluster_preferred_endpoint_type
8405 != CLUSTER_ENDPOINT_TYPE_HOSTNAME as libc::c_int
8406 && sdslen((*node).hostname) != 0 as libc::c_int as libc::c_ulong
8407 {
8408 addReplyBulkCString(c, b"hostname\0" as *const u8 as *const libc::c_char);
8409 addReplyBulkCBuffer(
8410 c,
8411 (*node).hostname as *const libc::c_void,
8412 sdslen((*node).hostname),
8413 );
8414 length += 1;
8415 }
8416 setDeferredMapLen(c, deflen, length as libc::c_long);
8417}
8418#[no_mangle]
8419pub unsafe extern "C" fn addNodeReplyForClusterSlot(
8420 mut c: *mut client,
8421 mut node: *mut clusterNode,
8422 mut start_slot: libc::c_int,
8423 mut end_slot: libc::c_int,
8424) {
8425 let mut i: libc::c_int = 0;
8426 let mut nested_elements: libc::c_int = 3 as libc::c_int;
8427 let mut nested_replylen: *mut libc::c_void = addReplyDeferredLen(c);
8428 addReplyLongLong(c, start_slot as libc::c_longlong);
8429 addReplyLongLong(c, end_slot as libc::c_longlong);
8430 addNodeToNodeReply(c, node);
8431 i = 0 as libc::c_int;
8432 while i < (*node).numslaves {
8433 if !(isReplicaAvailable(*((*node).slaves).offset(i as isize)) == 0) {
8434 addNodeToNodeReply(c, *((*node).slaves).offset(i as isize));
8435 nested_elements += 1;
8436 }
8437 i += 1;
8438 }
8439 setDeferredArrayLen(c, nested_replylen, nested_elements as libc::c_long);
8440}
8441#[no_mangle]
8442pub unsafe extern "C" fn addNodeDetailsToShardReply(
8443 mut c: *mut client,
8444 mut node: *mut clusterNode,
8445) {
8446 let mut reply_count: libc::c_int = 0 as libc::c_int;
8447 let mut node_replylen: *mut libc::c_void = addReplyDeferredLen(c);
8448 addReplyBulkCString(c, b"id\0" as *const u8 as *const libc::c_char);
8449 addReplyBulkCBuffer(
8450 c,
8451 ((*node).name).as_mut_ptr() as *const libc::c_void,
8452 40 as libc::c_int as size_t,
8453 );
8454 reply_count += 1;
8455 let mut plaintext_port: libc::c_int = if server.tls_cluster != 0 {
8456 (*node).pport
8457 } else {
8458 (*node).port
8459 };
8460 let mut tls_port: libc::c_int = if server.tls_cluster != 0 {
8461 (*node).port
8462 } else {
8463 0 as libc::c_int
8464 };
8465 if plaintext_port != 0 {
8466 addReplyBulkCString(c, b"port\0" as *const u8 as *const libc::c_char);
8467 addReplyLongLong(c, plaintext_port as libc::c_longlong);
8468 reply_count += 1;
8469 }
8470 if tls_port != 0 {
8471 addReplyBulkCString(c, b"tls-port\0" as *const u8 as *const libc::c_char);
8472 addReplyLongLong(c, tls_port as libc::c_longlong);
8473 reply_count += 1;
8474 }
8475 addReplyBulkCString(c, b"ip\0" as *const u8 as *const libc::c_char);
8476 addReplyBulkCString(c, ((*node).ip).as_mut_ptr());
8477 reply_count += 1;
8478 addReplyBulkCString(c, b"endpoint\0" as *const u8 as *const libc::c_char);
8479 addReplyBulkCString(c, getPreferredEndpoint(node));
8480 reply_count += 1;
8481 if sdslen((*node).hostname) != 0 as libc::c_int as libc::c_ulong {
8482 addReplyBulkCString(c, b"hostname\0" as *const u8 as *const libc::c_char);
8483 addReplyBulkCBuffer(
8484 c,
8485 (*node).hostname as *const libc::c_void,
8486 sdslen((*node).hostname),
8487 );
8488 reply_count += 1;
8489 }
8490 let mut node_offset: libc::c_longlong = 0;
8491 if (*node).flags & 16 as libc::c_int != 0 {
8492 node_offset = if (*node).flags & 2 as libc::c_int != 0 {
8493 replicationGetSlaveOffset()
8494 } else {
8495 server.master_repl_offset
8496 };
8497 } else {
8498 node_offset = (*node).repl_offset;
8499 }
8500 addReplyBulkCString(c, b"role\0" as *const u8 as *const libc::c_char);
8501 addReplyBulkCString(
8502 c,
8503 if (*node).flags & 2 as libc::c_int != 0 {
8504 b"replica\0" as *const u8 as *const libc::c_char
8505 } else {
8506 b"master\0" as *const u8 as *const libc::c_char
8507 },
8508 );
8509 reply_count += 1;
8510 addReplyBulkCString(c, b"replication-offset\0" as *const u8 as *const libc::c_char);
8511 addReplyLongLong(c, node_offset);
8512 reply_count += 1;
8513 addReplyBulkCString(c, b"health\0" as *const u8 as *const libc::c_char);
8514 let mut health_msg: *const libc::c_char = 0 as *const libc::c_char;
8515 if (*node).flags & 8 as libc::c_int != 0 {
8516 health_msg = b"fail\0" as *const u8 as *const libc::c_char;
8517 } else if (*node).flags & 2 as libc::c_int != 0
8518 && node_offset == 0 as libc::c_int as libc::c_longlong
8519 {
8520 health_msg = b"loading\0" as *const u8 as *const libc::c_char;
8521 } else {
8522 health_msg = b"online\0" as *const u8 as *const libc::c_char;
8523 }
8524 addReplyBulkCString(c, health_msg);
8525 reply_count += 1;
8526 setDeferredMapLen(c, node_replylen, reply_count as libc::c_long);
8527}
8528#[no_mangle]
8529pub unsafe extern "C" fn addShardReplyForClusterShards(
8530 mut c: *mut client,
8531 mut node: *mut clusterNode,
8532 mut slot_info_pairs: *mut uint16_t,
8533 mut slot_pairs_count: libc::c_int,
8534) {
8535 addReplyMapLen(c, 2 as libc::c_int as libc::c_long);
8536 addReplyBulkCString(c, b"slots\0" as *const u8 as *const libc::c_char);
8537 if !slot_info_pairs.is_null() {
8538 if slot_pairs_count % 2 as libc::c_int == 0 as libc::c_int {} else {
8539 _serverAssert(
8540 b"(slot_pairs_count % 2) == 0\0" as *const u8 as *const libc::c_char,
8541 b"cluster.c\0" as *const u8 as *const libc::c_char,
8542 5101 as libc::c_int,
8543 );
8544 unreachable!();
8545 };
8546 addReplyArrayLen(c, slot_pairs_count as libc::c_long);
8547 let mut i: libc::c_int = 0 as libc::c_int;
8548 while i < slot_pairs_count {
8549 addReplyLongLong(
8550 c,
8551 *slot_info_pairs.offset(i as isize) as libc::c_ulong as libc::c_longlong,
8552 );
8553 i += 1;
8554 }
8555 } else {
8556 addReplyArrayLen(c, 0 as libc::c_int as libc::c_long);
8557 }
8558 addReplyBulkCString(c, b"nodes\0" as *const u8 as *const libc::c_char);
8559 let mut nodes_for_slot: *mut list = clusterGetNodesServingMySlots(node);
8560 if !nodes_for_slot.is_null() {} else {
8561 _serverAssert(
8562 b"nodes_for_slot\0" as *const u8 as *const libc::c_char,
8563 b"cluster.c\0" as *const u8 as *const libc::c_char,
8564 5113 as libc::c_int,
8565 );
8566 unreachable!();
8567 };
8568 addReplyArrayLen(c, (*nodes_for_slot).len as libc::c_long);
8569 if (*nodes_for_slot).len != 0 as libc::c_int as libc::c_ulong {
8570 let mut li: listIter = listIter {
8571 next: 0 as *mut listNode,
8572 direction: 0,
8573 };
8574 let mut ln: *mut listNode = 0 as *mut listNode;
8575 listRewind(nodes_for_slot, &mut li);
8576 loop {
8577 ln = listNext(&mut li);
8578 if ln.is_null() {
8579 break;
8580 }
8581 let mut node_0: *mut clusterNode = (*ln).value as *mut clusterNode;
8582 addNodeDetailsToShardReply(c, node_0);
8583 }
8584 listRelease(nodes_for_slot);
8585 }
8586}
8587#[no_mangle]
8588pub unsafe extern "C" fn clusterReplyShards(mut c: *mut client) {
8589 let mut shard_replylen: *mut libc::c_void = addReplyDeferredLen(c);
8590 let mut shard_count: libc::c_int = 0 as libc::c_int;
8591 clusterGenNodesSlotsInfo(0 as libc::c_int);
8592 let mut di: *mut dictIterator = dictGetSafeIterator((*server.cluster).nodes);
8593 let mut de: *mut dictEntry = 0 as *mut dictEntry;
8594 loop {
8595 de = dictNext(di);
8596 if de.is_null() {
8597 break;
8598 }
8599 let mut n: *mut clusterNode = (*de).v.val as *mut clusterNode;
8600 if (*n).flags & 1 as libc::c_int == 0 {
8601 clusterFreeNodesSlotsInfo(n);
8602 } else {
8603 shard_count += 1;
8604 addShardReplyForClusterShards(
8605 c,
8606 n,
8607 (*n).slot_info_pairs,
8608 (*n).slot_info_pairs_count,
8609 );
8610 clusterFreeNodesSlotsInfo(n);
8611 }
8612 }
8613 dictReleaseIterator(di);
8614 setDeferredArrayLen(c, shard_replylen, shard_count as libc::c_long);
8615}
8616#[no_mangle]
8617pub unsafe extern "C" fn clusterReplyMultiBulkSlots(mut c: *mut client) {
8618 let mut n: *mut clusterNode = 0 as *mut clusterNode;
8619 let mut num_masters: libc::c_int = 0 as libc::c_int;
8620 let mut start: libc::c_int = -(1 as libc::c_int);
8621 let mut slot_replylen: *mut libc::c_void = addReplyDeferredLen(c);
8622 let mut i: libc::c_int = 0 as libc::c_int;
8623 while i <= 16384 as libc::c_int {
8624 if n.is_null() {
8625 if i == 16384 as libc::c_int {
8626 break;
8627 }
8628 n = (*server.cluster).slots[i as usize];
8629 start = i;
8630 } else if i == 16384 as libc::c_int || n != (*server.cluster).slots[i as usize] {
8631 addNodeReplyForClusterSlot(c, n, start, i - 1 as libc::c_int);
8632 num_masters += 1;
8633 if i == 16384 as libc::c_int {
8634 break;
8635 }
8636 n = (*server.cluster).slots[i as usize];
8637 start = i;
8638 }
8639 i += 1;
8640 }
8641 setDeferredArrayLen(c, slot_replylen, num_masters as libc::c_long);
8642}
8643#[no_mangle]
8644pub unsafe extern "C" fn clusterCommand(mut c: *mut client) {
8645 if server.cluster_enabled == 0 as libc::c_int {
8646 addReplyError(
8647 c,
8648 b"This instance has cluster support disabled\0" as *const u8
8649 as *const libc::c_char,
8650 );
8651 return;
8652 }
8653 if (*c).argc == 2 as libc::c_int
8654 && strcasecmp(
8655 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8656 b"help\0" as *const u8 as *const libc::c_char,
8657 ) == 0
8658 {
8659 let mut help: [*const libc::c_char; 54] = [
8660 b"ADDSLOTS <slot> [<slot> ...]\0" as *const u8 as *const libc::c_char,
8661 b" Assign slots to current node.\0" as *const u8 as *const libc::c_char,
8662 b"ADDSLOTSRANGE <start slot> <end slot> [<start slot> <end slot> ...]\0"
8663 as *const u8 as *const libc::c_char,
8664 b" Assign slots which are between <start-slot> and <end-slot> to current node.\0"
8665 as *const u8 as *const libc::c_char,
8666 b"BUMPEPOCH\0" as *const u8 as *const libc::c_char,
8667 b" Advance the cluster config epoch.\0" as *const u8
8668 as *const libc::c_char,
8669 b"COUNT-FAILURE-REPORTS <node-id>\0" as *const u8 as *const libc::c_char,
8670 b" Return number of failure reports for <node-id>.\0" as *const u8
8671 as *const libc::c_char,
8672 b"COUNTKEYSINSLOT <slot>\0" as *const u8 as *const libc::c_char,
8673 b" Return the number of keys in <slot>.\0" as *const u8
8674 as *const libc::c_char,
8675 b"DELSLOTS <slot> [<slot> ...]\0" as *const u8 as *const libc::c_char,
8676 b" Delete slots information from current node.\0" as *const u8
8677 as *const libc::c_char,
8678 b"DELSLOTSRANGE <start slot> <end slot> [<start slot> <end slot> ...]\0"
8679 as *const u8 as *const libc::c_char,
8680 b" Delete slots information which are between <start-slot> and <end-slot> from current node.\0"
8681 as *const u8 as *const libc::c_char,
8682 b"FAILOVER [FORCE|TAKEOVER]\0" as *const u8 as *const libc::c_char,
8683 b" Promote current replica node to being a master.\0" as *const u8
8684 as *const libc::c_char,
8685 b"FORGET <node-id>\0" as *const u8 as *const libc::c_char,
8686 b" Remove a node from the cluster.\0" as *const u8 as *const libc::c_char,
8687 b"GETKEYSINSLOT <slot> <count>\0" as *const u8 as *const libc::c_char,
8688 b" Return key names stored by current node in a slot.\0" as *const u8
8689 as *const libc::c_char,
8690 b"FLUSHSLOTS\0" as *const u8 as *const libc::c_char,
8691 b" Delete current node own slots information.\0" as *const u8
8692 as *const libc::c_char,
8693 b"INFO\0" as *const u8 as *const libc::c_char,
8694 b" Return information about the cluster.\0" as *const u8
8695 as *const libc::c_char,
8696 b"KEYSLOT <key>\0" as *const u8 as *const libc::c_char,
8697 b" Return the hash slot for <key>.\0" as *const u8 as *const libc::c_char,
8698 b"MEET <ip> <port> [<bus-port>]\0" as *const u8 as *const libc::c_char,
8699 b" Connect nodes into a working cluster.\0" as *const u8
8700 as *const libc::c_char,
8701 b"MYID\0" as *const u8 as *const libc::c_char,
8702 b" Return the node id.\0" as *const u8 as *const libc::c_char,
8703 b"NODES\0" as *const u8 as *const libc::c_char,
8704 b" Return cluster configuration seen by node. Output format:\0"
8705 as *const u8 as *const libc::c_char,
8706 b" <id> <ip:port> <flags> <master> <pings> <pongs> <epoch> <link> <slot> ...\0"
8707 as *const u8 as *const libc::c_char,
8708 b"REPLICATE <node-id>\0" as *const u8 as *const libc::c_char,
8709 b" Configure current node as replica to <node-id>.\0" as *const u8
8710 as *const libc::c_char,
8711 b"RESET [HARD|SOFT]\0" as *const u8 as *const libc::c_char,
8712 b" Reset current node (default: soft).\0" as *const u8
8713 as *const libc::c_char,
8714 b"SET-CONFIG-EPOCH <epoch>\0" as *const u8 as *const libc::c_char,
8715 b" Set config epoch of current node.\0" as *const u8
8716 as *const libc::c_char,
8717 b"SETSLOT <slot> (IMPORTING <node-id>|MIGRATING <node-id>|STABLE|NODE <node-id>)\0"
8718 as *const u8 as *const libc::c_char,
8719 b" Set slot state.\0" as *const u8 as *const libc::c_char,
8720 b"REPLICAS <node-id>\0" as *const u8 as *const libc::c_char,
8721 b" Return <node-id> replicas.\0" as *const u8 as *const libc::c_char,
8722 b"SAVECONFIG\0" as *const u8 as *const libc::c_char,
8723 b" Force saving cluster configuration on disk.\0" as *const u8
8724 as *const libc::c_char,
8725 b"SLOTS\0" as *const u8 as *const libc::c_char,
8726 b" Return information about slots range mappings. Each range is made of:\0"
8727 as *const u8 as *const libc::c_char,
8728 b" start, end, master and replicas IP addresses, ports and ids\0"
8729 as *const u8 as *const libc::c_char,
8730 b"SHARDS\0" as *const u8 as *const libc::c_char,
8731 b" Return information about slot range mappings and the nodes associated with them.\0"
8732 as *const u8 as *const libc::c_char,
8733 b"LINKS\0" as *const u8 as *const libc::c_char,
8734 b" Return information about all network links between this node and its peers.\0"
8735 as *const u8 as *const libc::c_char,
8736 b" Output format is an array where each array element is a map containing attributes of a link\0"
8737 as *const u8 as *const libc::c_char,
8738 0 as *const libc::c_char,
8739 ];
8740 addReplyHelp(c, help.as_mut_ptr());
8741 } else if strcasecmp(
8742 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8743 b"meet\0" as *const u8 as *const libc::c_char,
8744 ) == 0 && ((*c).argc == 4 as libc::c_int || (*c).argc == 5 as libc::c_int)
8745 {
8746 let mut port: libc::c_longlong = 0;
8747 let mut cport: libc::c_longlong = 0;
8748 if getLongLongFromObject(
8749 *((*c).argv).offset(3 as libc::c_int as isize),
8750 &mut port,
8751 ) != 0 as libc::c_int
8752 {
8753 addReplyErrorFormat(
8754 c,
8755 b"Invalid TCP base port specified: %s\0" as *const u8
8756 as *const libc::c_char,
8757 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr
8758 as *mut libc::c_char,
8759 );
8760 return;
8761 }
8762 if (*c).argc == 5 as libc::c_int {
8763 if getLongLongFromObject(
8764 *((*c).argv).offset(4 as libc::c_int as isize),
8765 &mut cport,
8766 ) != 0 as libc::c_int
8767 {
8768 addReplyErrorFormat(
8769 c,
8770 b"Invalid TCP bus port specified: %s\0" as *const u8
8771 as *const libc::c_char,
8772 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
8773 as *mut libc::c_char,
8774 );
8775 return;
8776 }
8777 } else {
8778 cport = port + 10000 as libc::c_int as libc::c_longlong;
8779 }
8780 if clusterStartHandshake(
8781 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr as *mut libc::c_char,
8782 port as libc::c_int,
8783 cport as libc::c_int,
8784 ) == 0 as libc::c_int && *__errno_location() == 22 as libc::c_int
8785 {
8786 addReplyErrorFormat(
8787 c,
8788 b"Invalid node address specified: %s:%s\0" as *const u8
8789 as *const libc::c_char,
8790 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
8791 as *mut libc::c_char,
8792 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr
8793 as *mut libc::c_char,
8794 );
8795 } else {
8796 addReply(c, shared.ok);
8797 }
8798 } else if strcasecmp(
8799 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8800 b"nodes\0" as *const u8 as *const libc::c_char,
8801 ) == 0 && (*c).argc == 2 as libc::c_int
8802 {
8803 let mut use_pport: libc::c_int = (server.tls_cluster != 0
8804 && !((*c).conn).is_null() && connGetType((*c).conn) != 2 as libc::c_int)
8805 as libc::c_int;
8806 let mut nodes: sds = clusterGenNodesDescription(0 as libc::c_int, use_pport);
8807 addReplyVerbatim(
8808 c,
8809 nodes as *const libc::c_char,
8810 sdslen(nodes),
8811 b"txt\0" as *const u8 as *const libc::c_char,
8812 );
8813 sdsfree(nodes);
8814 } else if strcasecmp(
8815 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8816 b"myid\0" as *const u8 as *const libc::c_char,
8817 ) == 0 && (*c).argc == 2 as libc::c_int
8818 {
8819 addReplyBulkCBuffer(
8820 c,
8821 ((*myself).name).as_mut_ptr() as *const libc::c_void,
8822 40 as libc::c_int as size_t,
8823 );
8824 } else if strcasecmp(
8825 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8826 b"slots\0" as *const u8 as *const libc::c_char,
8827 ) == 0 && (*c).argc == 2 as libc::c_int
8828 {
8829 clusterReplyMultiBulkSlots(c);
8830 } else if strcasecmp(
8831 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8832 b"shards\0" as *const u8 as *const libc::c_char,
8833 ) == 0 && (*c).argc == 2 as libc::c_int
8834 {
8835 clusterReplyShards(c);
8836 } else if strcasecmp(
8837 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8838 b"flushslots\0" as *const u8 as *const libc::c_char,
8839 ) == 0 && (*c).argc == 2 as libc::c_int
8840 {
8841 if ((*(*(server.db).offset(0 as libc::c_int as isize)).dict)
8842 .ht_used[0 as libc::c_int as usize])
8843 .wrapping_add(
8844 (*(*(server.db).offset(0 as libc::c_int as isize)).dict)
8845 .ht_used[1 as libc::c_int as usize],
8846 ) != 0 as libc::c_int as libc::c_ulong
8847 {
8848 addReplyError(
8849 c,
8850 b"DB must be empty to perform CLUSTER FLUSHSLOTS.\0" as *const u8
8851 as *const libc::c_char,
8852 );
8853 return;
8854 }
8855 clusterDelNodeSlots(myself);
8856 clusterDoBeforeSleep(
8857 (1 as libc::c_int) << 1 as libc::c_int
8858 | (1 as libc::c_int) << 2 as libc::c_int,
8859 );
8860 addReply(c, shared.ok);
8861 } else if (strcasecmp(
8862 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8863 b"addslots\0" as *const u8 as *const libc::c_char,
8864 ) == 0
8865 || strcasecmp(
8866 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8867 b"delslots\0" as *const u8 as *const libc::c_char,
8868 ) == 0) && (*c).argc >= 3 as libc::c_int
8869 {
8870 let mut j: libc::c_int = 0;
8871 let mut slot: libc::c_int = 0;
8872 let mut slots: *mut libc::c_uchar = zmalloc(16384 as libc::c_int as size_t)
8873 as *mut libc::c_uchar;
8874 let mut del: libc::c_int = (strcasecmp(
8875 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8876 b"delslots\0" as *const u8 as *const libc::c_char,
8877 ) == 0) as libc::c_int;
8878 memset(
8879 slots as *mut libc::c_void,
8880 0 as libc::c_int,
8881 16384 as libc::c_int as libc::c_ulong,
8882 );
8883 j = 2 as libc::c_int;
8884 while j < (*c).argc {
8885 slot = getSlotOrReply(c, *((*c).argv).offset(j as isize));
8886 if slot == -(1 as libc::c_int) {
8887 zfree(slots as *mut libc::c_void);
8888 return;
8889 }
8890 j += 1;
8891 }
8892 j = 2 as libc::c_int;
8893 while j < (*c).argc {
8894 slot = getSlotOrReply(c, *((*c).argv).offset(j as isize));
8895 if checkSlotAssignmentsOrReply(c, slots, del, slot, slot)
8896 == -(1 as libc::c_int)
8897 {
8898 zfree(slots as *mut libc::c_void);
8899 return;
8900 }
8901 j += 1;
8902 }
8903 clusterUpdateSlots(c, slots, del);
8904 zfree(slots as *mut libc::c_void);
8905 clusterDoBeforeSleep(
8906 (1 as libc::c_int) << 1 as libc::c_int
8907 | (1 as libc::c_int) << 2 as libc::c_int,
8908 );
8909 addReply(c, shared.ok);
8910 } else if (strcasecmp(
8911 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8912 b"addslotsrange\0" as *const u8 as *const libc::c_char,
8913 ) == 0
8914 || strcasecmp(
8915 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8916 b"delslotsrange\0" as *const u8 as *const libc::c_char,
8917 ) == 0) && (*c).argc >= 4 as libc::c_int
8918 {
8919 if (*c).argc % 2 as libc::c_int == 1 as libc::c_int {
8920 addReplyErrorArity(c);
8921 return;
8922 }
8923 let mut j_0: libc::c_int = 0;
8924 let mut startslot: libc::c_int = 0;
8925 let mut endslot: libc::c_int = 0;
8926 let mut slots_0: *mut libc::c_uchar = zmalloc(16384 as libc::c_int as size_t)
8927 as *mut libc::c_uchar;
8928 let mut del_0: libc::c_int = (strcasecmp(
8929 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8930 b"delslotsrange\0" as *const u8 as *const libc::c_char,
8931 ) == 0) as libc::c_int;
8932 memset(
8933 slots_0 as *mut libc::c_void,
8934 0 as libc::c_int,
8935 16384 as libc::c_int as libc::c_ulong,
8936 );
8937 j_0 = 2 as libc::c_int;
8938 while j_0 < (*c).argc {
8939 startslot = getSlotOrReply(c, *((*c).argv).offset(j_0 as isize));
8940 if startslot == -(1 as libc::c_int) {
8941 zfree(slots_0 as *mut libc::c_void);
8942 return;
8943 }
8944 endslot = getSlotOrReply(
8945 c,
8946 *((*c).argv).offset((j_0 + 1 as libc::c_int) as isize),
8947 );
8948 if endslot == -(1 as libc::c_int) {
8949 zfree(slots_0 as *mut libc::c_void);
8950 return;
8951 }
8952 if startslot > endslot {
8953 addReplyErrorFormat(
8954 c,
8955 b"start slot number %d is greater than end slot number %d\0"
8956 as *const u8 as *const libc::c_char,
8957 startslot,
8958 endslot,
8959 );
8960 zfree(slots_0 as *mut libc::c_void);
8961 return;
8962 }
8963 if checkSlotAssignmentsOrReply(c, slots_0, del_0, startslot, endslot)
8964 == -(1 as libc::c_int)
8965 {
8966 zfree(slots_0 as *mut libc::c_void);
8967 return;
8968 }
8969 j_0 += 2 as libc::c_int;
8970 }
8971 clusterUpdateSlots(c, slots_0, del_0);
8972 zfree(slots_0 as *mut libc::c_void);
8973 clusterDoBeforeSleep(
8974 (1 as libc::c_int) << 1 as libc::c_int
8975 | (1 as libc::c_int) << 2 as libc::c_int,
8976 );
8977 addReply(c, shared.ok);
8978 } else if strcasecmp(
8979 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
8980 b"setslot\0" as *const u8 as *const libc::c_char,
8981 ) == 0 && (*c).argc >= 4 as libc::c_int
8982 {
8983 let mut slot_0: libc::c_int = 0;
8984 let mut n: *mut clusterNode = 0 as *mut clusterNode;
8985 if (*myself).flags & 2 as libc::c_int != 0 {
8986 addReplyError(
8987 c,
8988 b"Please use SETSLOT only with masters.\0" as *const u8
8989 as *const libc::c_char,
8990 );
8991 return;
8992 }
8993 slot_0 = getSlotOrReply(c, *((*c).argv).offset(2 as libc::c_int as isize));
8994 if slot_0 == -(1 as libc::c_int) {
8995 return;
8996 }
8997 if strcasecmp(
8998 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr as *const libc::c_char,
8999 b"migrating\0" as *const u8 as *const libc::c_char,
9000 ) == 0 && (*c).argc == 5 as libc::c_int
9001 {
9002 if (*server.cluster).slots[slot_0 as usize] != myself {
9003 addReplyErrorFormat(
9004 c,
9005 b"I'm not the owner of hash slot %u\0" as *const u8
9006 as *const libc::c_char,
9007 slot_0,
9008 );
9009 return;
9010 }
9011 n = clusterLookupNode(
9012 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
9013 as *const libc::c_char,
9014 sdslen((**((*c).argv).offset(4 as libc::c_int as isize)).ptr as sds)
9015 as libc::c_int,
9016 );
9017 if n.is_null() {
9018 addReplyErrorFormat(
9019 c,
9020 b"I don't know about node %s\0" as *const u8 as *const libc::c_char,
9021 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
9022 as *mut libc::c_char,
9023 );
9024 return;
9025 }
9026 if (*n).flags & 2 as libc::c_int != 0 {
9027 addReplyError(
9028 c,
9029 b"Target node is not a master\0" as *const u8 as *const libc::c_char,
9030 );
9031 return;
9032 }
9033 (*server.cluster).migrating_slots_to[slot_0 as usize] = n;
9034 } else if strcasecmp(
9035 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr as *const libc::c_char,
9036 b"importing\0" as *const u8 as *const libc::c_char,
9037 ) == 0 && (*c).argc == 5 as libc::c_int
9038 {
9039 if (*server.cluster).slots[slot_0 as usize] == myself {
9040 addReplyErrorFormat(
9041 c,
9042 b"I'm already the owner of hash slot %u\0" as *const u8
9043 as *const libc::c_char,
9044 slot_0,
9045 );
9046 return;
9047 }
9048 n = clusterLookupNode(
9049 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
9050 as *const libc::c_char,
9051 sdslen((**((*c).argv).offset(4 as libc::c_int as isize)).ptr as sds)
9052 as libc::c_int,
9053 );
9054 if n.is_null() {
9055 addReplyErrorFormat(
9056 c,
9057 b"I don't know about node %s\0" as *const u8 as *const libc::c_char,
9058 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
9059 as *mut libc::c_char,
9060 );
9061 return;
9062 }
9063 if (*n).flags & 2 as libc::c_int != 0 {
9064 addReplyError(
9065 c,
9066 b"Target node is not a master\0" as *const u8 as *const libc::c_char,
9067 );
9068 return;
9069 }
9070 (*server.cluster).importing_slots_from[slot_0 as usize] = n;
9071 } else if strcasecmp(
9072 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr as *const libc::c_char,
9073 b"stable\0" as *const u8 as *const libc::c_char,
9074 ) == 0 && (*c).argc == 4 as libc::c_int
9075 {
9076 (*server.cluster)
9077 .importing_slots_from[slot_0 as usize] = 0 as *mut clusterNode;
9078 (*server.cluster)
9079 .migrating_slots_to[slot_0 as usize] = 0 as *mut clusterNode;
9080 } else if strcasecmp(
9081 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr as *const libc::c_char,
9082 b"node\0" as *const u8 as *const libc::c_char,
9083 ) == 0 && (*c).argc == 5 as libc::c_int
9084 {
9085 n = clusterLookupNode(
9086 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
9087 as *const libc::c_char,
9088 sdslen((**((*c).argv).offset(4 as libc::c_int as isize)).ptr as sds)
9089 as libc::c_int,
9090 );
9091 if n.is_null() {
9092 addReplyErrorFormat(
9093 c,
9094 b"Unknown node %s\0" as *const u8 as *const libc::c_char,
9095 (**((*c).argv).offset(4 as libc::c_int as isize)).ptr
9096 as *mut libc::c_char,
9097 );
9098 return;
9099 }
9100 if (*n).flags & 2 as libc::c_int != 0 {
9101 addReplyError(
9102 c,
9103 b"Target node is not a master\0" as *const u8 as *const libc::c_char,
9104 );
9105 return;
9106 }
9107 if (*server.cluster).slots[slot_0 as usize] == myself && n != myself {
9108 if countKeysInSlot(slot_0 as libc::c_uint)
9109 != 0 as libc::c_int as libc::c_uint
9110 {
9111 addReplyErrorFormat(
9112 c,
9113 b"Can't assign hashslot %d to a different node while I still hold keys for this hash slot.\0"
9114 as *const u8 as *const libc::c_char,
9115 slot_0,
9116 );
9117 return;
9118 }
9119 }
9120 if countKeysInSlot(slot_0 as libc::c_uint)
9121 == 0 as libc::c_int as libc::c_uint
9122 && !((*server.cluster).migrating_slots_to[slot_0 as usize]).is_null()
9123 {
9124 (*server.cluster)
9125 .migrating_slots_to[slot_0 as usize] = 0 as *mut clusterNode;
9126 }
9127 let mut slot_was_mine: libc::c_int = ((*server.cluster)
9128 .slots[slot_0 as usize] == myself) as libc::c_int;
9129 clusterDelSlot(slot_0);
9130 clusterAddSlot(n, slot_0);
9131 if slot_was_mine != 0 && n != myself
9132 && (*myself).numslots == 0 as libc::c_int
9133 && server.cluster_allow_replica_migration != 0
9134 {
9135 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
9136 _serverLog(
9137 3 as libc::c_int,
9138 b"Configuration change detected. Reconfiguring myself as a replica of %.40s\0"
9139 as *const u8 as *const libc::c_char,
9140 ((*n).name).as_mut_ptr(),
9141 );
9142 }
9143 clusterSetMaster(n);
9144 clusterDoBeforeSleep(
9145 (1 as libc::c_int) << 2 as libc::c_int
9146 | (1 as libc::c_int) << 1 as libc::c_int
9147 | (1 as libc::c_int) << 3 as libc::c_int,
9148 );
9149 }
9150 if n == myself
9151 && !((*server.cluster).importing_slots_from[slot_0 as usize]).is_null()
9152 {
9153 if clusterBumpConfigEpochWithoutConsensus() == 0 as libc::c_int {
9154 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
9155 _serverLog(
9156 3 as libc::c_int,
9157 b"configEpoch updated after importing slot %d\0" as *const u8
9158 as *const libc::c_char,
9159 slot_0,
9160 );
9161 }
9162 }
9163 (*server.cluster)
9164 .importing_slots_from[slot_0 as usize] = 0 as *mut clusterNode;
9165 clusterBroadcastPong(0 as libc::c_int);
9166 }
9167 } else {
9168 addReplyError(
9169 c,
9170 b"Invalid CLUSTER SETSLOT action or number of arguments. Try CLUSTER HELP\0"
9171 as *const u8 as *const libc::c_char,
9172 );
9173 return;
9174 }
9175 clusterDoBeforeSleep(
9176 (1 as libc::c_int) << 2 as libc::c_int
9177 | (1 as libc::c_int) << 1 as libc::c_int,
9178 );
9179 addReply(c, shared.ok);
9180 } else if strcasecmp(
9181 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9182 b"bumpepoch\0" as *const u8 as *const libc::c_char,
9183 ) == 0 && (*c).argc == 2 as libc::c_int
9184 {
9185 let mut retval: libc::c_int = clusterBumpConfigEpochWithoutConsensus();
9186 let mut reply: sds = sdscatprintf(
9187 sdsempty(),
9188 b"+%s %llu\r\n\0" as *const u8 as *const libc::c_char,
9189 if retval == 0 as libc::c_int {
9190 b"BUMPED\0" as *const u8 as *const libc::c_char
9191 } else {
9192 b"STILL\0" as *const u8 as *const libc::c_char
9193 },
9194 (*myself).configEpoch as libc::c_ulonglong,
9195 );
9196 addReplySds(c, reply);
9197 } else if strcasecmp(
9198 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9199 b"info\0" as *const u8 as *const libc::c_char,
9200 ) == 0 && (*c).argc == 2 as libc::c_int
9201 {
9202 let mut statestr: [*mut libc::c_char; 2] = [
9203 b"ok\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
9204 b"fail\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
9205 ];
9206 let mut slots_assigned: libc::c_int = 0 as libc::c_int;
9207 let mut slots_ok: libc::c_int = 0 as libc::c_int;
9208 let mut slots_pfail: libc::c_int = 0 as libc::c_int;
9209 let mut slots_fail: libc::c_int = 0 as libc::c_int;
9210 let mut myepoch: uint64_t = 0;
9211 let mut j_1: libc::c_int = 0;
9212 j_1 = 0 as libc::c_int;
9213 while j_1 < 16384 as libc::c_int {
9214 let mut n_0: *mut clusterNode = (*server.cluster).slots[j_1 as usize];
9215 if !n_0.is_null() {
9216 slots_assigned += 1;
9217 if (*n_0).flags & 8 as libc::c_int != 0 {
9218 slots_fail += 1;
9219 } else if (*n_0).flags & 4 as libc::c_int != 0 {
9220 slots_pfail += 1;
9221 } else {
9222 slots_ok += 1;
9223 }
9224 }
9225 j_1 += 1;
9226 }
9227 myepoch = if (*myself).flags & 2 as libc::c_int != 0
9228 && !((*myself).slaveof).is_null()
9229 {
9230 (*(*myself).slaveof).configEpoch
9231 } else {
9232 (*myself).configEpoch
9233 };
9234 let mut info: sds = sdscatprintf(
9235 sdsempty(),
9236 b"cluster_state:%s\r\ncluster_slots_assigned:%d\r\ncluster_slots_ok:%d\r\ncluster_slots_pfail:%d\r\ncluster_slots_fail:%d\r\ncluster_known_nodes:%lu\r\ncluster_size:%d\r\ncluster_current_epoch:%llu\r\ncluster_my_epoch:%llu\r\n\0"
9237 as *const u8 as *const libc::c_char,
9238 statestr[(*server.cluster).state as usize],
9239 slots_assigned,
9240 slots_ok,
9241 slots_pfail,
9242 slots_fail,
9243 ((*(*server.cluster).nodes).ht_used[0 as libc::c_int as usize])
9244 .wrapping_add(
9245 (*(*server.cluster).nodes).ht_used[1 as libc::c_int as usize],
9246 ),
9247 (*server.cluster).size,
9248 (*server.cluster).currentEpoch as libc::c_ulonglong,
9249 myepoch as libc::c_ulonglong,
9250 );
9251 let mut tot_msg_sent: libc::c_longlong = 0 as libc::c_int as libc::c_longlong;
9252 let mut tot_msg_received: libc::c_longlong = 0 as libc::c_int
9253 as libc::c_longlong;
9254 let mut i: libc::c_int = 0 as libc::c_int;
9255 while i < 11 as libc::c_int {
9256 if !((*server.cluster).stats_bus_messages_sent[i as usize]
9257 == 0 as libc::c_int as libc::c_longlong)
9258 {
9259 tot_msg_sent += (*server.cluster).stats_bus_messages_sent[i as usize];
9260 info = sdscatprintf(
9261 info,
9262 b"cluster_stats_messages_%s_sent:%lld\r\n\0" as *const u8
9263 as *const libc::c_char,
9264 clusterGetMessageTypeString(i),
9265 (*server.cluster).stats_bus_messages_sent[i as usize],
9266 );
9267 }
9268 i += 1;
9269 }
9270 info = sdscatprintf(
9271 info,
9272 b"cluster_stats_messages_sent:%lld\r\n\0" as *const u8
9273 as *const libc::c_char,
9274 tot_msg_sent,
9275 );
9276 let mut i_0: libc::c_int = 0 as libc::c_int;
9277 while i_0 < 11 as libc::c_int {
9278 if !((*server.cluster).stats_bus_messages_received[i_0 as usize]
9279 == 0 as libc::c_int as libc::c_longlong)
9280 {
9281 tot_msg_received
9282 += (*server.cluster).stats_bus_messages_received[i_0 as usize];
9283 info = sdscatprintf(
9284 info,
9285 b"cluster_stats_messages_%s_received:%lld\r\n\0" as *const u8
9286 as *const libc::c_char,
9287 clusterGetMessageTypeString(i_0),
9288 (*server.cluster).stats_bus_messages_received[i_0 as usize],
9289 );
9290 }
9291 i_0 += 1;
9292 }
9293 info = sdscatprintf(
9294 info,
9295 b"cluster_stats_messages_received:%lld\r\n\0" as *const u8
9296 as *const libc::c_char,
9297 tot_msg_received,
9298 );
9299 info = sdscatprintf(
9300 info,
9301 b"total_cluster_links_buffer_limit_exceeded:%llu\r\n\0" as *const u8
9302 as *const libc::c_char,
9303 (*server.cluster).stat_cluster_links_buffer_limit_exceeded,
9304 );
9305 addReplyVerbatim(
9306 c,
9307 info as *const libc::c_char,
9308 sdslen(info),
9309 b"txt\0" as *const u8 as *const libc::c_char,
9310 );
9311 sdsfree(info);
9312 } else if strcasecmp(
9313 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9314 b"saveconfig\0" as *const u8 as *const libc::c_char,
9315 ) == 0 && (*c).argc == 2 as libc::c_int
9316 {
9317 let mut retval_0: libc::c_int = clusterSaveConfig(1 as libc::c_int);
9318 if retval_0 == 0 as libc::c_int {
9319 addReply(c, shared.ok);
9320 } else {
9321 addReplyErrorFormat(
9322 c,
9323 b"error saving the cluster node config: %s\0" as *const u8
9324 as *const libc::c_char,
9325 strerror(*__errno_location()),
9326 );
9327 }
9328 } else if strcasecmp(
9329 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9330 b"keyslot\0" as *const u8 as *const libc::c_char,
9331 ) == 0 && (*c).argc == 3 as libc::c_int
9332 {
9333 let mut key: sds = (**((*c).argv).offset(2 as libc::c_int as isize)).ptr as sds;
9334 addReplyLongLong(
9335 c,
9336 keyHashSlot(key, sdslen(key) as libc::c_int) as libc::c_longlong,
9337 );
9338 } else if strcasecmp(
9339 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9340 b"countkeysinslot\0" as *const u8 as *const libc::c_char,
9341 ) == 0 && (*c).argc == 3 as libc::c_int
9342 {
9343 let mut slot_1: libc::c_longlong = 0;
9344 if getLongLongFromObjectOrReply(
9345 c,
9346 *((*c).argv).offset(2 as libc::c_int as isize),
9347 &mut slot_1,
9348 0 as *const libc::c_char,
9349 ) != 0 as libc::c_int
9350 {
9351 return;
9352 }
9353 if slot_1 < 0 as libc::c_int as libc::c_longlong
9354 || slot_1 >= 16384 as libc::c_int as libc::c_longlong
9355 {
9356 addReplyError(c, b"Invalid slot\0" as *const u8 as *const libc::c_char);
9357 return;
9358 }
9359 addReplyLongLong(c, countKeysInSlot(slot_1 as libc::c_uint) as libc::c_longlong);
9360 } else if strcasecmp(
9361 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9362 b"getkeysinslot\0" as *const u8 as *const libc::c_char,
9363 ) == 0 && (*c).argc == 4 as libc::c_int
9364 {
9365 let mut maxkeys: libc::c_longlong = 0;
9366 let mut slot_2: libc::c_longlong = 0;
9367 if getLongLongFromObjectOrReply(
9368 c,
9369 *((*c).argv).offset(2 as libc::c_int as isize),
9370 &mut slot_2,
9371 0 as *const libc::c_char,
9372 ) != 0 as libc::c_int
9373 {
9374 return;
9375 }
9376 if getLongLongFromObjectOrReply(
9377 c,
9378 *((*c).argv).offset(3 as libc::c_int as isize),
9379 &mut maxkeys,
9380 0 as *const libc::c_char,
9381 ) != 0 as libc::c_int
9382 {
9383 return;
9384 }
9385 if slot_2 < 0 as libc::c_int as libc::c_longlong
9386 || slot_2 >= 16384 as libc::c_int as libc::c_longlong
9387 || maxkeys < 0 as libc::c_int as libc::c_longlong
9388 {
9389 addReplyError(
9390 c,
9391 b"Invalid slot or number of keys\0" as *const u8 as *const libc::c_char,
9392 );
9393 return;
9394 }
9395 let mut keys_in_slot: libc::c_uint = countKeysInSlot(slot_2 as libc::c_uint);
9396 let mut numkeys: libc::c_uint = (if maxkeys > keys_in_slot as libc::c_longlong {
9397 keys_in_slot as libc::c_longlong
9398 } else {
9399 maxkeys
9400 }) as libc::c_uint;
9401 addReplyArrayLen(c, numkeys as libc::c_long);
9402 let mut de: *mut dictEntry = (*(*server.db).slots_to_keys)
9403 .by_slot[slot_2 as usize]
9404 .head;
9405 let mut j_2: libc::c_uint = 0 as libc::c_int as libc::c_uint;
9406 while j_2 < numkeys {
9407 if !de.is_null() {} else {
9408 _serverAssert(
9409 b"de != NULL\0" as *const u8 as *const libc::c_char,
9410 b"cluster.c\0" as *const u8 as *const libc::c_char,
9411 5641 as libc::c_int,
9412 );
9413 unreachable!();
9414 };
9415 let mut sdskey: sds = (*de).key as sds;
9416 addReplyBulkCBuffer(c, sdskey as *const libc::c_void, sdslen(sdskey));
9417 de = (*(&mut (*de).metadata as *mut [*mut libc::c_void; 0]
9418 as *mut clusterDictEntryMetadata))
9419 .next;
9420 j_2 = j_2.wrapping_add(1);
9421 }
9422 } else if strcasecmp(
9423 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9424 b"forget\0" as *const u8 as *const libc::c_char,
9425 ) == 0 && (*c).argc == 3 as libc::c_int
9426 {
9427 let mut n_1: *mut clusterNode = clusterLookupNode(
9428 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr as *const libc::c_char,
9429 sdslen((**((*c).argv).offset(2 as libc::c_int as isize)).ptr as sds)
9430 as libc::c_int,
9431 );
9432 if n_1.is_null() {
9433 addReplyErrorFormat(
9434 c,
9435 b"Unknown node %s\0" as *const u8 as *const libc::c_char,
9436 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9437 as *mut libc::c_char,
9438 );
9439 return;
9440 } else {
9441 if n_1 == myself {
9442 addReplyError(
9443 c,
9444 b"I tried hard but I can't forget myself...\0" as *const u8
9445 as *const libc::c_char,
9446 );
9447 return;
9448 } else {
9449 if (*myself).flags & 2 as libc::c_int != 0 && (*myself).slaveof == n_1 {
9450 addReplyError(
9451 c,
9452 b"Can't forget my master!\0" as *const u8 as *const libc::c_char,
9453 );
9454 return;
9455 }
9456 }
9457 }
9458 clusterBlacklistAddNode(n_1);
9459 clusterDelNode(n_1);
9460 clusterDoBeforeSleep(
9461 (1 as libc::c_int) << 1 as libc::c_int
9462 | (1 as libc::c_int) << 2 as libc::c_int,
9463 );
9464 addReply(c, shared.ok);
9465 } else if strcasecmp(
9466 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9467 b"replicate\0" as *const u8 as *const libc::c_char,
9468 ) == 0 && (*c).argc == 3 as libc::c_int
9469 {
9470 let mut n_2: *mut clusterNode = clusterLookupNode(
9471 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr as *const libc::c_char,
9472 sdslen((**((*c).argv).offset(2 as libc::c_int as isize)).ptr as sds)
9473 as libc::c_int,
9474 );
9475 if n_2.is_null() {
9476 addReplyErrorFormat(
9477 c,
9478 b"Unknown node %s\0" as *const u8 as *const libc::c_char,
9479 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9480 as *mut libc::c_char,
9481 );
9482 return;
9483 }
9484 if n_2 == myself {
9485 addReplyError(
9486 c,
9487 b"Can't replicate myself\0" as *const u8 as *const libc::c_char,
9488 );
9489 return;
9490 }
9491 if (*n_2).flags & 2 as libc::c_int != 0 {
9492 addReplyError(
9493 c,
9494 b"I can only replicate a master, not a replica.\0" as *const u8
9495 as *const libc::c_char,
9496 );
9497 return;
9498 }
9499 if (*myself).flags & 1 as libc::c_int != 0
9500 && ((*myself).numslots != 0 as libc::c_int
9501 || ((*(*(server.db).offset(0 as libc::c_int as isize)).dict)
9502 .ht_used[0 as libc::c_int as usize])
9503 .wrapping_add(
9504 (*(*(server.db).offset(0 as libc::c_int as isize)).dict)
9505 .ht_used[1 as libc::c_int as usize],
9506 ) != 0 as libc::c_int as libc::c_ulong)
9507 {
9508 addReplyError(
9509 c,
9510 b"To set a master the node must be empty and without assigned slots.\0"
9511 as *const u8 as *const libc::c_char,
9512 );
9513 return;
9514 }
9515 clusterSetMaster(n_2);
9516 clusterDoBeforeSleep(
9517 (1 as libc::c_int) << 1 as libc::c_int
9518 | (1 as libc::c_int) << 2 as libc::c_int,
9519 );
9520 addReply(c, shared.ok);
9521 } else if (strcasecmp(
9522 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9523 b"slaves\0" as *const u8 as *const libc::c_char,
9524 ) == 0
9525 || strcasecmp(
9526 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9527 b"replicas\0" as *const u8 as *const libc::c_char,
9528 ) == 0) && (*c).argc == 3 as libc::c_int
9529 {
9530 let mut n_3: *mut clusterNode = clusterLookupNode(
9531 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr as *const libc::c_char,
9532 sdslen((**((*c).argv).offset(2 as libc::c_int as isize)).ptr as sds)
9533 as libc::c_int,
9534 );
9535 let mut j_3: libc::c_int = 0;
9536 if n_3.is_null() {
9537 addReplyErrorFormat(
9538 c,
9539 b"Unknown node %s\0" as *const u8 as *const libc::c_char,
9540 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9541 as *mut libc::c_char,
9542 );
9543 return;
9544 }
9545 if (*n_3).flags & 2 as libc::c_int != 0 {
9546 addReplyError(
9547 c,
9548 b"The specified node is not a master\0" as *const u8
9549 as *const libc::c_char,
9550 );
9551 return;
9552 }
9553 let mut use_pport_0: libc::c_int = (server.tls_cluster != 0
9554 && !((*c).conn).is_null() && connGetType((*c).conn) != 2 as libc::c_int)
9555 as libc::c_int;
9556 addReplyArrayLen(c, (*n_3).numslaves as libc::c_long);
9557 j_3 = 0 as libc::c_int;
9558 while j_3 < (*n_3).numslaves {
9559 let mut ni: sds = clusterGenNodeDescription(
9560 *((*n_3).slaves).offset(j_3 as isize),
9561 use_pport_0,
9562 );
9563 addReplyBulkCString(c, ni as *const libc::c_char);
9564 sdsfree(ni);
9565 j_3 += 1;
9566 }
9567 } else if strcasecmp(
9568 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9569 b"count-failure-reports\0" as *const u8 as *const libc::c_char,
9570 ) == 0 && (*c).argc == 3 as libc::c_int
9571 {
9572 let mut n_4: *mut clusterNode = clusterLookupNode(
9573 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr as *const libc::c_char,
9574 sdslen((**((*c).argv).offset(2 as libc::c_int as isize)).ptr as sds)
9575 as libc::c_int,
9576 );
9577 if n_4.is_null() {
9578 addReplyErrorFormat(
9579 c,
9580 b"Unknown node %s\0" as *const u8 as *const libc::c_char,
9581 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9582 as *mut libc::c_char,
9583 );
9584 return;
9585 } else {
9586 addReplyLongLong(c, clusterNodeFailureReportsCount(n_4) as libc::c_longlong);
9587 }
9588 } else if strcasecmp(
9589 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9590 b"failover\0" as *const u8 as *const libc::c_char,
9591 ) == 0 && ((*c).argc == 2 as libc::c_int || (*c).argc == 3 as libc::c_int)
9592 {
9593 let mut force: libc::c_int = 0 as libc::c_int;
9594 let mut takeover: libc::c_int = 0 as libc::c_int;
9595 if (*c).argc == 3 as libc::c_int {
9596 if strcasecmp(
9597 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9598 as *const libc::c_char,
9599 b"force\0" as *const u8 as *const libc::c_char,
9600 ) == 0
9601 {
9602 force = 1 as libc::c_int;
9603 } else if strcasecmp(
9604 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9605 as *const libc::c_char,
9606 b"takeover\0" as *const u8 as *const libc::c_char,
9607 ) == 0
9608 {
9609 takeover = 1 as libc::c_int;
9610 force = 1 as libc::c_int;
9611 } else {
9612 addReplyErrorObject(c, shared.syntaxerr);
9613 return;
9614 }
9615 }
9616 if (*myself).flags & 1 as libc::c_int != 0 {
9617 addReplyError(
9618 c,
9619 b"You should send CLUSTER FAILOVER to a replica\0" as *const u8
9620 as *const libc::c_char,
9621 );
9622 return;
9623 } else {
9624 if ((*myself).slaveof).is_null() {
9625 addReplyError(
9626 c,
9627 b"I'm a replica but my master is unknown to me\0" as *const u8
9628 as *const libc::c_char,
9629 );
9630 return;
9631 } else {
9632 if force == 0
9633 && ((*(*myself).slaveof).flags & 8 as libc::c_int != 0
9634 || ((*(*myself).slaveof).link).is_null())
9635 {
9636 addReplyError(
9637 c,
9638 b"Master is down or failed, please use CLUSTER FAILOVER FORCE\0"
9639 as *const u8 as *const libc::c_char,
9640 );
9641 return;
9642 }
9643 }
9644 }
9645 resetManualFailover();
9646 (*server.cluster).mf_end = mstime() + 5000 as libc::c_int as libc::c_longlong;
9647 if takeover != 0 {
9648 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
9649 _serverLog(
9650 3 as libc::c_int,
9651 b"Taking over the master (user request).\0" as *const u8
9652 as *const libc::c_char,
9653 );
9654 }
9655 clusterBumpConfigEpochWithoutConsensus();
9656 clusterFailoverReplaceYourMaster();
9657 } else if force != 0 {
9658 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
9659 _serverLog(
9660 3 as libc::c_int,
9661 b"Forced failover user request accepted.\0" as *const u8
9662 as *const libc::c_char,
9663 );
9664 }
9665 (*server.cluster).mf_can_start = 1 as libc::c_int;
9666 } else {
9667 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
9668 _serverLog(
9669 3 as libc::c_int,
9670 b"Manual failover user request accepted.\0" as *const u8
9671 as *const libc::c_char,
9672 );
9673 }
9674 clusterSendMFStart((*myself).slaveof);
9675 }
9676 addReply(c, shared.ok);
9677 } else if strcasecmp(
9678 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9679 b"set-config-epoch\0" as *const u8 as *const libc::c_char,
9680 ) == 0 && (*c).argc == 3 as libc::c_int
9681 {
9682 let mut epoch: libc::c_longlong = 0;
9683 if getLongLongFromObjectOrReply(
9684 c,
9685 *((*c).argv).offset(2 as libc::c_int as isize),
9686 &mut epoch,
9687 0 as *const libc::c_char,
9688 ) != 0 as libc::c_int
9689 {
9690 return;
9691 }
9692 if epoch < 0 as libc::c_int as libc::c_longlong {
9693 addReplyErrorFormat(
9694 c,
9695 b"Invalid config epoch specified: %lld\0" as *const u8
9696 as *const libc::c_char,
9697 epoch,
9698 );
9699 } else if ((*(*server.cluster).nodes).ht_used[0 as libc::c_int as usize])
9700 .wrapping_add((*(*server.cluster).nodes).ht_used[1 as libc::c_int as usize])
9701 > 1 as libc::c_int as libc::c_ulong
9702 {
9703 addReplyError(
9704 c,
9705 b"The user can assign a config epoch only when the node does not know any other node.\0"
9706 as *const u8 as *const libc::c_char,
9707 );
9708 } else if (*myself).configEpoch != 0 as libc::c_int as libc::c_ulong {
9709 addReplyError(
9710 c,
9711 b"Node config epoch is already non-zero\0" as *const u8
9712 as *const libc::c_char,
9713 );
9714 } else {
9715 (*myself).configEpoch = epoch as uint64_t;
9716 if !((3 as libc::c_int & 0xff as libc::c_int) < server.verbosity) {
9717 _serverLog(
9718 3 as libc::c_int,
9719 b"configEpoch set to %llu via CLUSTER SET-CONFIG-EPOCH\0"
9720 as *const u8 as *const libc::c_char,
9721 (*myself).configEpoch as libc::c_ulonglong,
9722 );
9723 }
9724 if (*server.cluster).currentEpoch < epoch as uint64_t {
9725 (*server.cluster).currentEpoch = epoch as uint64_t;
9726 }
9727 clusterDoBeforeSleep(
9728 (1 as libc::c_int) << 1 as libc::c_int
9729 | (1 as libc::c_int) << 2 as libc::c_int,
9730 );
9731 addReply(c, shared.ok);
9732 }
9733 } else if strcasecmp(
9734 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9735 b"reset\0" as *const u8 as *const libc::c_char,
9736 ) == 0 && ((*c).argc == 2 as libc::c_int || (*c).argc == 3 as libc::c_int)
9737 {
9738 let mut hard: libc::c_int = 0 as libc::c_int;
9739 if (*c).argc == 3 as libc::c_int {
9740 if strcasecmp(
9741 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9742 as *const libc::c_char,
9743 b"hard\0" as *const u8 as *const libc::c_char,
9744 ) == 0
9745 {
9746 hard = 1 as libc::c_int;
9747 } else if strcasecmp(
9748 (**((*c).argv).offset(2 as libc::c_int as isize)).ptr
9749 as *const libc::c_char,
9750 b"soft\0" as *const u8 as *const libc::c_char,
9751 ) == 0
9752 {
9753 hard = 0 as libc::c_int;
9754 } else {
9755 addReplyErrorObject(c, shared.syntaxerr);
9756 return;
9757 }
9758 }
9759 if (*myself).flags & 1 as libc::c_int != 0
9760 && ((*(*(*c).db).dict).ht_used[0 as libc::c_int as usize])
9761 .wrapping_add((*(*(*c).db).dict).ht_used[1 as libc::c_int as usize])
9762 != 0 as libc::c_int as libc::c_ulong
9763 {
9764 addReplyError(
9765 c,
9766 b"CLUSTER RESET can't be called with master nodes containing keys\0"
9767 as *const u8 as *const libc::c_char,
9768 );
9769 return;
9770 }
9771 clusterReset(hard);
9772 addReply(c, shared.ok);
9773 } else if strcasecmp(
9774 (**((*c).argv).offset(1 as libc::c_int as isize)).ptr as *const libc::c_char,
9775 b"links\0" as *const u8 as *const libc::c_char,
9776 ) == 0 && (*c).argc == 2 as libc::c_int
9777 {
9778 addReplyClusterLinksDescription(c);
9779 } else {
9780 addReplySubcommandSyntaxError(c);
9781 return;
9782 };
9783}
9784#[no_mangle]
9785pub unsafe extern "C" fn removeChannelsInSlot(mut slot: libc::c_uint) {
9786 let mut channelcount: libc::c_uint = countChannelsInSlot(slot);
9787 if channelcount == 0 as libc::c_int as libc::c_uint {
9788 return;
9789 }
9790 let mut channels: *mut *mut robj = zmalloc(
9791 (core::mem::size_of::<*mut robj>() as libc::c_ulong)
9792 .wrapping_mul(channelcount as libc::c_ulong),
9793 ) as *mut *mut robj;
9794 let mut iter: raxIterator = raxIterator {
9795 flags: 0,
9796 rt: 0 as *mut rax,
9797 key: 0 as *mut libc::c_uchar,
9798 data: 0 as *mut libc::c_void,
9799 key_len: 0,
9800 key_max: 0,
9801 key_static_string: [0; 128],
9802 node: 0 as *mut raxNode,
9803 stack: raxStack {
9804 stack: 0 as *mut *mut libc::c_void,
9805 items: 0,
9806 maxitems: 0,
9807 static_items: [0 as *mut libc::c_void; 32],
9808 oom: 0,
9809 },
9810 node_cb: None,
9811 };
9812 let mut j: libc::c_int = 0 as libc::c_int;
9813 let mut indexed: [libc::c_uchar; 2] = [0; 2];
9814 indexed[0 as libc::c_int
9815 as usize] = (slot >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_uint)
9816 as libc::c_uchar;
9817 indexed[1 as libc::c_int
9818 as usize] = (slot & 0xff as libc::c_int as libc::c_uint) as libc::c_uchar;
9819 raxStart(&mut iter, (*server.cluster).slots_to_channels);
9820 raxSeek(
9821 &mut iter,
9822 b">=\0" as *const u8 as *const libc::c_char,
9823 indexed.as_mut_ptr(),
9824 2 as libc::c_int as size_t,
9825 );
9826 while raxNext(&mut iter) != 0 {
9827 if *(iter.key).offset(0 as libc::c_int as isize) as libc::c_int
9828 != indexed[0 as libc::c_int as usize] as libc::c_int
9829 || *(iter.key).offset(1 as libc::c_int as isize) as libc::c_int
9830 != indexed[1 as libc::c_int as usize] as libc::c_int
9831 {
9832 break;
9833 }
9834 let fresh16 = j;
9835 j = j + 1;
9836 let ref mut fresh17 = *channels.offset(fresh16 as isize);
9837 *fresh17 = createStringObject(
9838 (iter.key as *mut libc::c_char).offset(2 as libc::c_int as isize),
9839 (iter.key_len).wrapping_sub(2 as libc::c_int as libc::c_ulong),
9840 );
9841 }
9842 raxStop(&mut iter);
9843 pubsubUnsubscribeShardChannels(channels, channelcount);
9844 zfree(channels as *mut libc::c_void);
9845}
9846#[no_mangle]
9847pub unsafe extern "C" fn createDumpPayload(
9848 mut payload: *mut rio,
9849 mut o: *mut robj,
9850 mut key: *mut robj,
9851 mut dbid: libc::c_int,
9852) {
9853 let mut buf: [libc::c_uchar; 2] = [0; 2];
9854 let mut crc: uint64_t = 0;
9855 rioInitWithBuffer(payload, sdsempty());
9856 if rdbSaveObjectType(payload, o) != 0 {} else {
9857 _serverAssert(
9858 b"rdbSaveObjectType(payload,o)\0" as *const u8 as *const libc::c_char,
9859 b"cluster.c\0" as *const u8 as *const libc::c_char,
9860 5902 as libc::c_int,
9861 );
9862 unreachable!();
9863 };
9864 if rdbSaveObject(payload, o, key, dbid) != 0 {} else {
9865 _serverAssert(
9866 b"rdbSaveObject(payload,o,key,dbid)\0" as *const u8 as *const libc::c_char,
9867 b"cluster.c\0" as *const u8 as *const libc::c_char,
9868 5903 as libc::c_int,
9869 );
9870 unreachable!();
9871 };
9872 buf[0 as libc::c_int
9873 as usize] = (10 as libc::c_int & 0xff as libc::c_int) as libc::c_uchar;
9874 buf[1 as libc::c_int
9875 as usize] = (10 as libc::c_int >> 8 as libc::c_int & 0xff as libc::c_int)
9876 as libc::c_uchar;
9877 (*payload)
9878 .io
9879 .buffer
9880 .ptr = sdscatlen(
9881 (*payload).io.buffer.ptr,
9882 buf.as_mut_ptr() as *const libc::c_void,
9883 2 as libc::c_int as size_t,
9884 );
9885 crc = crc64(
9886 0 as libc::c_int as uint64_t,
9887 (*payload).io.buffer.ptr as *mut libc::c_uchar,
9888 sdslen((*payload).io.buffer.ptr),
9889 );
9890 (*payload)
9891 .io
9892 .buffer
9893 .ptr = sdscatlen(
9894 (*payload).io.buffer.ptr,
9895 &mut crc as *mut uint64_t as *const libc::c_void,
9896 8 as libc::c_int as size_t,
9897 );
9898}
9899#[no_mangle]
9900pub unsafe extern "C" fn verifyDumpPayload(
9901 mut p: *mut libc::c_uchar,
9902 mut len: size_t,
9903 mut rdbver_ptr: *mut uint16_t,
9904) -> libc::c_int {
9905 let mut footer: *mut libc::c_uchar = 0 as *mut libc::c_uchar;
9906 let mut rdbver: uint16_t = 0;
9907 let mut crc: uint64_t = 0;
9908 if len < 10 as libc::c_int as libc::c_ulong {
9909 return -(1 as libc::c_int);
9910 }
9911 footer = p.offset(len.wrapping_sub(10 as libc::c_int as libc::c_ulong) as isize);
9912 rdbver = ((*footer.offset(1 as libc::c_int as isize) as libc::c_int)
9913 << 8 as libc::c_int | *footer.offset(0 as libc::c_int as isize) as libc::c_int)
9914 as uint16_t;
9915 if !rdbver_ptr.is_null() {
9916 *rdbver_ptr = rdbver;
9917 }
9918 if rdbver as libc::c_int > 10 as libc::c_int {
9919 return -(1 as libc::c_int);
9920 }
9921 if server.skip_checksum_validation != 0 {
9922 return 0 as libc::c_int;
9923 }
9924 crc = crc64(
9925 0 as libc::c_int as uint64_t,
9926 p,
9927 len.wrapping_sub(8 as libc::c_int as libc::c_ulong),
9928 );
9929 return if memcmp(
9930 &mut crc as *mut uint64_t as *const libc::c_void,
9931 footer.offset(2 as libc::c_int as isize) as *const libc::c_void,
9932 8 as libc::c_int as libc::c_ulong,
9933 ) == 0 as libc::c_int
9934 {
9935 0 as libc::c_int
9936 } else {
9937 -(1 as libc::c_int)
9938 };
9939}
9940#[no_mangle]
9941pub unsafe extern "C" fn dumpCommand(mut c: *mut client) {
9942 let mut o: *mut robj = 0 as *mut robj;
9943 let mut payload: rio = rio {
9944 read: None,
9945 write: None,
9946 tell: None,
9947 flush: None,
9948 update_cksum: None,
9949 cksum: 0,
9950 flags: 0,
9951 processed_bytes: 0,
9952 max_processing_chunk: 0,
9953 io: C2RustUnnamed {
9954 buffer: C2RustUnnamed_3 {
9955 ptr: 0 as *mut libc::c_char,
9956 pos: 0,
9957 },
9958 },
9959 };
9960 o = lookupKeyRead((*c).db, *((*c).argv).offset(1 as libc::c_int as isize));
9961 if o.is_null() {
9962 addReplyNull(c);
9963 return;
9964 }
9965 createDumpPayload(
9966 &mut payload,
9967 o,
9968 *((*c).argv).offset(1 as libc::c_int as isize),
9969 (*(*c).db).id,
9970 );
9971 addReplyBulkSds(c, payload.io.buffer.ptr);
9972}
9973#[no_mangle]
9974pub unsafe extern "C" fn restoreCommand(mut c: *mut client) {
9975 let mut ttl: libc::c_longlong = 0;
9976 let mut lfu_freq: libc::c_longlong = -(1 as libc::c_int) as libc::c_longlong;
9977 let mut lru_idle: libc::c_longlong = -(1 as libc::c_int) as libc::c_longlong;
9978 let mut lru_clock: libc::c_longlong = -(1 as libc::c_int) as libc::c_longlong;
9979 let mut payload: rio = rio {
9980 read: None,
9981 write: None,
9982 tell: None,
9983 flush: None,
9984 update_cksum: None,
9985 cksum: 0,
9986 flags: 0,
9987 processed_bytes: 0,
9988 max_processing_chunk: 0,
9989 io: C2RustUnnamed {
9990 buffer: C2RustUnnamed_3 {
9991 ptr: 0 as *mut libc::c_char,
9992 pos: 0,
9993 },
9994 },
9995 };
9996 let mut j: libc::c_int = 0;
9997 let mut type_0: libc::c_int = 0;
9998 let mut replace: libc::c_int = 0 as libc::c_int;
9999 let mut absttl: libc::c_int = 0 as libc::c_int;
10000 let mut obj: *mut robj = 0 as *mut robj;
10001 j = 4 as libc::c_int;
10002 while j < (*c).argc {
10003 let mut additional: libc::c_int = (*c).argc - j - 1 as libc::c_int;
10004 if strcasecmp(
10005 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10006 b"replace\0" as *const u8 as *const libc::c_char,
10007 ) == 0
10008 {
10009 replace = 1 as libc::c_int;
10010 } else if strcasecmp(
10011 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10012 b"absttl\0" as *const u8 as *const libc::c_char,
10013 ) == 0
10014 {
10015 absttl = 1 as libc::c_int;
10016 } else if strcasecmp(
10017 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10018 b"idletime\0" as *const u8 as *const libc::c_char,
10019 ) == 0 && additional >= 1 as libc::c_int
10020 && lfu_freq == -(1 as libc::c_int) as libc::c_longlong
10021 {
10022 if getLongLongFromObjectOrReply(
10023 c,
10024 *((*c).argv).offset((j + 1 as libc::c_int) as isize),
10025 &mut lru_idle,
10026 0 as *const libc::c_char,
10027 ) != 0 as libc::c_int
10028 {
10029 return;
10030 }
10031 if lru_idle < 0 as libc::c_int as libc::c_longlong {
10032 addReplyError(
10033 c,
10034 b"Invalid IDLETIME value, must be >= 0\0" as *const u8
10035 as *const libc::c_char,
10036 );
10037 return;
10038 }
10039 lru_clock = LRU_CLOCK() as libc::c_longlong;
10040 j += 1;
10041 } else if strcasecmp(
10042 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10043 b"freq\0" as *const u8 as *const libc::c_char,
10044 ) == 0 && additional >= 1 as libc::c_int
10045 && lru_idle == -(1 as libc::c_int) as libc::c_longlong
10046 {
10047 if getLongLongFromObjectOrReply(
10048 c,
10049 *((*c).argv).offset((j + 1 as libc::c_int) as isize),
10050 &mut lfu_freq,
10051 0 as *const libc::c_char,
10052 ) != 0 as libc::c_int
10053 {
10054 return;
10055 }
10056 if lfu_freq < 0 as libc::c_int as libc::c_longlong
10057 || lfu_freq > 255 as libc::c_int as libc::c_longlong
10058 {
10059 addReplyError(
10060 c,
10061 b"Invalid FREQ value, must be >= 0 and <= 255\0" as *const u8
10062 as *const libc::c_char,
10063 );
10064 return;
10065 }
10066 j += 1;
10067 } else {
10068 addReplyErrorObject(c, shared.syntaxerr);
10069 return;
10070 }
10071 j += 1;
10072 }
10073 let mut key: *mut robj = *((*c).argv).offset(1 as libc::c_int as isize);
10074 if replace == 0 && !(lookupKeyWrite((*c).db, key)).is_null() {
10075 addReplyErrorObject(c, shared.busykeyerr);
10076 return;
10077 }
10078 if getLongLongFromObjectOrReply(
10079 c,
10080 *((*c).argv).offset(2 as libc::c_int as isize),
10081 &mut ttl,
10082 0 as *const libc::c_char,
10083 ) != 0 as libc::c_int
10084 {
10085 return
10086 } else {
10087 if ttl < 0 as libc::c_int as libc::c_longlong {
10088 addReplyError(
10089 c,
10090 b"Invalid TTL value, must be >= 0\0" as *const u8 as *const libc::c_char,
10091 );
10092 return;
10093 }
10094 }
10095 if verifyDumpPayload(
10096 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr as *mut libc::c_uchar,
10097 sdslen((**((*c).argv).offset(3 as libc::c_int as isize)).ptr as sds),
10098 0 as *mut uint16_t,
10099 ) == -(1 as libc::c_int)
10100 {
10101 addReplyError(
10102 c,
10103 b"DUMP payload version or checksum are wrong\0" as *const u8
10104 as *const libc::c_char,
10105 );
10106 return;
10107 }
10108 rioInitWithBuffer(
10109 &mut payload,
10110 (**((*c).argv).offset(3 as libc::c_int as isize)).ptr as sds,
10111 );
10112 type_0 = rdbLoadObjectType(&mut payload);
10113 if type_0 == -(1 as libc::c_int)
10114 || {
10115 obj = rdbLoadObject(
10116 type_0,
10117 &mut payload,
10118 (*key).ptr as sds,
10119 (*(*c).db).id,
10120 0 as *mut libc::c_int,
10121 );
10122 obj.is_null()
10123 }
10124 {
10125 addReplyError(c, b"Bad data format\0" as *const u8 as *const libc::c_char);
10126 return;
10127 }
10128 let mut deleted: libc::c_int = 0 as libc::c_int;
10129 if replace != 0 {
10130 deleted = dbDelete((*c).db, key);
10131 }
10132 if ttl != 0 && absttl == 0 {
10133 ttl += mstime();
10134 }
10135 if ttl != 0 && checkAlreadyExpired(ttl) != 0 {
10136 if deleted != 0 {
10137 rewriteClientCommandVector(c, 2 as libc::c_int, shared.del, key);
10138 signalModifiedKey(c, (*c).db, key);
10139 notifyKeyspaceEvent(
10140 (1 as libc::c_int) << 2 as libc::c_int,
10141 b"del\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
10142 key,
10143 (*(*c).db).id,
10144 );
10145 server.dirty += 1;
10146 }
10147 decrRefCount(obj);
10148 addReply(c, shared.ok);
10149 return;
10150 }
10151 dbAdd((*c).db, key, obj);
10152 if ttl != 0 {
10153 setExpire(c, (*c).db, key, ttl);
10154 if absttl == 0 {
10155 let mut ttl_obj: *mut robj = createStringObjectFromLongLong(ttl);
10156 rewriteClientCommandArgument(c, 2 as libc::c_int, ttl_obj);
10157 decrRefCount(ttl_obj);
10158 rewriteClientCommandArgument(c, (*c).argc, shared.absttl);
10159 }
10160 }
10161 objectSetLRUOrLFU(obj, lfu_freq, lru_idle, lru_clock, 1000 as libc::c_int);
10162 signalModifiedKey(c, (*c).db, key);
10163 notifyKeyspaceEvent(
10164 (1 as libc::c_int) << 2 as libc::c_int,
10165 b"restore\0" as *const u8 as *const libc::c_char as *mut libc::c_char,
10166 key,
10167 (*(*c).db).id,
10168 );
10169 addReply(c, shared.ok);
10170 server.dirty += 1;
10171}
10172#[no_mangle]
10173pub unsafe extern "C" fn migrateGetSocket(
10174 mut c: *mut client,
10175 mut host: *mut robj,
10176 mut port: *mut robj,
10177 mut timeout: libc::c_long,
10178) -> *mut migrateCachedSocket {
10179 let mut conn: *mut connection = 0 as *mut connection;
10180 let mut name: sds = sdsempty();
10181 let mut cs: *mut migrateCachedSocket = 0 as *mut migrateCachedSocket;
10182 name = sdscatlen(name, (*host).ptr, sdslen((*host).ptr as sds));
10183 name = sdscatlen(
10184 name,
10185 b":\0" as *const u8 as *const libc::c_char as *const libc::c_void,
10186 1 as libc::c_int as size_t,
10187 );
10188 name = sdscatlen(name, (*port).ptr, sdslen((*port).ptr as sds));
10189 cs = dictFetchValue(server.migrate_cached_sockets, name as *const libc::c_void)
10190 as *mut migrateCachedSocket;
10191 if !cs.is_null() {
10192 sdsfree(name);
10193 (*cs).last_use_time = server.unixtime as time_t;
10194 return cs;
10195 }
10196 if ((*server.migrate_cached_sockets).ht_used[0 as libc::c_int as usize])
10197 .wrapping_add(
10198 (*server.migrate_cached_sockets).ht_used[1 as libc::c_int as usize],
10199 ) == 64 as libc::c_int as libc::c_ulong
10200 {
10201 let mut de: *mut dictEntry = dictGetRandomKey(server.migrate_cached_sockets);
10202 cs = (*de).v.val as *mut migrateCachedSocket;
10203 connClose((*cs).conn);
10204 zfree(cs as *mut libc::c_void);
10205 dictDelete(server.migrate_cached_sockets, (*de).key);
10206 }
10207 conn = if server.tls_cluster != 0 { connCreateTLS() } else { connCreateSocket() };
10208 if connBlockingConnect(
10209 conn,
10210 (*host).ptr as *const libc::c_char,
10211 atoi((*port).ptr as *const libc::c_char),
10212 timeout as libc::c_longlong,
10213 ) != 0 as libc::c_int
10214 {
10215 addReplyError(
10216 c,
10217 b"-IOERR error or timeout connecting to the client\0" as *const u8
10218 as *const libc::c_char,
10219 );
10220 connClose(conn);
10221 sdsfree(name);
10222 return 0 as *mut migrateCachedSocket;
10223 }
10224 connEnableTcpNoDelay(conn);
10225 cs = zmalloc(core::mem::size_of::<migrateCachedSocket>() as libc::c_ulong)
10226 as *mut migrateCachedSocket;
10227 (*cs).conn = conn;
10228 (*cs).last_dbid = -(1 as libc::c_int) as libc::c_long;
10229 (*cs).last_use_time = server.unixtime as time_t;
10230 dictAdd(
10231 server.migrate_cached_sockets,
10232 name as *mut libc::c_void,
10233 cs as *mut libc::c_void,
10234 );
10235 return cs;
10236}
10237#[no_mangle]
10238pub unsafe extern "C" fn migrateCloseSocket(mut host: *mut robj, mut port: *mut robj) {
10239 let mut name: sds = sdsempty();
10240 let mut cs: *mut migrateCachedSocket = 0 as *mut migrateCachedSocket;
10241 name = sdscatlen(name, (*host).ptr, sdslen((*host).ptr as sds));
10242 name = sdscatlen(
10243 name,
10244 b":\0" as *const u8 as *const libc::c_char as *const libc::c_void,
10245 1 as libc::c_int as size_t,
10246 );
10247 name = sdscatlen(name, (*port).ptr, sdslen((*port).ptr as sds));
10248 cs = dictFetchValue(server.migrate_cached_sockets, name as *const libc::c_void)
10249 as *mut migrateCachedSocket;
10250 if cs.is_null() {
10251 sdsfree(name);
10252 return;
10253 }
10254 connClose((*cs).conn);
10255 zfree(cs as *mut libc::c_void);
10256 dictDelete(server.migrate_cached_sockets, name as *const libc::c_void);
10257 sdsfree(name);
10258}
10259#[no_mangle]
10260pub unsafe extern "C" fn migrateCloseTimedoutSockets() {
10261 let mut di: *mut dictIterator = dictGetSafeIterator(server.migrate_cached_sockets);
10262 let mut de: *mut dictEntry = 0 as *mut dictEntry;
10263 loop {
10264 de = dictNext(di);
10265 if de.is_null() {
10266 break;
10267 }
10268 let mut cs: *mut migrateCachedSocket = (*de).v.val as *mut migrateCachedSocket;
10269 if server.unixtime as libc::c_long - (*cs).last_use_time
10270 > 10 as libc::c_int as libc::c_long
10271 {
10272 connClose((*cs).conn);
10273 zfree(cs as *mut libc::c_void);
10274 dictDelete(server.migrate_cached_sockets, (*de).key);
10275 }
10276 }
10277 dictReleaseIterator(di);
10278}
10279#[no_mangle]
10280pub unsafe extern "C" fn migrateCommand(mut c: *mut client) {
10281 let mut buf0: [libc::c_char; 1024] = [0; 1024];
10282 let mut buf1: [libc::c_char; 1024] = [0; 1024];
10283 let mut buf2: [libc::c_char; 1024] = [0; 1024];
10284 let mut error_from_target: libc::c_int = 0;
10285 let mut socket_error: libc::c_int = 0;
10286 let mut del_idx: libc::c_int = 0;
10287 let mut current_block: u64;
10288 let mut cs: *mut migrateCachedSocket = 0 as *mut migrateCachedSocket;
10289 let mut copy: libc::c_int = 0 as libc::c_int;
10290 let mut replace: libc::c_int = 0 as libc::c_int;
10291 let mut j: libc::c_int = 0;
10292 let mut username: *mut libc::c_char = 0 as *mut libc::c_char;
10293 let mut password: *mut libc::c_char = 0 as *mut libc::c_char;
10294 let mut timeout: libc::c_long = 0;
10295 let mut dbid: libc::c_long = 0;
10296 let mut ov: *mut *mut robj = 0 as *mut *mut robj;
10297 let mut kv: *mut *mut robj = 0 as *mut *mut robj;
10298 let mut newargv: *mut *mut robj = 0 as *mut *mut robj;
10299 let mut cmd: rio = rio {
10300 read: None,
10301 write: None,
10302 tell: None,
10303 flush: None,
10304 update_cksum: None,
10305 cksum: 0,
10306 flags: 0,
10307 processed_bytes: 0,
10308 max_processing_chunk: 0,
10309 io: C2RustUnnamed {
10310 buffer: C2RustUnnamed_3 {
10311 ptr: 0 as *mut libc::c_char,
10312 pos: 0,
10313 },
10314 },
10315 };
10316 let mut payload: rio = rio {
10317 read: None,
10318 write: None,
10319 tell: None,
10320 flush: None,
10321 update_cksum: None,
10322 cksum: 0,
10323 flags: 0,
10324 processed_bytes: 0,
10325 max_processing_chunk: 0,
10326 io: C2RustUnnamed {
10327 buffer: C2RustUnnamed_3 {
10328 ptr: 0 as *mut libc::c_char,
10329 pos: 0,
10330 },
10331 },
10332 };
10333 let mut may_retry: libc::c_int = 1 as libc::c_int;
10334 let mut write_error: libc::c_int = 0 as libc::c_int;
10335 let mut argv_rewritten: libc::c_int = 0 as libc::c_int;
10336 let mut first_key: libc::c_int = 3 as libc::c_int;
10337 let mut num_keys: libc::c_int = 1 as libc::c_int;
10338 j = 6 as libc::c_int;
10339 while j < (*c).argc {
10340 let mut moreargs: libc::c_int = (*c).argc - 1 as libc::c_int - j;
10341 if strcasecmp(
10342 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10343 b"copy\0" as *const u8 as *const libc::c_char,
10344 ) == 0
10345 {
10346 copy = 1 as libc::c_int;
10347 } else if strcasecmp(
10348 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10349 b"replace\0" as *const u8 as *const libc::c_char,
10350 ) == 0
10351 {
10352 replace = 1 as libc::c_int;
10353 } else if strcasecmp(
10354 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10355 b"auth\0" as *const u8 as *const libc::c_char,
10356 ) == 0
10357 {
10358 if moreargs == 0 {
10359 addReplyErrorObject(c, shared.syntaxerr);
10360 return;
10361 }
10362 j += 1;
10363 password = (**((*c).argv).offset(j as isize)).ptr as *mut libc::c_char;
10364 redactClientCommandArgument(c, j);
10365 } else if strcasecmp(
10366 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10367 b"auth2\0" as *const u8 as *const libc::c_char,
10368 ) == 0
10369 {
10370 if moreargs < 2 as libc::c_int {
10371 addReplyErrorObject(c, shared.syntaxerr);
10372 return;
10373 }
10374 j += 1;
10375 username = (**((*c).argv).offset(j as isize)).ptr as *mut libc::c_char;
10376 redactClientCommandArgument(c, j);
10377 j += 1;
10378 password = (**((*c).argv).offset(j as isize)).ptr as *mut libc::c_char;
10379 redactClientCommandArgument(c, j);
10380 } else if strcasecmp(
10381 (**((*c).argv).offset(j as isize)).ptr as *const libc::c_char,
10382 b"keys\0" as *const u8 as *const libc::c_char,
10383 ) == 0
10384 {
10385 if sdslen((**((*c).argv).offset(3 as libc::c_int as isize)).ptr as sds)
10386 != 0 as libc::c_int as libc::c_ulong
10387 {
10388 addReplyError(
10389 c,
10390 b"When using MIGRATE KEYS option, the key argument must be set to the empty string\0"
10391 as *const u8 as *const libc::c_char,
10392 );
10393 return;
10394 }
10395 first_key = j + 1 as libc::c_int;
10396 num_keys = (*c).argc - j - 1 as libc::c_int;
10397 break;
10398 } else {
10399 addReplyErrorObject(c, shared.syntaxerr);
10400 return;
10401 }
10402 j += 1;
10403 }
10404 if getLongFromObjectOrReply(
10405 c,
10406 *((*c).argv).offset(5 as libc::c_int as isize),
10407 &mut timeout,
10408 0 as *const libc::c_char,
10409 ) != 0 as libc::c_int
10410 || getLongFromObjectOrReply(
10411 c,
10412 *((*c).argv).offset(4 as libc::c_int as isize),
10413 &mut dbid,
10414 0 as *const libc::c_char,
10415 ) != 0 as libc::c_int
10416 {
10417 return;
10418 }
10419 if timeout <= 0 as libc::c_int as libc::c_long {
10420 timeout = 1000 as libc::c_int as libc::c_long;
10421 }
10422 ov = zrealloc(
10423 ov as *mut libc::c_void,
10424 (core::mem::size_of::<*mut robj>() as libc::c_ulong)
10425 .wrapping_mul(num_keys as libc::c_ulong),
10426 ) as *mut *mut robj;
10427 kv = zrealloc(
10428 kv as *mut libc::c_void,
10429 (core::mem::size_of::<*mut robj>() as libc::c_ulong)
10430 .wrapping_mul(num_keys as libc::c_ulong),
10431 ) as *mut *mut robj;
10432 let mut oi: libc::c_int = 0 as libc::c_int;
10433 j = 0 as libc::c_int;
10434 while j < num_keys {
10435 let ref mut fresh18 = *ov.offset(oi as isize);
10436 *fresh18 = lookupKeyRead((*c).db, *((*c).argv).offset((first_key + j) as isize));
10437 if !(*fresh18).is_null() {
10438 let ref mut fresh19 = *kv.offset(oi as isize);
10439 *fresh19 = *((*c).argv).offset((first_key + j) as isize);
10440 oi += 1;
10441 }
10442 j += 1;
10443 }
10444 num_keys = oi;
10445 if num_keys == 0 as libc::c_int {
10446 zfree(ov as *mut libc::c_void);
10447 zfree(kv as *mut libc::c_void);
10448 addReplySds(c, sdsnew(b"+NOKEY\r\n\0" as *const u8 as *const libc::c_char));
10449 return;
10450 }
10451 loop {
10452 write_error = 0 as libc::c_int;
10453 cs = migrateGetSocket(
10454 c,
10455 *((*c).argv).offset(1 as libc::c_int as isize),
10456 *((*c).argv).offset(2 as libc::c_int as isize),
10457 timeout,
10458 );
10459 if cs.is_null() {
10460 zfree(ov as *mut libc::c_void);
10461 zfree(kv as *mut libc::c_void);
10462 return;
10463 }
10464 rioInitWithBuffer(&mut cmd, sdsempty());
10465 if !password.is_null() {
10466 let mut arity: libc::c_int = if !username.is_null() {
10467 3 as libc::c_int
10468 } else {
10469 2 as libc::c_int
10470 };
10471 if rioWriteBulkCount(
10472 &mut cmd,
10473 '*' as i32 as libc::c_char,
10474 arity as libc::c_long,
10475 ) != 0
10476 {} else {
10477 _serverAssertWithInfo(
10478 c,
10479 0 as *const robj,
10480 b"rioWriteBulkCount(&cmd,'*',arity)\0" as *const u8
10481 as *const libc::c_char,
10482 b"cluster.c\0" as *const u8 as *const libc::c_char,
10483 6303 as libc::c_int,
10484 );
10485 unreachable!();
10486 };
10487 if rioWriteBulkString(
10488 &mut cmd,
10489 b"AUTH\0" as *const u8 as *const libc::c_char,
10490 4 as libc::c_int as size_t,
10491 ) != 0
10492 {} else {
10493 _serverAssertWithInfo(
10494 c,
10495 0 as *const robj,
10496 b"rioWriteBulkString(&cmd,\"AUTH\",4)\0" as *const u8
10497 as *const libc::c_char,
10498 b"cluster.c\0" as *const u8 as *const libc::c_char,
10499 6304 as libc::c_int,
10500 );
10501 unreachable!();
10502 };
10503 if !username.is_null() {
10504 if rioWriteBulkString(&mut cmd, username, sdslen(username)) != 0
10505 {} else {
10506 _serverAssertWithInfo(
10507 c,
10508 0 as *const robj,
10509 b"rioWriteBulkString(&cmd,username, sdslen(username))\0"
10510 as *const u8 as *const libc::c_char,
10511 b"cluster.c\0" as *const u8 as *const libc::c_char,
10512 6307 as libc::c_int,
10513 );
10514 unreachable!();
10515 };
10516 }
10517 if rioWriteBulkString(&mut cmd, password, sdslen(password)) != 0 {} else {
10518 _serverAssertWithInfo(
10519 c,
10520 0 as *const robj,
10521 b"rioWriteBulkString(&cmd,password, sdslen(password))\0" as *const u8
10522 as *const libc::c_char,
10523 b"cluster.c\0" as *const u8 as *const libc::c_char,
10524 6310 as libc::c_int,
10525 );
10526 unreachable!();
10527 };
10528 }
10529 let mut select: libc::c_int = ((*cs).last_dbid != dbid) as libc::c_int;
10530 if select != 0 {
10531 if rioWriteBulkCount(
10532 &mut cmd,
10533 '*' as i32 as libc::c_char,
10534 2 as libc::c_int as libc::c_long,
10535 ) != 0
10536 {} else {
10537 _serverAssertWithInfo(
10538 c,
10539 0 as *const robj,
10540 b"rioWriteBulkCount(&cmd,'*',2)\0" as *const u8
10541 as *const libc::c_char,
10542 b"cluster.c\0" as *const u8 as *const libc::c_char,
10543 6316 as libc::c_int,
10544 );
10545 unreachable!();
10546 };
10547 if rioWriteBulkString(
10548 &mut cmd,
10549 b"SELECT\0" as *const u8 as *const libc::c_char,
10550 6 as libc::c_int as size_t,
10551 ) != 0
10552 {} else {
10553 _serverAssertWithInfo(
10554 c,
10555 0 as *const robj,
10556 b"rioWriteBulkString(&cmd,\"SELECT\",6)\0" as *const u8
10557 as *const libc::c_char,
10558 b"cluster.c\0" as *const u8 as *const libc::c_char,
10559 6317 as libc::c_int,
10560 );
10561 unreachable!();
10562 };
10563 if rioWriteBulkLongLong(&mut cmd, dbid as libc::c_longlong) != 0 {} else {
10564 _serverAssertWithInfo(
10565 c,
10566 0 as *const robj,
10567 b"rioWriteBulkLongLong(&cmd,dbid)\0" as *const u8
10568 as *const libc::c_char,
10569 b"cluster.c\0" as *const u8 as *const libc::c_char,
10570 6318 as libc::c_int,
10571 );
10572 unreachable!();
10573 };
10574 }
10575 let mut non_expired: libc::c_int = 0 as libc::c_int;
10576 let mut current_block_91: u64;
10577 j = 0 as libc::c_int;
10578 while j < num_keys {
10579 let mut ttl: libc::c_longlong = 0 as libc::c_int as libc::c_longlong;
10580 let mut expireat: libc::c_longlong = getExpire(
10581 (*c).db,
10582 *kv.offset(j as isize),
10583 );
10584 if expireat != -(1 as libc::c_int) as libc::c_longlong {
10585 ttl = expireat - mstime();
10586 if ttl < 0 as libc::c_int as libc::c_longlong {
10587 current_block_91 = 8869332144787829186;
10588 } else {
10589 if ttl < 1 as libc::c_int as libc::c_longlong {
10590 ttl = 1 as libc::c_int as libc::c_longlong;
10591 }
10592 current_block_91 = 6367734732029634840;
10593 }
10594 } else {
10595 current_block_91 = 6367734732029634840;
10596 }
10597 match current_block_91 {
10598 6367734732029634840 => {
10599 let ref mut fresh20 = *ov.offset(non_expired as isize);
10600 *fresh20 = *ov.offset(j as isize);
10601 let fresh21 = non_expired;
10602 non_expired = non_expired + 1;
10603 let ref mut fresh22 = *kv.offset(fresh21 as isize);
10604 *fresh22 = *kv.offset(j as isize);
10605 if rioWriteBulkCount(
10606 &mut cmd,
10607 '*' as i32 as libc::c_char,
10608 (if replace != 0 { 5 as libc::c_int } else { 4 as libc::c_int })
10609 as libc::c_long,
10610 ) != 0
10611 {} else {
10612 _serverAssertWithInfo(
10613 c,
10614 0 as *const robj,
10615 b"rioWriteBulkCount(&cmd,'*',replace ? 5 : 4)\0" as *const u8
10616 as *const libc::c_char,
10617 b"cluster.c\0" as *const u8 as *const libc::c_char,
10618 6346 as libc::c_int,
10619 );
10620 unreachable!();
10621 };
10622 if server.cluster_enabled != 0 {
10623 if rioWriteBulkString(
10624 &mut cmd,
10625 b"RESTORE-ASKING\0" as *const u8 as *const libc::c_char,
10626 14 as libc::c_int as size_t,
10627 ) != 0
10628 {} else {
10629 _serverAssertWithInfo(
10630 c,
10631 0 as *const robj,
10632 b"rioWriteBulkString(&cmd,\"RESTORE-ASKING\",14)\0"
10633 as *const u8 as *const libc::c_char,
10634 b"cluster.c\0" as *const u8 as *const libc::c_char,
10635 6350 as libc::c_int,
10636 );
10637 unreachable!();
10638 };
10639 } else {
10640 if rioWriteBulkString(
10641 &mut cmd,
10642 b"RESTORE\0" as *const u8 as *const libc::c_char,
10643 7 as libc::c_int as size_t,
10644 ) != 0
10645 {} else {
10646 _serverAssertWithInfo(
10647 c,
10648 0 as *const robj,
10649 b"rioWriteBulkString(&cmd,\"RESTORE\",7)\0" as *const u8
10650 as *const libc::c_char,
10651 b"cluster.c\0" as *const u8 as *const libc::c_char,
10652 6352 as libc::c_int,
10653 );
10654 unreachable!();
10655 };
10656 }
10657 if (**kv.offset(j as isize)).encoding() as libc::c_int
10658 == 0 as libc::c_int
10659 || (**kv.offset(j as isize)).encoding() as libc::c_int
10660 == 8 as libc::c_int
10661 {} else {
10662 _serverAssertWithInfo(
10663 c,
10664 0 as *const robj,
10665 b"sdsEncodedObject(kv[j])\0" as *const u8
10666 as *const libc::c_char,
10667 b"cluster.c\0" as *const u8 as *const libc::c_char,
10668 6353 as libc::c_int,
10669 );
10670 unreachable!();
10671 };
10672 if rioWriteBulkString(
10673 &mut cmd,
10674 (**kv.offset(j as isize)).ptr as *const libc::c_char,
10675 sdslen((**kv.offset(j as isize)).ptr as sds),
10676 ) != 0
10677 {} else {
10678 _serverAssertWithInfo(
10679 c,
10680 0 as *const robj,
10681 b"rioWriteBulkString(&cmd,kv[j]->ptr, sdslen(kv[j]->ptr))\0"
10682 as *const u8 as *const libc::c_char,
10683 b"cluster.c\0" as *const u8 as *const libc::c_char,
10684 6355 as libc::c_int,
10685 );
10686 unreachable!();
10687 };
10688 if rioWriteBulkLongLong(&mut cmd, ttl) != 0 {} else {
10689 _serverAssertWithInfo(
10690 c,
10691 0 as *const robj,
10692 b"rioWriteBulkLongLong(&cmd,ttl)\0" as *const u8
10693 as *const libc::c_char,
10694 b"cluster.c\0" as *const u8 as *const libc::c_char,
10695 6356 as libc::c_int,
10696 );
10697 unreachable!();
10698 };
10699 createDumpPayload(
10700 &mut payload,
10701 *ov.offset(j as isize),
10702 *kv.offset(j as isize),
10703 dbid as libc::c_int,
10704 );
10705 if rioWriteBulkString(
10706 &mut cmd,
10707 payload.io.buffer.ptr as *const libc::c_char,
10708 sdslen(payload.io.buffer.ptr),
10709 ) != 0
10710 {} else {
10711 _serverAssertWithInfo(
10712 c,
10713 0 as *const robj,
10714 b"rioWriteBulkString(&cmd,payload.io.buffer.ptr, sdslen(payload.io.buffer.ptr))\0"
10715 as *const u8 as *const libc::c_char,
10716 b"cluster.c\0" as *const u8 as *const libc::c_char,
10717 6363 as libc::c_int,
10718 );
10719 unreachable!();
10720 };
10721 sdsfree(payload.io.buffer.ptr);
10722 if replace != 0 {
10723 if rioWriteBulkString(
10724 &mut cmd,
10725 b"REPLACE\0" as *const u8 as *const libc::c_char,
10726 7 as libc::c_int as size_t,
10727 ) != 0
10728 {} else {
10729 _serverAssertWithInfo(
10730 c,
10731 0 as *const robj,
10732 b"rioWriteBulkString(&cmd,\"REPLACE\",7)\0" as *const u8
10733 as *const libc::c_char,
10734 b"cluster.c\0" as *const u8 as *const libc::c_char,
10735 6369 as libc::c_int,
10736 );
10737 unreachable!();
10738 };
10739 }
10740 }
10741 _ => {}
10742 }
10743 j += 1;
10744 }
10745 num_keys = non_expired;
10746 *__errno_location() = 0 as libc::c_int;
10747 let mut buf: sds = cmd.io.buffer.ptr;
10748 let mut pos: size_t = 0 as libc::c_int as size_t;
10749 let mut towrite: size_t = 0;
10750 let mut nwritten: libc::c_int = 0 as libc::c_int;
10751 loop {
10752 towrite = (sdslen(buf)).wrapping_sub(pos);
10753 if !(towrite > 0 as libc::c_int as libc::c_ulong) {
10754 current_block = 10369920510435091891;
10755 break;
10756 }
10757 towrite = if towrite
10758 > (64 as libc::c_int * 1024 as libc::c_int) as libc::c_ulong
10759 {
10760 (64 as libc::c_int * 1024 as libc::c_int) as libc::c_ulong
10761 } else {
10762 towrite
10763 };
10764 nwritten = connSyncWrite(
10765 (*cs).conn,
10766 buf.offset(pos as isize),
10767 towrite as ssize_t,
10768 timeout as libc::c_longlong,
10769 ) as libc::c_int;
10770 if nwritten != towrite as libc::c_int {
10771 write_error = 1 as libc::c_int;
10772 current_block = 14587052215474842647;
10773 break;
10774 } else {
10775 pos = (pos as libc::c_ulong).wrapping_add(nwritten as libc::c_ulong)
10776 as size_t as size_t;
10777 }
10778 }
10779 match current_block {
10780 10369920510435091891 => {
10781 buf0 = [0; 1024];
10782 buf1 = [0; 1024];
10783 buf2 = [0; 1024];
10784 if !(!password.is_null()
10785 && connSyncReadLine(
10786 (*cs).conn,
10787 buf0.as_mut_ptr(),
10788 core::mem::size_of::<[libc::c_char; 1024]>() as libc::c_ulong
10789 as ssize_t,
10790 timeout as libc::c_longlong,
10791 ) <= 0 as libc::c_int as libc::c_long)
10792 {
10793 if !(select != 0
10794 && connSyncReadLine(
10795 (*cs).conn,
10796 buf1.as_mut_ptr(),
10797 core::mem::size_of::<[libc::c_char; 1024]>()
10798 as libc::c_ulong as ssize_t,
10799 timeout as libc::c_longlong,
10800 ) <= 0 as libc::c_int as libc::c_long)
10801 {
10802 error_from_target = 0 as libc::c_int;
10803 socket_error = 0 as libc::c_int;
10804 del_idx = 1 as libc::c_int;
10805 if copy == 0 {
10806 newargv = zmalloc(
10807 (core::mem::size_of::<*mut robj>() as libc::c_ulong)
10808 .wrapping_mul(
10809 (num_keys + 1 as libc::c_int) as libc::c_ulong,
10810 ),
10811 ) as *mut *mut robj;
10812 }
10813 j = 0 as libc::c_int;
10814 while j < num_keys {
10815 if connSyncReadLine(
10816 (*cs).conn,
10817 buf2.as_mut_ptr(),
10818 core::mem::size_of::<[libc::c_char; 1024]>()
10819 as libc::c_ulong as ssize_t,
10820 timeout as libc::c_longlong,
10821 ) <= 0 as libc::c_int as libc::c_long
10822 {
10823 socket_error = 1 as libc::c_int;
10824 break;
10825 } else {
10826 if !password.is_null()
10827 && buf0[0 as libc::c_int as usize] as libc::c_int
10828 == '-' as i32
10829 || select != 0
10830 && buf1[0 as libc::c_int as usize] as libc::c_int
10831 == '-' as i32
10832 || buf2[0 as libc::c_int as usize] as libc::c_int
10833 == '-' as i32
10834 {
10835 if error_from_target == 0 {
10836 (*cs).last_dbid = -(1 as libc::c_int) as libc::c_long;
10837 let mut errbuf: *mut libc::c_char = 0 as *mut libc::c_char;
10838 if !password.is_null()
10839 && buf0[0 as libc::c_int as usize] as libc::c_int
10840 == '-' as i32
10841 {
10842 errbuf = buf0.as_mut_ptr();
10843 } else if select != 0
10844 && buf1[0 as libc::c_int as usize] as libc::c_int
10845 == '-' as i32
10846 {
10847 errbuf = buf1.as_mut_ptr();
10848 } else {
10849 errbuf = buf2.as_mut_ptr();
10850 }
10851 error_from_target = 1 as libc::c_int;
10852 addReplyErrorFormat(
10853 c,
10854 b"Target instance replied with error: %s\0" as *const u8
10855 as *const libc::c_char,
10856 errbuf.offset(1 as libc::c_int as isize),
10857 );
10858 }
10859 } else if copy == 0 {
10860 dbDelete((*c).db, *kv.offset(j as isize));
10861 signalModifiedKey(c, (*c).db, *kv.offset(j as isize));
10862 notifyKeyspaceEvent(
10863 (1 as libc::c_int) << 2 as libc::c_int,
10864 b"del\0" as *const u8 as *const libc::c_char
10865 as *mut libc::c_char,
10866 *kv.offset(j as isize),
10867 (*(*c).db).id,
10868 );
10869 server.dirty += 1;
10870 let fresh23 = del_idx;
10871 del_idx = del_idx + 1;
10872 let ref mut fresh24 = *newargv.offset(fresh23 as isize);
10873 *fresh24 = *kv.offset(j as isize);
10874 incrRefCount(*kv.offset(j as isize));
10875 }
10876 j += 1;
10877 }
10878 }
10879 if !(error_from_target == 0 && socket_error != 0
10880 && j == 0 as libc::c_int && may_retry != 0
10881 && *__errno_location() != 110 as libc::c_int)
10882 {
10883 if socket_error != 0 {
10884 migrateCloseSocket(
10885 *((*c).argv).offset(1 as libc::c_int as isize),
10886 *((*c).argv).offset(2 as libc::c_int as isize),
10887 );
10888 }
10889 if copy == 0 {
10890 if del_idx > 1 as libc::c_int {
10891 let ref mut fresh25 = *newargv
10892 .offset(0 as libc::c_int as isize);
10893 *fresh25 = createStringObject(
10894 b"DEL\0" as *const u8 as *const libc::c_char,
10895 3 as libc::c_int as size_t,
10896 );
10897 replaceClientCommandVector(c, del_idx, newargv);
10898 argv_rewritten = 1 as libc::c_int;
10899 } else {
10900 zfree(newargv as *mut libc::c_void);
10901 }
10902 newargv = 0 as *mut *mut robj;
10903 }
10904 if error_from_target == 0 && socket_error != 0 {
10905 may_retry = 0 as libc::c_int;
10906 } else {
10907 if error_from_target == 0 {
10908 (*cs).last_dbid = dbid;
10909 addReply(c, shared.ok);
10910 }
10911 sdsfree(cmd.io.buffer.ptr);
10912 zfree(ov as *mut libc::c_void);
10913 zfree(kv as *mut libc::c_void);
10914 zfree(newargv as *mut libc::c_void);
10915 return;
10916 }
10917 }
10918 }
10919 }
10920 }
10921 _ => {}
10922 }
10923 sdsfree(cmd.io.buffer.ptr);
10924 if argv_rewritten == 0 {
10925 migrateCloseSocket(
10926 *((*c).argv).offset(1 as libc::c_int as isize),
10927 *((*c).argv).offset(2 as libc::c_int as isize),
10928 );
10929 }
10930 zfree(newargv as *mut libc::c_void);
10931 newargv = 0 as *mut *mut robj;
10932 if *__errno_location() != 110 as libc::c_int && may_retry != 0 {
10933 may_retry = 0 as libc::c_int;
10934 } else {
10935 zfree(ov as *mut libc::c_void);
10936 zfree(kv as *mut libc::c_void);
10937 addReplyErrorSds(
10938 c,
10939 sdscatprintf(
10940 sdsempty(),
10941 b"-IOERR error or timeout %s to target instance\0" as *const u8
10942 as *const libc::c_char,
10943 if write_error != 0 {
10944 b"writing\0" as *const u8 as *const libc::c_char
10945 } else {
10946 b"reading\0" as *const u8 as *const libc::c_char
10947 },
10948 ),
10949 );
10950 return;
10951 }
10952 };
10953}
10954#[no_mangle]
10955pub unsafe extern "C" fn askingCommand(mut c: *mut client) {
10956 if server.cluster_enabled == 0 as libc::c_int {
10957 addReplyError(
10958 c,
10959 b"This instance has cluster support disabled\0" as *const u8
10960 as *const libc::c_char,
10961 );
10962 return;
10963 }
10964 (*c).flags |= ((1 as libc::c_int) << 9 as libc::c_int) as libc::c_ulong;
10965 addReply(c, shared.ok);
10966}
10967#[no_mangle]
10968pub unsafe extern "C" fn readonlyCommand(mut c: *mut client) {
10969 if server.cluster_enabled == 0 as libc::c_int {
10970 addReplyError(
10971 c,
10972 b"This instance has cluster support disabled\0" as *const u8
10973 as *const libc::c_char,
10974 );
10975 return;
10976 }
10977 (*c).flags |= ((1 as libc::c_int) << 17 as libc::c_int) as libc::c_ulong;
10978 addReply(c, shared.ok);
10979}
10980#[no_mangle]
10981pub unsafe extern "C" fn readwriteCommand(mut c: *mut client) {
10982 if server.cluster_enabled == 0 as libc::c_int {
10983 addReplyError(
10984 c,
10985 b"This instance has cluster support disabled\0" as *const u8
10986 as *const libc::c_char,
10987 );
10988 return;
10989 }
10990 (*c).flags &= !((1 as libc::c_int) << 17 as libc::c_int) as libc::c_ulong;
10991 addReply(c, shared.ok);
10992}
10993#[no_mangle]
10994pub unsafe extern "C" fn getNodeByQuery(
10995 mut c: *mut client,
10996 mut cmd: *mut redisCommand,
10997 mut argv: *mut *mut robj,
10998 mut argc: libc::c_int,
10999 mut hashslot: *mut libc::c_int,
11000 mut error_code: *mut libc::c_int,
11001) -> *mut clusterNode {
11002 let mut n: *mut clusterNode = 0 as *mut clusterNode;
11003 let mut firstkey: *mut robj = 0 as *mut robj;
11004 let mut multiple_keys: libc::c_int = 0 as libc::c_int;
11005 let mut ms: *mut multiState = 0 as *mut multiState;
11006 let mut _ms: multiState = multiState {
11007 commands: 0 as *mut multiCmd,
11008 count: 0,
11009 cmd_flags: 0,
11010 cmd_inv_flags: 0,
11011 argv_len_sums: 0,
11012 alloc_count: 0,
11013 };
11014 let mut mc: multiCmd = multiCmd {
11015 argv: 0 as *mut *mut robj,
11016 argv_len: 0,
11017 argc: 0,
11018 cmd: 0 as *mut redisCommand,
11019 };
11020 let mut i: libc::c_int = 0;
11021 let mut slot: libc::c_int = 0 as libc::c_int;
11022 let mut migrating_slot: libc::c_int = 0 as libc::c_int;
11023 let mut importing_slot: libc::c_int = 0 as libc::c_int;
11024 let mut missing_keys: libc::c_int = 0 as libc::c_int;
11025 let mut existing_keys: libc::c_int = 0 as libc::c_int;
11026 if server.cluster_module_flags & (1 as libc::c_int) << 2 as libc::c_int != 0 {
11027 return myself;
11028 }
11029 if !error_code.is_null() {
11030 *error_code = 0 as libc::c_int;
11031 }
11032 if (*cmd).proc_0 == Some(execCommand as unsafe extern "C" fn(*mut client) -> ()) {
11033 if (*c).flags & ((1 as libc::c_int) << 3 as libc::c_int) as libc::c_ulong == 0 {
11034 return myself;
11035 }
11036 ms = &mut (*c).mstate;
11037 } else {
11038 ms = &mut _ms;
11039 _ms.commands = &mut mc;
11040 _ms.count = 1 as libc::c_int;
11041 mc.argv = argv;
11042 mc.argc = argc;
11043 mc.cmd = cmd;
11044 }
11045 let mut is_pubsubshard: libc::c_int = ((*cmd).proc_0
11046 == Some(ssubscribeCommand as unsafe extern "C" fn(*mut client) -> ())
11047 || (*cmd).proc_0
11048 == Some(sunsubscribeCommand as unsafe extern "C" fn(*mut client) -> ())
11049 || (*cmd).proc_0
11050 == Some(spublishCommand as unsafe extern "C" fn(*mut client) -> ()))
11051 as libc::c_int;
11052 i = 0 as libc::c_int;
11053 while i < (*ms).count {
11054 let mut mcmd: *mut redisCommand = 0 as *mut redisCommand;
11055 let mut margv: *mut *mut robj = 0 as *mut *mut robj;
11056 let mut margc: libc::c_int = 0;
11057 let mut numkeys: libc::c_int = 0;
11058 let mut j: libc::c_int = 0;
11059 let mut keyindex: *mut keyReference = 0 as *mut keyReference;
11060 mcmd = (*((*ms).commands).offset(i as isize)).cmd;
11061 margc = (*((*ms).commands).offset(i as isize)).argc;
11062 margv = (*((*ms).commands).offset(i as isize)).argv;
11063 let mut result: getKeysResult = {
11064 let mut init = getKeysResult {
11065 keysbuf: [
11066 {
11067 let mut init = keyReference {
11068 pos: 0 as libc::c_int,
11069 flags: 0,
11070 };
11071 init
11072 },
11073 keyReference { pos: 0, flags: 0 },
11074 keyReference { pos: 0, flags: 0 },
11075 keyReference { pos: 0, flags: 0 },
11076 keyReference { pos: 0, flags: 0 },
11077 keyReference { pos: 0, flags: 0 },
11078 keyReference { pos: 0, flags: 0 },
11079 keyReference { pos: 0, flags: 0 },
11080 keyReference { pos: 0, flags: 0 },
11081 keyReference { pos: 0, flags: 0 },
11082 keyReference { pos: 0, flags: 0 },
11083 keyReference { pos: 0, flags: 0 },
11084 keyReference { pos: 0, flags: 0 },
11085 keyReference { pos: 0, flags: 0 },
11086 keyReference { pos: 0, flags: 0 },
11087 keyReference { pos: 0, flags: 0 },
11088 keyReference { pos: 0, flags: 0 },
11089 keyReference { pos: 0, flags: 0 },
11090 keyReference { pos: 0, flags: 0 },
11091 keyReference { pos: 0, flags: 0 },
11092 keyReference { pos: 0, flags: 0 },
11093 keyReference { pos: 0, flags: 0 },
11094 keyReference { pos: 0, flags: 0 },
11095 keyReference { pos: 0, flags: 0 },
11096 keyReference { pos: 0, flags: 0 },
11097 keyReference { pos: 0, flags: 0 },
11098 keyReference { pos: 0, flags: 0 },
11099 keyReference { pos: 0, flags: 0 },
11100 keyReference { pos: 0, flags: 0 },
11101 keyReference { pos: 0, flags: 0 },
11102 keyReference { pos: 0, flags: 0 },
11103 keyReference { pos: 0, flags: 0 },
11104 keyReference { pos: 0, flags: 0 },
11105 keyReference { pos: 0, flags: 0 },
11106 keyReference { pos: 0, flags: 0 },
11107 keyReference { pos: 0, flags: 0 },
11108 keyReference { pos: 0, flags: 0 },
11109 keyReference { pos: 0, flags: 0 },
11110 keyReference { pos: 0, flags: 0 },
11111 keyReference { pos: 0, flags: 0 },
11112 keyReference { pos: 0, flags: 0 },
11113 keyReference { pos: 0, flags: 0 },
11114 keyReference { pos: 0, flags: 0 },
11115 keyReference { pos: 0, flags: 0 },
11116 keyReference { pos: 0, flags: 0 },
11117 keyReference { pos: 0, flags: 0 },
11118 keyReference { pos: 0, flags: 0 },
11119 keyReference { pos: 0, flags: 0 },
11120 keyReference { pos: 0, flags: 0 },
11121 keyReference { pos: 0, flags: 0 },
11122 keyReference { pos: 0, flags: 0 },
11123 keyReference { pos: 0, flags: 0 },
11124 keyReference { pos: 0, flags: 0 },
11125 keyReference { pos: 0, flags: 0 },
11126 keyReference { pos: 0, flags: 0 },
11127 keyReference { pos: 0, flags: 0 },
11128 keyReference { pos: 0, flags: 0 },
11129 keyReference { pos: 0, flags: 0 },
11130 keyReference { pos: 0, flags: 0 },
11131 keyReference { pos: 0, flags: 0 },
11132 keyReference { pos: 0, flags: 0 },
11133 keyReference { pos: 0, flags: 0 },
11134 keyReference { pos: 0, flags: 0 },
11135 keyReference { pos: 0, flags: 0 },
11136 keyReference { pos: 0, flags: 0 },
11137 keyReference { pos: 0, flags: 0 },
11138 keyReference { pos: 0, flags: 0 },
11139 keyReference { pos: 0, flags: 0 },
11140 keyReference { pos: 0, flags: 0 },
11141 keyReference { pos: 0, flags: 0 },
11142 keyReference { pos: 0, flags: 0 },
11143 keyReference { pos: 0, flags: 0 },
11144 keyReference { pos: 0, flags: 0 },
11145 keyReference { pos: 0, flags: 0 },
11146 keyReference { pos: 0, flags: 0 },
11147 keyReference { pos: 0, flags: 0 },
11148 keyReference { pos: 0, flags: 0 },
11149 keyReference { pos: 0, flags: 0 },
11150 keyReference { pos: 0, flags: 0 },
11151 keyReference { pos: 0, flags: 0 },
11152 keyReference { pos: 0, flags: 0 },
11153 keyReference { pos: 0, flags: 0 },
11154 keyReference { pos: 0, flags: 0 },
11155 keyReference { pos: 0, flags: 0 },
11156 keyReference { pos: 0, flags: 0 },
11157 keyReference { pos: 0, flags: 0 },
11158 keyReference { pos: 0, flags: 0 },
11159 keyReference { pos: 0, flags: 0 },
11160 keyReference { pos: 0, flags: 0 },
11161 keyReference { pos: 0, flags: 0 },
11162 keyReference { pos: 0, flags: 0 },
11163 keyReference { pos: 0, flags: 0 },
11164 keyReference { pos: 0, flags: 0 },
11165 keyReference { pos: 0, flags: 0 },
11166 keyReference { pos: 0, flags: 0 },
11167 keyReference { pos: 0, flags: 0 },
11168 keyReference { pos: 0, flags: 0 },
11169 keyReference { pos: 0, flags: 0 },
11170 keyReference { pos: 0, flags: 0 },
11171 keyReference { pos: 0, flags: 0 },
11172 keyReference { pos: 0, flags: 0 },
11173 keyReference { pos: 0, flags: 0 },
11174 keyReference { pos: 0, flags: 0 },
11175 keyReference { pos: 0, flags: 0 },
11176 keyReference { pos: 0, flags: 0 },
11177 keyReference { pos: 0, flags: 0 },
11178 keyReference { pos: 0, flags: 0 },
11179 keyReference { pos: 0, flags: 0 },
11180 keyReference { pos: 0, flags: 0 },
11181 keyReference { pos: 0, flags: 0 },
11182 keyReference { pos: 0, flags: 0 },
11183 keyReference { pos: 0, flags: 0 },
11184 keyReference { pos: 0, flags: 0 },
11185 keyReference { pos: 0, flags: 0 },
11186 keyReference { pos: 0, flags: 0 },
11187 keyReference { pos: 0, flags: 0 },
11188 keyReference { pos: 0, flags: 0 },
11189 keyReference { pos: 0, flags: 0 },
11190 keyReference { pos: 0, flags: 0 },
11191 keyReference { pos: 0, flags: 0 },
11192 keyReference { pos: 0, flags: 0 },
11193 keyReference { pos: 0, flags: 0 },
11194 keyReference { pos: 0, flags: 0 },
11195 keyReference { pos: 0, flags: 0 },
11196 keyReference { pos: 0, flags: 0 },
11197 keyReference { pos: 0, flags: 0 },
11198 keyReference { pos: 0, flags: 0 },
11199 keyReference { pos: 0, flags: 0 },
11200 keyReference { pos: 0, flags: 0 },
11201 keyReference { pos: 0, flags: 0 },
11202 keyReference { pos: 0, flags: 0 },
11203 keyReference { pos: 0, flags: 0 },
11204 keyReference { pos: 0, flags: 0 },
11205 keyReference { pos: 0, flags: 0 },
11206 keyReference { pos: 0, flags: 0 },
11207 keyReference { pos: 0, flags: 0 },
11208 keyReference { pos: 0, flags: 0 },
11209 keyReference { pos: 0, flags: 0 },
11210 keyReference { pos: 0, flags: 0 },
11211 keyReference { pos: 0, flags: 0 },
11212 keyReference { pos: 0, flags: 0 },
11213 keyReference { pos: 0, flags: 0 },
11214 keyReference { pos: 0, flags: 0 },
11215 keyReference { pos: 0, flags: 0 },
11216 keyReference { pos: 0, flags: 0 },
11217 keyReference { pos: 0, flags: 0 },
11218 keyReference { pos: 0, flags: 0 },
11219 keyReference { pos: 0, flags: 0 },
11220 keyReference { pos: 0, flags: 0 },
11221 keyReference { pos: 0, flags: 0 },
11222 keyReference { pos: 0, flags: 0 },
11223 keyReference { pos: 0, flags: 0 },
11224 keyReference { pos: 0, flags: 0 },
11225 keyReference { pos: 0, flags: 0 },
11226 keyReference { pos: 0, flags: 0 },
11227 keyReference { pos: 0, flags: 0 },
11228 keyReference { pos: 0, flags: 0 },
11229 keyReference { pos: 0, flags: 0 },
11230 keyReference { pos: 0, flags: 0 },
11231 keyReference { pos: 0, flags: 0 },
11232 keyReference { pos: 0, flags: 0 },
11233 keyReference { pos: 0, flags: 0 },
11234 keyReference { pos: 0, flags: 0 },
11235 keyReference { pos: 0, flags: 0 },
11236 keyReference { pos: 0, flags: 0 },
11237 keyReference { pos: 0, flags: 0 },
11238 keyReference { pos: 0, flags: 0 },
11239 keyReference { pos: 0, flags: 0 },
11240 keyReference { pos: 0, flags: 0 },
11241 keyReference { pos: 0, flags: 0 },
11242 keyReference { pos: 0, flags: 0 },
11243 keyReference { pos: 0, flags: 0 },
11244 keyReference { pos: 0, flags: 0 },
11245 keyReference { pos: 0, flags: 0 },
11246 keyReference { pos: 0, flags: 0 },
11247 keyReference { pos: 0, flags: 0 },
11248 keyReference { pos: 0, flags: 0 },
11249 keyReference { pos: 0, flags: 0 },
11250 keyReference { pos: 0, flags: 0 },
11251 keyReference { pos: 0, flags: 0 },
11252 keyReference { pos: 0, flags: 0 },
11253 keyReference { pos: 0, flags: 0 },
11254 keyReference { pos: 0, flags: 0 },
11255 keyReference { pos: 0, flags: 0 },
11256 keyReference { pos: 0, flags: 0 },
11257 keyReference { pos: 0, flags: 0 },
11258 keyReference { pos: 0, flags: 0 },
11259 keyReference { pos: 0, flags: 0 },
11260 keyReference { pos: 0, flags: 0 },
11261 keyReference { pos: 0, flags: 0 },
11262 keyReference { pos: 0, flags: 0 },
11263 keyReference { pos: 0, flags: 0 },
11264 keyReference { pos: 0, flags: 0 },
11265 keyReference { pos: 0, flags: 0 },
11266 keyReference { pos: 0, flags: 0 },
11267 keyReference { pos: 0, flags: 0 },
11268 keyReference { pos: 0, flags: 0 },
11269 keyReference { pos: 0, flags: 0 },
11270 keyReference { pos: 0, flags: 0 },
11271 keyReference { pos: 0, flags: 0 },
11272 keyReference { pos: 0, flags: 0 },
11273 keyReference { pos: 0, flags: 0 },
11274 keyReference { pos: 0, flags: 0 },
11275 keyReference { pos: 0, flags: 0 },
11276 keyReference { pos: 0, flags: 0 },
11277 keyReference { pos: 0, flags: 0 },
11278 keyReference { pos: 0, flags: 0 },
11279 keyReference { pos: 0, flags: 0 },
11280 keyReference { pos: 0, flags: 0 },
11281 keyReference { pos: 0, flags: 0 },
11282 keyReference { pos: 0, flags: 0 },
11283 keyReference { pos: 0, flags: 0 },
11284 keyReference { pos: 0, flags: 0 },
11285 keyReference { pos: 0, flags: 0 },
11286 keyReference { pos: 0, flags: 0 },
11287 keyReference { pos: 0, flags: 0 },
11288 keyReference { pos: 0, flags: 0 },
11289 keyReference { pos: 0, flags: 0 },
11290 keyReference { pos: 0, flags: 0 },
11291 keyReference { pos: 0, flags: 0 },
11292 keyReference { pos: 0, flags: 0 },
11293 keyReference { pos: 0, flags: 0 },
11294 keyReference { pos: 0, flags: 0 },
11295 keyReference { pos: 0, flags: 0 },
11296 keyReference { pos: 0, flags: 0 },
11297 keyReference { pos: 0, flags: 0 },
11298 keyReference { pos: 0, flags: 0 },
11299 keyReference { pos: 0, flags: 0 },
11300 keyReference { pos: 0, flags: 0 },
11301 keyReference { pos: 0, flags: 0 },
11302 keyReference { pos: 0, flags: 0 },
11303 keyReference { pos: 0, flags: 0 },
11304 keyReference { pos: 0, flags: 0 },
11305 keyReference { pos: 0, flags: 0 },
11306 keyReference { pos: 0, flags: 0 },
11307 keyReference { pos: 0, flags: 0 },
11308 keyReference { pos: 0, flags: 0 },
11309 keyReference { pos: 0, flags: 0 },
11310 keyReference { pos: 0, flags: 0 },
11311 keyReference { pos: 0, flags: 0 },
11312 keyReference { pos: 0, flags: 0 },
11313 keyReference { pos: 0, flags: 0 },
11314 keyReference { pos: 0, flags: 0 },
11315 keyReference { pos: 0, flags: 0 },
11316 keyReference { pos: 0, flags: 0 },
11317 keyReference { pos: 0, flags: 0 },
11318 keyReference { pos: 0, flags: 0 },
11319 keyReference { pos: 0, flags: 0 },
11320 keyReference { pos: 0, flags: 0 },
11321 keyReference { pos: 0, flags: 0 },
11322 keyReference { pos: 0, flags: 0 },
11323 keyReference { pos: 0, flags: 0 },
11324 keyReference { pos: 0, flags: 0 },
11325 keyReference { pos: 0, flags: 0 },
11326 keyReference { pos: 0, flags: 0 },
11327 keyReference { pos: 0, flags: 0 },
11328 ],
11329 keys: 0 as *mut keyReference,
11330 numkeys: 0 as libc::c_int,
11331 size: 256 as libc::c_int,
11332 };
11333 init
11334 };
11335 numkeys = getKeysFromCommand(mcmd, margv, margc, &mut result);
11336 keyindex = result.keys;
11337 j = 0 as libc::c_int;
11338 while j < numkeys {
11339 let mut thiskey: *mut robj = *margv
11340 .offset((*keyindex.offset(j as isize)).pos as isize);
11341 let mut thisslot: libc::c_int = keyHashSlot(
11342 (*thiskey).ptr as *mut libc::c_char,
11343 sdslen((*thiskey).ptr as sds) as libc::c_int,
11344 ) as libc::c_int;
11345 if firstkey.is_null() {
11346 firstkey = thiskey;
11347 slot = thisslot;
11348 n = (*server.cluster).slots[slot as usize];
11349 if n.is_null() {
11350 getKeysFreeResult(&mut result);
11351 if !error_code.is_null() {
11352 *error_code = 6 as libc::c_int;
11353 }
11354 return 0 as *mut clusterNode;
11355 }
11356 if n == myself
11357 && !((*server.cluster).migrating_slots_to[slot as usize]).is_null()
11358 {
11359 migrating_slot = 1 as libc::c_int;
11360 } else if !((*server.cluster).importing_slots_from[slot as usize])
11361 .is_null()
11362 {
11363 importing_slot = 1 as libc::c_int;
11364 }
11365 } else if equalStringObjects(firstkey, thiskey) == 0 {
11366 if slot != thisslot {
11367 getKeysFreeResult(&mut result);
11368 if !error_code.is_null() {
11369 *error_code = 1 as libc::c_int;
11370 }
11371 return 0 as *mut clusterNode;
11372 } else {
11373 multiple_keys = 1 as libc::c_int;
11374 }
11375 }
11376 let mut flags: libc::c_int = (1 as libc::c_int) << 0 as libc::c_int
11377 | (1 as libc::c_int) << 2 as libc::c_int
11378 | (1 as libc::c_int) << 1 as libc::c_int
11379 | (1 as libc::c_int) << 4 as libc::c_int;
11380 if (migrating_slot != 0 || importing_slot != 0) && is_pubsubshard == 0 {
11381 if (lookupKeyReadWithFlags(
11382 &mut *(server.db).offset(0 as libc::c_int as isize),
11383 thiskey,
11384 flags,
11385 ))
11386 .is_null()
11387 {
11388 missing_keys += 1;
11389 } else {
11390 existing_keys += 1;
11391 }
11392 }
11393 j += 1;
11394 }
11395 getKeysFreeResult(&mut result);
11396 i += 1;
11397 }
11398 if n.is_null() {
11399 return myself;
11400 }
11401 let mut cmd_flags: uint64_t = getCommandFlags(c);
11402 if (*server.cluster).state != 0 as libc::c_int {
11403 if is_pubsubshard != 0 {
11404 if server.cluster_allow_pubsubshard_when_down == 0 {
11405 if !error_code.is_null() {
11406 *error_code = 5 as libc::c_int;
11407 }
11408 return 0 as *mut clusterNode;
11409 }
11410 } else if server.cluster_allow_reads_when_down == 0 {
11411 if !error_code.is_null() {
11412 *error_code = 5 as libc::c_int;
11413 }
11414 return 0 as *mut clusterNode;
11415 } else {
11416 if cmd_flags as libc::c_ulonglong
11417 & (1 as libc::c_ulonglong) << 0 as libc::c_int != 0
11418 {
11419 if !error_code.is_null() {
11420 *error_code = 7 as libc::c_int;
11421 }
11422 return 0 as *mut clusterNode;
11423 }
11424 }
11425 }
11426 if !hashslot.is_null() {
11427 *hashslot = slot;
11428 }
11429 if (migrating_slot != 0 || importing_slot != 0)
11430 && (*cmd).proc_0
11431 == Some(migrateCommand as unsafe extern "C" fn(*mut client) -> ())
11432 {
11433 return myself;
11434 }
11435 if migrating_slot != 0 && missing_keys != 0 {
11436 if existing_keys != 0 {
11437 if !error_code.is_null() {
11438 *error_code = 2 as libc::c_int;
11439 }
11440 return 0 as *mut clusterNode;
11441 } else {
11442 if !error_code.is_null() {
11443 *error_code = 3 as libc::c_int;
11444 }
11445 return (*server.cluster).migrating_slots_to[slot as usize];
11446 }
11447 }
11448 if importing_slot != 0
11449 && ((*c).flags & ((1 as libc::c_int) << 9 as libc::c_int) as libc::c_ulong != 0
11450 || cmd_flags as libc::c_ulonglong
11451 & (1 as libc::c_ulonglong) << 13 as libc::c_int != 0)
11452 {
11453 if multiple_keys != 0 && missing_keys != 0 {
11454 if !error_code.is_null() {
11455 *error_code = 2 as libc::c_int;
11456 }
11457 return 0 as *mut clusterNode;
11458 } else {
11459 return myself
11460 }
11461 }
11462 let mut is_write_command: libc::c_int = (cmd_flags as libc::c_ulonglong
11463 & (1 as libc::c_ulonglong) << 0 as libc::c_int != 0
11464 || (*(*c).cmd).proc_0
11465 == Some(execCommand as unsafe extern "C" fn(*mut client) -> ())
11466 && (*c).mstate.cmd_flags as libc::c_ulonglong
11467 & (1 as libc::c_ulonglong) << 0 as libc::c_int != 0) as libc::c_int;
11468 if ((*c).flags & ((1 as libc::c_int) << 17 as libc::c_int) as libc::c_ulong != 0
11469 || is_pubsubshard != 0) && is_write_command == 0
11470 && (*myself).flags & 2 as libc::c_int != 0 && (*myself).slaveof == n
11471 {
11472 return myself;
11473 }
11474 if n != myself && !error_code.is_null() {
11475 *error_code = 4 as libc::c_int;
11476 }
11477 return n;
11478}
11479#[no_mangle]
11480pub unsafe extern "C" fn clusterRedirectClient(
11481 mut c: *mut client,
11482 mut n: *mut clusterNode,
11483 mut hashslot: libc::c_int,
11484 mut error_code: libc::c_int,
11485) {
11486 if error_code == 1 as libc::c_int {
11487 addReplyError(
11488 c,
11489 b"-CROSSSLOT Keys in request don't hash to the same slot\0" as *const u8
11490 as *const libc::c_char,
11491 );
11492 } else if error_code == 2 as libc::c_int {
11493 addReplyError(
11494 c,
11495 b"-TRYAGAIN Multiple keys request during rehashing of slot\0" as *const u8
11496 as *const libc::c_char,
11497 );
11498 } else if error_code == 5 as libc::c_int {
11499 addReplyError(
11500 c,
11501 b"-CLUSTERDOWN The cluster is down\0" as *const u8 as *const libc::c_char,
11502 );
11503 } else if error_code == 7 as libc::c_int {
11504 addReplyError(
11505 c,
11506 b"-CLUSTERDOWN The cluster is down and only accepts read commands\0"
11507 as *const u8 as *const libc::c_char,
11508 );
11509 } else if error_code == 6 as libc::c_int {
11510 addReplyError(
11511 c,
11512 b"-CLUSTERDOWN Hash slot not served\0" as *const u8 as *const libc::c_char,
11513 );
11514 } else if error_code == 4 as libc::c_int || error_code == 3 as libc::c_int {
11515 let mut use_pport: libc::c_int = (server.tls_cluster != 0
11516 && !((*c).conn).is_null() && connGetType((*c).conn) != 2 as libc::c_int)
11517 as libc::c_int;
11518 let mut port: libc::c_int = if use_pport != 0 && (*n).pport != 0 {
11519 (*n).pport
11520 } else {
11521 (*n).port
11522 };
11523 addReplyErrorSds(
11524 c,
11525 sdscatprintf(
11526 sdsempty(),
11527 b"-%s %d %s:%d\0" as *const u8 as *const libc::c_char,
11528 if error_code == 3 as libc::c_int {
11529 b"ASK\0" as *const u8 as *const libc::c_char
11530 } else {
11531 b"MOVED\0" as *const u8 as *const libc::c_char
11532 },
11533 hashslot,
11534 getPreferredEndpoint(n),
11535 port,
11536 ),
11537 );
11538 } else {
11539 _serverPanic(
11540 b"cluster.c\0" as *const u8 as *const libc::c_char,
11541 6857 as libc::c_int,
11542 b"getNodeByQuery() unknown error.\0" as *const u8 as *const libc::c_char,
11543 );
11544 unreachable!();
11545 };
11546}
11547#[no_mangle]
11548pub unsafe extern "C" fn clusterRedirectBlockedClientIfNeeded(
11549 mut c: *mut client,
11550) -> libc::c_int {
11551 if (*c).flags & ((1 as libc::c_int) << 4 as libc::c_int) as libc::c_ulong != 0
11552 && ((*c).btype == 1 as libc::c_int || (*c).btype == 5 as libc::c_int
11553 || (*c).btype == 4 as libc::c_int || (*c).btype == 3 as libc::c_int)
11554 {
11555 let mut de: *mut dictEntry = 0 as *mut dictEntry;
11556 let mut di: *mut dictIterator = 0 as *mut dictIterator;
11557 if (*server.cluster).state == 1 as libc::c_int {
11558 clusterRedirectClient(
11559 c,
11560 0 as *mut clusterNode,
11561 0 as libc::c_int,
11562 5 as libc::c_int,
11563 );
11564 return 1 as libc::c_int;
11565 }
11566 if (*c).btype == 3 as libc::c_int && moduleClientIsBlockedOnKeys(c) == 0 {
11567 return 0 as libc::c_int;
11568 }
11569 di = dictGetIterator((*c).bpop.keys);
11570 de = dictNext(di);
11571 if !de.is_null() {
11572 let mut key: *mut robj = (*de).key as *mut robj;
11573 let mut slot: libc::c_int = keyHashSlot(
11574 (*key).ptr as *mut libc::c_char,
11575 sdslen((*key).ptr as sds) as libc::c_int,
11576 ) as libc::c_int;
11577 let mut node: *mut clusterNode = (*server.cluster).slots[slot as usize];
11578 if (*c).flags & ((1 as libc::c_int) << 17 as libc::c_int) as libc::c_ulong
11579 != 0
11580 && (*(*c).lastcmd).flags as libc::c_ulonglong
11581 & (1 as libc::c_ulonglong) << 0 as libc::c_int == 0
11582 && (*myself).flags & 2 as libc::c_int != 0 && (*myself).slaveof == node
11583 {
11584 node = myself;
11585 }
11586 if node != myself
11587 && ((*server.cluster).importing_slots_from[slot as usize]).is_null()
11588 {
11589 if node.is_null() {
11590 clusterRedirectClient(
11591 c,
11592 0 as *mut clusterNode,
11593 0 as libc::c_int,
11594 6 as libc::c_int,
11595 );
11596 } else {
11597 clusterRedirectClient(c, node, slot, 4 as libc::c_int);
11598 }
11599 dictReleaseIterator(di);
11600 return 1 as libc::c_int;
11601 }
11602 }
11603 dictReleaseIterator(di);
11604 }
11605 return 0 as libc::c_int;
11606}
11607#[no_mangle]
11608pub unsafe extern "C" fn slotToKeyAddEntry(
11609 mut entry: *mut dictEntry,
11610 mut db: *mut redisDb,
11611) {
11612 let mut key: sds = (*entry).key as sds;
11613 let mut hashslot: libc::c_uint = keyHashSlot(key, sdslen(key) as libc::c_int);
11614 let mut slot_to_keys: *mut slotToKeys = &mut *((*(*db).slots_to_keys).by_slot)
11615 .as_mut_ptr()
11616 .offset(hashslot as isize) as *mut slotToKeys;
11617 (*slot_to_keys).count = ((*slot_to_keys).count).wrapping_add(1);
11618 let mut first: *mut dictEntry = (*slot_to_keys).head;
11619 let ref mut fresh26 = (*(&mut (*entry).metadata as *mut [*mut libc::c_void; 0]
11620 as *mut clusterDictEntryMetadata))
11621 .next;
11622 *fresh26 = first;
11623 if !first.is_null() {
11624 if ((*(&mut (*first).metadata as *mut [*mut libc::c_void; 0]
11625 as *mut clusterDictEntryMetadata))
11626 .prev)
11627 .is_null()
11628 {} else {
11629 _serverAssert(
11630 b"dictEntryPrevInSlot(first) == NULL\0" as *const u8
11631 as *const libc::c_char,
11632 b"cluster.c\0" as *const u8 as *const libc::c_char,
11633 6949 as libc::c_int,
11634 );
11635 unreachable!();
11636 };
11637 let ref mut fresh27 = (*(&mut (*first).metadata as *mut [*mut libc::c_void; 0]
11638 as *mut clusterDictEntryMetadata))
11639 .prev;
11640 *fresh27 = entry;
11641 }
11642 if ((*(&mut (*entry).metadata as *mut [*mut libc::c_void; 0]
11643 as *mut clusterDictEntryMetadata))
11644 .prev)
11645 .is_null()
11646 {} else {
11647 _serverAssert(
11648 b"dictEntryPrevInSlot(entry) == NULL\0" as *const u8 as *const libc::c_char,
11649 b"cluster.c\0" as *const u8 as *const libc::c_char,
11650 6952 as libc::c_int,
11651 );
11652 unreachable!();
11653 };
11654 (*slot_to_keys).head = entry;
11655}
11656#[no_mangle]
11657pub unsafe extern "C" fn slotToKeyDelEntry(
11658 mut entry: *mut dictEntry,
11659 mut db: *mut redisDb,
11660) {
11661 let mut key: sds = (*entry).key as sds;
11662 let mut hashslot: libc::c_uint = keyHashSlot(key, sdslen(key) as libc::c_int);
11663 let mut slot_to_keys: *mut slotToKeys = &mut *((*(*db).slots_to_keys).by_slot)
11664 .as_mut_ptr()
11665 .offset(hashslot as isize) as *mut slotToKeys;
11666 (*slot_to_keys).count = ((*slot_to_keys).count).wrapping_sub(1);
11667 let mut next: *mut dictEntry = (*(&mut (*entry).metadata
11668 as *mut [*mut libc::c_void; 0] as *mut clusterDictEntryMetadata))
11669 .next;
11670 let mut prev: *mut dictEntry = (*(&mut (*entry).metadata
11671 as *mut [*mut libc::c_void; 0] as *mut clusterDictEntryMetadata))
11672 .prev;
11673 if !next.is_null() {
11674 let ref mut fresh28 = (*(&mut (*next).metadata as *mut [*mut libc::c_void; 0]
11675 as *mut clusterDictEntryMetadata))
11676 .prev;
11677 *fresh28 = prev;
11678 }
11679 if !prev.is_null() {
11680 let ref mut fresh29 = (*(&mut (*prev).metadata as *mut [*mut libc::c_void; 0]
11681 as *mut clusterDictEntryMetadata))
11682 .next;
11683 *fresh29 = next;
11684 } else {
11685 if (*slot_to_keys).head == entry {} else {
11686 _serverAssert(
11687 b"slot_to_keys->head == entry\0" as *const u8 as *const libc::c_char,
11688 b"cluster.c\0" as *const u8 as *const libc::c_char,
11689 6972 as libc::c_int,
11690 );
11691 unreachable!();
11692 };
11693 (*slot_to_keys).head = next;
11694 };
11695}
11696#[no_mangle]
11697pub unsafe extern "C" fn slotToKeyReplaceEntry(
11698 mut entry: *mut dictEntry,
11699 mut db: *mut redisDb,
11700) {
11701 let mut next: *mut dictEntry = (*(&mut (*entry).metadata
11702 as *mut [*mut libc::c_void; 0] as *mut clusterDictEntryMetadata))
11703 .next;
11704 let mut prev: *mut dictEntry = (*(&mut (*entry).metadata
11705 as *mut [*mut libc::c_void; 0] as *mut clusterDictEntryMetadata))
11706 .prev;
11707 if !next.is_null() {
11708 let ref mut fresh30 = (*(&mut (*next).metadata as *mut [*mut libc::c_void; 0]
11709 as *mut clusterDictEntryMetadata))
11710 .prev;
11711 *fresh30 = entry;
11712 }
11713 if !prev.is_null() {
11714 let ref mut fresh31 = (*(&mut (*prev).metadata as *mut [*mut libc::c_void; 0]
11715 as *mut clusterDictEntryMetadata))
11716 .next;
11717 *fresh31 = entry;
11718 } else {
11719 let mut key: sds = (*entry).key as sds;
11720 let mut hashslot: libc::c_uint = keyHashSlot(key, sdslen(key) as libc::c_int);
11721 let mut slot_to_keys: *mut slotToKeys = &mut *((*(*db).slots_to_keys).by_slot)
11722 .as_mut_ptr()
11723 .offset(hashslot as isize) as *mut slotToKeys;
11724 (*slot_to_keys).head = entry;
11725 };
11726}
11727#[no_mangle]
11728pub unsafe extern "C" fn slotToKeyInit(mut db: *mut redisDb) {
11729 (*db)
11730 .slots_to_keys = zcalloc(
11731 core::mem::size_of::<clusterSlotToKeyMapping>() as libc::c_ulong,
11732 ) as *mut clusterSlotToKeyMapping;
11733}
11734#[no_mangle]
11735pub unsafe extern "C" fn slotToKeyFlush(mut db: *mut redisDb) {
11736 memset(
11737 (*db).slots_to_keys as *mut libc::c_void,
11738 0 as libc::c_int,
11739 core::mem::size_of::<clusterSlotToKeyMapping>() as libc::c_ulong,
11740 );
11741}
11742#[no_mangle]
11743pub unsafe extern "C" fn slotToKeyDestroy(mut db: *mut redisDb) {
11744 zfree((*db).slots_to_keys as *mut libc::c_void);
11745 (*db).slots_to_keys = 0 as *mut clusterSlotToKeyMapping;
11746}
11747#[no_mangle]
11748pub unsafe extern "C" fn delKeysInSlot(mut hashslot: libc::c_uint) -> libc::c_uint {
11749 let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
11750 let mut de: *mut dictEntry = (*(*server.db).slots_to_keys)
11751 .by_slot[hashslot as usize]
11752 .head;
11753 while !de.is_null() {
11754 let mut sdskey: sds = (*de).key as sds;
11755 de = (*(&mut (*de).metadata as *mut [*mut libc::c_void; 0]
11756 as *mut clusterDictEntryMetadata))
11757 .next;
11758 let mut key: *mut robj = createStringObject(
11759 sdskey as *const libc::c_char,
11760 sdslen(sdskey),
11761 );
11762 dbDelete(&mut *(server.db).offset(0 as libc::c_int as isize), key);
11763 decrRefCount(key);
11764 j = j.wrapping_add(1);
11765 }
11766 return j;
11767}
11768#[no_mangle]
11769pub unsafe extern "C" fn countKeysInSlot(mut hashslot: libc::c_uint) -> libc::c_uint {
11770 return (*(*server.db).slots_to_keys).by_slot[hashslot as usize].count
11771 as libc::c_uint;
11772}
11773#[no_mangle]
11774pub unsafe extern "C" fn slotToChannelUpdate(mut channel: sds, mut add: libc::c_int) {
11775 let mut keylen: size_t = sdslen(channel);
11776 let mut hashslot: libc::c_uint = keyHashSlot(channel, keylen as libc::c_int);
11777 let mut buf: [libc::c_uchar; 64] = [0; 64];
11778 let mut indexed: *mut libc::c_uchar = buf.as_mut_ptr();
11779 if keylen.wrapping_add(2 as libc::c_int as libc::c_ulong)
11780 > 64 as libc::c_int as libc::c_ulong
11781 {
11782 indexed = zmalloc(keylen.wrapping_add(2 as libc::c_int as libc::c_ulong))
11783 as *mut libc::c_uchar;
11784 }
11785 *indexed
11786 .offset(
11787 0 as libc::c_int as isize,
11788 ) = (hashslot >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_uint)
11789 as libc::c_uchar;
11790 *indexed
11791 .offset(
11792 1 as libc::c_int as isize,
11793 ) = (hashslot & 0xff as libc::c_int as libc::c_uint) as libc::c_uchar;
11794 memcpy(
11795 indexed.offset(2 as libc::c_int as isize) as *mut libc::c_void,
11796 channel as *const libc::c_void,
11797 keylen,
11798 );
11799 if add != 0 {
11800 raxInsert(
11801 (*server.cluster).slots_to_channels,
11802 indexed,
11803 keylen.wrapping_add(2 as libc::c_int as libc::c_ulong),
11804 0 as *mut libc::c_void,
11805 0 as *mut *mut libc::c_void,
11806 );
11807 } else {
11808 raxRemove(
11809 (*server.cluster).slots_to_channels,
11810 indexed,
11811 keylen.wrapping_add(2 as libc::c_int as libc::c_ulong),
11812 0 as *mut *mut libc::c_void,
11813 );
11814 }
11815 if indexed != buf.as_mut_ptr() {
11816 zfree(indexed as *mut libc::c_void);
11817 }
11818}
11819#[no_mangle]
11820pub unsafe extern "C" fn slotToChannelAdd(mut channel: sds) {
11821 slotToChannelUpdate(channel, 1 as libc::c_int);
11822}
11823#[no_mangle]
11824pub unsafe extern "C" fn slotToChannelDel(mut channel: sds) {
11825 slotToChannelUpdate(channel, 0 as libc::c_int);
11826}
11827#[no_mangle]
11828pub unsafe extern "C" fn countChannelsInSlot(
11829 mut hashslot: libc::c_uint,
11830) -> libc::c_uint {
11831 let mut iter: raxIterator = raxIterator {
11832 flags: 0,
11833 rt: 0 as *mut rax,
11834 key: 0 as *mut libc::c_uchar,
11835 data: 0 as *mut libc::c_void,
11836 key_len: 0,
11837 key_max: 0,
11838 key_static_string: [0; 128],
11839 node: 0 as *mut raxNode,
11840 stack: raxStack {
11841 stack: 0 as *mut *mut libc::c_void,
11842 items: 0,
11843 maxitems: 0,
11844 static_items: [0 as *mut libc::c_void; 32],
11845 oom: 0,
11846 },
11847 node_cb: None,
11848 };
11849 let mut j: libc::c_int = 0 as libc::c_int;
11850 let mut indexed: [libc::c_uchar; 2] = [0; 2];
11851 indexed[0 as libc::c_int
11852 as usize] = (hashslot >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_uint)
11853 as libc::c_uchar;
11854 indexed[1 as libc::c_int
11855 as usize] = (hashslot & 0xff as libc::c_int as libc::c_uint) as libc::c_uchar;
11856 raxStart(&mut iter, (*server.cluster).slots_to_channels);
11857 raxSeek(
11858 &mut iter,
11859 b">=\0" as *const u8 as *const libc::c_char,
11860 indexed.as_mut_ptr(),
11861 2 as libc::c_int as size_t,
11862 );
11863 while raxNext(&mut iter) != 0 {
11864 if *(iter.key).offset(0 as libc::c_int as isize) as libc::c_int
11865 != indexed[0 as libc::c_int as usize] as libc::c_int
11866 || *(iter.key).offset(1 as libc::c_int as isize) as libc::c_int
11867 != indexed[1 as libc::c_int as usize] as libc::c_int
11868 {
11869 break;
11870 }
11871 j += 1;
11872 }
11873 raxStop(&mut iter);
11874 return j as libc::c_uint;
11875}