summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorVikas Gorur <vikas@gluster.com>2009-10-26 05:24:19 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-10-26 07:09:32 -0700
commita284bf490cdf6ce334a4e70b22eedd7e639620f9 (patch)
tree71452ef51dab0ab1026a32258c6119ce92f77aa1 /xlators
parentd40ce2cbcd41a25eb053f2970db9bbaab2dafa22 (diff)
cluster/afr: Pick the data self-heal algorithm dynamically.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 320 (Improve self-heal performance) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=320
Diffstat (limited to 'xlators')
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-data.c77
-rw-r--r--xlators/cluster/afr/src/afr.c2
2 files changed, 66 insertions, 13 deletions
diff --git a/xlators/cluster/afr/src/afr-self-heal-data.c b/xlators/cluster/afr/src/afr-self-heal-data.c
index 2118fd66d..8c092522c 100644
--- a/xlators/cluster/afr/src/afr-self-heal-data.c
+++ b/xlators/cluster/afr/src/afr-self-heal-data.c
@@ -492,28 +492,81 @@ afr_sh_data_trim_sinks (call_frame_t *frame, xlator_t *this)
}
-struct afr_sh_algorithm *
-afr_sh_data_pick_algo (call_frame_t *frame, xlator_t *this)
+static struct afr_sh_algorithm *
+sh_algo_from_name (xlator_t *this, char *name)
{
- afr_private_t *priv = NULL;
int i = 0;
- priv = this->private;
-
while (afr_self_heal_algorithms[i].name) {
- if (!strcmp (priv->data_self_heal_algorithm,
- afr_self_heal_algorithms[i].name)) {
- goto out;
+ if (!strcmp (name, afr_self_heal_algorithms[i].name)) {
+ return &afr_self_heal_algorithms[i];
}
i++;
}
- /* No match found, so fall back on "full" */
+ return NULL;
+}
+
+
+static int
+sh_zero_byte_files_exist (afr_self_heal_t *sh, int child_count)
+{
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < child_count; i++) {
+ if (sh->buf[i].st_size == 0) {
+ ret = 1;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+
+struct afr_sh_algorithm *
+afr_sh_data_pick_algo (call_frame_t *frame, xlator_t *this)
+{
+ afr_private_t * priv = NULL;
+ struct afr_sh_algorithm * algo = NULL;
+ afr_local_t * local = NULL;
+ afr_self_heal_t * sh = NULL;
+
+ priv = this->private;
+ local = frame->local;
+ sh = &local->self_heal;
+ algo = sh_algo_from_name (this, priv->data_self_heal_algorithm);
+
+ if (algo == NULL) {
+ /* option not set, so fall back on heuristics */
+
+ if ((local->enoent_count != 0)
+ || sh_zero_byte_files_exist (sh, priv->child_count)
+ || (sh->file_size <= (priv->data_self_heal_window_size * this->ctx->page_size))) {
+
+ /*
+ * If the file does not exist on one of the subvolumes,
+ * or a zero-byte file exists (created by entry self-heal)
+ * the entire content has to be copied anyway, so there
+ * is no benefit from using the "diff" algorithm.
+ *
+ * If the file size is about the same as page size,
+ * the entire file can be read and written with a few
+ * (pipelined) STACK_WINDs, which will be faster
+ * than "diff" which has to read checksums and then
+ * read and write.
+ */
+
+ algo = sh_algo_from_name (this, "full");
+
+ } else {
+ algo = sh_algo_from_name (this, "diff");
+ }
+ }
- i = 0;
-out:
- return &afr_self_heal_algorithms[i];
+ return algo;
}
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index cf4b8d3bc..433f73b7d 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -2400,7 +2400,7 @@ init (xlator_t *this)
}
}
- priv->data_self_heal_algorithm = "full";
+ priv->data_self_heal_algorithm = "";
dict_ret = dict_get_str (this->options, "data-self-heal-algorithm",
&algo);