removed formatting, syncing with antirez/redis
This commit is contained in:
@@ -98,13 +98,11 @@ void notifyKeyspaceEvent(int type, char *event, robj *key, int dbid) {
|
||||
int len = -1;
|
||||
char buf[24];
|
||||
|
||||
#ifndef _WIN32
|
||||
/* If any modules are interested in events, notify the module system now.
|
||||
* This bypasses the notifications configuration, but the module engine
|
||||
* will only call event subscribers if the event type matches the types
|
||||
* they are interested in. */
|
||||
moduleNotifyKeyspaceEvent(type, event, key, dbid);
|
||||
#endif
|
||||
|
||||
/* If notifications for this class of events are off, return ASAP. */
|
||||
if (!(server.notify_keyspace_events & type)) return;
|
||||
|
||||
+12
-14
@@ -36,7 +36,6 @@
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
#define strtold(a,b) ((PORT_LONGDOUBLE)strtod((a),(b)))
|
||||
#endif
|
||||
@@ -143,14 +142,14 @@ robj *createStringObjectFromLongLong(PORT_LONGLONG value) {
|
||||
return o;
|
||||
}
|
||||
|
||||
/* Create a string object from a PORT_LONGDOUBLE. If humanfriendly is non-zero
|
||||
/* Create a string object from a long double. If humanfriendly is non-zero
|
||||
* it does not use exponential format and trims trailing zeroes at the end,
|
||||
* however this results in loss of precision. Otherwise exp format is used
|
||||
* and the output of snprintf() is not modified.
|
||||
*
|
||||
* The 'humanfriendly' option is used for INCRBYFLOAT and HINCRBYFLOAT. */
|
||||
robj *createStringObjectFromLongDouble(PORT_LONGDOUBLE value, int humanfriendly) {
|
||||
char buf[256];
|
||||
char buf[MAX_LONG_DOUBLE_CHARS];
|
||||
int len = ld2string(buf,sizeof(buf),value,humanfriendly);
|
||||
return createStringObject(buf,len);
|
||||
}
|
||||
@@ -536,7 +535,7 @@ int equalStringObjects(robj *a, robj *b) {
|
||||
if (a->encoding == OBJ_ENCODING_INT &&
|
||||
b->encoding == OBJ_ENCODING_INT){
|
||||
/* If both strings are integer encoded just check if the stored
|
||||
* PORT_LONG is the same. */
|
||||
* long is the same. */
|
||||
return a->ptr == b->ptr;
|
||||
} else {
|
||||
return compareStringObjects(a,b) == 0;
|
||||
@@ -552,8 +551,8 @@ size_t stringObjectLen(robj *o) {
|
||||
}
|
||||
}
|
||||
|
||||
int getDoubleFromObject(const robj *o, PORT_LONGDOUBLE *target) {
|
||||
PORT_LONGDOUBLE value;
|
||||
int getDoubleFromObject(const robj *o, double *target) {
|
||||
double value;
|
||||
char *eptr;
|
||||
|
||||
if (o == NULL) {
|
||||
@@ -580,8 +579,8 @@ int getDoubleFromObject(const robj *o, PORT_LONGDOUBLE *target) {
|
||||
return C_OK;
|
||||
}
|
||||
|
||||
int getDoubleFromObjectOrReply(client *c, robj *o, PORT_LONGDOUBLE *target, const char *msg) {
|
||||
PORT_LONGDOUBLE value;
|
||||
int getDoubleFromObjectOrReply(client *c, robj *o, double *target, const char *msg) {
|
||||
double value;
|
||||
if (getDoubleFromObject(o, &value) != C_OK) {
|
||||
if (msg != NULL) {
|
||||
addReplyError(c,(char*)msg);
|
||||
@@ -604,7 +603,7 @@ int getLongDoubleFromObject(robj *o, PORT_LONGDOUBLE *target) {
|
||||
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
|
||||
if (sdsEncodedObject(o)) {
|
||||
errno = 0;
|
||||
value = IF_WIN32(wstrtod,strtold)(o->ptr,&eptr); // TODO: verify for 32-bit
|
||||
value = IF_WIN32(wstrtod,strtold)(o->ptr, &eptr); // TODO: verify for 32-bit
|
||||
if (sdslen(o->ptr) == 0 ||
|
||||
isspace(((const char*)o->ptr)[0]) ||
|
||||
(size_t)(eptr-(char*)o->ptr) != sdslen(o->ptr) ||
|
||||
@@ -638,7 +637,6 @@ int getLongDoubleFromObjectOrReply(client *c, robj *o, PORT_LONGDOUBLE *target,
|
||||
|
||||
int getLongLongFromObject(robj *o, PORT_LONGLONG *target) {
|
||||
PORT_LONGLONG value;
|
||||
char *eptr;
|
||||
|
||||
if (o == NULL) {
|
||||
value = 0;
|
||||
@@ -733,7 +731,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
|
||||
elesize += sizeof(quicklistNode)+ziplistBlobLen(node->zl);
|
||||
samples++;
|
||||
} while ((node = node->next) && samples < sample_size);
|
||||
asize += (PORT_LONGDOUBLE)elesize/samples*ql->len;
|
||||
asize += (double)elesize/samples*ql->len;
|
||||
} else if (o->encoding == OBJ_ENCODING_ZIPLIST) {
|
||||
asize = sizeof(*o)+ziplistBlobLen(o->ptr);
|
||||
} else {
|
||||
@@ -750,7 +748,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
|
||||
samples++;
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
if (samples) asize += (PORT_LONGDOUBLE)elesize/samples*dictSize(d);
|
||||
if (samples) asize += (double)elesize/samples*dictSize(d);
|
||||
} else if (o->encoding == OBJ_ENCODING_INTSET) {
|
||||
intset *is = o->ptr;
|
||||
asize = sizeof(*o)+sizeof(*is)+is->encoding*is->length;
|
||||
@@ -771,7 +769,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
|
||||
samples++;
|
||||
znode = znode->level[0].forward;
|
||||
}
|
||||
if (samples) asize += (PORT_LONGDOUBLE)elesize/samples*dictSize(d);
|
||||
if (samples) asize += (double)elesize/samples*dictSize(d);
|
||||
} else {
|
||||
serverPanic("Unknown sorted set encoding");
|
||||
}
|
||||
@@ -790,7 +788,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
|
||||
samples++;
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
if (samples) asize += (PORT_LONGDOUBLE)elesize/samples*dictSize(d);
|
||||
if (samples) asize += (double)elesize/samples*dictSize(d);
|
||||
} else {
|
||||
serverPanic("Unknown hash encoding");
|
||||
}
|
||||
|
||||
+1
-1
@@ -1315,7 +1315,7 @@ void quicklistRotate(quicklist *quicklist) {
|
||||
/* pop from quicklist and return result in 'data' ptr. Value of 'data'
|
||||
* is the return value of 'saver' function pointer if the data is NOT a number.
|
||||
*
|
||||
* If the quicklist element is a PORT_LONGLONG, then the return value is returned in
|
||||
* If the quicklist element is a long long, then the return value is returned in
|
||||
* 'sval'.
|
||||
*
|
||||
* Return value of 0 means no elements available.
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ typedef struct quicklistLZF {
|
||||
char compressed[];
|
||||
} quicklistLZF;
|
||||
|
||||
/* quicklist is a 32 byte struct (on 64-bit systems) describing a quicklist.
|
||||
/* quicklist is a 40 byte struct (on 64-bit systems) describing a quicklist.
|
||||
* 'count' is the number of total entries.
|
||||
* 'len' is the number of quicklist nodes.
|
||||
* 'compress' is: -1 if compression disabled, otherwise it's the number
|
||||
@@ -78,7 +78,7 @@ typedef struct quicklist {
|
||||
quicklistNode *head;
|
||||
quicklistNode *tail;
|
||||
PORT_ULONG count; /* total count of all entries in all ziplists */
|
||||
unsigned int len; /* number of quicklistNodes */
|
||||
PORT_ULONG len; /* number of quicklistNodes */
|
||||
int fill : 16; /* fill factor for individual nodes */
|
||||
unsigned int compress : 16; /* depth of end nodes not to compress;0=off */
|
||||
} quicklist;
|
||||
|
||||
@@ -409,7 +409,7 @@ ssize_t rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
|
||||
}
|
||||
|
||||
/* Store verbatim */
|
||||
if ((n = rdbSaveLen(rdb,(uint32_t)len)) == -1) return -1; WIN_PORT_FIX /* cast (uint32_t) */
|
||||
if ((n = rdbSaveLen(rdb,len)) == -1) return -1;
|
||||
nwritten += n;
|
||||
if (len > 0) {
|
||||
if (rdbWriteRaw(rdb,s,len) == -1) return -1;
|
||||
@@ -418,7 +418,7 @@ ssize_t rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
/* Save a PORT_LONGLONG value as either an encoded string or a string. */
|
||||
/* Save a long long value as either an encoded string or a string. */
|
||||
ssize_t rdbSaveLongLongAsStringObject(rio *rdb, PORT_LONGLONG value) {
|
||||
unsigned char buf[32];
|
||||
ssize_t n, nwritten = 0;
|
||||
@@ -438,7 +438,7 @@ ssize_t rdbSaveLongLongAsStringObject(rio *rdb, PORT_LONGLONG value) {
|
||||
}
|
||||
|
||||
/* Like rdbSaveRawString() gets a Redis object instead. */
|
||||
int rdbSaveStringObject(rio *rdb, robj *obj) {
|
||||
ssize_t rdbSaveStringObject(rio *rdb, robj *obj) {
|
||||
/* Avoid to decode the object, then encode it again, if the
|
||||
* object is already integer encoded. */
|
||||
if (obj->encoding == OBJ_ENCODING_INT) {
|
||||
@@ -535,12 +535,12 @@ int rdbSaveDoubleValue(rio *rdb, double val) {
|
||||
} else {
|
||||
#if (DBL_MANT_DIG >= 52) && (LLONG_MAX == 0x7fffffffffffffffLL)
|
||||
/* Check if the float is in a safe range to be casted into a
|
||||
* PORT_LONGLONG. We are assuming that PORT_LONGLONG is 64 bit here.
|
||||
* long long. We are assuming that long long is 64 bit here.
|
||||
* Also we are assuming that there are no implementations around where
|
||||
* double has precision < 52 bit.
|
||||
*
|
||||
* Under this assumptions we test if a double is inside an interval
|
||||
* where casting to PORT_LONGLONG is safe. Then using two castings we
|
||||
* where casting to long long is safe. Then using two castings we
|
||||
* make sure the decimal part is zero. If all this is true we use
|
||||
* integer printing function that is much faster. */
|
||||
double min = -4503599627370495; /* (2^52)-1 */
|
||||
@@ -707,7 +707,7 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
|
||||
dictIterator *di = dictGetIterator(set);
|
||||
dictEntry *de;
|
||||
|
||||
if ((n = rdbSaveLen(rdb,(uint32_t)dictSize(set))) == -1) return -1; WIN_PORT_FIX /* cast (uint32_t) */
|
||||
if ((n = rdbSaveLen(rdb,dictSize(set))) == -1) return -1;
|
||||
nwritten += n;
|
||||
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
@@ -773,7 +773,7 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
|
||||
dictIterator *di = dictGetIterator(o->ptr);
|
||||
dictEntry *de;
|
||||
|
||||
if ((n = rdbSaveLen(rdb,(uint32_t)dictSize((dict*)o->ptr))) == -1) return -1; WIN_PORT_FIX /* cast (uint32_t) */
|
||||
if ((n = rdbSaveLen(rdb,dictSize((dict*)o->ptr))) == -1) return -1;
|
||||
nwritten += n;
|
||||
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
@@ -865,12 +865,12 @@ ssize_t rdbSaveAuxField(rio *rdb, void *key, size_t keylen, void *val, size_t va
|
||||
|
||||
/* Wrapper for rdbSaveAuxField() used when key/val length can be obtained
|
||||
* with strlen(). */
|
||||
int rdbSaveAuxFieldStrStr(rio *rdb, char *key, char *val) {
|
||||
ssize_t rdbSaveAuxFieldStrStr(rio *rdb, char *key, char *val) {
|
||||
return rdbSaveAuxField(rdb,key,strlen(key),val,strlen(val));
|
||||
}
|
||||
|
||||
/* Wrapper for strlen(key) + integer type (up to PORT_LONGLONG range). */
|
||||
int rdbSaveAuxFieldStrInt(rio *rdb, char *key, PORT_LONGLONG val) {
|
||||
/* Wrapper for strlen(key) + integer type (up to long long range). */
|
||||
ssize_t rdbSaveAuxFieldStrInt(rio *rdb, char *key, PORT_LONGLONG val) {
|
||||
char buf[LONG_STR_SIZE];
|
||||
int vlen = ll2string(buf,sizeof(buf),val);
|
||||
return rdbSaveAuxField(rdb,key,strlen(key),buf,vlen);
|
||||
@@ -1126,7 +1126,7 @@ int rdbSaveBackground(char *filename, rdbSaveInfo *rsi) {
|
||||
#endif
|
||||
/* Parent */
|
||||
server.stat_fork_time = ustime()-start;
|
||||
server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
|
||||
server.stat_fork_rate = (double) (zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024)); /* GB per second. */
|
||||
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
|
||||
if (childpid == -1) {
|
||||
closeChildInfoPipe();
|
||||
@@ -1685,15 +1685,15 @@ int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi, int loading_aof) {
|
||||
|
||||
if (rioRead(rdb,&cksum,8) == 0) goto eoferr;
|
||||
if (server.rdb_checksum) {
|
||||
memrev64ifbe(&cksum);
|
||||
if (cksum == 0) {
|
||||
serverLog(LL_WARNING,"RDB file was saved with checksum disabled: no check performed.");
|
||||
} else if (cksum != expected) {
|
||||
serverLog(LL_WARNING,"Wrong RDB checksum. Aborting now.");
|
||||
rdbExitReportCorruptRDB("RDB CRC error");
|
||||
memrev64ifbe(&cksum);
|
||||
if (cksum == 0) {
|
||||
serverLog(LL_WARNING,"RDB file was saved with checksum disabled: no check performed.");
|
||||
} else if (cksum != expected) {
|
||||
serverLog(LL_WARNING,"Wrong RDB checksum. Aborting now.");
|
||||
rdbExitReportCorruptRDB("RDB CRC error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return C_OK;
|
||||
|
||||
eoferr: /* unexpected end of file is handled here with a fatal exit */
|
||||
@@ -2017,7 +2017,7 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
|
||||
closeChildInfoPipe();
|
||||
} else {
|
||||
server.stat_fork_time = ustime()-start;
|
||||
server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
|
||||
server.stat_fork_rate = (double) (zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024)); /* GB per second. */
|
||||
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
|
||||
|
||||
serverLog(LL_NOTICE,"Background RDB transfer started by pid %d",
|
||||
|
||||
@@ -137,9 +137,9 @@ ssize_t rdbSaveObject(rio *rdb, robj *o);
|
||||
size_t rdbSavedObjectLen(robj *o);
|
||||
robj *rdbLoadObject(int type, rio *rdb);
|
||||
void backgroundSaveDoneHandler(int exitcode, int bysignal);
|
||||
int rdbSaveKeyValuePair(rio *rdb, robj *key, robj *val, PORT_LONGLONG expiretime, PORT_LONGLONG now);
|
||||
int rdbSaveKeyValuePair(rio *rdb, robj *key, robj *val, PORT_LONGLONG expiretime);
|
||||
robj *rdbLoadStringObject(rio *rdb);
|
||||
int rdbSaveStringObject(rio *rdb, robj *obj);
|
||||
ssize_t rdbSaveStringObject(rio *rdb, robj *obj);
|
||||
ssize_t rdbSaveRawString(rio *rdb, unsigned char *s, size_t len);
|
||||
void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr);
|
||||
int rdbSaveBinaryDoubleValue(rio *rdb, double val);
|
||||
|
||||
@@ -349,6 +349,7 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
ssize_t nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
|
||||
if (nwritten == -1) {
|
||||
if (errno != EPIPE)
|
||||
fprintf(stderr, "Writing to socket: %s\n", strerror(errno));
|
||||
@@ -695,7 +696,7 @@ int showThroughput(struct aeEventLoop *eventLoop, PORT_LONGLONG id, void *client
|
||||
UNUSED(id);
|
||||
UNUSED(clientData);
|
||||
|
||||
if (config.liveclients == 0) {
|
||||
if (config.liveclients == 0 && config.requests_finished != config.requests) {
|
||||
fprintf(stderr,"All clients disconnected... aborting.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
+40
-55
@@ -33,17 +33,10 @@
|
||||
#include "Win32_Interop/win32_types.h"
|
||||
#include "Win32_Interop/Win32_Error.h"
|
||||
#include "Win32_Interop/win32fixes.h"
|
||||
#include "zmalloc.h"
|
||||
#endif
|
||||
|
||||
#include "server.h"
|
||||
#include "fmacros.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
POSIX_ONLY(#include <unistd.h>)
|
||||
#include <sys/stat.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define strcasecmp _stricmp
|
||||
@@ -60,8 +53,8 @@ static char error[1024];
|
||||
static off_t epos;
|
||||
|
||||
int consumeNewline(char *buf) {
|
||||
if (strncmp(buf, "\r\n", 2) != 0) {
|
||||
ERROR("Expected \\r\\n, got: %02x%02x", buf[0], buf[1]);
|
||||
if (strncmp(buf,"\r\n",2) != 0) {
|
||||
ERROR("Expected \\r\\n, got: %02x%02x",buf[0],buf[1]);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -70,24 +63,24 @@ int consumeNewline(char *buf) {
|
||||
int readLong(FILE *fp, char prefix, PORT_LONG *target) {
|
||||
char buf[128], *eptr;
|
||||
epos = ftello(fp);
|
||||
if (fgets(buf, sizeof(buf), fp) == NULL) {
|
||||
if (fgets(buf,sizeof(buf),fp) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (buf[0] != prefix) {
|
||||
ERROR("Expected prefix '%c', got: '%c'", prefix, buf[0]);
|
||||
ERROR("Expected prefix '%c', got: '%c'",prefix,buf[0]);
|
||||
return 0;
|
||||
}
|
||||
*target = strtol(buf + 1, &eptr, 10);
|
||||
*target = strtol(buf+1,&eptr,10);
|
||||
return consumeNewline(eptr);
|
||||
}
|
||||
|
||||
int readBytes(FILE *fp, char *target, PORT_LONG length) {
|
||||
PORT_LONG real;
|
||||
epos = ftello(fp);
|
||||
real = (PORT_LONG) fread(target, 1, length, fp);
|
||||
real = (PORT_LONG)fread(target,1,length,fp);
|
||||
if (real != length) {
|
||||
ERROR("Expected to read %Id bytes, got %Id bytes", length, real); WIN_PORT_FIX /* %ld -> %Id */
|
||||
return 0;
|
||||
ERROR("Expected to read %Id bytes, got %Id bytes",length,real); WIN_PORT_FIX /* %ld -> %Id */
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -95,25 +88,25 @@ int readBytes(FILE *fp, char *target, PORT_LONG length) {
|
||||
int readString(FILE *fp, char** target) {
|
||||
PORT_LONG len;
|
||||
*target = NULL;
|
||||
if (!readLong(fp, '$', &len)) {
|
||||
if (!readLong(fp,'$',&len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Increase length to also consume \r\n */
|
||||
len += 2;
|
||||
*target = (char*) zmalloc(len);
|
||||
if (!readBytes(fp, *target, len)) {
|
||||
*target = (char*)zmalloc(len);
|
||||
if (!readBytes(fp,*target,len)) {
|
||||
return 0;
|
||||
}
|
||||
if (!consumeNewline(*target + len - 2)) {
|
||||
if (!consumeNewline(*target+len-2)) {
|
||||
return 0;
|
||||
}
|
||||
(*target)[len - 2] = '\0';
|
||||
(*target)[len-2] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
int readArgc(FILE *fp, PORT_LONG *target) {
|
||||
return readLong(fp, '*', target);
|
||||
return readLong(fp,'*',target);
|
||||
}
|
||||
|
||||
off_t process(FILE *fp) {
|
||||
@@ -122,20 +115,19 @@ off_t process(FILE *fp) {
|
||||
int i, multi = 0;
|
||||
char *str;
|
||||
|
||||
while (1) {
|
||||
if (!multi) pos = (off_t) ftello(fp);
|
||||
while(1) {
|
||||
if (!multi) pos = ftello(fp);
|
||||
if (!readArgc(fp, &argc)) break;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (!readString(fp, &str)) break;
|
||||
if (!readString(fp,&str)) break;
|
||||
if (i == 0) {
|
||||
if (strcasecmp(str, "multi") == 0) {
|
||||
if (multi++) {
|
||||
ERROR("Unexpected MULTI");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(str, "exec") == 0) {
|
||||
} else if (strcasecmp(str, "exec") == 0) {
|
||||
if (--multi) {
|
||||
ERROR("Unexpected EXEC");
|
||||
break;
|
||||
@@ -174,19 +166,16 @@ int redis_check_aof_main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s [--fix] <file.aof>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
else if (argc == 2) {
|
||||
} else if (argc == 2) {
|
||||
filename = argv[1];
|
||||
}
|
||||
else if (argc == 3) {
|
||||
if (strcmp(argv[1], "--fix") != 0) {
|
||||
} else if (argc == 3) {
|
||||
if (strcmp(argv[1],"--fix") != 0) {
|
||||
printf("Invalid argument: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
filename = argv[2];
|
||||
fix = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("Invalid arguments\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -198,7 +187,7 @@ int redis_check_aof_main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
struct redis_stat sb;
|
||||
if (redis_fstat(fileno(fp), &sb) == -1) {
|
||||
if (redis_fstat(fileno(fp),&sb) == -1) {
|
||||
printf("Cannot stat file: %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
@@ -213,54 +202,50 @@ int redis_check_aof_main(int argc, char **argv) {
|
||||
* is the case, start processing the RDB part. */
|
||||
if (size >= 8) { /* There must be at least room for the RDB header. */
|
||||
char sig[5];
|
||||
int has_preamble = fread(sig, sizeof(sig), 1, fp) == 1 &&
|
||||
memcmp(sig, "REDIS", sizeof(sig)) == 0;
|
||||
int has_preamble = fread(sig,sizeof(sig),1,fp) == 1 &&
|
||||
memcmp(sig,"REDIS",sizeof(sig)) == 0;
|
||||
rewind(fp);
|
||||
if (has_preamble) {
|
||||
printf("The AOF appears to start with an RDB preamble.\n"
|
||||
"Checking the RDB preamble to start:\n");
|
||||
if (redis_check_rdb_main(argc, argv, fp) == C_ERR) {
|
||||
"Checking the RDB preamble to start:\n");
|
||||
if (redis_check_rdb_main(argc,argv,fp) == C_ERR) {
|
||||
printf("RDB preamble of AOF file is not sane, aborting.\n");
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("RDB preamble is OK, proceeding with AOF tail...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
off_t pos = process(fp);
|
||||
off_t diff = size - pos;
|
||||
off_t diff = size-pos;
|
||||
printf("AOF analyzed: size=%lld, ok_up_to=%lld, diff=%lld\n",
|
||||
(PORT_LONGLONG) size, (PORT_LONGLONG) pos, (PORT_LONGLONG) diff);
|
||||
if (diff > 0) {
|
||||
if (fix) {
|
||||
char buf[2];
|
||||
printf("This will shrink the AOF from %lld bytes, with %lld bytes, to %lld bytes\n", (PORT_LONGLONG) size, (PORT_LONGLONG) diff, (PORT_LONGLONG) pos);
|
||||
printf("This will shrink the AOF from %lld bytes, with %lld bytes, to %lld bytes\n", (PORT_LONGLONG)size, (PORT_LONGLONG)diff, (PORT_LONGLONG)pos);
|
||||
printf("Continue? [y/N]: ");
|
||||
if (fgets(buf, sizeof(buf), stdin) == NULL ||
|
||||
strncasecmp(buf, "y", 1) != 0) {
|
||||
printf("Aborting...\n");
|
||||
exit(1);
|
||||
if (fgets(buf,sizeof(buf),stdin) == NULL ||
|
||||
strncasecmp(buf,"y",1) != 0) {
|
||||
printf("Aborting...\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ftruncate(fileno(fp), pos) == -1) {
|
||||
printf("Failed to truncate AOF\n");
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("Successfully truncated AOF\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("AOF is not valid. "
|
||||
"Use the --fix option to try fixing it.\n");
|
||||
"Use the --fix option to try fixing it.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("AOF is valid\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
+39
-45
@@ -53,10 +53,10 @@ struct {
|
||||
rio *rio;
|
||||
robj *key; /* Current key we are reading. */
|
||||
int key_type; /* Current key type if != -1. */
|
||||
PORT_ULONG keys; /* Number of keys processed. */ WIN_PORT_FIX
|
||||
PORT_ULONG expires; /* Number of keys with an expire. */ WIN_PORT_FIX
|
||||
PORT_ULONG already_expired; /* Number of keys already expired. */ WIN_PORT_FIX
|
||||
int doing; /* The state while reading the RDB. */
|
||||
PORT_ULONG keys; /* Number of keys processed. */ WIN_PORT_FIX
|
||||
PORT_ULONG expires; /* Number of keys with an expire. */ WIN_PORT_FIX
|
||||
PORT_ULONG already_expired; /* Number of keys already expired. */ WIN_PORT_FIX
|
||||
int doing; /* The state while reading the RDB. */
|
||||
int error_set; /* True if error is populated. */
|
||||
char error[1024];
|
||||
} rdbstate;
|
||||
@@ -103,8 +103,8 @@ char *rdb_type_string[] = {
|
||||
/* Show a few stats collected into 'rdbstate' */
|
||||
void rdbShowGenericInfo(void) {
|
||||
printf("[info] %Iu keys read\n", rdbstate.keys); WIN_PORT_FIX /* %lu -> %Iu */
|
||||
printf("[info] %Iu expires\n", rdbstate.expires); WIN_PORT_FIX /* %lu -> %Iu */
|
||||
printf("[info] %Iu already expired\n", rdbstate.already_expired); WIN_PORT_FIX /* %lu -> %Iu */
|
||||
printf("[info] %Iu expires\n", rdbstate.expires); WIN_PORT_FIX /* %lu -> %Iu */
|
||||
printf("[info] %Iu already expired\n", rdbstate.already_expired); WIN_PORT_FIX /* %lu -> %Iu */
|
||||
}
|
||||
|
||||
/* Called on RDB errors. Provides details about the RDB and the offset
|
||||
@@ -125,13 +125,13 @@ void rdbCheckError(const char *fmt, ...) {
|
||||
rdb_check_doing_string[rdbstate.doing]);
|
||||
if (rdbstate.key)
|
||||
printf("[additional info] Reading key '%s'\n",
|
||||
(char*) rdbstate.key->ptr);
|
||||
(char*)rdbstate.key->ptr);
|
||||
if (rdbstate.key_type != -1)
|
||||
printf("[additional info] Reading type %d (%s)\n",
|
||||
rdbstate.key_type,
|
||||
((unsigned) rdbstate.key_type <
|
||||
sizeof(rdb_type_string) / sizeof(char*)) ?
|
||||
rdb_type_string[rdbstate.key_type] : "unknown");
|
||||
((unsigned)rdbstate.key_type <
|
||||
sizeof(rdb_type_string)/sizeof(char*)) ?
|
||||
rdb_type_string[rdbstate.key_type] : "unknown");
|
||||
rdbShowGenericInfo();
|
||||
}
|
||||
|
||||
@@ -200,23 +200,23 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
int closefile = (fp == NULL);
|
||||
if (fp == NULL && (fp = fopen(rdbfilename, IF_WIN32("rb", "r"))) == NULL) return 1;
|
||||
|
||||
rioInitWithFile(&rdb, fp);
|
||||
rioInitWithFile(&rdb,fp);
|
||||
rdbstate.rio = &rdb;
|
||||
rdb.update_cksum = rdbLoadProgressCallback;
|
||||
if (rioRead(&rdb, buf, 9) == 0) goto eoferr;
|
||||
if (rioRead(&rdb,buf,9) == 0) goto eoferr;
|
||||
buf[9] = '\0';
|
||||
if (memcmp(buf, "REDIS", 5) != 0) {
|
||||
if (memcmp(buf,"REDIS",5) != 0) {
|
||||
rdbCheckError("Wrong signature trying to load DB from file");
|
||||
return 1;
|
||||
goto err;
|
||||
}
|
||||
rdbver = atoi(buf + 5);
|
||||
rdbver = atoi(buf+5);
|
||||
if (rdbver < 1 || rdbver > RDB_VERSION) {
|
||||
rdbCheckError("Can't handle RDB format version %d", rdbver);
|
||||
return 1;
|
||||
rdbCheckError("Can't handle RDB format version %d",rdbver);
|
||||
goto err;
|
||||
}
|
||||
|
||||
startLoading(fp);
|
||||
while (1) {
|
||||
while(1) {
|
||||
robj *key, *val;
|
||||
expiretime = -1;
|
||||
|
||||
@@ -237,8 +237,7 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
/* the EXPIRETIME opcode specifies time in seconds, so convert
|
||||
* into milliseconds. */
|
||||
expiretime *= 1000;
|
||||
}
|
||||
else if (type == RDB_OPCODE_EXPIRETIME_MS) {
|
||||
} else if (type == RDB_OPCODE_EXPIRETIME_MS) {
|
||||
/* EXPIRETIME_MS: milliseconds precision expire times introduced
|
||||
* with RDB v3. Like EXPIRETIME but no with more precision. */
|
||||
rdbstate.doing = RDB_CHECK_DOING_READ_EXPIRE;
|
||||
@@ -246,31 +245,27 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
/* We read the time so we need to read the object type again. */
|
||||
rdbstate.doing = RDB_CHECK_DOING_READ_TYPE;
|
||||
if ((type = rdbLoadType(&rdb)) == -1) goto eoferr;
|
||||
}
|
||||
else if (type == RDB_OPCODE_EOF) {
|
||||
} else if (type == RDB_OPCODE_EOF) {
|
||||
/* EOF: End of file, exit the main loop. */
|
||||
break;
|
||||
}
|
||||
else if (type == RDB_OPCODE_SELECTDB) {
|
||||
} else if (type == RDB_OPCODE_SELECTDB) {
|
||||
/* SELECTDB: Select the specified database. */
|
||||
rdbstate.doing = RDB_CHECK_DOING_READ_LEN;
|
||||
if ((dbid = rdbLoadLen(&rdb, NULL)) == RDB_LENERR)
|
||||
if ((dbid = rdbLoadLen(&rdb,NULL)) == RDB_LENERR)
|
||||
goto eoferr;
|
||||
rdbCheckInfo("Selecting DB ID %d", dbid);
|
||||
continue; /* Read type again. */
|
||||
}
|
||||
else if (type == RDB_OPCODE_RESIZEDB) {
|
||||
} else if (type == RDB_OPCODE_RESIZEDB) {
|
||||
/* RESIZEDB: Hint about the size of the keys in the currently
|
||||
* selected data base, in order to avoid useless rehashing. */
|
||||
uint64_t db_size, expires_size;
|
||||
rdbstate.doing = RDB_CHECK_DOING_READ_LEN;
|
||||
if ((db_size = rdbLoadLen(&rdb, NULL)) == RDB_LENERR)
|
||||
if ((db_size = rdbLoadLen(&rdb,NULL)) == RDB_LENERR)
|
||||
goto eoferr;
|
||||
if ((expires_size = rdbLoadLen(&rdb, NULL)) == RDB_LENERR)
|
||||
if ((expires_size = rdbLoadLen(&rdb,NULL)) == RDB_LENERR)
|
||||
goto eoferr;
|
||||
continue; /* Read type again. */
|
||||
}
|
||||
else if (type == RDB_OPCODE_AUX) {
|
||||
} else if (type == RDB_OPCODE_AUX) {
|
||||
/* AUX: generic string-string fields. Use to add state to RDB
|
||||
* which is backward compatible. Implementations of RDB loading
|
||||
* are requierd to skip AUX fields they don't understand.
|
||||
@@ -282,15 +277,14 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
if ((auxval = rdbLoadStringObject(&rdb)) == NULL) goto eoferr;
|
||||
|
||||
rdbCheckInfo("AUX FIELD %s = '%s'",
|
||||
(char*) auxkey->ptr, (char*) auxval->ptr);
|
||||
(char*)auxkey->ptr, (char*)auxval->ptr);
|
||||
decrRefCount(auxkey);
|
||||
decrRefCount(auxval);
|
||||
continue; /* Read type again. */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!rdbIsObjectType(type)) {
|
||||
rdbCheckError("Invalid object type: %d", type);
|
||||
return 1;
|
||||
goto err;
|
||||
}
|
||||
rdbstate.key_type = type;
|
||||
}
|
||||
@@ -302,7 +296,7 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
rdbstate.keys++;
|
||||
/* Read value */
|
||||
rdbstate.doing = RDB_CHECK_DOING_READ_OBJECT_VALUE;
|
||||
if ((val = rdbLoadObject(type, &rdb)) == NULL) goto eoferr;
|
||||
if ((val = rdbLoadObject(type,&rdb)) == NULL) goto eoferr;
|
||||
/* Check if the key already expired. This function is used when loading
|
||||
* an RDB file from disk, either at startup, or when an RDB was
|
||||
* received from the master. In the latter case, the master is
|
||||
@@ -321,15 +315,14 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
uint64_t cksum, expected = rdb.cksum;
|
||||
|
||||
rdbstate.doing = RDB_CHECK_DOING_CHECK_SUM;
|
||||
if (rioRead(&rdb, &cksum, 8) == 0) goto eoferr;
|
||||
if (rioRead(&rdb,&cksum,8) == 0) goto eoferr;
|
||||
memrev64ifbe(&cksum);
|
||||
if (cksum == 0) {
|
||||
rdbCheckInfo("RDB file was saved with checksum disabled: no check performed.");
|
||||
}
|
||||
else if (cksum != expected) {
|
||||
} else if (cksum != expected) {
|
||||
rdbCheckError("RDB CRC error");
|
||||
}
|
||||
else {
|
||||
goto err;
|
||||
} else {
|
||||
rdbCheckInfo("Checksum OK");
|
||||
}
|
||||
}
|
||||
@@ -340,10 +333,11 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
eoferr: /* unexpected end of file is handled here with a fatal exit */
|
||||
if (rdbstate.error_set) {
|
||||
rdbCheckError(rdbstate.error);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
rdbCheckError("Unexpected EOF reading RDB file");
|
||||
}
|
||||
err:
|
||||
if (closefile) fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -373,11 +367,11 @@ int redis_check_rdb_main(int argc, char **argv, FILE *fp) {
|
||||
rdbCheckMode = 1;
|
||||
rdbCheckInfo("Checking RDB file %s", argv[1]);
|
||||
POSIX_ONLY(rdbCheckSetupSignals();)
|
||||
int retval = redis_check_rdb(argv[1], fp);
|
||||
int retval = redis_check_rdb(argv[1],fp);
|
||||
if (retval == 0) {
|
||||
rdbCheckInfo("\\o/ RDB looks OK! \\o/");
|
||||
rdbShowGenericInfo();
|
||||
}
|
||||
if (fp) return (retval == 0) ? C_OK : C_ERR;
|
||||
exit(retval);
|
||||
}
|
||||
}
|
||||
|
||||
+647
-724
File diff suppressed because it is too large
Load Diff
+6
-5
@@ -27,11 +27,12 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Every time the Redis Git SHA1 or Dirty status changes only this small
|
||||
* file is recompiled, as we access this information in all the other
|
||||
* files using this functions. */
|
||||
/* Every time the Redis Git SHA1 or Dirty status changes only this small
|
||||
* file is recompiled, as we access this information in all the other
|
||||
* files using this functions. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "release.h"
|
||||
#include "version.h"
|
||||
#include "crc64.h"
|
||||
@@ -47,5 +48,5 @@ char *redisGitDirty(void) {
|
||||
uint64_t redisBuildId(void) {
|
||||
char *buildid = REDIS_VERSION REDIS_BUILD_ID REDIS_GIT_DIRTY REDIS_GIT_SHA1;
|
||||
|
||||
return crc64(0, (unsigned char*) buildid, strlen(buildid));
|
||||
}
|
||||
return crc64(0,(unsigned char*)buildid,strlen(buildid));
|
||||
}
|
||||
|
||||
+14
-14
@@ -39,6 +39,7 @@
|
||||
#endif
|
||||
|
||||
#include "server.h"
|
||||
|
||||
POSIX_ONLY(#include <sys/time.h>)
|
||||
POSIX_ONLY(#include <unistd.h>)
|
||||
#include <fcntl.h>
|
||||
@@ -1289,7 +1290,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
(nread == -1) ? wsa_strerror(errno) : "connection lost");
|
||||
}
|
||||
#else
|
||||
serverLog(LL_WARNING, "I/O error trying to sync with MASTER: %s",
|
||||
serverLog(LL_WARNING,"I/O error trying to sync with MASTER: %s",
|
||||
(nread == -1) ? strerror(errno) : "connection lost");
|
||||
#endif
|
||||
cancelReplicationHandshake();
|
||||
@@ -1368,7 +1369,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
"any race",
|
||||
(PORT_LONG) server.rdb_child_pid);
|
||||
|
||||
IF_WIN32(AbortForkOperation(), kill(server.rdb_child_pid, SIGUSR1));
|
||||
IF_WIN32(AbortForkOperation(), kill(server.rdb_child_pid,SIGUSR1));
|
||||
rdbRemoveTempFile(server.rdb_child_pid);
|
||||
}
|
||||
if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) {
|
||||
@@ -1464,7 +1465,7 @@ char *sendSynchronousCommand(int flags, int fd, ...) {
|
||||
}
|
||||
cmd = sdscatlen(cmd,"\r\n",2);
|
||||
va_end(ap);
|
||||
|
||||
|
||||
/* Transfer command to the server. */
|
||||
if (syncWrite(fd,cmd,(ssize_t)sdslen(cmd),server.repl_syncio_timeout*1000) WIN_PORT_FIX /* cast (ssize_t) */
|
||||
== -1)
|
||||
@@ -1951,7 +1952,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
dfd = open(tmpfile,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,_S_IREAD|_S_IWRITE);
|
||||
#else
|
||||
snprintf(tmpfile,256,
|
||||
"temp-%d.%ld.rdb",(int)server.unixtime,(PORT_LONG int)getpid());
|
||||
"temp-%d.%ld.rdb",(int)server.unixtime,(long int)getpid());
|
||||
dfd = open(tmpfile,O_CREAT|O_WRONLY|O_EXCL,0644);
|
||||
#endif
|
||||
if (dfd != -1) break;
|
||||
@@ -2086,7 +2087,6 @@ void replicationSetMaster(char *ip, int port) {
|
||||
* our own parameters, to later PSYNC with the new master. */
|
||||
if (was_master) replicationCacheMasterUsingMyself();
|
||||
server.repl_state = REPL_STATE_CONNECT;
|
||||
server.repl_down_since = 0;
|
||||
}
|
||||
|
||||
/* Cancel replication, setting the instance as a master itself. */
|
||||
@@ -2155,14 +2155,14 @@ void slaveofCommand(client *c) {
|
||||
} else {
|
||||
PORT_LONG port;
|
||||
|
||||
if (c->flags & CLIENT_SLAVE)
|
||||
{
|
||||
/* If a client is already a replica they cannot run this command,
|
||||
* because it involves flushing all replicas (including this
|
||||
* client) */
|
||||
addReplyError(c,"Command is not valid when client is a replica.");
|
||||
return;
|
||||
}
|
||||
if (c->flags & CLIENT_SLAVE)
|
||||
{
|
||||
/* If a client is already a replica they cannot run this command,
|
||||
* because it involves flushing all replicas (including this
|
||||
* client) */
|
||||
addReplyError(c, "Command is not valid when client is a replica.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != C_OK))
|
||||
return;
|
||||
@@ -2743,7 +2743,7 @@ void replicationCron(void) {
|
||||
#else
|
||||
if (write(slave->fd, "\n", 1) == -1) {
|
||||
#endif
|
||||
/* Don't worry, it's just a ping. */
|
||||
/* Don't worry about socket errors, it's just a ping. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ size_t rioWriteBulkString(rio *r, const char *buf, size_t len) {
|
||||
return nwritten+len+2;
|
||||
}
|
||||
|
||||
/* Write a PORT_LONGLONG value in format: "$<count>\r\n<payload>\r\n". */
|
||||
/* Write a long long value in format: "$<count>\r\n<payload>\r\n". */
|
||||
size_t rioWriteBulkLongLong(rio *r, PORT_LONGLONG l) {
|
||||
char lbuf[32];
|
||||
unsigned int llen;
|
||||
|
||||
+8
-7
@@ -1186,7 +1186,7 @@ sds luaCreateFunction(client *c, lua_State *lua, robj *body) {
|
||||
if (c != NULL) {
|
||||
addReplyErrorFormat(c,
|
||||
"Error compiling script (new function): %s\n",
|
||||
lua_tostring(lua,-1));
|
||||
lua_tostring(lua,-1));
|
||||
}
|
||||
lua_pop(lua,1);
|
||||
sdsfree(sha);
|
||||
@@ -1194,10 +1194,11 @@ sds luaCreateFunction(client *c, lua_State *lua, robj *body) {
|
||||
return NULL;
|
||||
}
|
||||
sdsfree(funcdef);
|
||||
|
||||
if (lua_pcall(lua,0,0,0)) {
|
||||
if (c != NULL) {
|
||||
addReplyErrorFormat(c,"Error running script (new function): %s\n",
|
||||
lua_tostring(lua,-1));
|
||||
addReplyErrorFormat(c,"Error running script (new function): %s\n",
|
||||
lua_tostring(lua,-1));
|
||||
}
|
||||
lua_pop(lua,1);
|
||||
sdsfree(sha);
|
||||
@@ -1209,7 +1210,7 @@ sds luaCreateFunction(client *c, lua_State *lua, robj *body) {
|
||||
* EVALSHA commands as EVAL using the original script. */
|
||||
int retval = dictAdd(server.lua_scripts,sha,body);
|
||||
serverAssertWithInfo(c ? c : server.lua_client,NULL,retval == DICT_OK);
|
||||
incrRefCount(body);
|
||||
incrRefCount(body);
|
||||
return sha;
|
||||
}
|
||||
|
||||
@@ -1636,7 +1637,7 @@ int ldbStartSession(client *c) {
|
||||
closeListeningSockets(0);
|
||||
} else {
|
||||
/* Parent */
|
||||
listAddNodeTail(ldb.children,(void*)(PORT_ULONG)cp);
|
||||
listAddNodeTail(ldb.children,(void*)(unsigned long)cp);
|
||||
freeClientAsync(c); /* Close the client in the parent side. */
|
||||
return 0;
|
||||
}
|
||||
@@ -1724,8 +1725,8 @@ void ldbKillForkedSessions(void) {
|
||||
|
||||
listRewind(ldb.children,&li);
|
||||
while((ln = listNext(&li))) {
|
||||
pid_t pid = (PORT_ULONG) ln->value;
|
||||
serverLog(LL_WARNING,"Killing debugging session %ld",(PORT_LONG)pid);
|
||||
pid_t pid = (unsigned long) ln->value;
|
||||
serverLog(LL_WARNING,"Killing debugging session %ld",(long)pid);
|
||||
kill(pid,SIGKILL);
|
||||
}
|
||||
listRelease(ldb.children);
|
||||
|
||||
@@ -472,7 +472,7 @@ int sdsll2str(char *s, PORT_LONGLONG value) {
|
||||
return (int)l; WIN_PORT_FIX /* cast (int) */
|
||||
}
|
||||
|
||||
/* Identical sdsll2str(), but for PORT_ULONGLONG type. */
|
||||
/* Identical sdsll2str(), but for unsigned long long type. */
|
||||
int sdsull2str(char *s, PORT_ULONGLONG v) {
|
||||
char *p, aux;
|
||||
size_t l;
|
||||
@@ -501,7 +501,7 @@ int sdsull2str(char *s, PORT_ULONGLONG v) {
|
||||
return (int)l;
|
||||
}
|
||||
|
||||
/* Create an sds string from a PORT_LONGLONG value. It is much faster than:
|
||||
/* Create an sds string from a long long value. It is much faster than:
|
||||
*
|
||||
* sdscatprintf(sdsempty(),"%lld\n", value);
|
||||
*/
|
||||
@@ -587,20 +587,20 @@ sds sdscatprintf(sds s, const char *fmt, ...) {
|
||||
* %s - C String
|
||||
* %S - SDS string
|
||||
* %i - signed int
|
||||
* %I - 64 bit signed integer (PORT_LONGLONG, int64_t)
|
||||
* %I - 64 bit signed integer (long long, int64_t)
|
||||
* %u - unsigned int
|
||||
* %U - 64 bit unsigned integer (PORT_ULONGLONG, uint64_t)
|
||||
* %U - 64 bit unsigned integer (unsigned long long, uint64_t)
|
||||
* %% - Verbatim "%" character.
|
||||
*/
|
||||
sds sdscatfmt(sds s, char const *fmt, ...) {
|
||||
size_t initlen = sdslen(s);
|
||||
const char *f = fmt;
|
||||
int i;
|
||||
PORT_LONG i;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap,fmt);
|
||||
f = fmt; /* Next format specifier byte to process. */
|
||||
i = (int)initlen; /* Position of the next byte to write to dest str. */
|
||||
i = initlen; /* Position of the next byte to write to dest str. */
|
||||
while(*f) {
|
||||
char next, *str;
|
||||
size_t l;
|
||||
@@ -741,9 +741,9 @@ void sdsrange(sds s, ssize_t start, ssize_t end) {
|
||||
}
|
||||
newlen = (start > end) ? 0 : (end-start)+1;
|
||||
if (newlen != 0) {
|
||||
if (start >= (signed)len) {
|
||||
if (start >= (ssize_t)len) {
|
||||
newlen = 0;
|
||||
} else if (end >= (signed)len) {
|
||||
} else if (end >= (ssize_t)len) {
|
||||
end = (int)len-1; WIN_PORT_FIX /* cast (int) */
|
||||
newlen = (start > end) ? 0 : (end-start)+1;
|
||||
}
|
||||
@@ -757,14 +757,14 @@ void sdsrange(sds s, ssize_t start, ssize_t end) {
|
||||
|
||||
/* Apply tolower() to every character of the sds string 's'. */
|
||||
void sdstolower(sds s) {
|
||||
int len = (int)sdslen(s), j; WIN_PORT_FIX /* cast (int) */
|
||||
size_t len = sdslen(s), j;
|
||||
|
||||
for (j = 0; j < len; j++) s[j] = tolower(s[j]);
|
||||
}
|
||||
|
||||
/* Apply toupper() to every character of the sds string 's'. */
|
||||
void sdstoupper(sds s) {
|
||||
int len = (int)sdslen(s), j; WIN_PORT_FIX /* cast (int) */
|
||||
size_t len = sdslen(s), j;
|
||||
|
||||
for (j = 0; j < len; j++) s[j] = toupper(s[j]);
|
||||
}
|
||||
|
||||
@@ -280,11 +280,11 @@ sds sdscatprintf(sds s, const char *fmt, ...);
|
||||
|
||||
sds sdscatfmt(sds s, char const *fmt, ...);
|
||||
sds sdstrim(sds s, const char *cset);
|
||||
void sdsrange(sds s, int start, int end);
|
||||
void sdsrange(sds s, ssize_t start, ssize_t end);
|
||||
void sdsupdatelen(sds s);
|
||||
void sdsclear(sds s);
|
||||
int sdscmp(const sds s1, const sds s2);
|
||||
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
|
||||
sds *sdssplitlen(const char *s, ssize_t len, const char *sep, int seplen, int *count);
|
||||
void sdsfreesplitres(sds *tokens, int count);
|
||||
void sdstolower(sds s);
|
||||
void sdstoupper(sds s);
|
||||
@@ -297,7 +297,7 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);
|
||||
|
||||
/* Low level functions exposed to the user API */
|
||||
sds sdsMakeRoomFor(sds s, size_t addlen);
|
||||
void sdsIncrLen(sds s,ssize_t incr);
|
||||
void sdsIncrLen(sds s, ssize_t incr);
|
||||
sds sdsRemoveFreeSpace(sds s);
|
||||
size_t sdsAllocSize(sds s);
|
||||
void *sdsAllocPtr(sds s);
|
||||
|
||||
+11
-11
@@ -258,8 +258,8 @@ struct sentinelState {
|
||||
int announce_port; /* Port that is gossiped to other sentinels if
|
||||
non zero. */
|
||||
PORT_ULONG simfailure_flags; /* Failures simulation. */
|
||||
int deny_scripts_reconfig; /* Allow SENTINEL SET ... to change script
|
||||
paths at runtime? */
|
||||
int deny_scripts_reconfig; /* Allow SENTINEL SET ... to change script
|
||||
paths at runtime? */
|
||||
} sentinel;
|
||||
|
||||
/* A script execution job. */
|
||||
@@ -456,7 +456,7 @@ dictType instancesDictType = {
|
||||
dictInstancesValDestructor /* val destructor */
|
||||
};
|
||||
|
||||
/* Instance runid (sds) -> votes (PORT_LONG casted to void*)
|
||||
/* Instance runid (sds) -> votes (long casted to void*)
|
||||
*
|
||||
* This is useful into sentinelGetObjectiveLeader() function in order to
|
||||
* count the votes and understand who is the leader. */
|
||||
@@ -875,7 +875,7 @@ void sentinelRunPendingScripts(void) {
|
||||
} else {
|
||||
sentinel.running_scripts++;
|
||||
sj->pid = pid;
|
||||
sentinelEvent(LL_DEBUG,"+script-child",NULL,"%ld",(PORT_LONG)pid);
|
||||
sentinelEvent(LL_DEBUG,"+script-child",NULL,"%ld",(long)pid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -954,11 +954,11 @@ void sentinelCollectTerminatedScripts(void) {
|
||||
|
||||
if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc);
|
||||
sentinelEvent(LL_DEBUG,"-script-child",NULL,"%ld %d %d",
|
||||
(PORT_LONG)pid, exitcode, bysignal);
|
||||
(long)pid, exitcode, bysignal);
|
||||
|
||||
ln = sentinelGetScriptListNodeByPid(pid);
|
||||
if (ln == NULL) {
|
||||
serverLog(LL_WARNING,"wait3() returned a pid (%ld) we can't find in our scripts execution queue!", (PORT_LONG)pid);
|
||||
serverLog(LL_WARNING,"wait3() returned a pid (%ld) we can't find in our scripts execution queue!", (long)pid);
|
||||
continue;
|
||||
}
|
||||
sj = ln->value;
|
||||
@@ -2738,7 +2738,7 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
|
||||
* also have a limit of SENTINEL_MAX_PENDING_COMMANDS. We don't
|
||||
* want to use a lot of memory just because a link is not working
|
||||
* properly (note that anyway there is a redundant protection about this,
|
||||
* that is, the link will be disconnected and reconnected if a PORT_LONG
|
||||
* that is, the link will be disconnected and reconnected if a long
|
||||
* timeout condition is detected. */
|
||||
if (ri->link->pending_commands >=
|
||||
SENTINEL_MAX_PENDING_COMMANDS * ri->link->refcount) return;
|
||||
@@ -2776,13 +2776,13 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
|
||||
if (retval == C_OK) ri->link->pending_commands++;
|
||||
}
|
||||
|
||||
/* Send PING to all the three kinds of instances. */
|
||||
/* Send PING to all the three kinds of instances. */
|
||||
if ((now - ri->link->last_pong_time) > ping_period &&
|
||||
(now - ri->link->last_ping_time) > ping_period/2) {
|
||||
sentinelSendPing(ri);
|
||||
}
|
||||
|
||||
/* PUBLISH hello messages to all the three kinds of instances. */
|
||||
/* PUBLISH hello messages to all the three kinds of instances. */
|
||||
if ((now - ri->last_pub_time) > SENTINEL_PUBLISH_PERIOD) {
|
||||
sentinelSendHello(ri);
|
||||
}
|
||||
@@ -3000,7 +3000,7 @@ void addReplyDictOfRedisInstances(client *c, dict *instances) {
|
||||
dictEntry *de;
|
||||
|
||||
di = dictGetIterator(instances);
|
||||
addReplyMultiBulkLen(c, (PORT_LONG) dictSize(instances)); WIN_PORT_FIX /* cast (PORT_LONG) */
|
||||
addReplyMultiBulkLen(c,(PORT_LONG)dictSize(instances)); WIN_PORT_FIX /* cast (PORT_LONG) */
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
sentinelRedisInstance *ri = dictGetVal(de);
|
||||
|
||||
@@ -3450,7 +3450,7 @@ void sentinelRoleCommand(client *c) {
|
||||
|
||||
addReplyMultiBulkLen(c,2);
|
||||
addReplyBulkCBuffer(c,"sentinel",8);
|
||||
addReplyMultiBulkLen(c, (PORT_LONG) dictSize(sentinel.masters));
|
||||
addReplyMultiBulkLen(c,(PORT_LONG)dictSize(sentinel.masters));
|
||||
|
||||
di = dictGetIterator(sentinel.masters);
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
|
||||
+612
-663
File diff suppressed because it is too large
Load Diff
+8
-8
@@ -52,14 +52,14 @@
|
||||
#include <limits.h>
|
||||
POSIX_ONLY(#include <unistd.h>)
|
||||
#include <errno.h>
|
||||
POSIX_ONLY(#include <inttypes.h>)
|
||||
#ifndef _WIN32
|
||||
#include <inttypes.h>
|
||||
#include <pthread.h>
|
||||
#include <syslog.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#include "Win32_Interop\Win32_PThread.h"
|
||||
#endif
|
||||
POSIX_ONLY(#include <syslog.h>)
|
||||
POSIX_ONLY(#include <netinet/in.h>)
|
||||
#include <lua.h>
|
||||
#include <signal.h>
|
||||
|
||||
@@ -195,7 +195,7 @@ POSIX_ONLY(#define LOG_MAX_LEN 1024) /* Default maximum length of syslog mess
|
||||
#define PROTO_REPLY_CHUNK_BYTES (16*1024) /* 16k output buffer */
|
||||
#define PROTO_INLINE_MAX_SIZE (1024*64) /* Max size of inline reads */
|
||||
#define PROTO_MBULK_BIG_ARG (1024*32)
|
||||
#define LONG_STR_SIZE 21 /* Bytes needed for PORT_LONG -> str + '\0' */
|
||||
#define LONG_STR_SIZE 21 /* Bytes needed for long -> str + '\0' */
|
||||
#define AOF_AUTOSYNC_BYTES (1024*1024*32) /* fdatasync every 32MB */
|
||||
|
||||
/* When configuring the server eventloop, we setup it so that the total number
|
||||
@@ -439,7 +439,7 @@ POSIX_ONLY(#define CONFIG_DEFAULT_VERBOSITY LL_NOTICE)
|
||||
#define NOTIFY_ZSET (1<<7) /* z */
|
||||
#define NOTIFY_EXPIRED (1<<8) /* x */
|
||||
#define NOTIFY_EVICTED (1<<9) /* e */
|
||||
#define NOTIFY_ALL (NOTIFY_GENERIC | NOTIFY_STRING | NOTIFY_LIST | NOTIFY_SET | NOTIFY_HASH | NOTIFY_ZSET | NOTIFY_EXPIRED | NOTIFY_EVICTED) /* A */
|
||||
#define NOTIFY_ALL (NOTIFY_GENERIC | NOTIFY_STRING | NOTIFY_LIST | NOTIFY_SET | NOTIFY_HASH | NOTIFY_ZSET | NOTIFY_EXPIRED | NOTIFY_EVICTED) /* A flag */
|
||||
|
||||
/* Get the first bind addr or NULL */
|
||||
#define NET_FIRST_BIND_ADDR (server.bindaddr_count ? server.bindaddr[0] : NULL)
|
||||
@@ -737,7 +737,7 @@ typedef struct client {
|
||||
dict *pubsub_channels; /* channels a client is interested in (SUBSCRIBE) */
|
||||
list *pubsub_patterns; /* patterns a client is interested in (SUBSCRIBE) */
|
||||
sds peerid; /* Cached peer ID. */
|
||||
listNode *client_list_node; /* list node in client list */
|
||||
listNode *client_list_node; /* list node in client list */
|
||||
WIN32_ONLY(char replFileCopy[_MAX_PATH];)
|
||||
|
||||
/* Response buffer */
|
||||
@@ -904,7 +904,7 @@ struct redisServer {
|
||||
int active_defrag_running; /* Active defragmentation running (holds current scan aggressiveness) */
|
||||
char *requirepass; /* Pass for AUTH command, or NULL */
|
||||
char *pidfile; /* PID file path */
|
||||
int arch_bits; /* 32 or 64 depending on sizeof(PORT_LONG) */
|
||||
int arch_bits; /* 32 or 64 depending on sizeof(long) */
|
||||
int cronloops; /* Number of times the cron function run */
|
||||
char runid[CONFIG_RUN_ID_SIZE+1]; /* ID always different at every exec. */
|
||||
int sentinel_mode; /* True if this instance is a Sentinel. */
|
||||
@@ -1425,7 +1425,7 @@ void addReplyStatusFormat(client *c, const char *fmt, ...);
|
||||
void listTypeTryConversion(robj *subject, robj *value);
|
||||
void listTypePush(robj *subject, robj *value, int where);
|
||||
robj *listTypePop(robj *subject, int where);
|
||||
PORT_ULONG listTypeLength(robj *subject);
|
||||
PORT_ULONG listTypeLength(const robj *subject);
|
||||
listTypeIterator *listTypeInitIterator(robj *subject, PORT_LONG index, unsigned char direction);
|
||||
void listTypeReleaseIterator(listTypeIterator *li);
|
||||
int listTypeNext(listTypeIterator *li, listTypeEntry *entry);
|
||||
|
||||
+5
-1
@@ -39,7 +39,11 @@
|
||||
#include <errno.h> /* errno program_invocation_name program_invocation_short_name */
|
||||
|
||||
#if !defined(HAVE_SETPROCTITLE)
|
||||
#define HAVE_SETPROCTITLE (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)
|
||||
#if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)
|
||||
#define HAVE_SETPROCTITLE 1
|
||||
#else
|
||||
#define HAVE_SETPROCTITLE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ slowlogEntry *slowlogCreateEntry(client *c, robj **argv, int argc, PORT_LONGLONG
|
||||
sdscatprintf(sdsempty(),"... (%d more arguments)",
|
||||
argc-slargc+1));
|
||||
} else {
|
||||
/* Trim too PORT_LONG strings as well... */
|
||||
/* Trim too long strings as well... */
|
||||
if (argv[j]->type == OBJ_STRING &&
|
||||
sdsEncodedObject(argv[j]) &&
|
||||
sdslen(argv[j]->ptr) > SLOWLOG_ENTRY_MAX_STRING)
|
||||
|
||||
+2
-2
@@ -287,8 +287,8 @@ int hashTypeDelete(robj *o, sds field) {
|
||||
if (fptr != NULL) {
|
||||
fptr = ziplistFind(fptr, (unsigned char*)field, (unsigned int)sdslen(field), 1); WIN_PORT_FIX /* cast (unsigned int) */
|
||||
if (fptr != NULL) {
|
||||
zl = ziplistDelete(zl,&fptr);
|
||||
zl = ziplistDelete(zl,&fptr);
|
||||
zl = ziplistDelete(zl,&fptr); /* Delete the key. */
|
||||
zl = ziplistDelete(zl,&fptr); /* Delete the value. */
|
||||
o->ptr = zl;
|
||||
deleted = 1;
|
||||
}
|
||||
|
||||
+4
-4
@@ -213,7 +213,7 @@ void pushGenericCommand(client *c, int where) {
|
||||
listTypePush(lobj,c->argv[j],where);
|
||||
pushed++;
|
||||
}
|
||||
addReplyLongLong(c, (lobj ? listTypeLength(lobj) : (robj*)0));
|
||||
addReplyLongLong(c, (lobj ? listTypeLength(lobj) : 0));
|
||||
if (pushed) {
|
||||
char *event = (where == LIST_HEAD) ? "lpush" : "rpush";
|
||||
|
||||
@@ -596,9 +596,9 @@ void rpoplpushCommand(client *c) {
|
||||
signalModifiedKey(c->db,touchedkey);
|
||||
decrRefCount(touchedkey);
|
||||
server.dirty++;
|
||||
if (c->cmd->proc == brpoplpushCommand) {
|
||||
rewriteClientCommandVector(c,3,shared.rpoplpush,c->argv[1],c->argv[2]);
|
||||
}
|
||||
if (c->cmd->proc == brpoplpushCommand) {
|
||||
rewriteClientCommandVector(c,3,shared.rpoplpush,c->argv[1],c->argv[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -407,7 +407,7 @@ void spopWithCountCommand(client *c) {
|
||||
/* Get the count argument */
|
||||
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
|
||||
if (l >= 0) {
|
||||
count = (unsigned) l;
|
||||
count = (PORT_ULONG) l;
|
||||
} else {
|
||||
addReply(c,shared.outofrangeerr);
|
||||
return;
|
||||
@@ -626,7 +626,7 @@ void srandmemberWithCountCommand(client *c) {
|
||||
|
||||
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
|
||||
if (l >= 0) {
|
||||
count = (unsigned) l;
|
||||
count = (PORT_ULONG) l;
|
||||
} else {
|
||||
/* A negative count means: return the same elements multiple times
|
||||
* (i.e. don't remove the extracted element after every extraction). */
|
||||
|
||||
+14
-14
@@ -601,8 +601,8 @@ int zslIsInLexRange(zskiplist *zsl, zlexrangespec *range) {
|
||||
zskiplistNode *x;
|
||||
|
||||
/* Test for ranges that will always be empty. */
|
||||
int cmp = sdscmplex(range->min,range->max);
|
||||
if (cmp > 0 || (cmp == 0 && (range->minex || range->maxex)))
|
||||
int cmp = sdscmplex(range->min,range->max);
|
||||
if (cmp > 0 || (cmp == 0 && (range->minex || range->maxex)))
|
||||
return 0;
|
||||
x = zsl->tail;
|
||||
if (x == NULL || !zslLexValueGteMin(x->ele,range))
|
||||
@@ -715,7 +715,7 @@ int zzlCompareElements(unsigned char *eptr, unsigned char *cstr, unsigned int cl
|
||||
|
||||
serverAssert(ziplistGet(eptr,&vstr,&vlen,&vlong));
|
||||
if (vstr == NULL) {
|
||||
/* Store string representation of PORT_LONGLONG in buf. */
|
||||
/* Store string representation of long long in buf. */
|
||||
vlen = ll2string((char*)vbuf,sizeof(vbuf),vlong);
|
||||
vstr = vbuf;
|
||||
}
|
||||
@@ -875,8 +875,8 @@ int zzlIsInLexRange(unsigned char *zl, zlexrangespec *range) {
|
||||
unsigned char *p;
|
||||
|
||||
/* Test for ranges that will always be empty. */
|
||||
int cmp = sdscmplex(range->min,range->max);
|
||||
if (cmp > 0 || (cmp == 0 && (range->minex || range->maxex)))
|
||||
int cmp = sdscmplex(range->min,range->max);
|
||||
if (cmp > 0 || (cmp == 0 && (range->minex || range->maxex)))
|
||||
return 0;
|
||||
|
||||
p = ziplistIndex(zl,-2); /* Last element. */
|
||||
@@ -1794,10 +1794,10 @@ typedef struct {
|
||||
|
||||
|
||||
/* Use dirty flags for pointers that need to be cleaned up in the next
|
||||
* iteration over the zsetopval. The dirty flag for the PORT_LONGLONG value is
|
||||
* special, since PORT_LONGLONG values don't need cleanup. Instead, it means that
|
||||
* we already checked that "ell" holds a PORT_LONGLONG, or tried to convert another
|
||||
* representation into a PORT_LONGLONG value. When this was successful,
|
||||
* iteration over the zsetopval. The dirty flag for the long long value is
|
||||
* special, since long long values don't need cleanup. Instead, it means that
|
||||
* we already checked that "ell" holds a long long, or tried to convert another
|
||||
* representation into a long long value. When this was successful,
|
||||
* OPVAL_VALID_LL is set as well. */
|
||||
#define OPVAL_DIRTY_SDS 1
|
||||
#define OPVAL_DIRTY_LL 2
|
||||
@@ -1981,7 +1981,7 @@ int zuiLongLongFromValue(zsetopval *val) {
|
||||
if (string2ll((char*)val->estr,val->elen,&val->ell))
|
||||
val->flags |= OPVAL_VALID_LL;
|
||||
} else {
|
||||
/* The PORT_LONGLONG was already set, flag as valid. */
|
||||
/* The long long was already set, flag as valid. */
|
||||
val->flags |= OPVAL_VALID_LL;
|
||||
}
|
||||
}
|
||||
@@ -2858,10 +2858,10 @@ void genericZrangebylexCommand(client *c, int reverse) {
|
||||
while (remaining) {
|
||||
if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
|
||||
if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) ||
|
||||
(getLongFromObjectOrReply(c,c->argv[pos + 2],&limit,NULL) != C_OK)) {
|
||||
zslFreeLexRange(&range);
|
||||
return;
|
||||
}
|
||||
(getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) {
|
||||
zslFreeLexRange(&range);
|
||||
return;
|
||||
}
|
||||
pos += 3; remaining -= 3;
|
||||
} else {
|
||||
zslFreeLexRange(&range);
|
||||
|
||||
+9
-9
@@ -56,7 +56,7 @@ POSIX_ONLY(#include <sys/time.h>)
|
||||
int stringmatchlen(const char *pattern, int patternLen,
|
||||
const char *string, int stringLen, int nocase)
|
||||
{
|
||||
while (patternLen && stringLen) {
|
||||
while(patternLen && stringLen) {
|
||||
switch(pattern[0]) {
|
||||
case '*':
|
||||
while (pattern[1] == '*') {
|
||||
@@ -272,7 +272,7 @@ uint32_t sdigits10(int64_t v) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert a PORT_LONGLONG into a string. Returns the number of
|
||||
/* Convert a long long into a string. Returns the number of
|
||||
* characters needed to represent the number.
|
||||
* If the buffer is not big enough to store the string, 0 is returned.
|
||||
*
|
||||
@@ -337,17 +337,17 @@ int ll2string(char *dst, size_t dstlen, PORT_LONGLONG svalue) {
|
||||
return length;
|
||||
}
|
||||
|
||||
/* Convert a string into a PORT_LONGLONG. Returns 1 if the string could be parsed
|
||||
* into a (non-overflowing) PORT_LONGLONG, 0 otherwise. The value will be set to
|
||||
/* Convert a string into a long long. Returns 1 if the string could be parsed
|
||||
* into a (non-overflowing) long long, 0 otherwise. The value will be set to
|
||||
* the parsed value when appropriate.
|
||||
*
|
||||
* Note that this function demands that the string strictly represents
|
||||
* a PORT_LONGLONG: no spaces or other characters before or after the string
|
||||
* a long long: no spaces or other characters before or after the string
|
||||
* representing the number are accepted, nor zeroes at the start if not
|
||||
* for the string "0" representing the zero number.
|
||||
*
|
||||
* Because of its strictness, it is safe to use this function to check if
|
||||
* you can convert a string into a PORT_LONGLONG, and obtain back the string
|
||||
* you can convert a string into a long long, and obtain back the string
|
||||
* from the number without any loss in the string representation. */
|
||||
int string2ll(const char *s, size_t slen, PORT_LONGLONG *value) {
|
||||
const char *p = s;
|
||||
@@ -479,12 +479,12 @@ int d2string(char *buf, size_t len, double value) {
|
||||
} else {
|
||||
#if (DBL_MANT_DIG >= 52) && (LLONG_MAX == 0x7fffffffffffffffLL)
|
||||
/* Check if the float is in a safe range to be casted into a
|
||||
* PORT_LONGLONG. We are assuming that PORT_LONGLONG is 64 bit here.
|
||||
* long long. We are assuming that long long is 64 bit here.
|
||||
* Also we are assuming that there are no implementations around where
|
||||
* double has precision < 52 bit.
|
||||
*
|
||||
* Under this assumptions we test if a double is inside an interval
|
||||
* where casting to PORT_LONGLONG is safe. Then using two castings we
|
||||
* where casting to long long is safe. Then using two castings we
|
||||
* make sure the decimal part is zero. If all this is true we use
|
||||
* integer printing function that is much faster. */
|
||||
double min = -4503599627370495; /* (2^52)-1 */
|
||||
@@ -499,7 +499,7 @@ int d2string(char *buf, size_t len, double value) {
|
||||
return (int)len; WIN_PORT_FIX /* cast (int) */
|
||||
}
|
||||
|
||||
/* Convert a PORT_LONGDOUBLE into a string. If humanfriendly is non-zero
|
||||
/* Convert a long double into a string. If humanfriendly is non-zero
|
||||
* it does not use exponential format and trims trailing zeroes at the end,
|
||||
* however this results in loss of precision. Otherwise exp format is used
|
||||
* and the output of snprintf() is not modified.
|
||||
|
||||
+3
-3
@@ -444,7 +444,7 @@ unsigned int zipStorePrevEntryLength(unsigned char *p, unsigned int len) {
|
||||
if ((prevlensize) == 1) { \
|
||||
(prevlen) = (ptr)[0]; \
|
||||
} else if ((prevlensize) == 5) { \
|
||||
assert(sizeof((prevlensize)) == 4); \
|
||||
assert(sizeof((prevlen)) == 4); \
|
||||
memcpy(&(prevlen), ((char*)(ptr)) + 1, 4); \
|
||||
memrev32ifbe(&prevlen); \
|
||||
} \
|
||||
@@ -1284,13 +1284,13 @@ static unsigned char *createIntList() {
|
||||
return zl;
|
||||
}
|
||||
|
||||
PORT_LONGLONG usec(void) {
|
||||
static PORT_LONGLONG usec(void) {
|
||||
#ifdef _WIN32
|
||||
return GetHighResRelativeTime(1000000);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return (((PORT_LONGLONG)tv.tv_sec)*1000000)+tv.tv_usec;
|
||||
return (((long long)tv.tv_sec)*1000000)+tv.tv_usec;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -169,8 +169,8 @@ static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, uns
|
||||
return k;
|
||||
}
|
||||
|
||||
static unsigned int zipmapRequiredLength(unsigned int klen, unsigned int vlen) { WIN_PORT_FIX /* PORT_ULONG -> unsigned int */
|
||||
unsigned int l;
|
||||
static PORT_ULONG zipmapRequiredLength(unsigned int klen, unsigned int vlen) { WIN_PORT_FIX /* PORT_ULONG -> unsigned int */
|
||||
PORT_ULONG l;
|
||||
|
||||
l = klen+vlen+3;
|
||||
if (klen >= ZIPMAP_BIGLEN) l += 4;
|
||||
|
||||
+1
-45
@@ -75,31 +75,6 @@ POSIX_ONLY(#include <pthread.h>)
|
||||
#define free(ptr) je_free(ptr)
|
||||
#define mallocx(size,flags) je_mallocx(size,flags)
|
||||
#define dallocx(ptr,flags) je_dallocx(ptr,flags)
|
||||
#elif defined(USE_DLMALLOC)
|
||||
#define malloc(size) g_malloc(size)
|
||||
#define calloc(count,size) g_calloc(count,size)
|
||||
#define realloc(ptr,size) g_realloc(ptr,size)
|
||||
#define free(ptr) g_free(ptr)
|
||||
#endif
|
||||
|
||||
#if defined(__ATOMIC_RELAXED)
|
||||
#define update_zmalloc_stat_add(__n) __atomic_add_fetch(&used_memory, (__n), __ATOMIC_RELAXED)
|
||||
#define update_zmalloc_stat_sub(__n) __atomic_sub_fetch(&used_memory, (__n), __ATOMIC_RELAXED)
|
||||
#elif defined(HAVE_ATOMIC)
|
||||
#define update_zmalloc_stat_add(__n) __sync_add_and_fetch(&used_memory, (__n))
|
||||
#define update_zmalloc_stat_sub(__n) __sync_sub_and_fetch(&used_memory, (__n))
|
||||
#else
|
||||
#define update_zmalloc_stat_add(__n) do { \
|
||||
pthread_mutex_lock(&used_memory_mutex); \
|
||||
used_memory += (__n); \
|
||||
pthread_mutex_unlock(&used_memory_mutex); \
|
||||
} while(0)
|
||||
|
||||
#define update_zmalloc_stat_sub(__n) do { \
|
||||
pthread_mutex_lock(&used_memory_mutex); \
|
||||
used_memory -= (__n); \
|
||||
pthread_mutex_unlock(&used_memory_mutex); \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#define update_zmalloc_stat_alloc(__n) do { \
|
||||
@@ -115,7 +90,6 @@ POSIX_ONLY(#include <pthread.h>)
|
||||
} while(0)
|
||||
|
||||
static size_t used_memory = 0;
|
||||
static int zmalloc_thread_safe = 0;
|
||||
#ifdef _WIN32
|
||||
pthread_mutex_t used_memory_mutex;
|
||||
#else
|
||||
@@ -213,7 +187,7 @@ void *zrealloc(void *ptr, size_t size) {
|
||||
size_t zmalloc_size(void *ptr) {
|
||||
void *realptr = (char*)ptr-PREFIX_SIZE;
|
||||
size_t size = *((size_t*)realptr);
|
||||
/* Assume at least that all the allocations are padded at sizeof(PORT_LONG) by
|
||||
/* Assume at least that all the allocations are padded at sizeof(long) by
|
||||
* the underlying allocator. */
|
||||
if (size&(sizeof(PORT_LONG)-1)) size += sizeof(PORT_LONG)-(size&(sizeof(PORT_LONG)-1));
|
||||
return size+PREFIX_SIZE;
|
||||
@@ -252,24 +226,6 @@ size_t zmalloc_used_memory(void) {
|
||||
return um;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void zmalloc_free_used_memory_mutex(void) {
|
||||
/* Windows fix: Callabe mutex destroy. */
|
||||
if (zmalloc_thread_safe)
|
||||
pthread_mutex_destroy(&used_memory_mutex);
|
||||
}
|
||||
void zmalloc_enable_thread_safeness(void) {
|
||||
if (!zmalloc_thread_safe)
|
||||
pthread_mutex_init(&used_memory_mutex,0);
|
||||
|
||||
zmalloc_thread_safe = 1;
|
||||
}
|
||||
#else
|
||||
void zmalloc_enable_thread_safeness(void) {
|
||||
zmalloc_thread_safe = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {
|
||||
zmalloc_oom_handler = oom_handler;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ size_t zmalloc_get_private_dirty(PORT_LONG pid);
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field, PORT_LONG pid);
|
||||
size_t zmalloc_get_memory_size(void);
|
||||
void zlibc_free(void *ptr);
|
||||
WIN32_ONLY(void zmalloc_free_used_memory_mutex(void);)
|
||||
|
||||
#ifdef HAVE_DEFRAG
|
||||
void zfree_no_tcache(void *ptr);
|
||||
|
||||
Reference in New Issue
Block a user