[Groonga-commit] groonga/groonga at cd21d9a [master] grn_plugin_get_names: reduce the max opened files when 1 thread mode

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jun 23 14:02:49 JST 2016


Kouhei Sutou	2016-06-23 14:02:49 +0900 (Thu, 23 Jun 2016)

  New Revision: cd21d9af3569486186183a07cb65aa5abba1649e
  https://github.com/groonga/groonga/commit/cd21d9af3569486186183a07cb65aa5abba1649e

  Message:
    grn_plugin_get_names: reduce the max opened files when 1 thread mode

  Modified files:
    lib/plugin.c

  Modified: lib/plugin.c (+20 -9)
===================================================================
--- lib/plugin.c    2016-06-23 13:32:45 +0900 (0cd5c12)
+++ lib/plugin.c    2016-06-23 14:02:49 +0900 (ab2eab6)
@@ -955,6 +955,7 @@ grn_plugin_get_names(grn_ctx *ctx, grn_obj *names)
   const char *system_plugins_dir;
   const char *native_plugin_suffix;
   const char *ruby_plugin_suffix;
+  grn_bool is_close_opened_object_mode = GRN_FALSE;
 
   GRN_API_ENTER;
 
@@ -962,6 +963,10 @@ grn_plugin_get_names(grn_ctx *ctx, grn_obj *names)
     GRN_API_RETURN(ctx->rc);
   }
 
+  if (grn_thread_get_limit() == 1) {
+    is_close_opened_object_mode = GRN_TRUE;
+  }
+
   db = ctx->impl->db;
   cursor = grn_table_cursor_open(ctx, db, NULL, 0, NULL, 0, 0, -1,
                                  GRN_CURSOR_BY_ID);
@@ -981,38 +986,39 @@ grn_plugin_get_names(grn_ctx *ctx, grn_obj *names)
   native_plugin_suffix = grn_plugin_get_suffix();
   ruby_plugin_suffix = grn_plugin_get_ruby_suffix();
   while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) {
+    grn_bool is_opened = GRN_TRUE;
     grn_obj *object;
     const char *path;
     grn_id processed_path_id;
 
+    if (is_close_opened_object_mode) {
+      is_opened = grn_ctx_is_opened(ctx, id);
+    }
+
     object = grn_ctx_at(ctx, id);
     if (!object) {
       ERRCLR(ctx);
-      continue;
+      goto next_loop;
     }
 
     if (!grn_obj_is_proc(ctx, object)) {
-      grn_obj_unlink(ctx, object);
-      continue;
+      goto next_loop;
     }
 
     if (grn_obj_is_builtin(ctx, object)) {
-      grn_obj_unlink(ctx, object);
-      continue;
+      goto next_loop;
     }
 
     path = grn_obj_path(ctx, object);
     if (!path) {
-      grn_obj_unlink(ctx, object);
-      continue;
+      goto next_loop;
     }
 
     processed_path_id = grn_hash_get(ctx, processed_paths,
                                      path, strlen(path),
                                      NULL);
     if (processed_path_id != GRN_ID_NIL) {
-      grn_obj_unlink(ctx, object);
-      continue;
+      goto next_loop;
     }
 
     grn_hash_add(ctx, processed_paths,
@@ -1052,6 +1058,11 @@ grn_plugin_get_names(grn_ctx *ctx, grn_obj *names)
                              name, strlen(name),
                              0, GRN_DB_TEXT);
     }
+
+  next_loop :
+    if (object && is_close_opened_object_mode && !is_opened) {
+      grn_obj_close(ctx, object);
+    }
   }
   grn_table_cursor_close(ctx, cursor);
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index