将物理复制槽的名字的最大长度从62改为63,跟pg保持一致。

This commit is contained in:
zhouxiongjia
2020-09-15 17:24:55 +08:00
parent 774c14fcde
commit dcbdbcfa4e
7 changed files with 36 additions and 23 deletions

View File

@ -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)));
}
}

View File

@ -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;
}
/*

View File

@ -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),

View File

@ -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);

View File

@ -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);

View File

@ -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
my_physical_slot1my_physical_slot2my_physical_slot6my_physical_ | | physical | 0 | | f | | | | t
standby_slot | | physical | 0 | | f | | | | f
(2 rows)
(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)

View File

@ -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');
select * from pg_drop_replication_slot('my_physical_slot1my_physical_slot2my_physical_slot6my_physical_');