]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: create plain processor for small objects
authorYehuda Sadeh <yehuda@hq.newdream.net>
Sat, 7 Jan 2012 00:16:06 +0000 (16:16 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Sat, 7 Jan 2012 00:53:28 +0000 (16:53 -0800)
src/rgw/rgw_access.h
src/rgw/rgw_cache.h
src/rgw/rgw_fs.cc
src/rgw/rgw_fs.h
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 8245eef5c84636dbf6956e89b3fa785104bc818d..e3c39c126a7caedc44ae33397edfa6f926b6b981 100644 (file)
@@ -72,7 +72,8 @@ public:
     with the given stats */
   virtual int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
                       map<std::string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
-                      map<std::string, bufferlist>* rmattrs) = 0;
+                      map<std::string, bufferlist>* rmattrs,
+                      const bufferlist *data) = 0;
   virtual int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
                       off_t ofs, size_t len, bool exclusive) = 0;
   virtual int aio_put_obj_data(void *ctx, rgw_obj& obj, bufferlist& bl,
@@ -81,10 +82,9 @@ public:
   /* note that put_obj doesn't set category on an object, only use it for none user objects */
   int put_obj(void *ctx, rgw_obj& obj, const char *data, size_t len, bool exclusive,
               time_t *mtime, map<std::string, bufferlist>& attrs) {
-    int ret = put_obj_data(ctx, obj, data, -1, len, exclusive);
-    if (ret >= 0 && (attrs.size() || mtime)) {
-      ret = put_obj_meta(ctx, obj, len, mtime, attrs, RGW_OBJ_CATEGORY_NONE, false, NULL);
-    }
+    bufferlist bl;
+    bl.append(data, len);
+    int ret = put_obj_meta(ctx, obj, len, mtime, attrs, RGW_OBJ_CATEGORY_NONE, exclusive, NULL, &bl);
     return ret;
   }
 
index 82582389d51333b1f7be9db0b4b358e58f4fde90..3a29fae7a1212ff5459674a12139fbeee5ffc8a0 100644 (file)
@@ -177,7 +177,7 @@ public:
   int set_attr(void *ctx, rgw_obj& obj, const char *name, bufferlist& bl);
   int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
                    map<std::string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
-                   map<std::string, bufferlist>* rmattrs);
+                   map<std::string, bufferlist>* rmattrs, const bufferlist *data);
 
   int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
               off_t ofs, size_t len, bool exclusive);
@@ -283,7 +283,7 @@ int RGWCache<T>::set_attr(void *ctx, rgw_obj& obj, const char *attr_name, buffer
 template <class T>
 int RGWCache<T>::put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
                               map<std::string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
-                              map<std::string, bufferlist>* rmattrs)
+                              map<std::string, bufferlist>* rmattrs, const bufferlist *data)
 {
   rgw_bucket bucket;
   string oid;
@@ -295,8 +295,12 @@ int RGWCache<T>::put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mt
     info.xattrs = attrs;
     info.status = 0;
     info.flags = CACHE_FLAG_XATTRS;
+    if (data) {
+      info.data = *data;
+      info.flags |= CACHE_FLAG_DATA;
+    }
   }
