From: levin li <xingke.lwp at taobao.com> Signed-off-by: levin li <xingke.lwp at taobao.com> --- sheep/sheep.c | 16 +++++++++++++++- sheep/sheep_priv.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sheep/sheep.c b/sheep/sheep.c index 380a129..8b78669 100644 --- a/sheep/sheep.c +++ b/sheep/sheep.c @@ -48,12 +48,13 @@ static struct option const long_options[] = { {"port", required_argument, NULL, 'p'}, {"vnodes", required_argument, NULL, 'v'}, {"enable-cache", no_argument, NULL, 'w'}, + {"cache-size", optional_argument, NULL, 'W'}, {"zone", required_argument, NULL, 'z'}, {"pidfile", required_argument, NULL, 'P'}, {NULL, 0, NULL, 0}, }; -static const char *short_options = "c:dDfghl:op:P:v:wy:z:"; +static const char *short_options = "c:dDfghl:op:P:v:wW:y:z:"; static void usage(int status) { @@ -77,6 +78,7 @@ Options:\n\ -P, --pidfile create a pid file\n\ -v, --vnodes specify the number of virtual nodes\n\ -w, --enable-cache enable object cache\n\ + -W, --cache-size specify the max cache size in megabytes\n\ -y, --myaddr specify the address advertised to other sheep\n\ -z, --zone specify the zone id\n\ ", PACKAGE_VERSION, program_name); @@ -186,6 +188,7 @@ int main(int argc, char **argv) int log_level = SDOG_INFO; char path[PATH_MAX]; int64_t zone = -1; + int64_t cache_size = 0; int nr_vnodes = SD_DEFAULT_VNODES; bool explicit_addr = false; int af; @@ -263,6 +266,17 @@ int main(int argc, char **argv) vprintf(SDOG_INFO, "enable write cache\n"); enable_write_cache = 1; break; + case 'W': + cache_size = strtol(optarg, &p, 10); + if (optarg == p || cache_size < 0 || + UINT32_MAX < cache_size) { + fprintf(stderr, "Invalid cache size '%s': " + "must be an integer between 0 and %u\n", + optarg, UINT32_MAX); + exit(1); + } + sys->cache_size = cache_size * 1024; + break; case 'v': nr_vnodes = strtol(optarg, &p, 10); if (optarg == p || nr_vnodes < 0 || SD_MAX_VNODES < nr_vnodes) { diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h index 530fe14..fe61411 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -87,6 +87,8 @@ struct cluster_info { uint32_t status; uint16_t flags; + uint64_t cache_size; + /* * List of nodes that were past of the last epoch before a shutdown, * but failed to join. -- 1.7.10 |