discivigour commented on code in PR #160: URL: https://github.com/apache/paimon-rust/pull/160#discussion_r3019497427
########## crates/paimon/src/catalog/rest/rest_token_file_io.rs: ########## @@ -0,0 +1,183 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! REST token-based FileIO for Apache Paimon. +//! +//! This module provides a FileIO wrapper that supports getting data access +//! tokens from a REST Server. It handles token caching, expiration detection, +//! and automatic refresh. + +use std::collections::HashMap; + +use tokio::sync::{Mutex, RwLock}; + +use crate::api::rest_api::RESTApi; +use crate::api::rest_util::RESTUtil; +use crate::catalog::Identifier; +use crate::common::{CatalogOptions, Options}; +use crate::io::storage_oss::OSS_ENDPOINT; +use crate::io::FileIO; +use crate::Result; + +use super::rest_token::RESTToken; + +/// Safe time margin (in milliseconds) before token expiration to trigger refresh. +const TOKEN_EXPIRATION_SAFE_TIME_MILLIS: i64 = 3_600_000; + +/// A FileIO wrapper that supports getting data access tokens from a REST Server. +/// +/// This struct handles: +/// - Token caching with expiration detection +/// - Automatic token refresh via `RESTApi::load_table_token` +/// - Merging token credentials into catalog options to build the underlying `FileIO` +pub struct RESTTokenFileIO { + /// Table identifier for token requests. + identifier: Identifier, + /// Table path (e.g. "oss://bucket/warehouse/db.db/table"). + path: String, + /// Catalog options used to build FileIO and create RESTApi. + catalog_options: Options, + /// Lazily-initialized REST API client for token refresh. + /// Created on first token refresh and reused for subsequent refreshes. + api: Mutex<Option<RESTApi>>, Review Comment: It will init api in refresh_token(), which has read-then-write, too. I plan to use OnceCell to init. -- 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]
