]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: drop misdirected ops 36787/head
authorKefu Chai <kchai@redhat.com>
Tue, 25 Aug 2020 09:30:00 +0000 (17:30 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 25 Aug 2020 10:40:07 +0000 (18:40 +0800)
see also `PrimaryLogPG::do_op()`, we should ignore the ops hitting us if
we are not supposed to serve them. this happens when the client is using
a stale osdmap.

Fixes: https://tracker.ceph.com/issues/47031
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/osd_operations/client_request.cc
src/crimson/osd/osd_operations/client_request.h
src/crimson/osd/pg.h

index 339d4c0935f78c0004fc183aaaa0c72b7747d642..c14a83a1c47377ecf73e71b4339406f7f5f2c14c 100644 (file)
@@ -137,8 +137,12 @@ seastar::future<> ClientRequest::process_op(
     return seastar::now();
   }).then([this, &pg] {
     return with_blocking_future(handle.enter(pp(pg).get_obc));
-  }).then([this, &pg]() {
+  }).then([this, &pg]() -> PG::load_obc_ertr::future<> {
     op_info.set_from_op(&*m, *pg.get_osdmap());
+    if (is_misdirected(pg)) {
+      logger().trace("process_op: dropping misdirected op");
+      return seastar::now();
+    }
     return pg.with_locked_obc(
       m,
       op_info,
@@ -159,4 +163,29 @@ seastar::future<> ClientRequest::process_op(
   }));
 }
 
+bool ClientRequest::is_misdirected(const PG& pg) const
+{
+  // primary can handle both normal ops and balanced reads
+  if (pg.is_primary()) {
+    return false;
+  }
+  // otherwise take a closer look
+  if (const int flags = m->get_flags();
+      flags & CEPH_OSD_FLAG_BALANCE_READS ||
+      flags & CEPH_OSD_FLAG_LOCALIZE_READS) {
+    if (!op_info.may_read()) {
+      // no read found, so it can't be balanced read
+      return true;
+    }
+    if (op_info.may_write() || op_info.may_cache()) {
+      // write op, but i am not primary
+      return true;
+    }
+    // balanced reads; any replica will do
+    return pg.is_nonprimary();
+  }
+  // neither balanced nor localize reads
+  return true;
+}
+
 }
index d2fdbe926dfe2f4ab7f8657577ca1f9abaeaf814..ea3124a93e532d0e2e1d86c27b683ab137990fa3 100644 (file)
@@ -68,6 +68,9 @@ private:
 
   ConnectionPipeline &cp();
   PGPipeline &pp(PG &pg);
+
+private:
+  bool is_misdirected(const PG& pg) const;
 };
 
 }
index 421ff418e4ef2b8ba4d286a76de7187dc17eb187..9335ca35fcca691635518f73bb19949cb1abfa84 100644 (file)
@@ -427,6 +427,9 @@ public:
   bool is_primary() const final {
     return peering_state.is_primary();
   }
+  bool is_nonprimary() const {
+    return peering_state.is_nonprimary();
+  }
   bool is_peered() const final {
     return peering_state.is_peered();
   }