[Groonga-commit] pgroonga/pgroonga at 1acf52d [master] Stop to ignore error on grn_obj_remove()

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Nov 7 22:44:11 JST 2016


Kouhei Sutou	2016-11-07 22:44:11 +0900 (Mon, 07 Nov 2016)

  New Revision: 1acf52d057192940b4527f82b81e15b667482ac1
  https://github.com/pgroonga/pgroonga/commit/1acf52d057192940b4527f82b81e15b667482ac1

  Message:
    Stop to ignore error on grn_obj_remove()

  Modified files:
    src/pgrn_groonga.c
    src/pgrn_groonga.h
    src/pgrn_jsonb.c
    src/pgroonga.c

  Modified: src/pgrn_groonga.c (+42 -16)
===================================================================
--- src/pgrn_groonga.c    2016-11-06 00:14:35 +0900 (c0f4ca1)
+++ src/pgrn_groonga.c    2016-11-07 22:44:11 +0900 (ce3e855)
@@ -372,30 +372,22 @@ PGrnIndexColumnSetSourceIDs(Relation index,
 	PGrnWALSetSourceIDs(index, indexColumn, sourceIDs);
 }
 
-bool
+void
 PGrnRemoveObject(const char *name)
 {
-	return PGrnRemoveObjectWithSize(name, strlen(name));
+	PGrnRemoveObjectWithSize(name, strlen(name));
 }
 
-bool
+void
 PGrnRemoveObjectWithSize(const char *name,
 						 size_t nameSize)
 {
 	grn_obj *object;
 
-	object = grn_ctx_get(ctx, name, nameSize);
-	if (object)
-	{
-		grn_obj_remove(ctx, object);
-		/* PGrnCheck("failed to remove: <%.*s>", */
-		/* 		  (int)nameSize, name); */
-		return true;
-	}
-	else
-	{
-		return false;
-	}
+	object = PGrnLookupWithSize(name, nameSize, ERROR);
+	grn_obj_remove(ctx, object);
+	PGrnCheck("failed to remove: <%.*s>",
+			  (int)nameSize, name);
 }
 
 void
@@ -418,5 +410,39 @@ PGrnFlushObject(grn_obj *object, bool recursive)
 
 	nameSize = grn_obj_name(ctx, object, name, GRN_TABLE_MAX_KEY_SIZE);
 	PGrnCheck("failed to flush: <%.*s>",
-			  (int)nameSize, name);
+			  nameSize, name);
+}
+
+void
+PGrnRemoveColumns(grn_obj *table)
+{
+	grn_hash *columns;
+
+	columns = grn_hash_create(ctx,
+							  NULL,
+							  sizeof(grn_id),
+							  0,
+							  GRN_TABLE_HASH_KEY | GRN_HASH_TINY);
+	if (!columns)
+	{
+		PGrnCheck("failed to create columns container for removing columns: "
+				  "<%s>",
+				  PGrnInspectName(table));
+	}
+
+	GRN_HASH_EACH_BEGIN(ctx, columns, cursor, id) {
+		grn_id *columnID;
+		grn_obj *column;
+
+		grn_hash_cursor_get_key(ctx, cursor, (void **)&columnID);
+		column = grn_ctx_at(ctx, *columnID);
+		if (!column)
+			continue;
+
+		grn_obj_remove(ctx, column);
+		PGrnCheck("failed to remove column: <%s>",
+				  PGrnInspectName(column));
+	} GRN_HASH_EACH_END(ctx, cursor);
+
+	grn_hash_close(ctx, columns);
 }

  Modified: src/pgrn_groonga.h (+4 -2)
===================================================================
--- src/pgrn_groonga.h    2016-11-06 00:14:35 +0900 (79887dd)
+++ src/pgrn_groonga.h    2016-11-07 22:44:11 +0900 (ffc7a96)
@@ -66,7 +66,9 @@ void PGrnIndexColumnSetSourceIDs(Relation index,
 								 grn_obj *indexColumn,
 								 grn_obj *sourceIDs);
 
