]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/fifo: Merge duplicate journal entries
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 30 Nov 2022 21:45:49 +0000 (16:45 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Mon, 9 Jan 2023 21:31:43 +0000 (16:31 -0500)
Since we no longer use tags, journal entries are just an operation and
a part number. If an entry being added is already in the journal, skip
it.

Fixes: https://tracker.ceph.com/issues/57562
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
(cherry picked from commit ade8909991682da9f665e75c16f1662f98f1e51a)
Fixes: https://tracker.ceph.com/issues/58402
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/cls/fifo/cls_fifo.cc
src/cls/fifo/cls_fifo_types.h
src/rgw/cls_fifo_legacy.cc

index 5e2e2d42f857d7a6d0ae240f979e13eca38e4946..5fe3404b995908925834b393fd7fa84e1b2c974c 100644 (file)
@@ -342,15 +342,7 @@ int update_meta(cls_method_context_t hctx, ceph::buffer::list* in,
     .journal_entries_rm(
       std::move(op.journal_entries_rm));
 
-  auto err = header.apply_update(u);
-  if (err) {
-    std::ostringstream ss;
-    ss << u;
-    CLS_ERR("%s: %s: %s", __PRETTY_FUNCTION__, err->c_str(),
-           ss.str().c_str());
-    return -EINVAL;
-  }
-
+  header.apply_update(u);
   r = write_header(hctx, header);
   if (r < 0) {
     CLS_ERR("%s: failed to write header: r=%d", __PRETTY_FUNCTION__, r);
index b3875e63cc0014462777649f6f792857f5a8c859..b8f6ceec87be716f315be870bf7ee2596262aa68 100644 (file)
@@ -15,6 +15,7 @@
 
 #pragma once
 
+#include <algorithm>
 #include <cstdint>
 #include <map>
 #include <optional>
@@ -363,8 +364,7 @@ struct info {
     return fmt::format("{}.{}", oid_prefix, part_num);
   }
 
-  std::optional<std::string>
-  apply_update(const update& update) {
+  void apply_update(const update& update) {
     if (update.tail_part_num()) {
       tail_part_num = *update.tail_part_num();
     }
@@ -378,16 +378,13 @@ struct info {
     }
 
     for (const auto& entry : update.journal_entries_add()) {
-      auto iter = journal.find(entry.part_num);
-      if (iter != journal.end() &&
-         iter->second.op == entry.op) {
-       /* don't allow multiple concurrent (same) operations on the same part,
-          racing clients should use objv to avoid races anyway */
-       return fmt::format("multiple concurrent operations on same part are not "
-                          "allowed, part num={}", entry.part_num);
+      if (std::find_if(journal.begin(), journal.end(),
+                      [&entry](const auto &x) { return x.second == entry; })
+         != journal.end()) {
+       continue;
+      } else {
+       journal.emplace(entry.part_num, entry);
       }
-
-      journal.emplace(entry.part_num, entry);
     }
 
     for (const auto& entry : update.journal_entries_rm()) {
@@ -397,8 +394,6 @@ struct info {
     if (update.head_part_num()) {
       head_part_num = *update.head_part_num();
     }
-
-    return std::nullopt;
   }
 };
 WRITE_CLASS_ENCODER(info)
index 6bff07e28697b08929ca5df500e81d1f87f4ac5f..42e1af391e5d78b375bfad8afbfdd10fecf2494d 100644 (file)
@@ -423,13 +423,7 @@ int FIFO::apply_update(const DoutPrefixProvider *dpp,
               << " version mismatch, canceling: tid=" << tid << dendl;
     return -ECANCELED;
   }
-  auto err = info->apply_update(update);
-  if (err) {
-    ldpp_dout(dpp, -1) << __PRETTY_FUNCTION__ << ":" << __LINE__
-              << " error applying update: " << *err << " tid=" << tid << dendl;
-    return -ECANCELED;
-  }
-
+  info->apply_update(update);
   ++info->version.ver;
 
   return {};