@@ -299,8 +299,8 @@ GetRestCatalogOptionsFromCatalog(const char *catalog)
299299 RestCatalogOptions * opts = palloc0 (sizeof (RestCatalogOptions ));
300300
301301 /*
302- * Normalize built-in catalog name to the canonical constant so that
303- * case variations (e.g. 'REST', 'rEst') compare equal with strcmp.
302+ * Normalize built-in catalog name to the canonical constant so that case
303+ * variations (e.g. 'REST', 'rEst') compare equal with strcmp.
304304 * User-created server names are case-sensitive and stored as-is.
305305 */
306306 if (pg_strcasecmp (catalog , REST_CATALOG_NAME ) == 0 )
@@ -319,9 +319,8 @@ GetRestCatalogOptionsFromCatalog(const char *catalog)
319319 opts -> locationPrefix = GetIcebergDefaultLocationPrefix ();
320320
321321 /*
322- * The built-in 'rest' name uses GUCs exclusively.
323- * For user-created servers, look up server options and
324- * override the GUC defaults.
322+ * The built-in 'rest' name uses GUCs exclusively. For user-created
323+ * servers, look up server options and override the GUC defaults.
325324 */
326325 if (pg_strcasecmp (catalog , REST_CATALOG_NAME ) != 0 )
327326 {
@@ -360,8 +359,9 @@ GetRestCatalogOptionsFromCatalog(const char *catalog)
360359 opts -> catalogName = defGetString (def );
361360 else if (pg_strcasecmp (def -> defname , "location_prefix" ) == 0 )
362361 {
363- bool inPlace = false;
364- opts -> locationPrefix = StripTrailingSlash (defGetString (def ), inPlace );
362+ bool inPlace = false;
363+
364+ opts -> locationPrefix = StripTrailingSlash (defGetString (def ), inPlace );
365365 }
366366 }
367367 }
@@ -1531,9 +1531,6 @@ ClassifyRestCatalogRequestRetry(long status, int maxRetry, int retryNo)
15311531 * so normally we wouldn't want any errors to happen, but then
15321532 * Postgres already prevents post-commit backends to receive signals.
15331533 *
1534- * The serverName is used by the retry callback to invalidate only the
1535- * matching token cache entry on a 419 (token expired) response.
1536- *
15371534 * When opts is non-NULL the retry callback can force-refresh the
15381535 * access token and patch the Authorization header on a 419 response.
15391536 * Pass opts = NULL for the token-fetch request itself to avoid recursion.
@@ -1544,7 +1541,6 @@ SendRequestToRestCatalog(HttpMethod method, const char *url, const char *body,
15441541{
15451542 const int MAX_HTTP_RETRY_FOR_REST_CATALOG = 3 ;
15461543
1547- <<<<<<< HEAD
15481544 HttpResult result ;
15491545
15501546 for (int retryNo = 1 ; retryNo <= MAX_HTTP_RETRY_FOR_REST_CATALOG ; retryNo ++ )
@@ -1569,7 +1565,7 @@ SendRequestToRestCatalog(HttpMethod method, const char *url, const char *body,
15691565 * new token.
15701566 */
15711567 bool forceRefreshToken = true;
1572- char * freshToken = GetRestCatalogAccessToken (forceRefreshToken );
1568+ char * freshToken = GetRestCatalogAccessToken (opts , forceRefreshToken );
15731569
15741570 UpdateAuthorizationHeader (headers , freshToken );
15751571 continue ;
@@ -1582,76 +1578,3 @@ SendRequestToRestCatalog(HttpMethod method, const char *url, const char *body,
15821578
15831579 return result ;
15841580}
1585- = == == ==
1586- return SendHttpRequestWithRetry (method , url , body , headers ,
1587- ShouldRetryRequestToRestCatalog ,
1588- MAX_HTTP_RETRY_FOR_REST_CATALOG ,
1589- opts );
1590- }
1591-
1592-
1593- /*
1594- * ShouldRetryRequestToRestCatalog checks if the given HTTP result status is retriable.
1595- * If it is retriable, it performs necessary actions (like sleeping or refreshing token)
1596- * and returns true. Otherwise, it returns false.
1597- */
1598- bool
1599- ShouldRetryRequestToRestCatalog (long status , int maxRetry , int retryNo ,
1600- void * context , List * headers )
1601- {
1602- if (retryNo > maxRetry )
1603- return false;
1604-
1605- const int TOO_MANY_REQUEST_STATUS = 429 ;
1606- const int SERVER_UNAVAILABLE_STATUS = 503 ;
1607- const int TOKEN_EXPIRED_STATUS = 419 ;
1608-
1609- /* too many request, wait some time */
1610- if (status == TOO_MANY_REQUEST_STATUS )
1611- {
1612- int baseMs = 500 ;
1613-
1614- /*
1615- * LightSleep reacts to signals, and can easily throw an error (e.g.,
1616- * cancel backend). This function can be called at post-commit hook,
1617- * so normally we wouldn't want any errors to happen, but then
1618- * Postgres already prevents post-commit backends to receive signals.
1619- */
1620- LightSleep (LinearBackoffSleepMs (baseMs , retryNo ));
1621- return true;
1622- }
1623-
1624- /* server unavailable, lets wait a bit more */
1625- else if (status == SERVER_UNAVAILABLE_STATUS )
1626- {
1627- int baseMs = 5000 ;
1628-
1629- LightSleep (LinearBackoffSleepMs (baseMs , retryNo ));
1630- return true;
1631- }
1632-
1633- /* token expired, retry after refreshing token */
1634- else if (status == TOKEN_EXPIRED_STATUS )
1635- {
1636- RestCatalogOptions * opts = (RestCatalogOptions * ) context ;
1637-
1638- if (opts == NULL )
1639- return false;
1640-
1641- /*
1642- * We normally refresh the token only when it is about to expire
1643- * (forceRefreshToken = false), just 1 minute before the expiration
1644- * for each request. Retry logic makes it safer by ensuring we get a
1645- * fresh token for unforeseen circumstances.
1646- */
1647- bool forceRefreshToken = true;
1648- char * newToken = GetRestCatalogAccessToken (opts , forceRefreshToken );
1649-
1650- linitial (headers ) = psprintf ("Authorization: Bearer %s" , newToken );
1651- return true;
1652- }
1653-
1654- /* successful or other error, no retry */
1655- return false;
1656- }
1657- >>>>>>> 5f 24f 40 (Address Onder 's review)
0 commit comments