Skip to content

Commit 3cb87ff

Browse files
author
stvchu
committed
* Bugfix: 64bit box can not specify memory pool size larger than 2G with '-m' option
* new option '-E' to automatically remove log files that are no longer needed, but PLEASE NOTICE: - "Automatic log file removal is likely to make catastrophic recovery impossible." - "Replication applications will rarely want to configure automatic log file removal as it increases the likelihood a master will be unable to satisfy a client's request for a recent log record." So this option will be disabled when replication is on regardless of whether you specify it. * Bugfix: slight security issue when client specify a negative value length git-svn-id: http://memcachedb.googlecode.com/svn/trunk@94 8a849e15-1439-0410-a037-f546adf1399c
1 parent 66eb5cd commit 3cb87ff

File tree

6 files changed

+53
-12
lines changed

6 files changed

+53
-12
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2009-02-26 Steve Chu <[email protected]>
2+
* Bugfix: 64bit box can not specify memory pool size larger than 2G with '-m' option
3+
* new option '-E' to automatically remove log files that are no longer needed, but PLEASE NOTICE:
4+
- "Automatic log file removal is likely to make catastrophic recovery impossible."
5+
- "Replication applications will rarely want to configure automatic log file removal as it increases the likelihood a master will be unable to satisfy a client's request for a recent log record." So this option will be disabled when replication is on regardless of whether you specify it.
6+
* Bugfix: slight security issue when client specify a negative value length
7+
18
2009-01-13 Steve Chu <[email protected]>
29
* some default settings policy changed(because most of us is using powerful box):
310
max simultaneous connections ('-c'): 1024 -> 4096