-  int ret = T::put_obj_meta(ctx, obj, size, mtime, attrs, category, exclusive, rmattrs);
+  int ret = T::put_obj_meta(ctx, obj, size, mtime, attrs, category, exclusive, rmattrs, data);
   if (cacheable) {
     string name = normal_name(bucket, oid);
     if (ret >= 0) {
index 4ba843365473db4f74316e5b01adcfcd21f8da36..704e23d6d656a47ba14bad53aa5f3f91b529c015 100644 (file)
@@ -207,7 +207,7 @@ int RGWFS::create_bucket(std::string& owner, rgw_bucket& bucket, map<std::string
 int RGWFS::put_obj_meta(void *ctx, rgw_obj& obj,
                   uint64_t size, time_t *mtime, map<string, bufferlist>& attrs,
                   RGWObjCategory category, bool exclusive,
-                 map<std::string, bufferlist> *rmattrs)
+                 map<std::string, bufferlist> *rmattrs, const bufferlist *data)
 {
   rgw_bucket& bucket = obj.bucket;
   std::string& oid = obj.object;
index 2a5954c8b5488f3f93e97e2b38f0def24ec91d48..6d15a5cbda4cd75c05b83aa07c5cae445ca06225 100644 (file)
@@ -21,7 +21,7 @@ public:
   int create_bucket(std::string& owner, rgw_bucket& bucket, map<std::string, bufferlist>& attrs, bool system_bucket, bool exclusive, uint64_t auid=0);
   int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
              map<std::string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
-             map<std::string, bufferlist> *rmattrs);
+             map<std::string, bufferlist> *rmattrs, const bufferlist *data);
   int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
               off_t ofs, size_t size, bool exclusive);
   int copy_obj(void *ctx, rgw_obj& dest_obj,
index 3e5aeb80f2f76f08646000534d674211a2f1da20..f1ccd7a353778bff22c21a9195aaa4271e41a3cb 100644 (file)
@@ -611,6 +611,50 @@ int RGWPutObj::verify_permission()
   return 0;
 }
 
