[Groonga-commit] groonga/groonga [master] add --default-query-escalation-threshold for dynamic threshold change. #628

Back to archive index

null+****@clear***** null+****@clear*****
2010年 10月 21日 (木) 18:08:22 JST


Kouhei Sutou	2010-10-21 09:08:22 +0000 (Thu, 21 Oct 2010)

  New Revision: ded7d788b2ad8171c75cebc3cafec43234d4454e

  Log:
    add --default-query-escalation-threshold for dynamic threshold change. #628

  Modified files:
    groonga.h
    lib/ctx.c
    lib/ii.c
    lib/ql.h
    src/groonga.c

  Modified: groonga.h (+30 -0)
===================================================================
--- groonga.h    2010-10-28 01:42:12 +0000 (baefdbe)
+++ groonga.h    2010-10-21 09:08:22 +0000 (ccb47b1)
@@ -283,6 +283,36 @@ GRN_API grn_command_version grn_ctx_get_command_version(grn_ctx *ctx);
  **/
 GRN_API grn_rc grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version);
 
+/**
+ * grn_ctx_get_query_escalation_threshold:
+ *
+ * クエリをエスカレーションする閾値を返します。
+ **/
+GRN_API long long int grn_ctx_get_query_escalation_threshold(grn_ctx *ctx);
+
+/**
+ * grn_ctx_set_query_escalation_threshold:
+ * @threshold: 変更後のクエリをエスカレーションする閾値を指定します。
+ *
+ * クエリをエスカレーションする閾値を変更します。
+ **/
+GRN_API grn_rc grn_ctx_set_query_escalation_threshold(grn_ctx *ctx, long long int threshold);
+
+/**
+ * grn_get_default_query_escalation_threshold:
+ *
+ * デフォルトのクエリをエスカレーションする閾値を返します。
+ **/
+GRN_API long long int grn_get_default_query_escalation_threshold(void);
+
+/**
+ * grn_set_default_query_escalation_threshold:
+ * @threshold: 変更後のデフォルトのクエリをエスカレーションする閾値を指定します。
+ *
+ * デフォルトのクエリをエスカレーションする閾値を変更します。
+ **/
+GRN_API grn_rc grn_set_default_query_escalation_threshold(long long int threshold);
+
 
 /* obj */
 

  Modified: lib/ctx.c (+35 -0)
===================================================================
--- lib/ctx.c    2010-10-28 01:42:12 +0000 (96be9d0)
+++ lib/ctx.c    2010-10-21 09:08:22 +0000 (abcbaf0)
@@ -285,6 +285,12 @@ grn_ctx_impl_init(grn_ctx *ctx)
     ctx->impl->command_version = grn_get_default_command_version();
   }
 
+  if (ctx == &grn_gctx) {
+    ctx->impl->escalation_threshold = GROONGA_DEFAULT_QUERY_ESCALATION_THRESHOLD;
+  } else {
+    ctx->impl->escalation_threshold = grn_get_default_query_escalation_threshold();
+  }
+
   ctx->impl->phs = NIL;
   ctx->impl->code = NIL;
   ctx->impl->dump = NIL;
@@ -725,6 +731,18 @@ grn_set_default_command_version(grn_command_version version)
   return grn_ctx_set_command_version(&grn_gctx, version);
 }
 
+long long int
+grn_get_default_query_escalation_threshold(void)
+{
+  return grn_ctx_get_query_escalation_threshold(&grn_gctx);
+}
+
+grn_rc
+grn_set_default_query_escalation_threshold(long long int threshold)
+{
+  return grn_ctx_set_query_escalation_threshold(&grn_gctx, threshold);
+}
+
 static int alloc_count = 0;
 
 grn_rc
@@ -807,6 +825,23 @@ grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version)
   }
 }
 
