]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: RGWFormatter_Plain does support key-value style for Bulk Delete API.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 16 Oct 2015 17:12:01 +0000 (19:12 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 8 Dec 2015 16:57:22 +0000 (17:57 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_formats.cc
src/rgw/rgw_formats.h

index d7e47b0bf7a3a9946ae2e9b1c2bb01d178df21ee..1e730ea823eec2d39506c9a880897e0c5388a896 100644 (file)
 
 #define dout_subsys ceph_subsys_rgw
 
-RGWFormatter_Plain::RGWFormatter_Plain()
-  : buf(NULL), len(0), max_len(0), min_stack_level(0)
+RGWFormatter_Plain::RGWFormatter_Plain(const bool ukv)
+  : buf(NULL),
+    len(0),
+    max_len(0),
+    min_stack_level(0),
+    use_kv(ukv)
 {
 }
 
@@ -64,6 +68,14 @@ void RGWFormatter_Plain::open_array_section(const char *name)
   struct plain_stack_entry new_entry;
   new_entry.is_array = true;
   new_entry.size = 0;
+
+  if (use_kv && min_stack_level > 0 && !stack.empty()) {
+    struct plain_stack_entry& entry = stack.back();
+
+    if (!entry.is_array)
+      dump_format(name, "");
+  }
+
   stack.push_back(new_entry);
 }
 
@@ -79,6 +91,10 @@ void RGWFormatter_Plain::open_object_section(const char *name)
   struct plain_stack_entry new_entry;
   new_entry.is_array = false;
   new_entry.size = 0;
+
+  if (use_kv && min_stack_level > 0)
+    dump_format(name, "");
+
   stack.push_back(new_entry);
 }
 
@@ -131,7 +147,7 @@ void RGWFormatter_Plain::dump_format_va(const char *name, const char *ns, bool q
   if (!min_stack_level)
     min_stack_level = stack.size();
 
-  bool should_print = (stack.size() == min_stack_level && !entry.size);
+  bool should_print = ((stack.size() == min_stack_level && !entry.size) || use_kv);
 
   entry.size++;
 
@@ -139,12 +155,20 @@ void RGWFormatter_Plain::dump_format_va(const char *name, const char *ns, bool q
     return;
 
   vsnprintf(buf, LARGE_SIZE, fmt, ap);
-  if (len)
-    format = "\n%s";
-  else
-    format = "%s";
 
-  write_data(format, buf);
+  const char *eol;
+  if (len) {
+    if (use_kv && entry.is_array && entry.size > 1)
+      eol = ", ";
+    else
+      eol = "\n";
+  } else
+    eol = "";
+
+  if (use_kv && !entry.is_array)
+    write_data("%s%s: %s", eol, name, buf);
+  else
+    write_data("%s%s", eol, buf);
 }
 
 int RGWFormatter_Plain::get_len() const
@@ -233,7 +257,7 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...)
     min_stack_level = stack.size();
 
   struct plain_stack_entry& entry = stack.back();
-  bool should_print = (stack.size() == min_stack_level && !entry.size);
+  bool should_print = ((stack.size() == min_stack_level && !entry.size) || use_kv);
 
   entry.size++;
 
@@ -250,5 +274,9 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...)
   else
     eol = "";
 
-  write_data("%s%s", eol, buf);
+  if (use_kv && !entry.is_array)
+    write_data("%s%s: %s", eol, name, buf);
+  else
+    write_data("%s%s", eol, buf);
+
 }
index 6f7925e393147a7893be2df3e2a9be58cee7f3a0..43c087d440ead972ad8ec7141c22691ed6a3c397 100644 (file)
@@ -22,7 +22,7 @@ struct plain_stack_entry {
 class RGWFormatter_Plain : public Formatter {
   void reset_buf();
 public:
-  RGWFormatter_Plain();
+  RGWFormatter_Plain(bool use_kv = false);
   virtual ~RGWFormatter_Plain();
 
   virtual void flush(ostream& os);
@@ -52,6 +52,7 @@ private:
 
   std::list<struct plain_stack_entry> stack;
   size_t min_stack_level;
+  bool use_kv;
 };
 
 class RGWFormatterFlusher {