v1-0001-GetNewOidWithIndex_log_output.patch
application/octet-stream
Filename: v1-0001-GetNewOidWithIndex_log_output.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: GetNewOidWithIndex_log_output
| File | + | − |
|---|---|---|
| src/backend/catalog/catalog.c | 27 | 0 |
From 1b22f5363d688c8b034e89288d7c1a05d6247c4c Mon Sep 17 00:00:00 2001
From: Tomohiro <hiramit.tm@gmail.com>
Date: Mon, 28 Dec 2020 13:10:45 +0900
Subject: [PATCH v1] GetNewOidWithIndex_log_output
---
src/backend/catalog/catalog.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index f984514..c37b867 100644
--- a/src/backend/catalog/catalog.c
+++ b/src/backend/catalog/catalog.c
@@ -47,6 +47,10 @@
#include "utils/snapmgr.h"
#include "utils/syscache.h"
+/* Parameters for loop count notification in GetNewOidWithIndex() function */
+#define GETNEWOID_NOTIFICATION_INTERVAL_FACTOR 1000000
+#define GETNEWOID_NOTIFICATION_LIMIT 16000000
+
/*
* IsSystemRelation
* True iff the relation is either a system catalog or a toast table.
@@ -318,6 +322,8 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
SysScanDesc scan;
ScanKeyData key;
bool collides;
+ uint64 retry_count;
+ uint64 next_notify;
/* Only system relations are supported */
Assert(IsSystemRelation(relation));
@@ -335,6 +341,8 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Assert(!IsBinaryUpgrade || RelationGetRelid(relation) != TypeRelationId);
/* Generate new OIDs until we find one not in the table */
+ retry_count = 0;
+ next_notify = GETNEWOID_NOTIFICATION_INTERVAL_FACTOR; /* next notify interval */
do
{
CHECK_FOR_INTERRUPTS();
@@ -353,8 +361,27 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
collides = HeapTupleIsValid(systable_getnext(scan));
systable_endscan(scan);
+
+ /* retry count and notification limit check */
+ if (retry_count == next_notify && next_notify <= GETNEWOID_NOTIFICATION_LIMIT)
+ {
+ ereport(LOG,
+ (errmsg("failed to assign new OID in relation \"%s\" after "UINT64_FORMAT" retries",
+ RelationGetRelationName(relation), retry_count)));
+ next_notify *= 2; /* double it for the next notification */
+ }
+ retry_count++;
+
} while (collides);
+ /* if the retry log is output, the OID generation completion log is also output */
+ if (retry_count >= GETNEWOID_NOTIFICATION_INTERVAL_FACTOR)
+ {
+ ereport(LOG,
+ (errmsg("the new OID has been assigned in relation \"%s\" after "UINT64_FORMAT" retries",
+ RelationGetRelationName(relation), retry_count)));
+ }
+
return newOid;
}
--
1.8.3.1