diff options
| author | Venky Shankar <vshankar@redhat.com> | 2014-02-19 20:47:46 +0530 | 
|---|---|---|
| committer | Venky Shankar <vshankar@redhat.com> | 2014-05-14 05:10:15 -0700 | 
| commit | d2db585ce7e26851178104433fa9422482d8719e (patch) | |
| tree | 2e52f15cf261906debd8ec54106ffe9f84af881e /xlators/features/changelog/src/changelog-helpers.c | |
| parent | bfde478cedda8267134ee3807c8db5e042115eae (diff) | |
features/changelog : historical journal consumption.
Facilitates Glusterfs with the ability to detect file-operations
happened in past by scanning the back-end(brick-level) glusterfs
journal (changelog).
Design:
  * List of changelogs produces in one perfectly running session are
    stored in htime file which also holds necessary information about
    the session start and end time.
  * Involves fixed sized seeks to identify N'th changelog in the list.
  * Requires O(log n), (where n is number of changelogs in the list),
    time to identify the end changelog for the given start-end time
    interval.
Currently the background processing of changelogs is sub optimal. BZ
1097041 tracks the development effort.
For complete design, refer the below link:
http://lists.nongnu.org/archive/html/gluster-devel/2014-02/msg00206.html
Change-Id: I27e49f75e492e843084d0ecaf9130224d08462a0
BUG: 1091961
Signed-off-by: Ajeet Jha <ajha@redhat.com>
Signed-off-by: Venky Shankar <vshankar@redhat.com>
Signed-off-by: Ajeet Jha <ajha@redhat.com>
Reviewed-on: http://review.gluster.org/6930
Reviewed-by: Kotresh HR <khiremat@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'xlators/features/changelog/src/changelog-helpers.c')
| -rw-r--r-- | xlators/features/changelog/src/changelog-helpers.c | 103 | 
1 files changed, 102 insertions, 1 deletions
diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c index 71f2f7a25ad..984106b75e6 100644 --- a/xlators/features/changelog/src/changelog-helpers.c +++ b/xlators/features/changelog/src/changelog-helpers.c @@ -17,6 +17,7 @@  #include "defaults.h"  #include "logging.h"  #include "iobuf.h" +#include "syscall.h"  #include "changelog-helpers.h"  #include "changelog-mem-types.h" @@ -132,6 +133,49 @@ changelog_write (int fd, char *buffer, size_t len)          return (writen != len);  } +int +htime_update (xlator_t *this, +              changelog_priv_t *priv, unsigned long ts, +              char * buffer) +{ +        char changelog_path[PATH_MAX+1]   = {0,}; +        int len                           = -1; +        char x_value[25]                  = {0,}; +        /* time stamp(10) + : (1) + rolltime (12 ) + buffer (2) */ +        int ret                           = 0; + +        if (priv->htime_fd ==-1) { +                gf_log (this->name, GF_LOG_ERROR, +                        "Htime fd not available for updation"); +                ret = -1; +                goto out; +        } +        strcpy (changelog_path, buffer); +        len = strlen (changelog_path); +        changelog_path[len] = '\0'; /* redundant */ + +        if (changelog_write (priv->htime_fd, (void*) changelog_path, len+1 ) < 0) { +                gf_log (this->name, GF_LOG_ERROR, +                        "Htime file content write failed"); +                ret =-1; +                goto out; +        } + +        sprintf (x_value,"%lu:%d",ts, priv->rollover_count); + +        if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value, +                       strlen (x_value),  XATTR_REPLACE)) { +                gf_log (this->name, GF_LOG_ERROR, +                        "Htime xattr updation failed"); +                goto out; +        } + +        priv->rollover_count +=1; + +out: +        return ret; +} +  static int  changelog_rollover_changelog (xlator_t *this,                                changelog_priv_t *priv, unsigned long ts) @@ -173,6 +217,15 @@ changelog_rollover_changelog (xlator_t *this,                          ofile, nfile, strerror (errno));          } +        if (!ret) { +                ret = htime_update (this, priv, ts, nfile); +                if (ret == -1) { +                        gf_log (this->name, GF_LOG_ERROR, +                                "could not update htime file"); +                        goto out; +                } +        } +          if (notify) {                  bname = basename (nfile);                  gf_log (this->name, GF_LOG_DEBUG, "notifying: %s", bname); @@ -212,6 +265,54 @@ changelog_rollover_changelog (xlator_t *this,          return ret;  } +/* Returns 0 on successful creation of htime file + * returns -1 on failure or error + */ +int +htime_open (xlator_t *this, +            changelog_priv_t * priv, unsigned long ts) +{ +        int fd                          = -1; +        int ret                         = 0; +        char ht_dir_path[PATH_MAX]      = {0,}; +        char ht_file_path[PATH_MAX]     = {0,}; +        int flags                       = 0; + +        CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path); + +        /* get the htime file name in ht_file_path */ +        (void) snprintf (ht_file_path,PATH_MAX,"%s/%s.%lu",ht_dir_path, +                        HTIME_FILE_NAME, ts); + +        flags |= (O_CREAT | O_RDWR | O_SYNC); +        fd = open (ht_file_path, flags, +                        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); +        if (fd < 0) { +                gf_log (this->name, GF_LOG_ERROR, +                        "unable to open/create htime file: %s" +                        "(reason: %s)", ht_file_path, strerror (errno)); +                ret = -1; +                goto out; + +        } + +        if (sys_fsetxattr (fd, HTIME_KEY, HTIME_INITIAL_VALUE, +                       sizeof (HTIME_INITIAL_VALUE)-1,  0)) { +                gf_log (this->name, GF_LOG_ERROR, +                        "Htime xattr initialization failed"); +                ret = -1; +                goto out; +        } + +        /* save this htime_fd in priv->htime_fd */ +        priv->htime_fd = fd; +        /* initialize rollover-number in priv to 1 */ +        priv->rollover_count = 1; + +out: +        return ret; +} +  int  changelog_open (xlator_t *this,                  changelog_priv_t *priv) @@ -311,7 +412,7 @@ changelog_handle_change (xlator_t *this,          int ret = 0;          if (CHANGELOG_TYPE_IS_ROLLOVER (cld->cld_type)) { -                changelog_encode_change(priv); +                changelog_encode_change (priv);                  ret = changelog_start_next_change (this, priv,                                                     cld->cld_roll_time,                                                     cld->cld_finale);  | 
