summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendra@redhat.com>2014-01-28 22:58:27 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-02-02 20:58:12 -0800
commitaa53d35780a2b742a66c6b690d1d20dc173168cf (patch)
tree4564be32e7273868be33f1bdf3c4db8463111a3a
parent56b8ed7592e53226e356bced53147d365c5024e6 (diff)
mgmt/glusterd: perform store on only newly created snapshot
* Instead performing store on all the snaps of the volume when a new snap is created, store only the new snap's info. Otherwise with more and more snapshots in the volume, time creation for new snapshot becomes very large as glusterd has to store all the snapshots related info everytime (that too by doing fsyncs) Change-Id: I0e005d1d4c044b07a8abde8e6ba55e66a1bbd590 BUG: 1059146 Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-on: http://review.gluster.org/6841 Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c110
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.h4
3 files changed, 103 insertions, 13 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index b8ecb61..db1afd3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -3166,7 +3166,7 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
goto out;
}
- ret = glusterd_store_perform_snap_store (volinfo);
+ ret = glusterd_store_perform_snap_store (volinfo, snapname);
if (ret) {
gf_log (this->name, GF_LOG_WARNING, "could not do volume store"
" after taking the snapshot (volume: %s)",
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 8468231..5dfc964 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -1522,20 +1522,108 @@ out:
}
int32_t
-glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo)
+glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo, char *snapname)
{
- int fd = -1;
- int32_t ret = -1;
- glusterd_snap_t *entry = NULL;
- glusterd_snap_t *tmp = NULL;
- uint64_t count = 0;
+ int fd = -1;
+ int32_t ret = -1;
+ glusterd_snap_t *entry = NULL;
+ glusterd_snap_t *tmp = NULL;
+ uint64_t count = 0;
char buf[PATH_MAX] = {0,};
+ xlator_t *this = NULL;
GF_ASSERT (volinfo);
+ GF_ASSERT (snapname);
+
+ this = THIS;
+ GF_ASSERT (this);
ret = glusterd_store_create_snaps_dir (volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to create the snaps "
+ "directory for the volume %s (snap: %s)",
+ volinfo->volname, snapname);
+ goto out;
+ }
+
+ ret = glusterd_store_create_snap_list_sh_on_absence (volinfo);
if (ret)
goto out;
+ fd = gf_store_mkstemp (volinfo->snap_list_shandle);
+ if (fd <= 0) {
+ ret = -1;
+ goto out;
+ }
+
+ LOCK (&volinfo->lock);
+ {
+ list_for_each_entry_safe (entry, tmp, &volinfo->snaps,
+ snap_list) {
+ if (!strcmp (entry->snap_name, snapname)) {
+ ret = glusterd_store_snap_list_write (fd, entry,
+ count);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to write snap list to"
+ " store");
+ goto unlock;
+ }
+ ret = glusterd_store_snap_volume (volinfo,
+ entry);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to store snap volume");
+ goto unlock;
+ }
+ }
+ count++;
+ }
+ GF_ASSERT (count == volinfo->snap_count);
+ snprintf (buf, sizeof(buf), "%"PRIu64, count);
+ ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_COUNT,
+ buf);
+ if (ret)
+ goto unlock;
+ }
+unlock:
+ UNLOCK (&volinfo->lock);
+
+ ret = gf_store_rename_tmppath (volinfo->snap_list_shandle);
+ if (ret)
+ goto out;
+
+out:
+ if (ret && (fd > 0))
+ gf_store_unlink_tmppath (volinfo->snap_list_shandle);
+ if (fd > 0)
+ close (fd);
+
+ gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_store_perform_all_snap_store (glusterd_volinfo_t *volinfo)
+{
+ int fd = -1;
+ int32_t ret = -1;
+ glusterd_snap_t *entry = NULL;
+ glusterd_snap_t *tmp = NULL;
+ uint64_t count = 0;
+ char buf[PATH_MAX] = {0,};
+ xlator_t *this = NULL;
+
+ GF_ASSERT (volinfo);
+
+ this = THIS;
+ GF_ASSERT (this);
+
+ ret = glusterd_store_create_snaps_dir (volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to create the snaps "
+ "directory for the volume %s", volinfo->volname);
+ goto out;
+ }
ret = glusterd_store_create_snap_list_sh_on_absence (volinfo);
if (ret)
@@ -1552,13 +1640,13 @@ glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo)
snap_list) {
ret = glusterd_store_snap_list_write (fd, entry, count);
if (ret) {
- gf_log (THIS->name, GF_LOG_ERROR, "Failed to "
+ gf_log (this->name, GF_LOG_ERROR, "Failed to "
"write snap list to store");
goto unlock;
}
ret = glusterd_store_snap_volume (volinfo, entry);
if (ret) {
- gf_log (THIS->name, GF_LOG_ERROR, "Failed to "
+ gf_log (this->name, GF_LOG_ERROR, "Failed to "
"store snap volume");
goto unlock;
}
@@ -1583,7 +1671,7 @@ out:
if (fd > 0)
close (fd);
- gf_log ("", GF_LOG_TRACE, "Returning %d", ret);
+ gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret);
return ret;
}
@@ -1843,7 +1931,7 @@ glusterd_store_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_ver_ac_t a
if (ret)
goto out;
- ret = glusterd_store_perform_snap_store (volinfo);
+ ret = glusterd_store_perform_all_snap_store (volinfo);
if (ret)
goto out;
@@ -3508,7 +3596,7 @@ glusterd_store_retrieve_volumes (xlator_t *this)
ret = glusterd_volinfo_find (entry->d_name, &volinfo);
ret =
glusterd_store_create_snap_list_sh_on_absence (volinfo);
- ret = glusterd_store_perform_snap_store (volinfo);
+ ret = glusterd_store_perform_all_snap_store (volinfo);
//ret = glusterd_store_perform_snap_list_store (volinfo); TODO: Fix this
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index b8123f6..8ddd3e6 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -156,7 +156,9 @@ glusterd_replace_slash_with_hyphen (char *str);
int32_t
glusterd_store_perform_volume_store (glusterd_volinfo_t *volinfo);
int32_t
-glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo);
+glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo, char *snapname);
+int32_t
+glusterd_store_perform_all_snap_store (glusterd_volinfo_t *volinfo);
int32_t
glusterd_store_perform_snap_list_store (glusterd_volinfo_t *volinfo);
int32_t