]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: Implementation of Ioctx.set_read to allow read from snapshots 6813/head
authorFlorent Manens <florent@manens.org>
Sun, 6 Dec 2015 18:46:32 +0000 (19:46 +0100)
committerFlorent Manens <florent@manens.org>
Sun, 13 Dec 2015 13:51:40 +0000 (14:51 +0100)
Signed-off-by: Florent Manens <florent@beezim.fr>
src/pybind/rados.py
src/test/pybind/test_rados.py

index 2d4022f96fe42f5e707ee6525808a7f438345ab8..a599346ba0ba79120f0e5df0569efb30319f844f 100644 (file)
@@ -27,6 +27,7 @@ LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL = 0x8
 LIBRADOS_OP_FLAG_FADVISE_WILLNEED = 0x10
 LIBRADOS_OP_FLAG_FADVISE_DONTNEED = 0x20
 LIBRADOS_OP_FLAG_FADVISE_NOCACHE = 0x40
+LIBRADOS_SNAP_HEAD = -2
 
 
 # Are we running Python 2.x
@@ -1507,6 +1508,21 @@ class Ioctx(object):
         """
         return self.locator_key
 
+    @requires(('snap_id', int))
+    def set_read(self, snap_id):
+        """
+        Set the snapshot for reading objects.
+
+        To stop to read from snapshot, use set_read(LIBRADOS_SNAP_HEAD)
+
+        :param snap_id: the snapshot Id
+        :type snap_id: int
+
+        :raises: :class:`TypeError`
+        """
+        self.require_ioctx_open()
+        run_in_thread(self.librados.rados_ioctx_snap_set_read,
+                      (self.io, c_uint64(snap_id)))
 
     @requires(('nspace', str_type))
     def set_namespace(self, nspace):
index 9c1d86fddf5c2dff0941bc307136c098433d0051..b4d392bc8f28bcb73bab70c114b01aa644a887ae 100644 (file)
@@ -2,7 +2,8 @@ from __future__ import print_function
 from nose.tools import eq_ as eq, ok_ as ok, assert_raises
 from rados import (Rados, Error, RadosStateError, Object, ObjectExists,
                    ObjectNotFound, ObjectBusy, requires, opt,
-                   ANONYMOUS_AUID, ADMIN_AUID, LIBRADOS_ALL_NSPACES, WriteOpCtx, ReadOpCtx)
+                   ANONYMOUS_AUID, ADMIN_AUID, LIBRADOS_ALL_NSPACES, WriteOpCtx, ReadOpCtx,
+                   LIBRADOS_SNAP_HEAD)
 import time
 import threading
 import json
@@ -367,6 +368,19 @@ class TestIoctx(object):
         eq(self.ioctx.read("insnap"), b"contents1")
         self.ioctx.remove_snap("snap1")
         self.ioctx.remove_object("insnap")
+    
+    def test_snap_read(self):
+        self.ioctx.write("insnap", b"contents1")
+        self.ioctx.create_snap("snap1")
+        self.ioctx.remove_object("insnap")
+        snap = self.ioctx.lookup_snap("snap1")
+        self.ioctx.set_read(int(snap.snap_id.value))
+        eq(self.ioctx.read("insnap"), b"contents1")
+        self.ioctx.set_read(LIBRADOS_SNAP_HEAD)
+        self.ioctx.write("inhead", b"contents2")
+        eq(self.ioctx.read("inhead"), b"contents2")
+        self.ioctx.remove_snap("snap1")
+        self.ioctx.remove_object("inhead")
 
     def test_set_omap(self):
         keys = ("1", "2", "3", "4")