bdb.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void bdb_settings_init(void)
4444
bdb_settings.page_size = 4096; /* default is 4K */
4545
bdb_settings.db_type = DB_BTREE;
4646
bdb_settings.txn_nosync = 0; /* default DB_TXN_NOSYNC is off */
47+
bdb_settings.log_auto_remove = 0; /* default DB_LOG_AUTO_REMOVE is off */
4748
bdb_settings.dldetect_val = 100 * 1000; /* default is 100 millisecond */
4849
bdb_settings.chkpoint_val = 60 * 5;
4950
bdb_settings.memp_trickle_val = 30;
@@ -125,10 +126,16 @@ void bdb_env_init(void){
125126
exit(EXIT_FAILURE);
126127
}
127128
}
128-
129+
129130
/* set MPOOL size */
130-
env->set_cachesize(env, 0, bdb_settings.cache_size, 0);
131-
131+
if (sizeof(void *) == 4 && bdb_settings.cache_size > (1024uLL * 1024uLL * 1024uLL * 2uLL)) {
132+
fprintf(stderr, "32bit box only max 2GB memory pool allowed\n");
133+
exit(EXIT_FAILURE);
134+
}
135+
env->set_cachesize(env, (u_int32_t) (bdb_settings.cache_size / (1024uLL * 1024uLL * 1024uLL)),
136+
(u_int32_t) (bdb_settings.cache_size % (1024uLL * 1024uLL * 1024uLL)),
137+
(int) (bdb_settings.cache_size / (1024uLL * 1024uLL * 1024uLL * 4uLL) + 1uLL) );
138+
132139
/* set DB_TXN_NOSYNC flag */
133140
if (bdb_settings.txn_nosync){
134141
env->set_flags(env, DB_TXN_NOSYNC, 1);
@@ -145,6 +152,18 @@ void bdb_env_init(void){
145152
/* set transaction log buffer */
146153
env->set_lg_bsize(env, bdb_settings.txn_lg_bsize);
147154

155+
/* NOTICE:
156+
If set, Berkeley DB will automatically remove log files that are no longer needed.
157+
Automatic log file removal is likely to make catastrophic recovery impossible.
158+
Replication applications will rarely want to configure automatic log file removal as it
159+
increases the likelihood a master will be unable to satisfy a client's request
160+
for a recent log record.
161+
*/
162+
if (!bdb_settings.is_replicated && bdb_settings.log_auto_remove){
163+
fprintf(stderr, "log_auto_remove\n");
164+
env->log_set_config(env, DB_LOG_AUTO_REMOVE, 1);
165+
}
166+
148167
/* if no home dir existed, we create it */
149168
if (0 != access(bdb_settings.env_home, F_OK)) {
150169
if (0 != mkdir(bdb_settings.env_home, 0750)) {

memcachedb.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
12601260
exptime = strtol(tokens[3].value, NULL, 10);
12611261
vlen = strtol(tokens[4].value, NULL, 10);
12621262

1263-
if(errno == ERANGE || ((flags == 0 || exptime == 0) && errno == EINVAL)) {
1263+
if(errno == ERANGE || ((flags == 0 || exptime == 0) && errno == EINVAL)
1264+
|| vlen < 0) {
12641265
out_string(c, "CLIENT_ERROR bad command line format");
12651266
return;
12661267
}
@@ -2348,6 +2349,7 @@ static void usage(void) {
23482349
printf("-e <num> percent of the pages in the cache that should be clean, default is 60%%\n");
23492350
printf("-D <num> do deadlock detecting every <num> millisecond, 0 for disable, default is 100ms\n");
23502351
printf("-N enable DB_TXN_NOSYNC to gain big performance improved, default is off\n");
2352+
printf("-E automatically remove log files that are no longer needed\n");
23512353
printf("-X allocate region memory from the heap, default is off\n");
23522354
printf("--------------------Replication Options-------------------------------\n");
23532355
printf("-R identifies the host and port used by this site (required).\n");
@@ -2564,7 +2566,7 @@ int main (int argc, char **argv) {
25642566
setbuf(stderr, NULL);
25652567

25662568
/* process arguments */
2567-
while ((c = getopt(argc, argv, "a:U:p:s:c:hivl:dru:P:t:b:f:H:B:m:A:L:C:T:e:D:NXMSR:O:n:")) != -1) {
2569+
while ((c = getopt(argc, argv, "a:U:p:s:c:hivl:dru:P:t:b:f:H:B:m:A:L:C:T:e:D:NEXMSR:O:n:")) != -1) {
25682570
switch (c) {
25692571
case 'a':
25702572
/* access for unix domain socket, as octal mask (like chmod)*/
@@ -2643,7 +2645,7 @@ int main (int argc, char **argv) {
26432645
}
26442646
break;
26452647
case 'm':
2646-
bdb_settings.cache_size = atoi(optarg) * 1024 * 1024;
2648+
bdb_settings.cache_size = atoi(optarg) * 1024uLL * 1024uLL;
26472649
break;
26482650
case 'A':
26492651
bdb_settings.page_size = atoi(optarg);
@@ -2671,6 +2673,9 @@ int main (int argc, char **argv) {
26712673
case 'N':
26722674
bdb_settings.txn_nosync = 1;
26732675
break;
2676+
case 'E':
2677+
bdb_settings.log_auto_remove = 1;
2678+
break;
26742679
case 'X':
26752680
bdb_settings.env_flags |= DB_PRIVATE;
26762681
break;

memcachedb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ enum mdb_rep_role { MDB_MASTER, MDB_CLIENT, MDB_UNKNOWN };
124124
struct bdb_settings {
125125
char *db_file; /* db filename, where dbfile located. */
126126
char *env_home; /* db env home dir path */
127-
u_int32_t cache_size; /* cache size */
127+
u_int64_t cache_size; /* cache size */
128128
u_int32_t txn_lg_bsize; /* transaction log buffer size */
129129
u_int32_t page_size; /* underlying database pagesize*/
130130
DBTYPE db_type;
131131
int txn_nosync; /* DB_TXN_NOSYNC flag, if 1 will lose transaction's durability for performance */
132+
int log_auto_remove; /* DB_LOG_AUTO_REMOVE flag, if 1 will make catastrophic recovery impossible. */
132133
int dldetect_val; /* do deadlock detect every *db_lock_detect_val* millisecond, 0 for disable */
133134
int chkpoint_val; /* do checkpoint every *db_chkpoint_val* second, 0 for disable */
134135
int memp_trickle_val; /* do memp_trickle every *memp_trickle_val* second, 0 for disable */

run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
#./memcachedb -p21201 -d -r -H ./testenv -N -v >log 2>&1
4-
./memcachedb -p21201 -d -r -H ./testenv0 -N -R 127.0.0.1:31201 -M -n 2 -v >log_m 2>&1
5-
sleep 5
6-
./memcachedb -p21202 -d -r -H ./testenv1 -N -R 127.0.0.1:31202 -O 127.0.0.1:31201 -S -n 2 -v >log_s 2>&1
3+
./memcachedb -p21201 -d -r -H ./testenv -N -E -v >log 2>&1
4+
#./memcachedb -p21201 -d -r -H ./testenv0 -N -R 127.0.0.1:31201 -M -n 2 -v >log_m 2>&1
5+
#sleep 5
6+
#./memcachedb -p21202 -d -r -H ./testenv1 -N -R 127.0.0.1:31202 -O 127.0.0.1:31201 -S -n 2 -v >log_s 2>&1

stats.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
void stats_bdb(char *temp){
2424
char *pos = temp;
2525
int ret;
26+
u_int32_t gbytes = 0;
27+
u_int32_t bytes = 0;
28+
int ncache = 0;
2629
/* get bdb version */
2730
pos += sprintf(pos, "STAT db_ver %d.%d.%d\r\n", bdb_version.majver,
2831
bdb_version.minver,
@@ -40,9 +43,15 @@ void stats_bdb(char *temp){
4043
pos += sprintf(pos, "STAT db_type hash\r\n");
4144
}
4245
}
43-
pos += sprintf(pos, "STAT cache_size %u\r\n", bdb_settings.cache_size);
46+
47+
/* get cache size */
48+
if((ret = env->get_cachesize(env, &gbytes, &bytes, &ncache)) == 0){
49+
pos += sprintf(pos, "STAT cache_size %lu/%lu/%d\r\n", gbytes, bytes, ncache);
50+
}
51+
4452
pos += sprintf(pos, "STAT txn_lg_bsize %u\r\n", bdb_settings.txn_lg_bsize);
4553
pos += sprintf(pos, "STAT txn_nosync %d\r\n", bdb_settings.txn_nosync);
54+
pos += sprintf(pos, "STAT log_auto_remove %d\r\n", bdb_settings.log_auto_remove);
4655
pos += sprintf(pos, "STAT dldetect_val %d\r\n", bdb_settings.dldetect_val);
4756
pos += sprintf(pos, "STAT chkpoint_val %d\r\n", bdb_settings.chkpoint_val);
4857
pos += sprintf(pos, "STAT memp_trickle_val %d\r\n", bdb_settings.memp_trickle_val);

0 commit comments

Comments
 (0)