Skip to content
Browse files

now can add a unlimited queue where the value euqals 0

git-svn-id: http://svn1.bj.corp.yahoo.com/repos/WebEng/lifesearch/memcacheq@59824 82b2e94c-9313-0410-8ced-81db5252d7f6
  • Loading branch information...
1 parent d5b9e0e commit f9c176a685dd45bd035f1875401c609e4c94d456 xunxin committed
Showing with 115 additions and 72 deletions.
  1. +5 −4 bdb.c
  2. +1 −6 memcacheq.c
  3. +0 −1 memcacheq.h
  4. +3 −1 run.sh
  5. +13 −60 test/basic.t
  6. +93 −0 test/enable-limit.t
View
9 bdb.c
@@ -651,7 +651,7 @@ item *bdb_get(char *key, size_t nkey){
if (ret != 0){
goto err;
}
- if (settings.enable_size_limit) {
+ if (queue_rec.max_size) {
UPDATE_QUEUE_LENGTH_LOCK();
ret = update_queue_length(txn, key, nkey, -1);
UPDATE_QUEUE_LENGTH_UNLOCK();
@@ -700,7 +700,8 @@ int bdb_add(char *key, size_t nkey, item *it){
char* max_size_str = ITEM_data(it);
max_size = atoi(max_size_str);
- if (max_size < 1) {
+ if (strlen(max_size_str) < 1 ||
+ *max_size_str < '0' || *max_size_str > '9' || max_size < 0) {
if (settings.verbose > 1) {
fprintf(stderr, "bdb_add: max_size: %d is not valid!\n", max_size);
}
@@ -786,7 +787,7 @@ int bdb_put(char *key, size_t nkey, item *it){
queue_dbp = queue_rec.queue_dbp;
- if (settings.enable_size_limit && queue_rec.size + 1 > queue_rec.max_size) {
+ if (queue_rec.max_size && (queue_rec.size + 1 > queue_rec.max_size)) {
if (txn != NULL){
txn->abort(txn);
}
@@ -801,7 +802,7 @@ int bdb_put(char *key, size_t nkey, item *it){
goto err;
}
- if (settings.enable_size_limit) {
+ if (queue_rec.max_size) {
UPDATE_QUEUE_LENGTH_LOCK();
ret = update_queue_length(txn, key, nkey, 1);
UPDATE_QUEUE_LENGTH_UNLOCK();
View
7 memcacheq.c
@@ -153,7 +153,6 @@ static void settings_init(void) {
#else
settings.num_threads = 1;
#endif
- settings.enable_size_limit = 0; /* default no limit of queue size */
}
/*
@@ -1929,7 +1928,6 @@ static void usage(void) {
"-r maximize core file limit\n"
"-u <username> assume identity of <username> (only when run as root)\n"
"-c <num> max simultaneous connections, default is 1024\n"
- "-S enabled limit of queue size\n"
"-v verbose (print errors/warnings while in event loop)\n"
"-vv very verbose (also print client commands/reponses)\n"
"-h print this help and exit\n"
@@ -2162,7 +2160,7 @@ int main (int argc, char **argv) {
setbuf(stderr, NULL);
/* process arguments */
- while ((c = getopt(argc, argv, "a:U:p:s:c:Shivl:dru:P:t:f:H:m:A:L:C:T:e:D:E:B:NMSR:O:")) != -1) {
+ while ((c = getopt(argc, argv, "a:U:p:s:c:hivl:dru:P:t:f:H:m:A:L:C:T:e:D:E:B:NMSR:O:")) != -1) {
switch (c) {
case 'a':
/* access for unix domain socket, as octal mask (like chmod)*/
@@ -2181,9 +2179,6 @@ int main (int argc, char **argv) {
case 'c':
settings.maxconns = atoi(optarg);
break;
- case 'S':
- settings.enable_size_limit = 1;
- break;
case 'h':
usage();
exit(EXIT_SUCCESS);
View
1 memcacheq.h
@@ -101,7 +101,6 @@ struct settings {
char *socketpath; /* path to unix socket if using local socket */
int access; /* access mask (a la chmod) for unix domain socket */
int num_threads; /* number of libevent threads to run */
- int enable_size_limit; /* enable queue size limit */
};
extern struct stats stats;
View
4 run.sh
@@ -6,7 +6,9 @@ killall memcacheq
rm -rf mydata
#./memcacheq -p 22201 -B 65500 -d -r -c 1024 -m 256 -H ./mydata -A 65536 -N -v > ./testenv.log 2>&1
sleep 1
-exec ./memcacheq -p 22201 -B 992 -r -c 1024 -m 64 -S -A 2048 -H ./mydata -vv
+exec ./memcacheq -p 22201 -B 4064 -r -c 1024 -m 64 -S -A 4096 -H ./mydata
+#-N -v > ./testenv.log 2>&1
+
#exec ./memcacheq -p 22201 -B 1020 -d -r -c 1024 -m 256 -A 1024 -H ./mydata -N -v > ./testenv.log 2>&1
View
73 test/basic.t
@@ -3,87 +3,40 @@
use strict;
use warnings;
+use FindBin;
use Memcached::libmemcached qw(/^memcached/);
-
use Test::More 'no_plan';
+#warn $FindBin::Bin;
+
+system("rm -rf $FindBin::Bin/../mydata");
+system("$FindBin::Bin/../memcacheq -d -p 22202 -B 4064 -r -c 1024 -m 64 -A 4096 -H $FindBin::Bin/../mydata -N -v > ./testenv.log 2>&1");
+
my $memc = memcached_create();
-memcached_server_add($memc, "localhost", 22201);
+memcached_server_add($memc, "localhost", 22202);
my $q = "test" . time;
-#my $q = "test";
my $ret;
my $err;
my $max_size = 10;
-$ret = memcached_add($memc, $q, "xaf");
-$err = $memc->errstr;
-ok(!(defined $ret), "add a queue no max size");
-is($err, "NOT STORED");
-
-$ret = memcached_add($memc, $q, $max_size);
+$ret = memcached_add($memc, $q, 0);
$err = $memc->errstr;
-ok($ret, "add a queue");
+ok($ret, "add a queue no size limited");
is($err, "SUCCESS");
-$ret = memcached_add($memc, $q, 100);
-$err = $memc->errstr;
-ok(!(defined $ret), "add a queue again");
-is($err, "NOT STORED");
-
for my $i (1..$max_size) {
$ret = memcached_set($memc, $q, $i);
ok($ret, "set a item $i");
}
$ret = memcached_set($memc, $q, $max_size + 1);
-ok(!$ret, "set a item will exceed the limit of max size");
-
-for my $i (1..$max_size) {
- $ret = memcached_get($memc, $q);
- is($ret, $i, "get item $i");
-}
-$ret = memcached_get($memc, $q);
-ok(!$ret, "get a item will exceed the limit of max size");
-
-my $q2 = "test-q2" . time;
-$max_size = 5;
-
-$ret = memcached_add($memc, $q2, "xaf");
-$err = $memc->errstr;
-ok(!(defined $ret), "add a queue no max size");
-is($err, "NOT STORED");
-
-
-$ret = memcached_add($memc, $q2, $max_size);
-$err = $memc->errstr;
-ok($ret, "add a queue");
-is($err, "SUCCESS");
-
-$ret = memcached_add($memc, $q2, 100);
-$err = $memc->errstr;
-ok(!(defined $ret), "add a queue again");
-is($err, "NOT STORED");
-
-for my $i (1..$max_size) {
- $ret = memcached_set($memc, $q2, $i);
- ok($ret, "set a item $i");
-}
-
-$ret = memcached_set($memc, $q2, $max_size + 1);
-ok(!$ret, "set a item will exceed the limit of max size");
-
-for my $i (1..$max_size) {
- $ret = memcached_get($memc, $q2);
- is($ret, $i, "get item $i");
-}
-$ret = memcached_get($memc, $q2);
-ok(!$ret, "get a item will exceed the limit of max size");
+ok($ret, "set a item exceed the max size limit when not enabled limit");
-ok(memcached_delete($memc, $q), "delete queue 1");
-ok(memcached_delete($memc, $q2), "delete queue 2");
-ok(!memcached_delete($memc, $q2), "delete queue 2 again");
+$ret = memcached_set($memc, $q, 't' x (4064-30-(length $q)));
+ok($ret, "set a item exceed the max size limit when not enabled limit");
+system("pkill memcacheq");
View
93 test/enable-limit.t
@@ -0,0 +1,93 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use Memcached::libmemcached qw(/^memcached/);
+
+use Test::More 'no_plan';
+
+system("rm -rf $FindBin::Bin/../mydata");
+system("$FindBin::Bin/../memcacheq -d -p 22202 -B 4064 -r -c 1024 -m 64 -A 4096 -H $FindBin::Bin/../mydata -N -v > ./testenv.log 2>&1");
+
+my $memc = memcached_create();
+memcached_server_add($memc, "localhost", 22202);
+
+my $q = "test" . time;
+#my $q = "test";
+
+my $ret;
+my $err;
+my $max_size = 10;
+
+$ret = memcached_add($memc, $q, "xaf");
+$err = $memc->errstr;
+ok(!(defined $ret), "add a queue no max size");
+is($err, "NOT STORED");
+
+
+$ret = memcached_add($memc, $q, $max_size);
+$err = $memc->errstr;
+ok($ret, "add a queue");
+is($err, "SUCCESS");
+
+$ret = memcached_add($memc, $q, 100);
+$err = $memc->errstr;
+ok(!(defined $ret), "add a queue again");
+is($err, "NOT STORED");
+
+for my $i (1..$max_size) {
+ $ret = memcached_set($memc, $q, $i);
+ ok($ret, "set a item $i");
+}
+
+$ret = memcached_set($memc, $q, $max_size + 1);
+ok(!$ret, "set a item will exceed the limit of max size");
+
+for my $i (1..$max_size) {
+ $ret = memcached_get($memc, $q);
+ is($ret, $i, "get item $i");
+}
+$ret = memcached_get($memc, $q);
+ok(!$ret, "get a item will exceed the limit of max size");
+
+my $q2 = "test-q2" . time;
+$max_size = 5;
+
+$ret = memcached_add($memc, $q2, "xaf");
+$err = $memc->errstr;
+ok(!(defined $ret), "add a queue no max size");
+is($err, "NOT STORED");
+
+
+$ret = memcached_add($memc, $q2, $max_size);
+$err = $memc->errstr;
+ok($ret, "add a queue");
+is($err, "SUCCESS");
+
+$ret = memcached_add($memc, $q2, 100);
+$err = $memc->errstr;
+ok(!(defined $ret), "add a queue again");
+is($err, "NOT STORED");
+
+for my $i (1..$max_size) {
+ $ret = memcached_set($memc, $q2, $i);
+ ok($ret, "set a item $i");
+}
+
+$ret = memcached_set($memc, $q2, $max_size + 1);
+ok(!$ret, "set a item will exceed the limit of max size");
+
+for my $i (1..$max_size) {
+ $ret = memcached_get($memc, $q2);
+ is($ret, $i, "get item $i");
+}
+$ret = memcached_get($memc, $q2);
+ok(!$ret, "get a item will exceed the limit of max size");
+
+ok(memcached_delete($memc, $q), "delete queue 1");
+ok(memcached_delete($memc, $q2), "delete queue 2");
+ok(!memcached_delete($memc, $q2), "delete queue 2 again");
+
+system("pkill memcacheq");

0 comments on commit f9c176a

Please sign in to comment.
Something went wrong with that request. Please try again.