Navigation Menu

Skip to content

Commit

Permalink
Fix a bug that Groonga object for creating index may be removed by AU…
Browse files Browse the repository at this point in the history
…TO VACUUM
  • Loading branch information
kou committed Oct 8, 2017
1 parent af2d78b commit 754a5ff
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/pgroonga.c
Expand Up @@ -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;
Expand All @@ -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];
Expand Down

0 comments on commit 754a5ff

Please sign in to comment.