+long long int
+grn_ctx_get_query_escalation_threshold(grn_ctx *ctx)
+{
+  if (ctx->impl) {
+    return ctx->impl->escalation_threshold;
+  } else {
+    return GROONGA_DEFAULT_QUERY_ESCALATION_THRESHOLD;
+  }
+}
+
+grn_rc
+grn_ctx_set_query_escalation_threshold(grn_ctx *ctx, long long int threshold)
+{
+  ctx->impl->escalation_threshold = threshold;
+  return GRN_SUCCESS;
+}
+
 grn_content_type
 grn_get_ctype(grn_obj *var)
 {

  Modified: lib/ii.c (+2 -2)
===================================================================
--- lib/ii.c    2010-10-28 01:42:12 +0000 (d022c4b)
+++ lib/ii.c    2010-10-21 09:08:22 +0000 (e7f3b5b)
@@ -5941,7 +5941,7 @@ grn_ii_sel(grn_ctx *ctx, grn_ii *ii, const char *string, unsigned int string_len
     }
     GRN_LOG(ctx, GRN_LOG_INFO, "exact: %d", GRN_HASH_SIZE(s));
     if (op == GRN_OP_OR) {
-      if (GRN_HASH_SIZE(s) <= GROONGA_DEFAULT_QUERY_ESCALATION_THRESHOLD) {
+      if ((int64_t)GRN_HASH_SIZE(s) <= ctx->impl->escalation_threshold) {
         arg.mode = GRN_OP_UNSPLIT;
         if (grn_ii_select(ctx, ii, string, string_len, s, op, &arg)) {
           GRN_LOG(ctx, GRN_LOG_ERROR, "grn_ii_select on grn_ii_sel(2) failed !");
@@ -5949,7 +5949,7 @@ grn_ii_sel(grn_ctx *ctx, grn_ii *ii, const char *string, unsigned int string_len
         }
         GRN_LOG(ctx, GRN_LOG_INFO, "unsplit: %d", GRN_HASH_SIZE(s));
       }
-      if (GRN_HASH_SIZE(s) <= GROONGA_DEFAULT_QUERY_ESCALATION_THRESHOLD) {
+      if ((int64_t)GRN_HASH_SIZE(s) <= ctx->impl->escalation_threshold) {
         arg.mode = GRN_OP_PARTIAL;
         if (grn_ii_select(ctx, ii, string, string_len, s, op, &arg)) {
           GRN_LOG(ctx, GRN_LOG_ERROR, "grn_ii_select on grn_ii_sel(3) failed !");

  Modified: lib/ql.h (+3 -0)
===================================================================
--- lib/ql.h    2010-10-28 01:42:12 +0000 (b0ff6d4)
+++ lib/ql.h    2010-10-21 09:08:22 +0000 (bfa96cc)
@@ -221,6 +221,9 @@ struct _grn_ctx_impl {
   /* command portion */
   grn_command_version command_version;
 
+  /* query escalation portion */
+  int64_t escalation_threshold;
+
   /* ql portion */
   uint32_t ncells;
   uint32_t seqno;

  Modified: src/groonga.c (+20 -4)
===================================================================
--- src/groonga.c    2010-10-28 01:42:12 +0000 (d24fb7a)
+++ src/groonga.c    2010-10-21 09:08:22 +0000 (996feb4)
@@ -111,6 +111,8 @@ usage(FILE *output)
           "  --file <path>:                    read commands from specified file\n"
           "  --default-command-version <version>:\n"
           "                                    specify default command version\n"
+          "  --default-query-escalation-threshold <threshold>:\n"
+          "                                    specify default query escalation threshold\n"
           "\n"
           "dest: <db pathname> [<command>] or <dest hostname>\n"
           "  <db pathname> [<command>]: when standalone/server mode\n"
@@ -135,9 +137,8 @@ show_version(void)
 #endif
   printf("%s", GROONGA_DEFAULT_ENCODING);
 
-#ifdef GROONGA_DEFAULT_QUERY_ESCALATION_THRESHOLD
-  printf(",query-cache=%ds", GROONGA_DEFAULT_QUERY_ESCALATION_THRESHOLD);
-#endif
+  printf(",query-escalation-threshold=%" GRN_FMT_LLD,
+         grn_get_default_query_escalation_threshold());
 
 #ifndef NO_NFKC
   printf(",nfkc");
@@ -2064,7 +2065,8 @@ main(int argc, char **argv)
   const char *portstr = NULL, *encstr = NULL,
     *max_nfthreadsstr = NULL, *loglevel = NULL,
     *listen_addressstr = NULL, *hostnamestr = NULL, *protocol = NULL,
-    *cache_limitstr = NULL, *admin_html_path = NULL, *command_versionstr = NULL;
+    *cache_limitstr = NULL, *admin_html_path = NULL, *command_versionstr = NULL,
+    *query_escalation_thresholdstr = NULL;
   const char *config_path = NULL;
   const char *input_path = NULL;
   int r, i, mode = mode_alone;
@@ -2093,6 +2095,7 @@ main(int argc, char **argv)
     {'\0', "file", NULL, 0, getopt_op_none},
     {'\0', "document-root", NULL, 0, getopt_op_none},
     {'\0', "default-command-version", NULL, 0, getopt_op_none},
+    {'\0', "default-query-escalation-threshold", NULL, 0, getopt_op_none},
     {'\0', NULL, NULL, 0, 0}
   };
   opts[0].arg = &portstr;
@@ -2111,6 +2114,7 @@ main(int argc, char **argv)
   opts[21].arg = &input_path;
   opts[22].arg = &grn_document_root;
   opts[23].arg = &command_versionstr;
+  opts[24].arg = &query_escalation_thresholdstr;
   if (!(default_max_nfthreads = get_core_number())) {
     default_max_nfthreads = DEFAULT_MAX_NFTHREADS;
   }
@@ -2250,6 +2254,18 @@ main(int argc, char **argv)
   if (command_versionstr) {
     grn_set_default_command_version(atoi(command_versionstr));
   }
+  if (query_escalation_thresholdstr) {
+    int64_t threshold;
+    const char *end, *rest;
+    end = query_escalation_thresholdstr + strlen(query_escalation_thresholdstr);
+    threshold = grn_atoll(query_escalation_thresholdstr, end, &rest);
+    if (end != rest) {
+      fprintf(stderr, "invalid default query escalation threshold: <%s>\n",
+              query_escalation_thresholdstr);
+      return EXIT_FAILURE;
+    }
+    grn_set_default_query_escalation_threshold(threshold);
+  }
   if (loglevel) { SET_LOGLEVEL(atoi(loglevel)); }
   grn_set_segv_handler();
   grn_set_int_handler();




Groonga-commit メーリングリストの案内
Back to archive index