Introduced the Build ID in INFO and --version output.

The idea is to be able to identify a build in a unique way, so for
instance after a bug report we can recognize that the build is the one
of a popular Linux distribution and perform the debugging in the same
environment.
This commit is contained in:
antirez 2012-11-29 14:20:08 +01:00
parent b1b602a928
commit 2f62c9663c
9 changed files with 30 additions and 9 deletions

View File

@ -101,7 +101,7 @@ REDIS_SERVER_NAME= redis-server
REDIS_SENTINEL_NAME= redis-sentinel REDIS_SENTINEL_NAME= redis-sentinel
REDIS_SERVER_OBJ= adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o REDIS_SERVER_OBJ= adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o
REDIS_CLI_NAME= redis-cli REDIS_CLI_NAME= redis-cli
REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o
REDIS_BENCHMARK_NAME= redis-benchmark REDIS_BENCHMARK_NAME= redis-benchmark
REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
REDIS_CHECK_DUMP_NAME= redis-check-dump REDIS_CHECK_DUMP_NAME= redis-check-dump

8
src/crc64.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef CRC64_H
#define CRC64_H
#include <stdint.h>
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
#endif

View File

@ -29,6 +29,7 @@
#include "redis.h" #include "redis.h"
#include "sha1.h" /* SHA1 is used for DEBUG DIGEST */ #include "sha1.h" /* SHA1 is used for DEBUG DIGEST */
#include "crc64.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <signal.h> #include <signal.h>
@ -667,7 +668,6 @@ void logCurrentClient(void) {
} }
#if defined(HAVE_PROC_MAPS) #if defined(HAVE_PROC_MAPS)
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
void memtest_non_destructive_invert(void *addr, size_t size); void memtest_non_destructive_invert(void *addr, size_t size);
void memtest_non_destructive_swap(void *addr, size_t size); void memtest_non_destructive_swap(void *addr, size_t size);
#define MEMTEST_MAX_REGIONS 128 #define MEMTEST_MAX_REGIONS 128

View File

@ -1,9 +1,11 @@
#!/bin/sh #!/bin/sh
GIT_SHA1=`(git show-ref --head --hash=8 2> /dev/null || echo 00000000) | head -n1` GIT_SHA1=`(git show-ref --head --hash=8 2> /dev/null || echo 00000000) | head -n1`
GIT_DIRTY=`git diff 2> /dev/null | wc -l` GIT_DIRTY=`git diff 2> /dev/null | wc -l`
BUILD_ID=`uname -n`"-"`date +%s`
test -f release.h || touch release.h test -f release.h || touch release.h
(cat release.h | grep SHA1 | grep $GIT_SHA1) && \ (cat release.h | grep SHA1 | grep $GIT_SHA1) && \
(cat release.h | grep DIRTY | grep $GIT_DIRTY) && exit 0 # Already uptodate (cat release.h | grep DIRTY | grep $GIT_DIRTY) && exit 0 # Already uptodate
echo "#define REDIS_GIT_SHA1 \"$GIT_SHA1\"" > release.h echo "#define REDIS_GIT_SHA1 \"$GIT_SHA1\"" > release.h
echo "#define REDIS_GIT_DIRTY \"$GIT_DIRTY\"" >> release.h echo "#define REDIS_GIT_DIRTY \"$GIT_DIRTY\"" >> release.h
echo "#define REDIS_BUILD_ID \"$BUILD_ID\"" >> release.h
touch release.c # Force recompile of release.c touch release.c # Force recompile of release.c

View File

@ -40,6 +40,7 @@
#include <stdint.h> #include <stdint.h>
#include <limits.h> #include <limits.h>
#include "lzf.h" #include "lzf.h"
#include "crc64.h"
/* Object types */ /* Object types */
#define REDIS_STRING 0 #define REDIS_STRING 0
@ -140,9 +141,6 @@ static double R_Zero, R_PosInf, R_NegInf, R_Nan;
/* store string types for output */ /* store string types for output */
static char types[256][16]; static char types[256][16];
/* Prototypes */
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
/* Return true if 't' is a valid object type. */ /* Return true if 't' is a valid object type. */
int checkType(unsigned char t) { int checkType(unsigned char t) {
/* In case a new object type is added, update the following /* In case a new object type is added, update the following

View File

@ -1929,6 +1929,7 @@ sds genRedisInfoString(char *section) {
"redis_version:%s\r\n" "redis_version:%s\r\n"
"redis_git_sha1:%s\r\n" "redis_git_sha1:%s\r\n"
"redis_git_dirty:%d\r\n" "redis_git_dirty:%d\r\n"
"redis_build_id:%llx\r\n"
"redis_mode:%s\r\n" "redis_mode:%s\r\n"
"os:%s %s %s\r\n" "os:%s %s %s\r\n"
"arch_bits:%d\r\n" "arch_bits:%d\r\n"
@ -1943,6 +1944,7 @@ sds genRedisInfoString(char *section) {
REDIS_VERSION, REDIS_VERSION,
redisGitSHA1(), redisGitSHA1(),
strtol(redisGitDirty(),NULL,10) > 0, strtol(redisGitDirty(),NULL,10) > 0,
redisBuildId(),
mode, mode,
name.sysname, name.release, name.machine, name.sysname, name.release, name.machine,
server.arch_bits, server.arch_bits,
@ -2489,12 +2491,13 @@ void daemonize(void) {
} }
void version() { void version() {
printf("Redis server v=%s sha=%s:%d malloc=%s bits=%d\n", printf("Redis server v=%s sha=%s:%d malloc=%s bits=%d build=%llx\n",
REDIS_VERSION, REDIS_VERSION,
redisGitSHA1(), redisGitSHA1(),
atoi(redisGitDirty()) > 0, atoi(redisGitDirty()) > 0,
ZMALLOC_LIB, ZMALLOC_LIB,
sizeof(long) == 4 ? 32 : 64); sizeof(long) == 4 ? 32 : 64,
redisBuildId());
exit(0); exit(0);
} }

View File

@ -1192,6 +1192,7 @@ void scriptingInit(void);
/* Git SHA1 */ /* Git SHA1 */
char *redisGitSHA1(void); char *redisGitSHA1(void);
char *redisGitDirty(void); char *redisGitDirty(void);
uint64_t redisBuildId(void);
/* Commands prototypes */ /* Commands prototypes */
void authCommand(redisClient *c); void authCommand(redisClient *c);

View File

@ -31,7 +31,11 @@
* small file is recompiled, as we access this information in all the other * small file is recompiled, as we access this information in all the other
* files using this functions. */ * files using this functions. */
#include <string.h>
#include "release.h" #include "release.h"
#include "version.h"
#include "crc64.h"
char *redisGitSHA1(void) { char *redisGitSHA1(void) {
return REDIS_GIT_SHA1; return REDIS_GIT_SHA1;
@ -40,3 +44,9 @@ char *redisGitSHA1(void) {
char *redisGitDirty(void) { char *redisGitDirty(void) {
return REDIS_GIT_DIRTY; return REDIS_GIT_DIRTY;
} }
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));
}

View File

@ -50,8 +50,7 @@
#include <stdio.h> #include <stdio.h>
#include "rio.h" #include "rio.h"
#include "util.h" #include "util.h"
#include "crc64.h"
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
/* Returns 1 or 0 for success/failure. */ /* Returns 1 or 0 for success/failure. */
static size_t rioBufferWrite(rio *r, const void *buf, size_t len) { static size_t rioBufferWrite(rio *r, const void *buf, size_t len) {