[sheepdog] [PATCH] sheep/http: rework kv_find_object()

Liu Yuan namei.unix at gmail.com
Tue Dec 24 04:12:04 CET 2013


On Tue, Dec 24, 2013 at 09:24:57AM +0800, Robin Dong wrote:
> 2013/12/23 Liu Yuan <namei.unix at gmail.com>
> 
> > We duplicately call vdi_lookup twice for every object operation, which
> > isn't
> > necessary. This patch reduce it to a single call of vdi_lookup.
> >
> > Also rename kv_list_{objects, buckets} as kv_iterate_{object, bucket}
> >
> > Signed-off-by: Liu Yuan <namei.unix at gmail.com>
> > ---
> >  sheep/http/http.h  |  18 ++-
> >  sheep/http/kv.c    | 361
> > +++++++++++++++++++++++++++--------------------------
> >  sheep/http/s3.c    |  64 +---------
> >  sheep/http/swift.c |  19 ++-
> >  4 files changed, 200 insertions(+), 262 deletions(-)
> >
> > diff --git a/sheep/http/http.h b/sheep/http/http.h
> > index 3141c09..dea34e0 100644
> > --- a/sheep/http/http.h
> > +++ b/sheep/http/http.h
> > @@ -129,23 +129,19 @@ int kv_create_bucket(const char *account, const char
> > *bucket);
> >  int kv_read_bucket(const char *account, const char *bucket);
> >  int kv_update_bucket(const char *account, const char *bucket);
> >  int kv_delete_bucket(const char *account, const char *bucket);
> > -int kv_list_buckets(struct http_request *req, const char *account,
> > -                   void (*cb)(struct http_request *req, const char
> > *bucket,
> > -                              void *opaque),
> > -                   void *opaque);
> > +int kv_iterate_bucket(const char *account,
> > +                     void (*cb)(const char *bucket, void *opaque),
> > +                     void *opaque);
> >
> >  /* Object operations */
> >  int kv_create_object(struct http_request *req, const char *account,
> >                      const char *bucket, const char *object);
> >  int kv_read_object(struct http_request *req, const char *account,
> >                    const char *bucket, const char *object);
> > -int kv_delete_object(struct http_request *req, const char *account,
> > -                    const char *bucket, const char *object);
> > -int kv_list_objects(struct http_request *req, const char *account,
> > -                   const char *bucket,
> > -                   void (*cb)(struct http_request *req, const char
> > *bucket,
> > -                              const char *object, void *opaque),
> > -                   void *opaque);
> > +int kv_delete_object(const char *account, const char *bucket, const char
> > *);
> > +int kv_iterate_object(const char *account, const char *bucket,
> > +                     void (*cb)(const char *object, void *opaque),
> > +                     void *opaque);
> >
> >  /* object_allocator.c */
> >  int oalloc_new_prepare(uint32_t vid, uint64_t *start, uint64_t count);
> > diff --git a/sheep/http/kv.c b/sheep/http/kv.c
> > index ed2f999..64a6e05 100644
> > --- a/sheep/http/kv.c
> > +++ b/sheep/http/kv.c
> > @@ -23,6 +23,42 @@ struct kv_bnode {
> >         uint64_t oid;
> >  };
> >
> > +struct onode_extent {
> > +       uint64_t start;
> > +       uint64_t count;
> > +};
> > +
> > +struct kv_onode {
> > +       union {
> > +               struct {
> > +                       char name[SD_MAX_OBJECT_NAME];
> > +                       /* a hash value for etag */
> > +                       uint8_t sha1[round_up(SHA1_DIGEST_SIZE, 8)];
> > +                       uint64_t size;
> > +                       uint64_t ctime;
> > +                       uint64_t mtime;
> > +                       uint32_t data_vid;
> > +                       uint32_t nr_extent;
> > +                       uint64_t oid;
> > +                       uint8_t inlined;
> > +               };
> > +
> > +               uint8_t __pad[BLOCK_SIZE];
> > +       };
> > +       union {
> > +               uint8_t data[SD_DATA_OBJ_SIZE - BLOCK_SIZE];
> > +               struct onode_extent o_extent[0];
> > +       };
> > +};
> > +
> > +typedef void (*b_iter_cb)(const char *bucket, void *opaque);
> >
> 
> I think "bucket_iter_cb" is better than "b_iter_cb".
> 
> 
> > +
> > +struct bucket_iterater_arg {
> > +       void *opaque;
> > +       b_iter_cb cb;
> > +       uint32_t count;
> > +};
> > +
> >  static int kv_create_hyper_volume(const char *name, uint32_t *vdi_id)
> >  {
> >         struct sd_req hdr;
> > @@ -143,20 +179,10 @@ int kv_create_account(const char *account)
> >         return kv_create_hyper_volume(account, &vdi_id);
> >  }
> >
> > -typedef void (*list_bucket_cb)(struct http_request *req, const char
> > *bucket,
> > -                              void *opaque);
> > -
> > -struct list_buckets_arg {
> > -       struct http_request *req;
> > -       void *opaque;
> > -       list_bucket_cb cb;
> > -       uint32_t bucket_counter;
> > -};
> > -
> > -static void list_buckets_cb(void *data, enum btree_node_type type, void
> > *arg)
> > +static void bucket_iterater(void *data, enum btree_node_type type, void
> > *arg)
> >  {
> >         struct sd_extent *ext;
> > -       struct list_buckets_arg *lbarg = arg;
> > +       struct bucket_iterater_arg *biarg = arg;
> >         struct kv_bnode bnode;
> >         uint64_t oid;
> >         int ret;
> > @@ -175,9 +201,9 @@ static void list_buckets_cb(void *data, enum
> > btree_node_type type, void *arg)
> >
> >                 if (bnode.name[0] == 0)
> >                         return;
> > -               if (lbarg->cb)
> > -                       lbarg->cb(lbarg->req, bnode.name, lbarg->opaque);
> > -               lbarg->bucket_counter++;
> > +               if (biarg->cb)
> > +                       biarg->cb(bnode.name, biarg->opaque);
> > +               biarg->count++;
> >         }
> >  }
> >
> > @@ -187,7 +213,7 @@ static int kv_get_account(const char *account,
> > uint32_t *nr_buckets)
> >         struct sd_inode inode;
> >         uint64_t oid;
> >         uint32_t account_vid;
> > -       struct list_buckets_arg arg = {NULL, NULL, NULL, 0};
> > +       struct bucket_iterater_arg arg = {NULL, NULL, 0};
> >         int ret;
> >
> >         ret = sd_lookup_vdi(account, &account_vid);
> > @@ -202,9 +228,9 @@ static int kv_get_account(const char *account,
> > uint32_t *nr_buckets)
> >                 goto out;
> >         }
> >
> > -       traverse_btree(sheep_bnode_reader, &inode, list_buckets_cb, &arg);
> > +       traverse_btree(sheep_bnode_reader, &inode, bucket_iterater, &arg);
> >         if (nr_buckets)
> > -               *nr_buckets = arg.bucket_counter;
> > +               *nr_buckets = arg.count;
> >  out:
> >         return ret;
> >  }
> > @@ -257,7 +283,7 @@ int kv_delete_account(const char *account)
> >   *         |            |
> >    |
> >   *          \           v
> >    v
> >   *          \
> > +---------------------------------------------------------+
> > - * onode_vdi  \----> |coly/fruit | ... | kv_onode: banana | kv_onode:
> > apple    |
> > + * bucket_vdi  \---> |coly/fruit | ... | kv_onode: banana | kv_onode:
> > apple    |
> >   *
> > +---------------------------------------------------------+
> >   *                                                    |             |
> >   *      oalloc.c manages allocation and deallocation  |             |
> > @@ -371,6 +397,66 @@ static int bucket_delete(const char *account,
> > uint32_t avid, const char *bucket)
> >         return SD_RES_SUCCESS;
> >  }
> >
> > +typedef void (*o_iter_cb)(const char *object, void *opaque);
> >
> 
> May be "object_iter_cb" better ?
> 

Applied after rename o_iter_cb and b_iter_cb as you suggested

Thanks
Yuan



More information about the sheepdog mailing list