From 98eab30b93d52a114bd65e154cda3402d0630667 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Mon, 5 Aug 2019 11:47:34 -0700 Subject: [PATCH] Show specific OID suggestion in unused_oids output. Commit a6417078 established a new project policy around OID assignment: new patches are encouraged to choose a random OID in the 8000..9999 range when a manually-assigned OID is required (if multiple OIDs are required, a consecutive block of OIDs starting from the random point should be used). Catalog entries added by committed patches that use OIDs from this "unstable" range are renumbered after feature freeze. This practice minimizes OID collisions among concurrently-developed patches. Show a specific random OID suggestion when the unused_oids script is run. This makes it easy for patch authors to use a random OID from the unstable range, per the new policy. Author: Julien Rouhaud, Peter Geoghegan Reviewed-By: Tom Lane Discussion: https://postgr.es/m/CAH2-WzkkRs2ScmuBQ7xWi7xzp7fC1B3w0Nt8X+n4rBw5k+Z=zA@mail.gmail.com --- src/include/catalog/unused_oids | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/include/catalog/unused_oids b/src/include/catalog/unused_oids index e3fcd913e8..3903dc1f5b 100755 --- a/src/include/catalog/unused_oids +++ b/src/include/catalog/unused_oids @@ -38,7 +38,8 @@ my $FirstGenbkiObjectId = push @{$oids}, $FirstGenbkiObjectId; my $prev_oid = 0; -foreach my $oid (sort { $a <=> $b } @{$oids}) +my @sortedoids = sort { $a <=> $b } @{$oids}; +foreach my $oid (@sortedoids) { if ($oid > $prev_oid + 1) { @@ -53,3 +54,25 @@ foreach my $oid (sort { $a <=> $b } @{$oids}) } $prev_oid = $oid; } + +my $suggestion; +do +{ + $suggestion = int(8000 + rand(2000)); +} while (grep(/^$suggestion$/, @{$oids})); + +my $navailable = 0; +foreach my $oid (@sortedoids) +{ + if ($oid > $suggestion) + { + $navailable = $oid - $suggestion; + last; + } +} + +printf "Patches should use a more-or-less consecutive range of OIDs.\n"; +printf + "Best practice is to start with a random choice in the range 8000-9999.\n"; +printf + "Suggested random unused OID: $suggestion ($navailable consecutive OID(s) available starting here)\n";