summaryrefslogtreecommitdiffstats
path: root/geo-replication/syncdaemon/libgfchangelog.py
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2014-02-07 11:24:41 +0530
committerVijay Bellur <vbellur@redhat.com>2014-04-30 07:36:19 -0700
commit45d70cc74828b636c0d3c8e388f5b111e1a563ad (patch)
tree14456b46d9d7e9becba73e3d430c14da260d27a3 /geo-replication/syncdaemon/libgfchangelog.py
parentd09b327a2796152eb80074169e17359394ae7cf8 (diff)
geo-rep: Consume Changelog History API
Every time when geo-rep restarts it first does FS crawl using XCrawl and then switches to Changelog Mode. This is because changelog only had live API, that is we can get changes only after registering. Now this(http://review.gluster.org/#/c/6930/) patch introduces History API for changelogs. If history is available then geo-rep will use it instead of FS Crawl. History API returns TS till what time history is available for given start and end time. If TS < endtime then switch to FS Crawl. (History => FS Crawl => Live Changelog) If TS >= endtime, then switch directly to Changelog mode (History => Live Changelog) Change-Id: I4922f62b9f899c40643bd35720e0c81c36b2f255 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/6938 Reviewed-by: Venky Shankar <vshankar@redhat.com> Reviewed-by: Humble Devassy Chirammal <humble.devassy@gmail.com> Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'geo-replication/syncdaemon/libgfchangelog.py')
-rw-r--r--geo-replication/syncdaemon/libgfchangelog.py62
1 files changed, 55 insertions, 7 deletions
diff --git a/geo-replication/syncdaemon/libgfchangelog.py b/geo-replication/syncdaemon/libgfchangelog.py
index ec563b36f29..0fa32a73499 100644
--- a/geo-replication/syncdaemon/libgfchangelog.py
+++ b/geo-replication/syncdaemon/libgfchangelog.py
@@ -13,6 +13,10 @@ from ctypes import CDLL, create_string_buffer, get_errno
from ctypes.util import find_library
+class ChangelogException(OSError):
+ pass
+
+
class Changes(object):
libgfc = CDLL(find_library("gfchangelog"), use_errno=True)
@@ -21,9 +25,9 @@ class Changes(object):
return get_errno()
@classmethod
- def raise_oserr(cls):
+ def raise_changelog_err(cls):
errn = cls.geterrno()
- raise OSError(errn, os.strerror(errn))
+ raise ChangelogException(errn, os.strerror(errn))
@classmethod
def _get_api(cls, call):
@@ -35,19 +39,19 @@ class Changes(object):
log_file,
log_level, retries)
if ret == -1:
- cls.raise_oserr()
+ cls.raise_changelog_err()
@classmethod
def cl_scan(cls):
ret = cls._get_api('gf_changelog_scan')()
if ret == -1:
- cls.raise_oserr()
+ cls.raise_changelog_err()
@classmethod
def cl_startfresh(cls):
ret = cls._get_api('gf_changelog_start_fresh')()
if ret == -1:
- cls.raise_oserr()
+ cls.raise_changelog_err()
@classmethod
def cl_getchanges(cls):
@@ -64,7 +68,7 @@ class Changes(object):
break
changes.append(buf.raw[:ret - 1])
if ret == -1:
- cls.raise_oserr()
+ cls.raise_changelog_err()
# cleanup tracker
cls.cl_startfresh()
return sorted(changes, key=clsort)
@@ -73,4 +77,48 @@ class Changes(object):
def cl_done(cls, clfile):
ret = cls._get_api('gf_changelog_done')(clfile)
if ret == -1:
- cls.raise_oserr()
+ cls.raise_changelog_err()
+
+ @classmethod
+ def cl_history_scan(cls):
+ ret = cls._get_api('gf_history_changelog_scan')()
+ if ret == -1:
+ cls.raise_changelog_err()
+
+ return ret
+
+ @classmethod
+ def cl_history_changelog(cls, changelog_path, start, end):
+ ret = cls._get_api('gf_history_changelog')(changelog_path, start, end)
+ if ret == -1:
+ cls.raise_changelog_err()
+
+ return ret
+
+ @classmethod
+ def cl_history_startfresh(cls):
+ ret = cls._get_api('gf_history_changelog_start_fresh')()
+ if ret == -1:
+ cls.raise_changelog_err()
+
+ @classmethod
+ def cl_history_getchanges(cls):
+ changes = []
+ buf = create_string_buffer('\0', 4096)
+ call = cls._get_api('gf_history_changelog_next_change')
+
+ while True:
+ ret = call(buf, 4096)
+ if ret in (0, -1):
+ break
+ changes.append(buf.raw[:ret - 1])
+ if ret == -1:
+ cls.raise_changelog_err()
+
+ return changes
+
+ @classmethod
+ def cl_history_done(cls, clfile):
+ ret = cls._get_api('gf_history_changelog_done')(clfile)
+ if ret == -1:
+ cls.raise_changelog_err()