-bool PGrnRemoveObject(const char *name);
-bool PGrnRemoveObjectWithSize(const char *name, size_t nameSize);
+void PGrnRemoveObject(const char *name);
+void PGrnRemoveObjectWithSize(const char *name, size_t nameSize);
+
+void PGrnRemoveColumns(grn_obj *table);
 
 void PGrnFlushObject(grn_obj *object, bool recursive);

  Modified: src/pgrn_jsonb.c (+11 -2)
===================================================================
--- src/pgrn_jsonb.c    2016-11-06 00:14:35 +0900 (9595f1e)
+++ src/pgrn_jsonb.c    2016-11-07 22:44:11 +0900 (22c0c15)
@@ -1583,14 +1583,14 @@ PGrnJSONBBulkDeleteFin(PGrnJSONBBulkDeleteData *data)
 }
 
 #ifdef PGRN_SUPPORT_JSONB
-static bool
+static void
 PGrnRemoveJSONValueLexicon(const char *typeName, unsigned int relationID)
 {
 	char tableName[GRN_TABLE_MAX_KEY_SIZE];
 	snprintf(tableName, sizeof(tableName),
 			 PGrnJSONValueLexiconNameFormat,
 			 typeName, relationID, 0);
-	return PGrnRemoveObject(tableName);
+	PGrnRemoveObject(tableName);
 }
 #endif
 
@@ -1598,6 +1598,15 @@ void
 PGrnJSONBRemoveUnusedTables(Oid relationFileNodeID)
 {
 #ifdef PGRN_SUPPORT_JSONB
+	{
+		char jsonValuesTableName[GRN_TABLE_MAX_KEY_SIZE];
+		snprintf(jsonValuesTableName, sizeof(jsonValuesTableName),
+				 PGrnJSONValuesTableNameFormat,
+				 relationFileNodeID, 0);
+		if (!grn_ctx_get(ctx, jsonValuesTableName, -1))
+			return;
+	}
+
 		PGrnRemoveJSONValueLexicon("FullTextSearch", relationFileNodeID);
 		PGrnRemoveJSONValueLexicon("String", relationFileNodeID);
 		PGrnRemoveJSONValueLexicon("Number", relationFileNodeID);

  Modified: src/pgroonga.c (+20 -1)
===================================================================
--- src/pgroonga.c    2016-11-06 00:14:35 +0900 (6ff61cd)
+++ src/pgroonga.c    2016-11-07 22:44:11 +0900 (6c5aa18)
@@ -4000,10 +4000,15 @@ PGrnRemoveUnusedTables(void)
 		for (i = 0; true; i++)
 		{
 			char tableName[GRN_TABLE_MAX_KEY_SIZE];
+			grn_obj *lexicon;
+
 			snprintf(tableName, sizeof(tableName),
 					 PGrnLexiconNameFormat, relationFileNodeID, i);
-			if (!PGrnRemoveObject(tableName))
+			lexicon = grn_ctx_get(ctx, tableName, -1);
+			if (!lexicon)
 				break;
+
+			PGrnRemoveColumns(lexicon);
 		}
 
 		{
@@ -4013,6 +4018,20 @@ PGrnRemoveUnusedTables(void)
 			PGrnRemoveObject(tableName);
 		}
 
+		for (i = 0; true; i++)
+		{
+			char tableName[GRN_TABLE_MAX_KEY_SIZE];
+			grn_obj *lexicon;
+
+			snprintf(tableName, sizeof(tableName),
+					 PGrnLexiconNameFormat, relationFileNodeID, i);
+			lexicon = grn_ctx_get(ctx, tableName, -1);
+			if (!lexicon)
+				break;
+
+			PGrnRemoveObject(tableName);
+		}
+
 		PGrnJSONBRemoveUnusedTables(relationFileNodeID);
 	}
 	grn_table_cursor_close(ctx, cursor);
-------------- next part --------------
HTML����������������������������...
Download 



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