diff --git a/src/gausskernel/storage/replication/logical/logicalfuncs.cpp b/src/gausskernel/storage/replication/logical/logicalfuncs.cpp index 67db95fec..545d6add4 100755 --- a/src/gausskernel/storage/replication/logical/logicalfuncs.cpp +++ b/src/gausskernel/storage/replication/logical/logicalfuncs.cpp @@ -316,7 +316,7 @@ static Datum pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool conf struct stat st; check_permissions(); - (void)ValidateName(NameStr(*name)); + ValidateName(NameStr(*name)); if (RecoveryInProgress() && confirm) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("couldn't advance in recovery"))); @@ -324,7 +324,7 @@ static Datum pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool conf upto_lsn = InvalidXLogRecPtr; else { const char* str_upto_lsn = TextDatumGetCString(PG_GETARG_DATUM(1)); - (void)ValidateName(str_upto_lsn); + ValidateName(str_upto_lsn); if (!AssignLsn(&upto_lsn, str_upto_lsn)) { ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), @@ -386,7 +386,7 @@ static Datum pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool conf for (i = 0; i < nelems; i += 2) { char* dname = TextDatumGetCString(datum_opts[i]); char* opt = TextDatumGetCString(datum_opts[i + 1]); - (void)ValidateName(dname); + ValidateName(dname); options = lappend(options, makeDefElem(dname, (Node*)makeString(opt))); } } diff --git a/src/gausskernel/storage/replication/slot.cpp b/src/gausskernel/storage/replication/slot.cpp index f6f073804..0274345bb 100644 --- a/src/gausskernel/storage/replication/slot.cpp +++ b/src/gausskernel/storage/replication/slot.cpp @@ -156,7 +156,7 @@ bool ReplicationSlotValidateName(const char* name, int elevel) * * Returns whether the directory name is valid or not if elevel < ERROR. */ -bool ValidateName(const char* name) +void ValidateName(const char* name) { if (name == NULL) { ereport(ERROR, (errcode(ERRCODE_INVALID_NAME), errmsg("replication slot name should not be NULL."))); @@ -164,10 +164,9 @@ bool ValidateName(const char* name) if (strlen(name) == 0) { ereport(ERROR, (errcode(ERRCODE_INVALID_NAME), errmsg("replication slot name \"%s\" is too short", name))); - return false; } - if (strlen(name) >= NAMEDATALEN - 1) { + if (strlen(name) >= NAMEDATALEN) { ereport(ERROR, (errcode(ERRCODE_NAME_TOO_LONG), errmsg("replication slot name \"%s\" is too long", name))); } const char* danger_character_list[] = {";", "`", "\\", "'", "\"", ">", "<", "&", "|", "!", "\n", NULL}; @@ -179,11 +178,8 @@ bool ValidateName(const char* name) (errcode(ERRCODE_INVALID_NAME), errmsg("replication slot name \"%s\" contains invalid character", name), errhint("Replication slot names may only contain letters, numbers and the underscore character."))); - return false; } } - - return true; } /* diff --git a/src/gausskernel/storage/replication/slotfuncs.cpp b/src/gausskernel/storage/replication/slotfuncs.cpp index 1f290a041..7faf4e101 100644 --- a/src/gausskernel/storage/replication/slotfuncs.cpp +++ b/src/gausskernel/storage/replication/slotfuncs.cpp @@ -318,8 +318,8 @@ Datum pg_create_logical_replication_slot(PG_FUNCTION_ARGS) char* str_tmp_lsn = NULL; NameData databaseName; - (void)ValidateName(NameStr(*name)); - (void)ValidateName(NameStr(*plugin)); + ValidateName(NameStr(*name)); + ValidateName(NameStr(*plugin)); str_tmp_lsn = (char*)palloc0(128); check_permissions(); @@ -351,7 +351,7 @@ Datum pg_drop_replication_slot(PG_FUNCTION_ARGS) { Name name = PG_GETARG_NAME(0); - (void)ValidateName(NameStr(*name)); + ValidateName(NameStr(*name)); check_permissions(); @@ -718,7 +718,7 @@ Datum pg_replication_slot_advance(PG_FUNCTION_ARGS) Datum result; NameData database; char EndLsn[NAMEDATALEN]; - (void)ValidateName(NameStr(*slotname)); + ValidateName(NameStr(*slotname)); if (RecoveryInProgress()) { ereport(ERROR, (errcode(ERRCODE_INVALID_OPERATION), errmsg("couldn't advance in recovery"))); } @@ -729,7 +729,7 @@ Datum pg_replication_slot_advance(PG_FUNCTION_ARGS) moveto = GetXLogReplayRecPtr(NULL); } else { const char* str_upto_lsn = TextDatumGetCString(PG_GETARG_DATUM(1)); - (void)ValidateName(str_upto_lsn); + ValidateName(str_upto_lsn); if (!AssignLsn(&moveto, str_upto_lsn)) { ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), diff --git a/src/gausskernel/storage/replication/walsender.cpp b/src/gausskernel/storage/replication/walsender.cpp index 04cef91f8..8b968cc6c 100755 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -1091,8 +1091,8 @@ static void CreateReplicationSlot(const CreateReplicationSlotCmd* cmd) slot_name = NameStr(t_thrd.slot_cxt.MyReplicationSlot->data.name); if (cmd->kind == REPLICATION_KIND_LOGICAL) { - (void)ValidateName(cmd->slotname); - (void)ValidateName(cmd->plugin); + ValidateName(cmd->slotname); + ValidateName(cmd->plugin); char* fullname = NULL; fullname = expand_dynamic_library_name(cmd->plugin); diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index 27976a9db..104f462f1 100755 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -195,7 +195,7 @@ extern void CreateSlotOnDisk(ReplicationSlot* slot); /* misc stuff */ extern bool ReplicationSlotValidateName(const char* name, int elevel); -extern bool ValidateName(const char* name); +extern void ValidateName(const char* name); extern void ReplicationSlotsComputeRequiredXmin(bool already_locked); extern void ReplicationSlotsComputeRequiredLSN(ReplicationSlotState* repl_slt_state); extern void ReplicationSlotReportRestartLSN(void); diff --git a/src/test/regress/expected/hw_replication_slots.out b/src/test/regress/expected/hw_replication_slots.out index d76a4ef5b..4f4a5ddcd 100644 --- a/src/test/regress/expected/hw_replication_slots.out +++ b/src/test/regress/expected/hw_replication_slots.out @@ -18,12 +18,19 @@ WARNING: replication slot "standby_slot" already exists standby_slot | (1 row) +select * from pg_create_physical_replication_slot('my_physical_slot1my_physical_slot2my_physical_slot6my_physical_slot7', 'True'); + slotname | xlog_position +-----------------------------------------------------------------+--------------- + my_physical_slot1my_physical_slot2my_physical_slot6my_physical_ | +(1 row) + select * from pg_replication_slots order by 1; - slot_name | plugin | slot_type | datoid | database | active | xmin | catalog_xmin | restart_lsn | dummy_standby --------------------+--------+-----------+--------+----------+--------+------+--------------+-------------+--------------- - dummystandby_slot | | physical | 0 | | f | | | | t - standby_slot | | physical | 0 | | f | | | | f -(2 rows) + slot_name | plugin | slot_type | datoid | database | active | xmin | catalog_xmin | restart_lsn | dummy_standby +-----------------------------------------------------------------+--------+-----------+--------+----------+--------+------+--------------+-------------+--------------- + dummystandby_slot | | physical | 0 | | f | | | | t + my_physical_slot1my_physical_slot2my_physical_slot6my_physical_ | | physical | 0 | | f | | | | t + standby_slot | | physical | 0 | | f | | | | f +(3 rows) select * from pg_drop_replication_slot('dummystandby_slot'); WARNING: replicationSlotMinLSN is InvalidXLogRecPtr!!! @@ -43,3 +50,11 @@ WARNING: replicationSlotMaxLSN is InvalidXLogRecPtr!!! select * from pg_drop_replication_slot('wrong_slot_name'); ERROR: replication slot "wrong_slot_name" does not exist +select * from pg_drop_replication_slot('my_physical_slot1my_physical_slot2my_physical_slot6my_physical_'); +WARNING: replicationSlotMinLSN is InvalidXLogRecPtr!!! +WARNING: replicationSlotMaxLSN is InvalidXLogRecPtr!!! + pg_drop_replication_slot +-------------------------- + +(1 row) + diff --git a/src/test/regress/sql/hw_replication_slots.sql b/src/test/regress/sql/hw_replication_slots.sql index 1898b0744..de8a69db5 100644 --- a/src/test/regress/sql/hw_replication_slots.sql +++ b/src/test/regress/sql/hw_replication_slots.sql @@ -3,9 +3,11 @@ select * from pg_create_physical_replication_slot('dummystandby_slot',true); select * from pg_create_physical_replication_slot('standby_slot',false); select * from pg_create_physical_replication_slot('standby_slot',false); +select * from pg_create_physical_replication_slot('my_physical_slot1my_physical_slot2my_physical_slot6my_physical_slot7', 'True'); select * from pg_replication_slots order by 1; select * from pg_drop_replication_slot('dummystandby_slot'); select * from pg_drop_replication_slot('standby_slot'); -select * from pg_drop_replication_slot('wrong_slot_name'); \ No newline at end of file +select * from pg_drop_replication_slot('wrong_slot_name'); +select * from pg_drop_replication_slot('my_physical_slot1my_physical_slot2my_physical_slot6my_physical_');