Kouhei Sutou
null+****@clear*****
Sun Oct 8 09:40:23 JST 2017
Kouhei Sutou 2017-10-08 09:40:23 +0900 (Sun, 08 Oct 2017) New Revision: 754a5ffdd839d3f3223fae382447b186dec7c3bd https://github.com/pgroonga/pgroonga/commit/754a5ffdd839d3f3223fae382447b186dec7c3bd Message: Fix a bug that Groonga object for creating index may be removed by AUTO VACUUM Modified files: src/pgroonga.c Modified: src/pgroonga.c (+45 -1) =================================================================== --- src/pgroonga.c 2017-10-07 16:48:12 +0900 (a7bbfe5) +++ src/pgroonga.c 2017-10-08 09:40:23 +0900 (4891e33) @@ -4870,18 +4870,59 @@ pgroonga_bulkdelete(PG_FUNCTION_ARGS) PG_RETURN_POINTER(stats); } +static bool +PGrnIsCreatingFileNodeID(grn_id id, Oid fileNodeID) +{ + grn_obj *object; + const char *path; + char pgPath[MAXPGPATH]; + const char *lastDirSeparator; + pgrn_stat_buffer status; + + object = grn_ctx_at(ctx, id); + if (!object) + return false; + + path = grn_obj_path(ctx, object); + if (!path) + return false; + + lastDirSeparator = last_dir_separator(path); + if (lastDirSeparator) + { + char baseDir[MAXPGPATH]; + char pgBaseName[MAXPGPATH]; + + snprintf(baseDir, sizeof(baseDir), + "%.*s", + (int)(lastDirSeparator - path), + path); + snprintf(pgBaseName, sizeof(pgBaseName), "%u", fileNodeID); + join_path_components(pgPath, + baseDir, + pgBaseName); + } + else + { + snprintf(pgPath, sizeof(pgPath), "%u", fileNodeID); + } + + return pgrn_stat(pgPath, &status) == 0; +} + static void PGrnRemoveUnusedTables(void) { #ifdef PGRN_SUPPORT_FILE_NODE_ID_TO_RELATION_ID grn_table_cursor *cursor; const char *min = PGrnSourcesTableNamePrefix; + grn_id id; cursor = grn_table_cursor_open(ctx, grn_ctx_db(ctx), min, strlen(min), NULL, 0, 0, -1, GRN_CURSOR_BY_KEY|GRN_CURSOR_PREFIX); - while (grn_table_cursor_next(ctx, cursor) != GRN_ID_NIL) + while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) { char *name; char *nameEnd; @@ -4898,6 +4939,9 @@ PGrnRemoveUnusedTables(void) if (PGrnPGIsValidFileNodeID(relationFileNodeID)) continue; + if (PGrnIsCreatingFileNodeID(id, relationFileNodeID)) + continue; + for (i = 0; true; i++) { char tableName[GRN_TABLE_MAX_KEY_SIZE]; -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171008/ef60a202/attachment-0001.htm