At Sat,  9 Aug 2014 11:36:13 +0800,
Liu Yuan wrote:
> 
> There is no reason we can't multi-thread it. Let's go multi-threading and 
> enjoy
> boost.
> 
> Consider that we often save snapshots on the fly so we use single thread as
> default to minimize the impact of running cluster.
> 
> usage:
>  $ dog cluster snapshot save -m ... # enable multi-threads
> 
> Signed-off-by: Liu Yuan <[email protected]>
> ---
>  dog/cluster.c   | 8 +++++++-
>  dog/farm/farm.c | 5 +++--
>  dog/farm/farm.h | 2 +-
>  3 files changed, 11 insertions(+), 4 deletions(-)

Applied with adding "m" to the accepted options of cluster snapshot
command, thanks.

Thanks,
Hitoshi

> 
> diff --git a/dog/cluster.c b/dog/cluster.c
> index e36e308..12dabac 100644
> --- a/dog/cluster.c
> +++ b/dog/cluster.c
> @@ -21,6 +21,8 @@ static struct sd_option cluster_options[] = {
>       {'b', "store", true, "specify backend store"},
>       {'c', "copies", true, "specify the default data redundancy (number of 
> copies)"},
>       {'f', "force", false, "do not prompt for confirmation"},
> +     {'m', "multithread", false,
> +      "use multi-thread for 'cluster snapshot save'"},
>       {'t', "strict", false,
>        "do not serve write request if number of nodes is not sufficient"},
>       { 0, NULL, false, NULL },
> @@ -29,6 +31,7 @@ static struct sd_option cluster_options[] = {
>  static struct cluster_cmd_data {
>       uint8_t copies;
>       uint8_t copy_policy;
> +     uint8_t multithread;
>       bool force;
>       bool strict;
>       char name[STORE_LEN];
> @@ -432,7 +435,8 @@ static int save_snapshot(int argc, char **argv)
>               goto out;
>       }
>  
> -     if (farm_save_snapshot(tag) != SD_RES_SUCCESS)
> +     if (farm_save_snapshot(tag, cluster_cmd_data.multithread)
> +         != SD_RES_SUCCESS)
>               goto out;
>  
>       ret = EXIT_SUCCESS;
> @@ -788,6 +792,8 @@ static int cluster_parser(int ch, const char *opt)
>       case 'f':
>               cluster_cmd_data.force = true;
>               break;
> +     case 'm':
> +             cluster_cmd_data.multithread = true;
>       case 't':
>               cluster_cmd_data.strict = true;
>               break;
> diff --git a/dog/farm/farm.c b/dog/farm/farm.c
> index e4f532e..5d07be9 100644
> --- a/dog/farm/farm.c
> +++ b/dog/farm/farm.c
> @@ -315,7 +315,7 @@ static int queue_save_snapshot_work(uint64_t oid, 
> uint32_t nr_copies,
>       return 0;
>  }
>  
> -int farm_save_snapshot(const char *tag)
> +int farm_save_snapshot(const char *tag, bool multithread)
>  {
>       unsigned char trunk_sha1[SHA1_DIGEST_SIZE];
>       struct strbuf trunk_buf;
> @@ -357,7 +357,8 @@ int farm_save_snapshot(const char *tag)
>  
>       strbuf_init(&trunk_buf, sizeof(struct trunk_entry) * nr_objects);
>  
> -     wq = create_work_queue("save snapshot", WQ_ORDERED);
> +     wq = create_work_queue("save snapshot",
> +                            multithread ? WQ_DYNAMIC : WQ_ORDERED);
>       if (for_each_object_in_tree(queue_save_snapshot_work,
>                                   &trunk_buf) < 0) {
>               ret = -1;
> diff --git a/dog/farm/farm.h b/dog/farm/farm.h
> index b95006a..745aa15 100644
> --- a/dog/farm/farm.h
> +++ b/dog/farm/farm.h
> @@ -59,7 +59,7 @@ struct vdi_option {
>  /* farm.c */
>  int farm_init(const char *path);
>  bool farm_contain_snapshot(uint32_t idx, const char *tag);
> -int farm_save_snapshot(const char *tag);
> +int farm_save_snapshot(const char *tag, bool);
>  int farm_load_snapshot(uint32_t idx, const char *tag, int count, char 
> **name);
>  int farm_show_snapshot(uint32_t idx, const char *tag, int count, char 
> **name);
>  char *get_object_directory(void);
> -- 
> 1.9.1
> 
> -- 
> sheepdog mailing list
> [email protected]
> http://lists.wpkg.org/mailman/listinfo/sheepdog
-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to