Kouhei Sutou
null+****@clear*****
Tue Feb 28 12:55:02 JST 2017
Kouhei Sutou 2017-02-28 12:55:02 +0900 (Tue, 28 Feb 2017) New Revision: afb04246d5c57f73b18722ed7330fa631e5be40c https://github.com/groonga/groonga/commit/afb04246d5c57f73b18722ed7330fa631e5be40c Message: table_remove: reduce temporary memory usage on dependent mode The previous implementation can't close implicitly opened objects. For example, if we open a column, its table is also opened implicitly. The previous implementation can't close the table. The new implementation can close implicitly opened objects. It reduces memory usage for temporary opened objects including implicitly opened objects. It's enabled when the number of max threads is 0. Modified files: lib/db.c Modified: lib/db.c (+9 -32) =================================================================== --- lib/db.c 2017-02-28 12:39:27 +0900 (537b2cc) +++ lib/db.c 2017-02-28 12:55:02 +0900 (cef49af) @@ -9284,7 +9284,6 @@ remove_reference_tables(grn_ctx *ctx, grn_obj *table, grn_obj *db) { grn_rc rc = GRN_SUCCESS; grn_bool is_close_opened_object_mode = GRN_FALSE; - grn_obj not_opened_ids; grn_id table_id; char table_name[GRN_TABLE_MAX_KEY_SIZE]; int table_name_size; @@ -9294,8 +9293,6 @@ remove_reference_tables(grn_ctx *ctx, grn_obj *table, grn_obj *db) is_close_opened_object_mode = GRN_TRUE; } - GRN_TEXT_INIT(¬_opened_ids, 0); - table_id = DB_OBJ(table)->id; table_name_size = grn_obj_name(ctx, table, table_name, GRN_TABLE_MAX_KEY_SIZE); if ((cursor = grn_table_cursor_open(ctx, db, NULL, 0, NULL, 0, 0, -1, @@ -9303,16 +9300,18 @@ remove_reference_tables(grn_ctx *ctx, grn_obj *table, grn_obj *db) grn_id id; while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) { grn_obj *object; - grn_bool is_opened = GRN_TRUE; grn_bool is_removed = GRN_FALSE; if (is_close_opened_object_mode) { - is_opened = grn_ctx_is_opened(ctx, id); + grn_ctx_push_temporary_open_space(ctx); } object = grn_ctx_at(ctx, id); if (!object) { ERRCLR(ctx); + if (is_close_opened_object_mode) { + grn_ctx_pop_temporary_open_space(ctx); + } continue; } @@ -9344,18 +9343,15 @@ remove_reference_tables(grn_ctx *ctx, grn_obj *table, grn_obj *db) case GRN_COLUMN_INDEX : break; default: - is_opened = GRN_TRUE; break; } if (!is_removed) { - if (is_close_opened_object_mode && !is_opened) { - grn_bulk_write(ctx, ¬_opened_ids, - (const char *)&id, sizeof(grn_id)); - grn_obj_close(ctx, object); - } else { - grn_obj_unlink(ctx, object); - } + grn_obj_unlink(ctx, object); + } + + if (is_close_opened_object_mode) { + grn_ctx_pop_temporary_open_space(ctx); } if (rc != GRN_SUCCESS) { @@ -9365,25 +9361,6 @@ remove_reference_tables(grn_ctx *ctx, grn_obj *table, grn_obj *db) grn_table_cursor_close(ctx, cursor); } - if (is_close_opened_object_mode) { - int i, n_not_opened_ids; - - n_not_opened_ids = GRN_TEXT_LEN(¬_opened_ids) / sizeof(grn_id); - for (i = 0; i < n_not_opened_ids; i++) { - grn_id id = ((grn_id *)GRN_BULK_HEAD(¬_opened_ids))[i]; - grn_obj *opened_object; - - if (!grn_ctx_is_opened(ctx, id)) { - continue; - } - - opened_object = grn_ctx_at(ctx, id); - grn_obj_close(ctx, opened_object); - } - } - - GRN_OBJ_FIN(ctx, ¬_opened_ids); - return rc; } -------------- next part -------------- HTML����������������������������...Download