Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7fc9775

Browse files
committed
Don't try to print data type names in slot_store_error_callback().
The existing code tried to do syscache lookups in an already-failedtransaction, which is problematic to say the least. After someconsideration of alternatives, the best fix seems to be to just droptype names from the error message altogether. The table and columnnames seem like sufficient localization. If the user is unsure whattypes are involved, she can check the local and remote tabledefinitions.Having done that, we can also discard the LogicalRepTypMap hashtable, which had no other use. Arguably, LOGICAL_REP_MSG_TYPEreplication messages are now obsolete as well; but we shouldprobably keep them in case some other use emerges. (The complexityof removing something from the replication protocol would likelyoutweigh any savings anyhow.)Masahiko Sawada and Bharath Rupireddy, per complaint from AndresFreund. Back-patch to v10 where this code originated.Discussion:https://postgr.es/m/20210106020229.ne5xnuu6wlondjpe@alap3.anarazel.de
1 parent8d2be14 commit7fc9775

File tree

3 files changed

+6
-135
lines changed

3 files changed

+6
-135
lines changed

‎src/backend/replication/logical/relation.c

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,19 @@
1717
#include"postgres.h"
1818

1919
#include"access/relation.h"
20-
#include"access/sysattr.h"
2120
#include"access/table.h"
2221
#include"catalog/namespace.h"
2322
#include"catalog/pg_subscription_rel.h"
2423
#include"executor/executor.h"
2524
#include"nodes/makefuncs.h"
2625
#include"replication/logicalrelation.h"
2726
#include"replication/worker_internal.h"
28-
#include"utils/builtins.h"
2927
#include"utils/inval.h"
30-
#include"utils/lsyscache.h"
31-
#include"utils/memutils.h"
32-
#include"utils/syscache.h"
28+
3329

3430
staticMemoryContextLogicalRepRelMapContext=NULL;
3531

3632
staticHTAB*LogicalRepRelMap=NULL;
37-
staticHTAB*LogicalRepTypMap=NULL;
3833

3934
/*
4035
* Partition map (LogicalRepPartMap)
@@ -119,16 +114,6 @@ logicalrep_relmap_init(void)
119114
LogicalRepRelMap=hash_create("logicalrep relation map cache",128,&ctl,
120115
HASH_ELEM |HASH_BLOBS |HASH_CONTEXT);
121116

122-
/* Initialize the type hash table. */
123-
MemSet(&ctl,0,sizeof(ctl));
124-
ctl.keysize=sizeof(Oid);
125-
ctl.entrysize=sizeof(LogicalRepTyp);
126-
ctl.hcxt=LogicalRepRelMapContext;
127-
128-
/* This will usually be small. */
129-
LogicalRepTypMap=hash_create("logicalrep type map cache",2,&ctl,
130-
HASH_ELEM |HASH_BLOBS |HASH_CONTEXT);
131-
132117
/* Watch for invalidation events. */
133118
CacheRegisterRelcacheCallback(logicalrep_relmap_invalidate_cb,
134119
(Datum)0);
@@ -418,95 +403,6 @@ logicalrep_rel_close(LogicalRepRelMapEntry *rel, LOCKMODE lockmode)
418403
rel->localrel=NULL;
419404
}
420405

