Skip to content

Commit f1bb78f

Browse files
committed
Cleanup from rebase and fix style
Signed-off-by: sfc-gh-npuka <naisila.puka@snowflake.com>
1 parent 4566882 commit f1bb78f

7 files changed

Lines changed: 21 additions & 103 deletions

File tree

pg_lake_iceberg/include/pg_lake/http/http_client.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern bool HttpClientTraceTraffic;
5050
#define HTTP_STATUS_SERVICE_UNAVAILABLE 503
5151

5252
/* Callback function to determine if a request should be retried */
53-
typedef bool (*HttpRetryFn) (long status, int maxRetry, int retryNo, void *context, List *headers);
53+
typedef bool (*HttpRetryFn) (long status, int maxRetry, int retryNo);
5454

5555
/* plain C API (no PostgreSQL types) */
5656
extern PGDLLEXPORT HttpResult HttpGet(const char *url, List *headers);
@@ -60,6 +60,5 @@ extern PGDLLEXPORT HttpResult HttpDelete(const char *url, List *headers);
6060
extern PGDLLEXPORT HttpResult HttpPut(const char *url, const char *body, List *headers);
6161
extern PGDLLEXPORT HttpResult SendHttpRequest(HttpMethod method, const char *url, const char *body, List *headers);
6262
extern PGDLLEXPORT HttpResult SendHttpRequestWithRetry(HttpMethod method, const char *url, const char *body,
63-
List *headers, HttpRetryFn retryFn, int maxRetry,
64-
void *retryContext);
63+
List *headers, HttpRetryFn retryFn, int maxRetry);
6564
extern PGDLLEXPORT int LinearBackoffSleepMs(int baseMs, int retryNo);

pg_lake_iceberg/include/pg_lake/rest_catalog/rest_catalog.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ extern bool RestCatalogEnableVendedCredentials;
4444
typedef struct RestCatalogOptions
4545
{
4646
char *catalog; /* catalog name, used for token cache keying;
47-
* can be 'rest' or a user-created server name
48-
* of TYPE 'rest'
49-
*/
47+
* can be 'rest' or a user-created server name
48+
* of TYPE 'rest' */
5049
char *host;
5150
char *oauthHostPath;
5251
char *clientId;

pg_lake_iceberg/src/http/http_client.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ CurlReturnError(CURL *curl, struct curl_slist *headerList,
276276
*/
277277
HttpResult
278278
SendHttpRequestWithRetry(HttpMethod method, const char *url, const char *body,
279-
List *headers, HttpRetryFn retryFn, int maxRetry,
280-
void *retryContext)
279+
List *headers, HttpRetryFn retryFn, int maxRetry)
281280
{
282281
Assert(maxRetry > 0);
283282

@@ -287,7 +286,7 @@ SendHttpRequestWithRetry(HttpMethod method, const char *url, const char *body,
287286
{
288287
result = SendHttpRequest(method, url, body, headers);
289288

290-
if (retryFn != NULL && retryFn(result.status, maxRetry, retryNo, retryContext, headers))
289+
if (retryFn != NULL && retryFn(result.status, maxRetry, retryNo))
291290
continue;
292291
else
293292
break;

pg_lake_iceberg/src/rest_catalog/rest_catalog.c

Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
>>>>>>> 5f24f40 (Address Onder's review)

pg_lake_iceberg/src/test/test_http_client.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PG_FUNCTION_INFO_V1(test_http_with_retry);
3434

3535
static Datum build_http_result(FunctionCallInfo fcinfo, const HttpResult * r);
3636
static List *extract_headers(FunctionCallInfo fcinfo, int argno);
37-
static bool TestShouldRetryRequestToRestCatalog(long status, int maxRetry, int retryNo, void *context, List *headers);
37+
static bool TestShouldRetryRequestToRestCatalog(long status, int maxRetry, int retryNo);
3838

3939

4040
Datum
@@ -132,8 +132,7 @@ test_http_with_retry(PG_FUNCTION_ARGS)
132132

133133
HttpResult r = SendHttpRequestWithRetry(method, url, body, headers,
134134
TestShouldRetryRequestToRestCatalog,
135-
MAX_HTTP_RETRY_FOR_REST_CATALOG,
136-
NULL);
135+
MAX_HTTP_RETRY_FOR_REST_CATALOG);
137136

138137
PG_RETURN_DATUM(build_http_result(fcinfo, &r));
139138
}
@@ -193,8 +192,7 @@ build_http_result(FunctionCallInfo fcinfo, const HttpResult * r)
193192
* retries until maxRetry is reached.
194193
*/
195194
static bool
196-
TestShouldRetryRequestToRestCatalog(long status, int maxRetry, int retryNo,
197-
void *context, List *headers)
195+
TestShouldRetryRequestToRestCatalog(long status, int maxRetry, int retryNo)
198196
{
199197
if (retryNo > maxRetry)
200198
return false;

pg_lake_table/src/ddl/create_table.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,9 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
789789
/*
790790
* Writable tables always derive catalog_name, catalog_namespace,
791791
* and catalog_table_name from the database name, schema name, and
792-
* table name. Explicit catalog options on the table are rejected,
793-
* and the server must not have catalog_name set either, since that
794-
* would conflict with the derived values.
792+
* table name. Explicit catalog options on the table are
793+
* rejected, and the server must not have catalog_name set either,
794+
* since that would conflict with the derived values.
795795
*/
796796
if (catalogNamespaceProvided != NULL ||
797797
catalogTableNameProvided != NULL ||

pg_lake_table/src/transaction/track_iceberg_metadata_changes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static MemoryContext PgLakeXactCommitContext = NULL;
124124
* where syscache lookups are forbidden. Only one REST catalog server is allowed
125125
* per transaction.
126126
*/
127-
static RestCatalogOptions *PgLakeXactRestCatalogOpts = NULL;
127+
static RestCatalogOptions * PgLakeXactRestCatalogOpts = NULL;
128128

129129

130130
/*

0 commit comments

Comments
 (0)