|
47 | 47 | #include "utils/snapmgr.h"
|
48 | 48 | #include "utils/syscache.h"
|
49 | 49 |
|
| 50 | +/* |
| 51 | + * Parameters to determine when to emit a log message in |
| 52 | + * GetNewOidWithIndex() |
| 53 | + */ |
| 54 | +#define GETNEWOID_LOG_THRESHOLD 1000000 |
| 55 | +#define GETNEWOID_LOG_MAX_INTERVAL 128000000 |
| 56 | + |
50 | 57 | /*
|
51 | 58 | * IsSystemRelation
|
52 | 59 | * True iff the relation is either a system catalog or a toast table.
|
@@ -318,6 +325,8 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
|
318 | 325 | SysScanDesc scan;
|
319 | 326 | ScanKeyData key;
|
320 | 327 | bool collides;
|
| 328 | + uint64 retries = 0; |
| 329 | + uint64 retries_before_log = GETNEWOID_LOG_THRESHOLD; |
321 | 330 |
|
322 | 331 | /* Only system relations are supported */
|
323 | 332 | Assert(IsSystemRelation(relation));
|
@@ -353,8 +362,48 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
|
353 | 362 | collides = HeapTupleIsValid(systable_getnext(scan));
|
354 | 363 |
|
355 | 364 | systable_endscan(scan);
|
| 365 | + |
| 366 | + /* |
| 367 | + * Log that we iterate more than GETNEWOID_LOG_THRESHOLD but have not |
| 368 | + * yet found OID unused in the relation. Then repeat logging with |
| 369 | + * exponentially increasing intervals until we iterate more than |
| 370 | + * GETNEWOID_LOG_MAX_INTERVAL. Finally repeat logging every |
| 371 | + * GETNEWOID_LOG_MAX_INTERVAL unless an unused OID is found. This |
| 372 | + * logic is necessary not to fill up the server log with the similar |
| 373 | + * messages. |
| 374 | + */ |
| 375 | + if (retries >= retries_before_log) |
| 376 | + { |
| 377 | + ereport(LOG, |
| 378 | + (errmsg("still finding an unused OID within relation \"%s\"", |
| 379 | + RelationGetRelationName(relation)), |
| 380 | + errdetail("OID candidates were checked \"%llu\" times, but no unused OID is yet found.", |
| 381 | + (unsigned long long) retries))); |
| 382 | + |
| 383 | + /* |
| 384 | + * Double the number of retries to do before logging next until it |
| 385 | + * reaches GETNEWOID_LOG_MAX_INTERVAL. |
| 386 | + */ |
| 387 | + if (retries_before_log * 2 <= GETNEWOID_LOG_MAX_INTERVAL) |
| 388 | + retries_before_log *= 2; |
| 389 | + else |
| 390 | + retries_before_log += GETNEWOID_LOG_MAX_INTERVAL; |
| 391 | + } |
| 392 | + |
| 393 | + retries++; |
356 | 394 | } while (collides);
|
357 | 395 |
|
| 396 | + /* |
| 397 | + * If at least one log message is emitted, also log the completion of OID |
| 398 | + * assignment. |
| 399 | + */ |
| 400 | + if (retries > GETNEWOID_LOG_THRESHOLD) |
| 401 | + { |
| 402 | + ereport(LOG, |
| 403 | + (errmsg("new OID has been assigned in relation \"%s\" after \"%llu\" retries", |
| 404 | + RelationGetRelationName(relation), (unsigned long long) retries))); |
| 405 | + } |
| 406 | + |
358 | 407 | return newOid;
|
359 | 408 | }
|
360 | 409 |
|
|
0 commit comments