From: levin li <xingke.lwp at taobao.com> Signed-off-by: levin li <xingke.lwp at taobao.com> --- sheep/sheep.c | 17 ++++++++++++++--- sheep/sheep_priv.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sheep/sheep.c b/sheep/sheep.c index 380a129..9f371ba 100644 --- a/sheep/sheep.c +++ b/sheep/sheep.c @@ -53,7 +53,7 @@ static struct option const long_options[] = { {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:w:y:z:"; static void usage(int status) { @@ -76,7 +76,7 @@ Options:\n\ -p, --port specify the TCP port on which to listen\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, --enable-cache enable object cache and 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 +186,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; @@ -260,8 +261,18 @@ int main(int argc, char **argv) sys->this_node.zone = zone; break; case 'w': - vprintf(SDOG_INFO, "enable write cache\n"); enable_write_cache = 1; + cache_size = strtol(optarg, &p, 10); + if (optarg == p || cache_size < 0 || + UINT64_MAX < cache_size) { + fprintf(stderr, "Invalid cache size '%s': " + "must be an integer between 0 and %lu\n", + optarg, UINT64_MAX); + exit(1); + } + vprintf(SDOG_INFO, "enable write cache, max cache size %" PRIu64 "M\n", + cache_size); + sys->cache_size = cache_size * 1024 * 1024; break; case 'v': nr_vnodes = strtol(optarg, &p, 10); 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.1 |