]> git.apps.os.sepia.ceph.com Git - ceph-ci.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 18:37:06 +0000 (13:37 -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>
src/cls/fifo/cls_fifo.cc
src/cls/fifo/cls_fifo_types.h
src/rgw/driver/rados/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 5c7e6769ea3a93b67c8137e44f5caba6fb8bbf9f..c2cb5b62796bd7783bf89010198bcdf91ceb8b8b 100644 (file)
@@ -15,6 +15,7 @@
 
 #pragma once
 
+#include <algorithm>
 #include <cstdint>
 #include <map>
 #include <optional>
@@ -358,8 +359,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();
     }
@@ -373,16 +373,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()) {
@@ -392,8 +389,6 @@ struct info {
     if (update.head_part_num()) {
       head_part_num = *update.head_part_num();
     }
-
-    return std::nullopt;
   }
 };
 WRITE_CLASS_ENCODER(info)
index 3edec238014f2f1590a3bcb650869b2e50f9f4cf..a6e04f10f3b8aedb10481364e47f15adaaa17a3f 100644 (file)
@@ -421,13 +421,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 {};