Kouhei Sutou
null+****@clear*****
Mon Oct 9 21:35:47 JST 2017
Kouhei Sutou 2017-10-09 21:35:47 +0900 (Mon, 09 Oct 2017) New Revision: 7ee23fdba65caf6649f3aae906bd343fb4cb5226 https://github.com/pgroonga/pgroonga/commit/7ee23fdba65caf6649f3aae906bd343fb4cb5226 Message: Support WAL again Modified files: src/pgrn-create.c src/pgrn-groonga.c src/pgrn-groonga.h src/pgrn-wal.c src/pgrn-wal.h Modified: src/pgrn-create.c (+1 -1) =================================================================== --- src/pgrn-create.c 2017-10-09 20:18:20 +0900 (46140bf) +++ src/pgrn-create.c 2017-10-09 21:35:47 +0900 (c230167) @@ -45,7 +45,7 @@ PGrnCreateSourcesTableFinish(PGrnCreateData *data) snprintf(sourcesTableName, sizeof(sourcesTableName), PGrnSourcesTableNameFormat, data->relNode); - PGrnRenameTable(data->sourcesTable, sourcesTableName); + PGrnRenameTable(data->index, data->sourcesTable, sourcesTableName); } void Modified: src/pgrn-groonga.c (+21 -9) =================================================================== --- src/pgrn-groonga.c 2017-10-09 20:18:20 +0900 (b9cc597) +++ src/pgrn-groonga.c 2017-10-09 21:35:47 +0900 (f9ab46a) @@ -392,6 +392,27 @@ PGrnIndexColumnSetSourceIDs(Relation index, } void +PGrnRenameTable(Relation index, grn_obj *table, const char *newName) +{ + char name[GRN_TABLE_MAX_KEY_SIZE]; + int nameSize; + size_t newNameSize; + + nameSize = grn_obj_name(ctx, table, name, GRN_TABLE_MAX_KEY_SIZE); + newNameSize = strlen(newName); + grn_table_rename(ctx, table, newName, strlen(newName)); + PGrnCheck("failed to rename table: <%s> -> <%s>", + PGrnInspectName(table), + newName); + + PGrnWALRenameTable(index, + name, + nameSize, + newName, + newNameSize); +} + +void PGrnRemoveObject(const char *name) { PGrnRemoveObjectWithSize(name, strlen(name)); @@ -465,12 +486,3 @@ PGrnRemoveColumns(grn_obj *table) grn_hash_close(ctx, columns); } - -void -PGrnRenameTable(grn_obj *table, const char *newName) -{ - grn_table_rename(ctx, table, newName, strlen(newName)); - PGrnCheck("failed to rename table: <%s> -> <%s>", - PGrnInspectName(table), - newName); -} Modified: src/pgrn-groonga.h (+4 -2) =================================================================== --- src/pgrn-groonga.h 2017-10-09 20:18:20 +0900 (60e290b) +++ src/pgrn-groonga.h 2017-10-09 21:35:47 +0900 (b908272) @@ -70,11 +70,13 @@ void PGrnIndexColumnSetSourceIDs(Relation index, grn_obj *indexColumn, grn_obj *sourceIDs); +void PGrnRenameTable(Relation index, + grn_obj *table, + const char *newName); + 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); - -void PGrnRenameTable(grn_obj *table, const char *newName); Modified: src/pgrn-wal.c (+68 -1) =================================================================== --- src/pgrn-wal.c 2017-10-09 20:18:20 +0900 (f5b4ac4) +++ src/pgrn-wal.c 2017-10-09 21:35:47 +0900 (8d60a67) @@ -47,7 +47,8 @@ typedef enum { PGRN_WAL_ACTION_INSERT, PGRN_WAL_ACTION_CREATE_TABLE, PGRN_WAL_ACTION_CREATE_COLUMN, - PGRN_WAL_ACTION_SET_SOURCES + PGRN_WAL_ACTION_SET_SOURCES, + PGRN_WAL_ACTION_RENAME_TABLE } PGrnWALAction; #define PGRN_WAL_META_PAGE_SPECIAL_VERSION 1 @@ -870,6 +871,40 @@ PGrnWALSetSourceIDs(Relation index, #endif } +void +PGrnWALRenameTable(Relation index, + const char *name, + size_t nameSize, + const char *newName, + size_t newNameSize) +{ +#ifdef PGRN_SUPPORT_WAL + PGrnWALData *data; + msgpack_packer *packer; + size_t nElements = 3; + + data = PGrnWALStart(index); + if (!data) + return; + + packer = &(data->packer); + msgpack_pack_map(packer, nElements); + + msgpack_pack_cstr(packer, "_action"); + msgpack_pack_uint32(packer, PGRN_WAL_ACTION_RENAME_TABLE); + + msgpack_pack_cstr(packer, "name"); + msgpack_pack_str(packer, nameSize); + msgpack_pack_str_body(packer, name, nameSize); + + msgpack_pack_cstr(packer, "new_name"); + msgpack_pack_str(packer, newNameSize); + msgpack_pack_str_body(packer, newName, newNameSize); + + PGrnWALFinish(data); +#endif +} + #ifdef PGRN_SUPPORT_WAL typedef struct { Relation index; @@ -1461,6 +1496,35 @@ PGrnWALApplySetSources(PGrnWALApplyData *data, } static void +PGrnWALApplyRenameTable(PGrnWALApplyData *data, + msgpack_object_map *map, + uint32_t currentElement) +{ + const char *context = "rename table"; + grn_obj *table = NULL; + const char *newName = NULL; + size_t newNameSize = 0; + uint32_t i; + + for (i = currentElement; i < map->size; i++) + { + msgpack_object_kv *kv; + + kv = &(map->ptr[i]); + if (PGrnWALApplyKeyEqual(context, &(kv->key), "name")) + { + table = PGrnWALApplyValueGetGroongaObject(context, kv); + } + else if (PGrnWALApplyKeyEqual(context, &(kv->key), "new_name")) + { + PGrnWALApplyValueGetString(context, kv, &newName, &newNameSize); + } + } + + grn_table_rename(ctx, table, newName, newNameSize); +} + +static void PGrnWALApplyObject(PGrnWALApplyData *data, msgpack_object *object) { const char *context = NULL; @@ -1504,6 +1568,9 @@ PGrnWALApplyObject(PGrnWALApplyData *data, msgpack_object *object) case PGRN_WAL_ACTION_SET_SOURCES: PGrnWALApplySetSources(data, map, currentElement); break; + case PGRN_WAL_ACTION_RENAME_TABLE: + PGrnWALApplyRenameTable(data, map, currentElement); + break; default: ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), Modified: src/pgrn-wal.h (+6 -0) =================================================================== --- src/pgrn-wal.h 2017-10-09 20:18:20 +0900 (3efaaac) +++ src/pgrn-wal.h 2017-10-09 21:35:47 +0900 (1d21ff2) @@ -52,4 +52,10 @@ void PGrnWALSetSourceIDs(Relation index, grn_obj *column, grn_obj *sourceIDs); +void PGrnWALRenameTable(Relation index, + const char *name, + size_t nameSize, + const char *newName, + size_t newNameSize); + void PGrnWALApply(Relation index); -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171009/d5aac80c/attachment-0001.htm