]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: RGWObjVersionTracker tracks read version over increments
authorCasey Bodley <cbodley@redhat.com>
Tue, 4 Aug 2020 19:03:35 +0000 (15:03 -0400)
committerNathan Cutler <ncutler@suse.com>
Tue, 29 Sep 2020 15:51:48 +0000 (17:51 +0200)
when no write_version is given, cls_version_inc() is used to increment
the version so other writers can use cls_version_check() to detect races

however, apply_write() will clear its cached read_version, which means
that later writes can no longer use cls_version_check() to detect other
racing writers

in cases where cls_version_inc() is used AND we know the previous version,
we can increment the cached read_version and preserve the ability to use
cls_version_check(). we know the previous version if we provided a valid
read_version to cls_version_check() and it succeeded

Fixes: https://tracker.ceph.com/issues/46849
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit 298d721c1d3d8d430bfbc9e0ef5db7b44cdbe017)

Conflicts:
src/rgw/rgw_rados.cc
- nautilus does not have "RGWObjState::RGWObjState()"

src/rgw/rgw_common.h
src/rgw/rgw_rados.cc

index 1a7603320979efdccbb5601340c7b279667b73ee..c8491b03d2e65c14f06b5bc15a35d5a8bd66dcbc 100644 (file)
@@ -1321,10 +1321,7 @@ struct RGWObjVersionTracker {
   void prepare_op_for_read(librados::ObjectReadOperation *op);
   void prepare_op_for_write(librados::ObjectWriteOperation *op);
 
-  void apply_write() {
-    read_version = write_version;
-    write_version = obj_version();
-  }
+  void apply_write();
 
   void clear() {
     read_version = obj_version();
index 9835f9f7c4ad896e048e7dbde771c9d902cb06ec..526c5ed718dbcb7197177fba3a694781d8a5bd0b 100644 (file)
@@ -187,6 +187,20 @@ void RGWObjVersionTracker::prepare_op_for_write(ObjectWriteOperation *op)
   }
 }
 
+void RGWObjVersionTracker::apply_write()
+{
+  const bool checked = (read_version.ver != 0);
+  const bool incremented = (write_version.ver == 0);
+
+  if (checked && incremented) {
+    // apply cls_version_inc() so our next operation can recheck it
+    ++read_version.ver;
+  } else {
+    read_version = write_version;
+  }
+  write_version = obj_version();
+}
+
 void RGWObjManifest::obj_iterator::operator++()
 {
   if (manifest->explicit_objs) {