Permalink
Browse files

shortcut macro of logs

  • Loading branch information...
1 parent 8717525 commit 2b92576b852c2eced11f1e4fde9d1ab595c2df00 @BohuTANG committed May 15, 2012
Showing with 42 additions and 33 deletions.
  1. +2 −2 bench/db-bench.c
  2. +11 −2 engine/debug.h
  3. +5 −5 engine/index.c
  4. +6 −6 engine/log.c
  5. +9 −9 engine/sst.c
  6. +6 −6 server/db-server.c
  7. +3 −3 server/request.c
View
@@ -198,10 +198,10 @@ void _readone_test(char *key)
ret = db_get(db, &sk, &sv);
if (ret){
- __DEBUG(LEVEL_INFO, "Get Key:<%s>--->value is :<%s>", key, sv.data);
+ __INFO("Get Key:<%s>--->value is :<%s>", key, sv.data);
free(sv.data);
} else
- __DEBUG(LEVEL_INFO, "Get Key:<%s>,but value is NULL", key);
+ __INFO("Get Key:<%s>,but value is NULL", key);
db_close(db);
free(dir);
View
@@ -17,8 +17,17 @@ typedef enum {LEVEL_DEBUG = 0, LEVEL_INFO, LEVEL_WARNING, LEVEL_ERROR} DEBUG_LEV
void __debug(char *file, int line, DEBUG_LEVEL level, const char *fmt, ...);
-#define __DEBUG(_v1, format, args...)\
- do { __debug(__FILE__, __LINE__, _v1, format, ##args); } while (0)
+#define __DEBUG(format, args...)\
+ do { __debug(__FILE__, __LINE__, LEVEL_DEBUG, format, ##args); } while (0)
+
+#define __ERROR(format, args...)\
+ do { __debug(__FILE__, __LINE__, LEVEL_ERROR, format, ##args); } while (0)
+
+#define __WARN(format, args...)\
+ do { __debug(__FILE__, __LINE__, LEVEL_WARNING, format, ##args); } while (0)
+
+#define __INFO(format, args...)\
+ do { __debug(__FILE__, __LINE__, LEVEL_INFO, format, ##args); } while (0)
#define __PANIC(format, args...)\
do { __debug(__FILE__, __LINE__, LEVEL_ERROR, format, ##args); exit(1); } while (0)
View
@@ -98,7 +98,7 @@ struct index *index_new(const char *basedir, int max_mtbl_size, int tolog)
* 5) create new memtable and log file
*/
if (log_recovery(idx->log, idx->list)) {
- __DEBUG(LEVEL_DEBUG, "prepare to merge logs, merge count #%d....", idx->list->count);
+ __DEBUG("prepare to merge logs, merge count #%d....", idx->list->count);
/* Merge log entries */
sst_merge(idx->sst, idx->list, 1);
@@ -209,12 +209,12 @@ void _index_flush(struct index *idx)
if (log_idx_fd > 0) {
if (fsync(log_idx_fd) == -1)
- __DEBUG(LEVEL_ERROR, "fsync idx fd error when db close");
+ __ERROR("fsync idx fd error when db close");
}
if (log_db_fd > 0) {
if (fsync(log_db_fd) == -1)
- __DEBUG(LEVEL_ERROR, "fsync db fd error when db close");
+ __ERROR("fsync db fd error when db close");
}
}
@@ -265,7 +265,7 @@ int index_get(struct index *idx, struct slice *sk, struct slice *sv)
if (value_off != 0UL) {
__be32 be32len;
if (lseek(idx->db_rfd, value_off, SEEK_SET) == -1) {
- __DEBUG(LEVEL_ERROR, "seek error when index get");
+ __ERROR("seek error when index get");
goto out_get;
}
@@ -314,7 +314,7 @@ void index_free(struct index *idx)
_index_flush(idx);
if (idx->max_merge_time > 0) {
- __DEBUG(LEVEL_INFO, "max merge time:%lu sec;"
+ __INFO("max merge time:%lu sec;"
"the slowest merge-count:%d and merge-speed:%.1f/sec"
, idx->max_merge_time
, idx->slowest_merge_count
View
@@ -89,20 +89,20 @@ int _log_read(char *logname, struct skiplist *list)
fd = open(logname, O_RDWR, 0644);
if (fd == -1) {
- __DEBUG(LEVEL_ERROR, "open log error when log read, file:<%s>", logname);
+ __ERROR("open log error when log read, file:<%s>", logname);
return 0;
}
size = lseek(fd, 0, SEEK_END);
if (size == 0) {
- __DEBUG(LEVEL_ERROR, "seek end error when log read,file:<%s>", logname);
+ __ERROR("seek end error when log read,file:<%s>", logname);
return 0;
}
rem = size;
if (lseek(fd, 0, SEEK_SET) == -1) {
- __DEBUG(LEVEL_ERROR, "seek begin when log read,file:<%s>", logname);
+ __ERROR("seek begin when log read,file:<%s>", logname);
return 0;
}
@@ -162,7 +162,7 @@ int _log_read(char *logname, struct skiplist *list)
rem -= isize;
}
- __DEBUG(LEVEL_DEBUG, "recovery count ADD#%d, DEL#%d", count, del_count);
+ __DEBUG("recovery count ADD#%d, DEL#%d", count, del_count);
return 1;
}
@@ -204,7 +204,7 @@ int log_recovery(struct log *l, struct skiplist *list)
memset(l->log_new, 0, FILE_PATH_SIZE);
snprintf(l->log_new, FILE_PATH_SIZE, "%s/%s", l->basedir, new_log);
- __DEBUG(LEVEL_DEBUG, "prepare to recovery from new log#%s", l->log_new);
+ __DEBUG("prepare to recovery from new log#%s", l->log_new);
ret = _log_read(l->log_new, list);
if (ret == 0)
@@ -215,7 +215,7 @@ int log_recovery(struct log *l, struct skiplist *list)
memset(l->log_old, 0, FILE_PATH_SIZE);
snprintf(l->log_old, FILE_PATH_SIZE, "%s/%s", l->basedir, old_log);
- __DEBUG(LEVEL_DEBUG, "prepare to recovery from old log#%s", l->log_old);
+ __DEBUG("prepare to recovery from old log#%s", l->log_old);
ret = _log_read(l->log_old, list);
if (ret == 0)
View
@@ -130,7 +130,7 @@ void _add_bloom(struct sst *sst, int fd, int count, int max_len)
bloom_add(sst->bloom, blks[i].key);
if (munmap(blks, blk_sizes) == -1)
- __DEBUG(LEVEL_ERROR, "Error:un-mmapping the file");
+ __ERROR("Error:un-mmapping the file");
}
void _sst_load(struct sst *sst)
@@ -274,12 +274,12 @@ void *_write_mmap(struct sst *sst, struct skipnode *x, size_t count, int need_ne
#ifdef MSYNC
if (msync(blks, sizes, MS_SYNC) == -1) {
- __DEBUG(LEVEL_ERROR, "Msync error");
+ __ERROR("Msync error");
}
#endif
if (munmap(blks, sizes) == -1) {
- __DEBUG(LEVEL_ERROR, "Un-mmapping the file");
+ __ERROR("Un-mmapping the file");
}
footer.count = to_be32(count);
@@ -365,7 +365,7 @@ struct skiplist *_read_mmap(struct sst *sst, size_t count)
}
if (munmap(blks, blk_sizes) == -1)
- __DEBUG(LEVEL_ERROR, "Un-mmapping the file");
+ __ERROR("Un-mmapping the file");
out:
close(fd);
@@ -389,20 +389,20 @@ uint64_t _read_offset(struct sst *sst, struct slice *sk)
fd = open(file, O_RDWR, 0644);
if (fd == -1) {
- __DEBUG(LEVEL_ERROR, "open sst error when read offset");
+ __ERROR("open sst error when read offset");
return 0UL;
}
result = lseek(fd, -fsize, SEEK_END);
if (result == -1) {
- __DEBUG(LEVEL_ERROR, "lseek error when read offset");
+ __ERROR("lseek error when read offset");
close(fd);
return off;
}
result = read(fd, &footer, fsize);
if (result == -1) {
- __DEBUG(LEVEL_ERROR, "read footer error when read offset");
+ __ERROR("read footer error when read offset");
close(fd);
return off;
}
@@ -423,7 +423,7 @@ uint64_t _read_offset(struct sst *sst, struct slice *sk)
/* Blocks read */
blks= mmap(0, blk_sizes, PROT_READ, MAP_SHARED, fd, 0);
if (blks == MAP_FAILED) {
- __DEBUG(LEVEL_ERROR, "Map_failed when read");
+ __ERROR("Map_failed when read");
close(fd);
return off;
}
@@ -444,7 +444,7 @@ uint64_t _read_offset(struct sst *sst, struct slice *sk)
}
if (munmap(blks, blk_sizes) == -1)
- __DEBUG(LEVEL_ERROR, "un-mmapping the file");
+ __ERROR("un-mmapping the file");
close(fd);
return off;
View
@@ -248,7 +248,7 @@ void _process_cmd(int fd, struct request *req)
break;
case CMD_SHUTDOWN:
- __DEBUG(LEVEL_ERROR, "db-server shutdown...");
+ __ERROR("db-server shutdown...");
db_close(_svr.db);
exit(2);
break;
@@ -326,7 +326,7 @@ int server_cron(struct aeEventLoop *eventLoop, long long id, void *clientData)
(void) id;
(void) clientData;
- __DEBUG(LEVEL_WARNING, "%d clients connected", _clicount);
+ __WARN("%d clients connected", _clicount);
return 3000;
}
@@ -364,22 +364,22 @@ int main(int argc, char **argv)
* set nonblock: single process no effect
*/
if (anetNonBlock(_svr.neterr, _svr.fd) == ANET_ERR) {
- __DEBUG(LEVEL_ERROR, "set nonblock #%s",_svr.neterr);
+ __ERROR("set nonblock #%s",_svr.neterr);
exit(1);
}
aeCreateTimeEvent(_svr.el, 3000, server_cron, NULL, NULL);
/*handler*/
if (aeCreateFileEvent(_svr.el, _svr.fd, AE_READABLE, accept_handler, NULL) == AE_ERR)
- __DEBUG(LEVEL_ERROR, "creating file event");
+ __ERROR("creating file event");
- __DEBUG(LEVEL_INFO, "nessDB server starting, port:%d, pid:%d", PORT, (long)getpid());
+ __INFO("nessDB server starting, port:%d, pid:%d", PORT, (long)getpid());
printf("%s", _ascii_logo);
aeMain(_svr.el);
- __DEBUG(LEVEL_ERROR, "oops,exit");
+ __ERROR("oops,exit");
aeDeleteEventLoop(_svr.el);
nessdb_close(_svr.db);
View
@@ -171,7 +171,7 @@ void _reset_request(struct request *req)
int request_append(struct request *req, const char *buf, int n)
{
if ((req->len + n) > REQ_MAX_BUFFSIZE){
- __DEBUG(LEVEL_ERROR, "req->len #%d", req->len);
+ __ERROR("req->len #%d", req->len);
return -1;
}
@@ -188,7 +188,7 @@ int request_parse(struct request *req)
if (req->multilen == 0) {
if (req_state_len(req, sb) != STATE_CONTINUE) {
- __DEBUG(LEVEL_ERROR,"argc error,buffer:%s", req->querybuf);
+ __ERROR("argc error,buffer:%s", req->querybuf);
return -1;
}
req->argc = atoi(sb);
@@ -211,7 +211,7 @@ int request_parse(struct request *req)
/*parse argv len*/
memset(sb, 0, BUF_SIZE);
if (req_state_len(req, sb) != STATE_CONTINUE) {
- __DEBUG(LEVEL_ERROR, "argv's len error,packet:%s\n", sb);
+ __ERROR("argv's len error,packet:%s\n", sb);
return -1;
}
argv_len = atoi(sb);

0 comments on commit 2b92576

Please sign in to comment.