From ef8fa8b9a40e2eac26def1641bca86609d564316 Mon Sep 17 00:00:00 2001 From: Florent Manens Date: Sun, 6 Dec 2015 19:46:32 +0100 Subject: [PATCH] pybind: Implementation of Ioctx.set_read to allow read from snapshots Signed-off-by: Florent Manens --- src/pybind/rados.py | 16 ++++++++++++++++ src/test/pybind/test_rados.py | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/pybind/rados.py b/src/pybind/rados.py index 2d4022f96fe42..a599346ba0ba7 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -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): diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py index 9c1d86fddf5c2..b4d392bc8f28b 100644 --- a/src/test/pybind/test_rados.py +++ b/src/test/pybind/test_rados.py @@ -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") -- 2.39.5