421-
/*
422-
* Free the type map cache entry data.
423-
*/
424-
staticvoid
425-
logicalrep_typmap_free_entry(LogicalRepTyp*entry)
426-
{
427-
pfree(entry->nspname);
428-
pfree(entry->typname);
429-
}
430-
431-
/*
432-
* Add new entry or update existing entry in the type map cache.
433-
*/
434-
void
435-
logicalrep_typmap_update(LogicalRepTyp*remotetyp)
436-
{
437-
MemoryContextoldctx;
438-
LogicalRepTyp*entry;
439-
boolfound;
440-
441-
if (LogicalRepTypMap==NULL)
442-
logicalrep_relmap_init();
443-
444-
/*
445-
* HASH_ENTER returns the existing entry if present or creates a new one.
446-
*/
447-
entry=hash_search(LogicalRepTypMap, (void*)&remotetyp->remoteid,
448-
HASH_ENTER,&found);
449-
450-
if (found)
451-
logicalrep_typmap_free_entry(entry);
452-
453-
/* Make cached copy of the data */
454-
entry->remoteid=remotetyp->remoteid;
455-
oldctx=MemoryContextSwitchTo(LogicalRepRelMapContext);
456-
entry->nspname=pstrdup(remotetyp->nspname);
457-
entry->typname=pstrdup(remotetyp->typname);
458-
MemoryContextSwitchTo(oldctx);
459-
}
460-
461-
/*
462-
* Fetch type name from the cache by remote type OID.
463-
*
464-
* Return a substitute value if we cannot find the data type; no message is
465-
* sent to the log in that case, because this is used by error callback
466-
* already.
467-
*/
468-
char*
469-
logicalrep_typmap_gettypname(Oidremoteid)
470-
{
471-
LogicalRepTyp*entry;
472-
boolfound;
473-
474-
/* Internal types are mapped directly. */
475-
if (remoteid<FirstGenbkiObjectId)
476-
{
477-
if (!get_typisdefined(remoteid))
478-
{
479-
/*
480-
* This can be caused by having a publisher with a higher
481-
* PostgreSQL major version than the subscriber.
482-
*/
483-
returnpsprintf("unrecognized %u",remoteid);
484-
}
485-
486-
returnformat_type_be(remoteid);
487-
}
488-
489-
if (LogicalRepTypMap==NULL)
490-
{
491-
/*
492-
* If the typemap is not initialized yet, we cannot possibly attempt
493-
* to search the hash table; but there's no way we know the type
494-
* locally yet, since we haven't received a message about this type,
495-
* so this is the best we can do.
496-
*/
497-
returnpsprintf("unrecognized %u",remoteid);
498-
}
499-
500-
/* search the mapping */
501-
entry=hash_search(LogicalRepTypMap, (void*)&remoteid,
502-
HASH_FIND,&found);
503-
if (!found)
504-
returnpsprintf("unrecognized %u",remoteid);
505-
506-
Assert(OidIsValid(entry->remoteid));
507-
returnpsprintf("%s.%s",entry->nspname,entry->typname);
508-
}
509-
510406
/*
511407
* Partition cache: look up partition LogicalRepRelMapEntry's
512408
*

‎src/backend/replication/logical/worker.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ static dlist_head lsn_mapping = DLIST_STATIC_INIT(lsn_mapping);
9393
typedefstructSlotErrCallbackArg
9494
{
9595
LogicalRepRelMapEntry*rel;
96-
intlocal_attnum;
9796
intremote_attnum;
9897
}SlotErrCallbackArg;
9998

@@ -344,36 +343,23 @@ slot_fill_defaults(LogicalRepRelMapEntry *rel, EState *estate,
344343
}
345344

346345
/*
347-
* Error callback to give more context info about type conversion failure.
346+
* Error callback to give more context info about data conversion failures
347+
* while reading data from the remote server.
348348
*/
349349
staticvoid
350350
slot_store_error_callback(void*arg)
351351
{
352352
SlotErrCallbackArg*errarg= (SlotErrCallbackArg*)arg;
353353
LogicalRepRelMapEntry*rel;
354-
char*remotetypname;
355-
Oidremotetypoid,
356-
localtypoid;
357354

358355
/* Nothing to do if remote attribute number is not set */
359356
if (errarg->remote_attnum<0)
360357
return;
361358

362359
rel=errarg->rel;
363-
remotetypoid=rel->remoterel.atttyps[errarg->remote_attnum];
364-
365-
/* Fetch remote type name from the LogicalRepTypMap cache */
366-
remotetypname=logicalrep_typmap_gettypname(remotetypoid);
367-
368-
/* Fetch local type OID from the local sys cache */
369-
localtypoid=get_atttype(rel->localreloid,errarg->local_attnum+1);
370-
371-
errcontext("processing remote data for replication target relation \"%s.%s\" column \"%s\", "
372-
"remote type %s, local type %s",
360+
errcontext("processing remote data for replication target relation \"%s.%s\" column \"%s\"",
373361
rel->remoterel.nspname,rel->remoterel.relname,
374-
rel->remoterel.attnames[errarg->remote_attnum],
375-
remotetypname,
376-
format_type_be(localtypoid));
362+
rel->remoterel.attnames[errarg->remote_attnum]);
377363
}
378364

