path: root/xlators/features/changelog/lib/src/gf-changelog-helpers.h
diff options
authorAvra Sengupta <>2013-06-04 14:20:58 +0530
committerVijay Bellur <>2013-07-22 01:52:24 -0700
commit11f6c56f83b977a08f9d74563249cef59e22a05d (patch)
treee6ba97e3a3aae7b555b77c8a18598d52f63e032e /xlators/features/changelog/lib/src/gf-changelog-helpers.h
parent41b721baee31356f442b1fb3f198456a0dd3b2db (diff)
features/changelog: changelog translator
This is the initial version of the Changelog Translator. What is it ----------- Goal is to capture changes performed on a GlusterFS volume. The translator needs to be loaded on the server (bricks) and captures changes in a plain text file inside a configured directory path (controlled by "changelog-dir", should be somewhere in <export>/.glusterfs/changelog by default). Changes are classified into 3 types: - Data: : TYPE-I - Metadata : TYPE-II - Entry : TYPE-III Changelog file is rolled over after a certain time interval (defauls to 60 seconds) after which a changelog is started. The thing to be noted here is that for a time interval (time slice) multiple changes for an inode are recorded only once (ie. say for 100+ writes on an inode that happens within the time slice has only a single corresponding entry in the changelog file). That way we do not bloat up the changelog and also save lots of writes. Changelog Format ----------------- TYPE-I and TYPE-II changes have the gfid on the entity on which the operation happened. TYPE-III being a entry op requires the parent gfid and the basename. Changelog format has been kept to a minimal and it's upto the consumers to do the heavy loading of figuring out deletes, renames etc.. A single changelog file records all three types of changes, with each change starting with an identifier ("D": DATA, "M": METADATA and "E": ENTRY). Option is provided for the encoding type (See TUNABLES). Consumers ---------- The only consumer as of today would be geo-replication, although backup utilities, self-heal, bit-rot detection could be possible consumers in the future. CLI ---- By default, change-logging is disabled (the translator is present in the server graph but does nothing). When enabled (via cli) each brick starts to log the changes. There are a set of tunable that can be used to change the translators behaviour: - enable/disable changelog (disabled by default) gluster volume set <volume> changelog {on|off} - set the logging directory (<brick>/.glusterfs/changelogs is the default) gluster volume set <volume> changelog-dir /path/to/dir - select encoding type (binary (default) or ascii) gluster volume set <volume> encoding {binary|ascii} - change the rollover time for the logs (60 secs by default) gluster volume set <volume> rollover-time <secs> - when secs > 0, changelog file is not open()'d with O_SYNC flag - and fsync is trigerred periodically every <secs> seconds. gluster volume set <volume> fsync-interval <secs> features/changelog: changelog consumer library (libgfchangelog) A shared library is provided for the consumer of the changelogs for easy acess via APIs. Application can link against this library and request for changelog updates. Conversion of binary logs to human-readable ascii format is also taken care by the library which keeps a copy of the changelog in application provided working directory. Change-Id: I75575fb7f1c53d2bec3dba1a329ea7bb3c628497 BUG: 847839 Original Author: Venky Shankar <> Signed-off-by: Avra Sengupta <> Reviewed-on: Tested-by: Gluster Build System <> Reviewed-by: Vijay Bellur <>
Diffstat (limited to 'xlators/features/changelog/lib/src/gf-changelog-helpers.h')
1 files changed, 97 insertions, 0 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.h b/xlators/features/changelog/lib/src/gf-changelog-helpers.h
new file mode 100644
index 000000000..3aa6ed7b8
--- /dev/null
+++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.h
@@ -0,0 +1,97 @@
+ Copyright (c) 2013 Red Hat, Inc. <>
+ This file is part of GlusterFS.
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
+#include <unistd.h>
+#include <dirent.h>
+#include <limits.h>
+#include <pthread.h>
+#include <xlator.h>
+#define GF_CHANGELOG_TRACKER "tracker"
+#define GF_CHANGELOG_CURRENT_DIR ".current"
+#define GF_CHANGELOG_PROCESSED_DIR ".processed"
+#define GF_CHANGELOG_PROCESSING_DIR ".processing"
+#ifndef MAXLINE
+#define MAXLINE 4096
+#define GF_CHANGELOG_FILL_BUFFER(ptr, ascii, off, len) do { \
+ memcpy (ascii + off, ptr, len); \
+ off += len; \
+ } while (0)
+typedef struct read_line {
+ int rl_cnt;
+ char *rl_bufptr;
+ char rl_buf[MAXLINE];
+} read_line_t;
+typedef struct gf_changelog {
+ xlator_t *this;
+ /* 'processing' directory stream */
+ DIR *gfc_dir;
+ /* fd to the tracker file */
+ int gfc_fd;
+ /* connection retries */
+ int gfc_connretries;
+ char gfc_sockpath[PATH_MAX];
+ char gfc_brickpath[PATH_MAX];
+ /* socket for recieving notifications */
+ int gfc_sockfd;
+ char *gfc_working_dir;
+ /* RFC 3986 string encoding */
+ char rfc3986[256];
+ char gfc_current_dir[PATH_MAX];
+ char gfc_processed_dir[PATH_MAX];
+ char gfc_processing_dir[PATH_MAX];
+ pthread_t gfc_changelog_processor;
+} gf_changelog_t;
+gf_changelog_notification_init (xlator_t *this, gf_changelog_t *gfc);
+void *
+gf_changelog_process (void *data);
+gf_changelog_read_path (int fd, char *buffer, size_t bufsize);
+gf_rfc3986_encode (unsigned char *s, char *enc, char *estr);
+gf_changelog_write (int fd, char *buffer, size_t len);
+gf_readline (int fd, void *vptr, size_t maxlen);
+gf_ftruncate (int fd, off_t length);
+gf_lseek (int fd, off_t offset, int whence);