Kouhei Sutou
null+****@clear*****
Mon Mar 27 18:19:52 JST 2017
Kouhei Sutou 2017-03-27 18:19:52 +0900 (Mon, 27 Mar 2017) New Revision: e2fd7346419494fac7270f22534d4b5bf645a747 https://github.com/groonga/groonga/commit/e2fd7346419494fac7270f22534d4b5bf645a747 Message: logical_table_remove: fix a crash bug It may be occurred when the max number of threads is 1. See also the test for details. Added files: test/command/suite/sharding/logical_table_remove/referenced/dependent_no_open.expected test/command/suite/sharding/logical_table_remove/referenced/dependent_no_open.test Modified files: lib/db.c Modified: lib/db.c (+32 -2) =================================================================== --- lib/db.c 2017-03-27 17:21:52 +0900 (6743f1c) +++ lib/db.c 2017-03-27 18:19:52 +0900 (b5b20d7) @@ -9779,6 +9779,8 @@ _grn_obj_remove(grn_ctx *ctx, grn_obj *obj, grn_bool dependent) grn_obj *db = NULL; const char *io_path; char *path; + grn_bool is_temporary_open_target = GRN_FALSE; + if (ctx->impl && ctx->impl->db) { grn_id id; uint32_t s = 0; @@ -9809,24 +9811,31 @@ _grn_obj_remove(grn_ctx *ctx, grn_obj *obj, grn_bool dependent) break; case GRN_TABLE_PAT_KEY : rc = _grn_obj_remove_pat(ctx, obj, db, id, path, dependent); + is_temporary_open_target = GRN_TRUE; break; case GRN_TABLE_DAT_KEY : rc = _grn_obj_remove_dat(ctx, obj, db, id, path, dependent); + is_temporary_open_target = GRN_TRUE; break; case GRN_TABLE_HASH_KEY : rc = _grn_obj_remove_hash(ctx, obj, db, id, path, dependent); + is_temporary_open_target = GRN_TRUE; break; case GRN_TABLE_NO_KEY : rc = _grn_obj_remove_array(ctx, obj, db, id, path, dependent); + is_temporary_open_target = GRN_TRUE; break; case GRN_COLUMN_VAR_SIZE : rc = _grn_obj_remove_ja(ctx, obj, db, id, path); + is_temporary_open_target = GRN_TRUE; break; case GRN_COLUMN_FIX_SIZE : rc = _grn_obj_remove_ra(ctx, obj, db, id, path); + is_temporary_open_target = GRN_TRUE; break; case GRN_COLUMN_INDEX : rc = _grn_obj_remove_index(ctx, obj, db, id, path); + is_temporary_open_target = GRN_TRUE; break; default : if (GRN_DB_OBJP(obj)) { @@ -9835,7 +9844,26 @@ _grn_obj_remove(grn_ctx *ctx, grn_obj *obj, grn_bool dependent) rc = _grn_obj_remove_other(ctx, obj, db, id, path); } } - if (path) { GRN_FREE(path); } + if (path) { + GRN_FREE(path); + } else { + is_temporary_open_target = GRN_FALSE; + } + + if (is_temporary_open_target && rc == GRN_SUCCESS) { + grn_obj *space; + space = ctx->impl->temporary_open_spaces.current; + if (space) { + unsigned int i, n_elements; + n_elements = GRN_BULK_VSIZE(space) / sizeof(grn_obj *); + for (i = 0; i < n_elements; i++) { + if (GRN_PTR_VALUE_AT(space, i) == obj) { + GRN_PTR_SET_AT(ctx, space, i, NULL); + } + } + } + } + return rc; } @@ -10591,7 +10619,9 @@ grn_pvector_fin(grn_ctx *ctx, grn_obj *obj) n_elements = GRN_BULK_VSIZE(obj) / sizeof(grn_obj *); for (i = 0; i < n_elements; i++) { grn_obj *element = GRN_PTR_VALUE_AT(obj, n_elements - i - 1); - grn_obj_close(ctx, element); + if (element) { + grn_obj_close(ctx, element); + } } } obj->header.type = GRN_VOID; Added: test/command/suite/sharding/logical_table_remove/referenced/dependent_no_open.expected (+20 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_table_remove/referenced/dependent_no_open.expected 2017-03-27 18:19:52 +0900 (ca24fe3) @@ -0,0 +1,20 @@ +plugin_register sharding +[[0,0.0,0.0],true] +table_create NotRelated_20150204 TABLE_NO_KEY +[[0,0.0,0.0],true] +table_create Logs_20150204 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +table_create Bookmarks TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Bookmarks log_20150204 COLUMN_SCALAR Logs_20150204 +[[0,0.0,0.0],true] +logical_table_remove --logical_table Logs --shard_key timestamp --dependent yes +[[0,0.0,0.0],true] +dump +plugin_register sharding + +table_create Bookmarks TABLE_HASH_KEY ShortText + +table_create NotRelated_20150204 TABLE_NO_KEY Added: test/command/suite/sharding/logical_table_remove/referenced/dependent_no_open.test (+23 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_table_remove/referenced/dependent_no_open.test 2017-03-27 18:19:52 +0900 (d68f40f) @@ -0,0 +1,23 @@ +#@on-error omit +plugin_register sharding +#@on-error default + +table_create NotRelated_20150204 TABLE_NO_KEY + +table_create Logs_20150204 TABLE_NO_KEY +column_create Logs_20150204 timestamp COLUMN_SCALAR Time + +table_create Bookmarks TABLE_HASH_KEY ShortText +column_create Bookmarks log_20150204 COLUMN_SCALAR Logs_20150204 + +#@disable-logging +thread_limit 1 +database_unmap +#@enable-logging + +logical_table_remove \ + --logical_table Logs \ + --shard_key timestamp \ + --dependent yes + +dump -------------- next part -------------- HTML����������������������������...Download