diff options
author | Kotresh HR <khiremat@redhat.com> | 2018-08-21 06:09:44 -0400 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 13:28:43 +0000 |
commit | 35aa67001c8fac99b040fbc61f36ef4f1b1590ac (patch) | |
tree | 2d0e75b469b37738a7a61c2171aadc5a58956b5d /tests | |
parent | 052849983e51a061d7fb2c3ffd74fa78bb257084 (diff) |
libgfchangelog: Fix changelog history API
Problem:
If requested start time and end time doesn't fall into
first HTIME file, then history API fails even though
continuous changelogs are avaiable for the requested range
in other HTIME files. This is induced by changelog disable
and enable which creates fresh HTIME index file.
Cause and Analysis:
Each HTIME index file represents the availability of
continuous changelogs. If changelog is disabled and enabled,
a new HTIME index file is created represents non availability
of continuous changelogs. So as long as the requested start
and end falls into single HTIME index file and not across,
history API should succeed.
But History API checks for the changelogs only in first
HTIME index file and errors out if not available.
Fix:
Check in all HTIME index files for availability of continuous
changelogs for requested change.
fixes: bz#1622549
Change-Id: I80eeceb5afbd1b89f86a9dc4c320e161907d3559
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/changelog/changelog-history.t | 86 | ||||
-rw-r--r-- | tests/utils/changelog/changelog.h | 120 | ||||
-rw-r--r-- | tests/utils/changelog/get-history.c | 73 |
3 files changed, 279 insertions, 0 deletions
diff --git a/tests/basic/changelog/changelog-history.t b/tests/basic/changelog/changelog-history.t new file mode 100644 index 00000000000..3ce40981c90 --- /dev/null +++ b/tests/basic/changelog/changelog-history.t @@ -0,0 +1,86 @@ +#!/bin/bash +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc +. $(dirname $0)/../../env.rc + +cleanup; + +HISTORY_BIN_PATH=$(dirname $0)/../../utils/changelog +build_tester $HISTORY_BIN_PATH/get-history.c -lgfchangelog + +time_before_enable1=$(date '+%s') +CHANGELOG_PATH_0="$B0/${V0}0/.glusterfs/changelogs" +ROLLOVER_TIME=2 + +TEST glusterd +TEST pidof glusterd + +sleep 3 +time_before_enable2=$(date '+%s') + +sleep 3 +TEST $CLI volume create $V0 $H0:$B0/${V0}0 +TEST $CLI volume set $V0 changelog.changelog on +TEST $CLI volume set $V0 changelog.rollover-time $ROLLOVER_TIME +TEST $CLI volume start $V0 + +sleep 3 +time_after_enable1=$(date '+%s') + +TEST $GFS --volfile-id=$V0 --volfile-server=$H0 $M0; +touch $M0/file{1..10} + +sleep 3 +time_after_enable2=$(date '+%s') + +let time_future=time_after_enable2+600 + +#Fails as start falls before changelog enable +EXPECT "-3" $HISTORY_BIN_PATH/get-history $time_before_enable1 $time_before_enable2 + +#Fails as start falls before changelog enable +EXPECT "-3" $HISTORY_BIN_PATH/get-history $time_before_enable2 $time_after_enable1 + +#Passes as start and end falls in same htime file +EXPECT "0" $HISTORY_BIN_PATH/get-history $time_after_enable1 $time_after_enable2 + +#Passes, gives the changelogs till continuous changelogs are available +# but returns 1 +EXPECT "1" $HISTORY_BIN_PATH/get-history $time_after_enable2 $time_future + +#Disable and enable changelog +TEST $CLI volume set $V0 changelog.changelog off +sleep 6 +time_between_htime=$(date '+%s') +sleep 6 +TEST $CLI volume set $V0 changelog.changelog on + +sleep 6 +touch $M0/test{1..10} +time_in_sec_htime1=$(date '+%s') + +sleep 6 +touch $M0/test1{1..10} +time_in_sec_htime2=$(date '+%s') + +sleep 3 +TEST $CLI volume set $V0 changelog.changelog off +sleep 3 +time_after_disable=$(date '+%s') + +#Passes, gives the changelogs till continuous changelogs are available +# but returns 1 +EXPECT "1" $HISTORY_BIN_PATH/get-history $time_after_enable1 $time_in_sec_htime2 + +#Fails as start falls between htime files +EXPECT "-3" $HISTORY_BIN_PATH/get-history $time_between_htime $time_in_sec_htime1 + +#Passes as start and end falls in same htime file +EXPECT "0" $HISTORY_BIN_PATH/get-history $time_in_sec_htime1 $time_in_sec_htime2 + +#Passes, gives the changelogs till continuous changelogs are available +EXPECT "0" $HISTORY_BIN_PATH/get-history $time_in_sec_htime2 $time_after_disable + +TEST rm $HISTORY_BIN_PATH/get-history + +cleanup; diff --git a/tests/utils/changelog/changelog.h b/tests/utils/changelog/changelog.h new file mode 100644 index 00000000000..14094cf3681 --- /dev/null +++ b/tests/utils/changelog/changelog.h @@ -0,0 +1,120 @@ +/* + Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + 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. +*/ + +#ifndef _GF_CHANGELOG_H +#define _GF_CHANGELOG_H + +struct gf_brick_spec; + +/** + * Max bit shiter for event selection + */ +#define CHANGELOG_EV_SELECTION_RANGE 5 + +#define CHANGELOG_OP_TYPE_JOURNAL (1<<0) +#define CHANGELOG_OP_TYPE_OPEN (1<<1) +#define CHANGELOG_OP_TYPE_CREATE (1<<2) +#define CHANGELOG_OP_TYPE_RELEASE (1<<3) +#define CHANGELOG_OP_TYPE_BR_RELEASE (1<<4) /* logical release (last close()), + sent by bitrot stub */ +#define CHANGELOG_OP_TYPE_MAX (1<<CHANGELOG_EV_SELECTION_RANGE) + + +struct ev_open { + unsigned char gfid[16]; + int32_t flags; +}; + +struct ev_creat { + unsigned char gfid[16]; + int32_t flags; +}; + +struct ev_release { + unsigned char gfid[16]; +}; + +struct ev_release_br { + unsigned long version; + unsigned char gfid[16]; + int32_t sign_info; +}; + +struct ev_changelog { + char path[PATH_MAX]; +}; + +typedef struct changelog_event { + unsigned int ev_type; + + union { + struct ev_open open; + struct ev_creat create; + struct ev_release release; + struct ev_changelog journal; + struct ev_release_br releasebr; + } u; +} changelog_event_t; + +#define CHANGELOG_EV_SIZE (sizeof (changelog_event_t)) + +/** + * event callback, connected & disconnection defs + */ +typedef void (CALLBACK) (void *, char *, + void *, changelog_event_t *); +typedef void *(INIT) (void *, struct gf_brick_spec *); +typedef void (FINI) (void *, char *, void *); +typedef void (CONNECT) (void *, char *, void *); +typedef void (DISCONNECT) (void *, char *, void *); + +struct gf_brick_spec { + char *brick_path; + unsigned int filter; + + INIT *init; + FINI *fini; + CALLBACK *callback; + CONNECT *connected; + DISCONNECT *disconnected; + + void *ptr; +}; + +/* API set */ + +int +gf_changelog_register (char *brick_path, char *scratch_dir, + char *log_file, int log_levl, int max_reconnects); +ssize_t +gf_changelog_scan (); + +int +gf_changelog_start_fresh (); + +ssize_t +gf_changelog_next_change (char *bufptr, size_t maxlen); + +int +gf_changelog_done (char *file); + +/* newer flexible API */ +int +gf_changelog_init (void *xl); + +int +gf_changelog_register_generic (struct gf_brick_spec *bricks, int count, + int ordered, char *logfile, int lvl, void *xl); + +int +gf_history_changelog (char *changelog_dir, unsigned long start, + unsigned long end, int n_parallel, + unsigned long *actual_end); +#endif diff --git a/tests/utils/changelog/get-history.c b/tests/utils/changelog/get-history.c new file mode 100644 index 00000000000..29dc60987ae --- /dev/null +++ b/tests/utils/changelog/get-history.c @@ -0,0 +1,73 @@ +/* + Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + 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. +*/ + +/** + * get set of new changes every 10 seconds (just print the file names) + * + * Compile it using: + * gcc -o gethistory `pkg-config --cflags libgfchangelog` get-history.c \ + * `pkg-config --libs libgfchangelog` + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/un.h> +#include <limits.h> +#include <sys/socket.h> +#include <sys/types.h> + +#include "changelog.h" + +int +main (int argc, char **argv) +{ + int ret = 0; + unsigned long end_ts = 0; + int start = 0; + int end = 0; + + ret = gf_changelog_init (NULL); + if (ret) { + printf ("-1"); + fflush(stdout); + return -1; + } + + ret = gf_changelog_register ("/d/backends/patchy0", + "/tmp/scratch_v1", + "/var/log/glusterfs/changes.log", + 9, 5); + if (ret) { + printf ("-2"); + fflush(stdout); + return -1; + } + + start = atoi(argv[1]); + end = atoi(argv[2]); + + ret = gf_history_changelog ("/d/backends/patchy0/.glusterfs/changelogs", + start, end, 3, &end_ts); + if (ret < 0) { + printf ("-3"); + fflush(stdout); + return -1; + } else if (ret == 1) { + printf ("1"); + fflush(stdout); + return 0; + } + +out: + printf ("0"); + fflush(stdout); + return 0; +} |