diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2019-04-28 22:05:44 +0300 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2019-05-08 06:46:24 +0000 |
commit | 1fa089e7a2b180e0bdcc1e7e09a63934a2a0c0ef (patch) | |
tree | 92e28f0fb24fd550375e4cb401b9e7bfaa098efa /libglusterfs | |
parent | aa52259de7b50625b754ce9fb5c0f38e22d79dd6 (diff) |
glusterd/store: store all key-values in one shot
Instead of saving each key-value separately, which is slow (
especially as we fflush() after each!), store them all as one
string and write all together.
Implements https://github.com/gluster/glusterfs/issues/629
Change-Id: Ie77a272446b0b6785584b710a4fdd9c613dd9578
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat,.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/glusterfs/store.h | 3 | ||||
-rw-r--r-- | libglusterfs/src/libglusterfs.sym | 1 | ||||
-rw-r--r-- | libglusterfs/src/store.c | 47 |
3 files changed, 51 insertions, 0 deletions
diff --git a/libglusterfs/src/glusterfs/store.h b/libglusterfs/src/glusterfs/store.h index 3b3a24c38f8..6e6e3b9ad6d 100644 --- a/libglusterfs/src/glusterfs/store.h +++ b/libglusterfs/src/glusterfs/store.h @@ -69,6 +69,9 @@ int32_t gf_store_save_value(int fd, char *key, char *value); int32_t +gf_store_save_items(int fd, char *items); + +int32_t gf_store_handle_new(const char *path, gf_store_handle_t **handle); int diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym index 5200b852154..7f762b19291 100644 --- a/libglusterfs/src/libglusterfs.sym +++ b/libglusterfs/src/libglusterfs.sym @@ -694,6 +694,7 @@ gf_store_read_and_tokenize gf_store_rename_tmppath gf_store_retrieve_value gf_store_save_value +gf_store_save_items gf_store_unlink_tmppath gf_store_unlock gf_string2boolean diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c index cdf0aeafe4c..0416a86d540 100644 --- a/libglusterfs/src/store.c +++ b/libglusterfs/src/store.c @@ -388,6 +388,53 @@ out: } int32_t +gf_store_save_items(int fd, char *items) +{ + int32_t ret = -1; + int dup_fd = -1; + FILE *fp = NULL; + + GF_ASSERT(fd > 0); + GF_ASSERT(items); + + dup_fd = dup(fd); + if (dup_fd == -1) + goto out; + + fp = fdopen(dup_fd, "a+"); + if (fp == NULL) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "fdopen failed."); + ret = -1; + goto out; + } + + ret = fputs(items, fp); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "Unable to store items: %s", items); + ret = -1; + goto out; + } + + ret = fflush(fp); + if (ret) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "fflush failed."); + ret = -1; + goto out; + } + + ret = 0; +out: + if (fp) + fclose(fp); + + gf_msg_debug(THIS->name, 0, "returning: %d", ret); + return ret; +} + +int32_t gf_store_handle_new(const char *path, gf_store_handle_t **handle) { int32_t ret = -1; |