shyjsarah opened a new pull request, #7562: URL: https://github.com/apache/paimon/pull/7562
### Purpose Fix token cache pollution in Python `RESTTokenFileIO` by aligning with the Java implementation. **Problem:** Python's `RESTTokenFileIO` had a class-level `_TOKEN_CACHE` (keyed by table identifier string) that caused token sharing across different catalog instances. When two catalogs with different AK/SK credentials operated on the same table within one process, the second catalog would reuse the first catalog's token — leading to permission errors (e.g., read AK/SK token used for write operations). **Root Cause:** Java's `RESTTokenFileIO` has **no token cache** — each instance manages its own `token` field independently. Python added an extra `_TOKEN_CACHE` class-level dict that Java never had. **Changes:** - Remove class-level `_TOKEN_CACHE`, `_TOKEN_LOCKS`, `_TOKEN_LOCKS_LOCK` and their associated methods (`_get_cached_token`, `_set_cached_token`, `_get_global_token_lock`, `_is_token_expired`) - Simplify `try_to_refresh_token()` to use instance-level lock with double-check pattern, aligned with Java's `tryToRefreshToken()` - Merge `should_refresh()` and `_is_token_expired()` into a single `_should_refresh()` method - Add system table identifier handling in `refresh_token()` (strip `$snapshots` suffix before requesting token), aligned with Java The `FILE_IO_CACHE` (keyed by `RESTToken` object) is kept unchanged — it correctly isolates different credentials since different tokens produce different cache keys. ### Tests Added 7 new unit tests covering the core changes: - `test_should_refresh_when_token_is_none` — Token refresh is triggered when token is None - `test_should_refresh_when_token_not_expired` — No refresh when token is far from expiry - `test_should_refresh_when_token_expired` — Refresh is triggered when token has expired - `test_try_to_refresh_token_calls_refresh_once` — Double-check locking pattern prevents duplicate refresh - `test_refresh_token_strips_system_table_suffix` — `my_table$snapshots` is stripped to `my_table` before requesting token - `test_refresh_token_keeps_normal_identifier` — Normal table identifier is not modified - `test_different_instances_do_not_share_token` — Two instances with same table name hold independent tokens (core bug regression test) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