379365
/*
@@ -394,7 +380,6 @@ slot_store_cstrings(TupleTableSlot *slot, LogicalRepRelMapEntry *rel,
394380

395381
/* Push callback + info on the error context stack */
396382
errarg.rel=rel;
397-
errarg.local_attnum=-1;
398383
errarg.remote_attnum=-1;
399384
errcallback.callback=slot_store_error_callback;
400385
errcallback.arg= (void*)&errarg;
@@ -414,7 +399,6 @@ slot_store_cstrings(TupleTableSlot *slot, LogicalRepRelMapEntry *rel,
414399
Oidtypinput;
415400
Oidtypioparam;
416401

417-
errarg.local_attnum=i;
418402
errarg.remote_attnum=remoteattnum;
419403

420404
getTypeInputInfo(att->atttypid,&typinput,&typioparam);
@@ -423,7 +407,6 @@ slot_store_cstrings(TupleTableSlot *slot, LogicalRepRelMapEntry *rel,
423407
typioparam,att->atttypmod);
424408
slot->tts_isnull[i]= false;
425409

426-
errarg.local_attnum=-1;
427410
errarg.remote_attnum=-1;
428411
}
429412
else
@@ -479,7 +462,6 @@ slot_modify_cstrings(TupleTableSlot *slot, TupleTableSlot *srcslot,
479462

480463
/* For error reporting, push callback + info on the error context stack */
481464
errarg.rel=rel;
482-
errarg.local_attnum=-1;
483465
errarg.remote_attnum=-1;
484466
errcallback.callback=slot_store_error_callback;
485467
errcallback.arg= (void*)&errarg;
@@ -504,7 +486,6 @@ slot_modify_cstrings(TupleTableSlot *slot, TupleTableSlot *srcslot,
504486
Oidtypinput;
505487
Oidtypioparam;
506488

507-
errarg.local_attnum=i;
508489
errarg.remote_attnum=remoteattnum;
509490

510491
getTypeInputInfo(att->atttypid,&typinput,&typioparam);
@@ -513,7 +494,6 @@ slot_modify_cstrings(TupleTableSlot *slot, TupleTableSlot *srcslot,
513494
typioparam,att->atttypmod);
514495
slot->tts_isnull[i]= false;
515496

516-
errarg.local_attnum=-1;
517497
errarg.remote_attnum=-1;
518498
}
519499
else
@@ -637,16 +617,14 @@ apply_handle_relation(StringInfo s)
637617
/*
638618
* Handle TYPE message.
639619
*
640-
* Note we don't do local mapping here, that's done when the type is
641-
* actually used.
620+
* This is now vestigial; we read the info and discard it.
642621
*/
643622
staticvoid
644623
apply_handle_type(StringInfos)
645624
{
646625
LogicalRepTyptyp;
647626

648627
logicalrep_read_typ(s,&typ);
649-
logicalrep_typmap_update(&typ);
650628
}
651629

652630
/*

‎src/include/replication/logicalrelation.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@ extern LogicalRepRelMapEntry *logicalrep_partition_open(LogicalRepRelMapEntry *r
4141
externvoidlogicalrep_rel_close(LogicalRepRelMapEntry*rel,
4242
LOCKMODElockmode);
4343

44-
externvoidlogicalrep_typmap_update(LogicalRepTyp*remotetyp);
45-
externchar*logicalrep_typmap_gettypname(Oidremoteid);
46-
4744
#endif/* LOGICALRELATION_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp