JingsongLi commented on code in PR #9715: URL: https://github.com/apache/paimon/pull/9715#discussion_r3986178941
########## paimon-python/pypaimon/filesystem/oss_file_io.py: ########## @@ -0,0 +1,127 @@ +# 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. + +"""OSS conditional metadata creation, reusing the existing Arrow/Jindo FileIO.""" + +import re +from urllib.parse import urlparse + +from pypaimon.common.options.config import OssOptions +from pypaimon.filesystem.pyarrow_file_io import PyArrowFileIO + + +class OssFileIO(PyArrowFileIO): + """Override atomic metadata creation; inherit all ordinary file operations.""" + + def try_to_write_atomic(self, path: str, content: str) -> bool: + uri = urlparse(path) + if uri.scheme: + if uri.scheme != 'oss' or self._extract_oss_bucket(path) != self._oss_bucket: + raise ValueError("Atomic write must target the configured OSS bucket") + key = re.sub(r'/+', '/', uri.path).lstrip('/') + if '@' in uri.netloc: + key = key.partition('/')[2] + path = 'oss://{}/{}'.format(self._oss_bucket, key) + else: + key = path + if not self._use_jindo and not self._oss_bucket_in_endpoint: + bucket, _, key = path.partition('/') + if bucket != self._oss_bucket: + raise ValueError("Atomic write must target the configured OSS bucket") + if not key or key == '.' or key.endswith('/'): + return False + + try: + import oss2 + except ImportError as error: + raise ImportError( + "OSS atomic writes require oss2. Install pypaimon[oss] or pypaimon[jindo]." + ) from error + + access_key = self.properties.get(OssOptions.OSS_ACCESS_KEY_ID) + secret_key = self.properties.get(OssOptions.OSS_ACCESS_KEY_SECRET) + token = self.properties.get(OssOptions.OSS_SECURITY_TOKEN) + endpoint = self.properties.get(OssOptions.OSS_ENDPOINT) + if not access_key or not secret_key or not endpoint: + raise ValueError( + "OSS atomic writes require fs.oss.accessKeyId, fs.oss.accessKeySecret " + "and fs.oss.endpoint; pass fs.oss.securityToken for STS credentials.") + if '://' not in endpoint: + endpoint = 'https://' + endpoint + headers = self._sse_headers() + headers['x-oss-forbid-overwrite'] = 'true' + auth = oss2.StsAuth(access_key, secret_key, token) if token else oss2.Auth(access_key, secret_key) Review Comment: [P1] Preserve OSS V4 authentication in the conditional-write backend Both constructors default to Signature V1; `Bucket(region=...)` does not change that, and `fs.oss.signer.version=4` is ignored here. The supported Jindo backend already defaults to V4, and [OSS has retired V1 for new accounts/buckets](https://www.alibabacloud.com/help/en/oss/developer-reference/guidelines-for-upgrading-v1-signatures-to-v4-signatures). A previously working V4 Jindo configuration can therefore receive a V1 authentication rejection specifically on schema/snapshot publication. If that is a 403 AccessDenied, lines 75–84 misclassify it as a versioning permission failure and use the unsafe rename fallback without ever issuing a conditional PUT. Other rejection codes fail the commit. With the real oss2 SDK, both AK and STS probes emitted `OSS` despite V4 configuration; a V1-rejecting simulated transport reached the legacy fallback. Changing the auth constructors produced `OSS4-HMAC-SHA256` and reached the conditional PUT. Please use AuthV4 / StsAuth with auth_version='v4' and proper region resolution, and add a signature-aware test for both credential types. -- 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]
