[Sheepdog] [PATCH] sheep: support specifying the initial count of virtual nodes

Liu Yuan namei.unix at gmail.com
Wed Feb 29 03:19:10 CET 2012


On 02/29/2012 12:48 AM, MORITA Kazutaka wrote:

> With this patch, you can set the weight of each node with the -v
> option.
> 
> Example:
> 
>   $ ./sheep/sheep /store/0 -p 7000 -z 0 -v 1000
>   $ ./sheep/sheep /store/1 -p 7001 -z 1 -v 2000
>   $ ./sheep/sheep /store/2 -p 7002 -z 2 -v 3000
>   $ ./collie/collie cluster format -c 1
>   using backend simple store
>   $ ./collie/collie node list
>   M   Id   Host:Port         V-Nodes       Zone
>   -    0   10.68.14.1:7000        1000          0
>   -    1   10.68.14.1:7001        2000          1
>   -    2   10.68.14.1:7002        3000          2
>   $ ./collie/collie vdi create image 600M -P
>   $ ./collie/collie node info
>   Id      Size    Used    Use%
>    0      188 GB  100 MB    0%
>    1      188 GB  200 MB    0%
>    2      188 GB  304 MB    0%
>   Total   564 GB  604 MB    0%
> 
>   Total virtual image size  600 MB
> 
> If you specify zero to the number of virtual nodes, no data will not
> be stored to the node.
> 


I guess 'not' in the 'no data will not' is not intended. Others looks
good to me.

Reviewed-by: Liu Yuan <tailai.ly at taobao.com>

> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
>  sheep/group.c      |    4 ++--
>  sheep/sheep.c      |   16 ++++++++++++++--
>  sheep/sheep_priv.h |    2 +-
>  3 files changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/sheep/group.c b/sheep/group.c
> index 1a212e3..dda468c 100644
> --- a/sheep/group.c
> +++ b/sheep/group.c
> @@ -1382,7 +1382,7 @@ oom:
>  	panic("failed to allocate memory for a confchg event\n");
>  }
>  
> -int create_cluster(int port, int64_t zone)
> +int create_cluster(int port, int64_t zone, int nr_vnodes)
>  {
>  	int ret;
>  	struct cdrv_handlers handlers = {
> @@ -1407,7 +1407,7 @@ int create_cluster(int port, int64_t zone)
>  		return -1;
>  
>  	sys->this_node.port = port;
> -	sys->this_node.nr_vnodes = SD_DEFAULT_VNODES;
> +	sys->this_node.nr_vnodes = nr_vnodes;
>  	if (zone == -1) {
>  		/* use last 4 bytes as zone id */
>  		uint8_t *b = sys->this_node.addr + 12;
> diff --git a/sheep/sheep.c b/sheep/sheep.c
> index 94b4a9e..b3b834b 100644
> --- a/sheep/sheep.c
> +++ b/sheep/sheep.c
> @@ -36,12 +36,13 @@ static struct option const long_options[] = {
>  	{"debug", no_argument, NULL, 'd'},
>  	{"directio", no_argument, NULL, 'D'},
>  	{"zone", required_argument, NULL, 'z'},
> +	{"vnodes", required_argument, NULL, 'v'},
>  	{"cluster", required_argument, NULL, 'c'},
>  	{"help", no_argument, NULL, 'h'},
>  	{NULL, 0, NULL, 0},
>  };
>  
> -static const char *short_options = "p:fl:dDz:c:h";
> +static const char *short_options = "p:fl:dDz:v:c:h";
>  
>  static void usage(int status)
>  {
> @@ -59,6 +60,7 @@ Options:\n\
>    -d, --debug             include debug messages in the log\n\
>    -D, --directio          use direct IO when accessing the object store\n\
>    -z, --zone              specify the zone id\n\
> +  -v, --vnodes            specify the number of virtual nodes\n\
>    -c, --cluster           specify the cluster driver\n\
>    -h, --help              display this help and exit\n\
>  ", PACKAGE_VERSION, program_name);
> @@ -92,6 +94,7 @@ int main(int argc, char **argv)
>  	int log_level = SDOG_INFO;
>  	char path[PATH_MAX];
>  	int64_t zone = -1;
> +	int nr_vnodes = SD_DEFAULT_VNODES;
>  	char *p;
>  	struct cluster_driver *cdrv;
>  
> @@ -139,6 +142,15 @@ int main(int argc, char **argv)
>  			}
>  			sys->this_node.zone = zone;
>  			break;
> +		case 'v':
> +			nr_vnodes = strtol(optarg, &p, 10);
> +			if (optarg == p || nr_vnodes < 0 || SD_MAX_VNODES < nr_vnodes) {
> +				fprintf(stderr, "Invalid number of virtual nodes '%s': "
> +					"must be an integer between 0 and %u\n",
> +					optarg, SD_MAX_VNODES);
> +				exit(1);
> +			}
> +			break;
>  		case 'c':
>  			sys->cdrv = find_cdrv(optarg);
>  			if (!sys->cdrv) {
> @@ -192,7 +204,7 @@ int main(int argc, char **argv)
>  	if (ret)
>  		exit(1);
>  
> -	ret = create_cluster(port, zone);
> +	ret = create_cluster(port, zone, nr_vnodes);
>  	if (ret) {
>  		eprintf("failed to create sheepdog cluster\n");
>  		exit(1);
> diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
> index 880bb74..db70c57 100644
> --- a/sheep/sheep_priv.h
> +++ b/sheep/sheep_priv.h
> @@ -235,7 +235,7 @@ int is_access_local(struct sd_vnode *e, int nr_nodes,
>  
>  void resume_pending_requests(void);
>  
> -int create_cluster(int port, int64_t zone);
> +int create_cluster(int port, int64_t zone, int nr_vnodes);
>  int leave_cluster(void);
>  
>  void start_cpg_event_work(void);





More information about the sheepdog mailing list