+class RGWPutObjProcessor_Plain : public RGWPutObjProcessor
+{
+  bufferlist data;
+  rgw_obj obj;
+  off_t ofs;
+
+protected:
+  int prepare(struct req_state *s);
+  int handle_data(bufferlist& bl, off_t ofs, void **phandle);
+  int throttle_data(void *handle) { return 0; }
+  int complete(string& etag, map<string, bufferlist>& attrs);
+
+public:
+  RGWPutObjProcessor_Plain() : ofs(0) {}
+};
+
+int RGWPutObjProcessor_Plain::prepare(struct req_state *s)
+{
+  RGWPutObjProcessor::prepare(s);
+
+  obj.init(s->bucket, s->object_str);
+
+  return 0;
+};
+
+int RGWPutObjProcessor_Plain::handle_data(bufferlist& bl, off_t _ofs, void **phandle)
+{
+  if (ofs != _ofs)
+    return -EINVAL;
+
+  data.append(bl);
+  ofs += bl.length();
+
+  return 0;
+}
+
+int RGWPutObjProcessor_Plain::complete(string& etag, map<string, bufferlist>& attrs)
+{
+  int r = rgwstore->put_obj_meta(s->obj_ctx, obj, data.length(), NULL, attrs,
+                                 RGW_OBJ_CATEGORY_MAIN, false, NULL, &data);
+  return r;
+}
+
+
 class RGWPutObjProcessor_Aio : public RGWPutObjProcessor
 {
   list<struct put_obj_aio_info> pending;
@@ -706,7 +750,6 @@ int RGWPutObjProcessor_Aio::throttle_data(void *handle)
 
 class RGWPutObjProcessor_Atomic : public RGWPutObjProcessor_Aio
 {
-  string oid;
   bool remove_temp_obj;
 protected:
   int prepare(struct req_state *s);
@@ -728,7 +771,7 @@ int RGWPutObjProcessor_Atomic::prepare(struct req_state *s)
 {
   RGWPutObjProcessor::prepare(s);
 
-  oid = s->object_str;
+  string oid = s->object_str;
   obj.set_ns(tmp_ns);
 
   char buf[33];
@@ -756,7 +799,6 @@ RGWPutObjProcessor_Atomic::~RGWPutObjProcessor_Atomic()
 
 class RGWPutObjProcessor_Multipart : public RGWPutObjProcessor_Aio
 {
-  string oid;
   string part_num;
   RGWMPObj mp;
 protected:
@@ -771,7 +813,7 @@ int RGWPutObjProcessor_Multipart::prepare(struct req_state *s)
 {
   RGWPutObjProcessor::prepare(s);
 
-  oid = s->object_str;
+  string oid = s->object_str;
   string upload_id;
   url_decode(s->args.get("uploadId"), upload_id);
   mp.init(oid, upload_id);
@@ -789,7 +831,7 @@ int RGWPutObjProcessor_Multipart::prepare(struct req_state *s)
 
 int RGWPutObjProcessor_Multipart::complete(string& etag, map<string, bufferlist>& attrs)
 {
-  int r = rgwstore->put_obj_meta(s->obj_ctx, obj, s->obj_size, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, NULL);
+  int r = rgwstore->put_obj_meta(s->obj_ctx, obj, s->obj_size, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, NULL, NULL);
   if (r < 0)
     return r;
 
@@ -859,7 +901,10 @@ void RGWPutObj::execute()
     bool multipart = s->args.exists("uploadId");
 
     if (!multipart) {
-      processor = new RGWPutObjProcessor_Atomic();
+      if (s->content_length <= RGW_MAX_CHUNK_SIZE)
+        processor = new RGWPutObjProcessor_Plain();
+      else
+        processor = new RGWPutObjProcessor_Atomic();
     } else {
       processor = new RGWPutObjProcessor_Multipart();
     }
@@ -985,7 +1030,7 @@ void RGWPutObjMetadata::execute()
     }
   }
 
-  ret = rgwstore->put_obj_meta(s->obj_ctx, obj, obj_size, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, &rmattrs);
+  ret = rgwstore->put_obj_meta(s->obj_ctx, obj, obj_size, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, &rmattrs, NULL);
 
 done:
   send_response();
@@ -1406,7 +1451,7 @@ void RGWInitMultipart::execute()
 
     obj.init(s->bucket, tmp_obj_name, s->object_str, mp_ns);
     // the meta object will be indexed with 0 size, we c
-    ret = rgwstore->put_obj_meta(s->obj_ctx, obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MULTIMETA, true, NULL);
+    ret = rgwstore->put_obj_meta(s->obj_ctx, obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MULTIMETA, true, NULL, NULL);
   } while (ret == -EEXIST);
 done:
   send_response();
@@ -1555,7 +1600,7 @@ void RGWCompleteMultipart::execute()
 
   target_obj.init(s->bucket, s->object_str);
   rgwstore->set_atomic(s->obj_ctx, target_obj);
-  ret = rgwstore->put_obj_meta(s->obj_ctx, target_obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, NULL);
+  ret = rgwstore->put_obj_meta(s->obj_ctx, target_obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, NULL, NULL);
   if (ret < 0)
     goto done;
   
index b48b1349117e1cbb530408cbc4a2acb549b51c8f..d74e03fa396ecb7dde5fc7991cc309e1c90f06a3 100644 (file)
@@ -614,7 +614,8 @@ int RGWRados::create_pools(vector<string>& names, vector<int>& retcodes, int aui
  */
 int RGWRados::put_obj_meta(void *ctx, rgw_obj& obj,  uint64_t size,
                   time_t *mtime, map<string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
-                  map<string, bufferlist>* rmattrs)
+                  map<string, bufferlist>* rmattrs,
+                  const bufferlist *data)
 {
   rgw_bucket bucket;
   std::string oid, key;
@@ -661,6 +662,9 @@ int RGWRados::put_obj_meta(void *ctx, rgw_obj& obj,  uint64_t size,
     }
   }
 
+  if (data)
+    op.write_full(*data);
+
   if (!op.size())
     return 0;
 
index 4586557f615d6f8f4853a9be3c79bf21260df537..afb7694b89698cac9048b04eea9f1814930f888c 100644 (file)
@@ -194,7 +194,7 @@ public:
   /** Write/overwrite an object to the bucket storage. */
   virtual int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
               map<std::string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
-              map<std::string, bufferlist>* rmattrs);
+              map<std::string, bufferlist>* rmattrs, const bufferlist *data);
   virtual int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
               off_t ofs, size_t len, bool exclusive);
   virtual int aio_put_obj_data(void *ctx, rgw_obj& obj, bufferlist& bl,