v2-0001-GetNewOidWithIndex_log_output.patch
application/octet-stream
Filename: v2-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 v2-0001
Subject: GetNewOidWithIndex_log_output
| File | + | − |
|---|---|---|
| src/backend/catalog/catalog.c | 32 | 0 |
From e9e8e68c83c460b79a8735726441535871b6f7dd Mon Sep 17 00:00:00 2001
From: Tomohiro <hiramit.tm@gmail.com>
Date: Fri, 26 Feb 2021 16:55:42 +0900
Subject: [PATCH v2] GetNewOidWithIndex_log_output
---
src/backend/catalog/catalog.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index e2ed80a..ceb08cb 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_MINVAL 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_MINVAL; /* next notify timing */
do
{
CHECK_FOR_INTERRUPTS();
@@ -353,8 +361,32 @@ 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)
+ {
+ /*
+ * The query waits until the OID generation is successful.
+ * If the number of retries for OID generation is large,
+ * the number of retries will be notified.
+ */
+ 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_MINVAL)
+ {
+ 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