2222import org .apache .paimon .fs .FileIO ;
2323import org .apache .paimon .options .Options ;
2424import org .apache .paimon .utils .IOUtils ;
25+ import org .apache .paimon .utils .ReflectionUtils ;
2526
27+ import com .aliyun .oss .OSSClient ;
28+ import com .aliyun .oss .common .comm .ServiceClient ;
2629import org .apache .hadoop .conf .Configuration ;
2730import org .apache .hadoop .fs .FileSystem ;
2831import org .apache .hadoop .fs .aliyun .oss .AliyunOSSFileSystem ;
32+ import org .apache .hadoop .fs .aliyun .oss .AliyunOSSFileSystemStore ;
2933import org .slf4j .Logger ;
3034import org .slf4j .LoggerFactory ;
3135
@@ -56,6 +60,7 @@ public class OSSFileIO extends HadoopCompliantFileIO {
5660 private static final String OSS_ACCESS_KEY_ID = "fs.oss.accessKeyId" ;
5761 private static final String OSS_ACCESS_KEY_SECRET = "fs.oss.accessKeySecret" ;
5862 private static final String OSS_SECURITY_TOKEN = "fs.oss.securityToken" ;
63+ private static final String OSS_SECOND_LEVEL_DOMAIN_ENABLED = "fs.oss.sld.enabled" ;
5964
6065 private static final Map <String , String > CASE_SENSITIVE_KEYS =
6166 new HashMap <String , String >() {
@@ -137,6 +142,11 @@ protected AliyunOSSFileSystem createFileSystem(org.apache.hadoop.fs.Path path) {
137142 } catch (IOException e ) {
138143 throw new UncheckedIOException (e );
139144 }
145+
146+ if (hadoopOptions .getBoolean (OSS_SECOND_LEVEL_DOMAIN_ENABLED , false )) {
147+ enableSecondLevelDomain (fs );
148+ }
149+
140150 return fs ;
141151 };
142152
@@ -156,6 +166,19 @@ public void close() {
156166 }
157167 }
158168
169+ public void enableSecondLevelDomain (AliyunOSSFileSystem fs ) {
170+ AliyunOSSFileSystemStore store = fs .getStore ();
171+ try {
172+ OSSClient ossClient = ReflectionUtils .getPrivateFieldValue (store , "ossClient" );
173+ ServiceClient serviceClient =
174+ ReflectionUtils .getPrivateFieldValue (ossClient , "serviceClient" );
175+ serviceClient .getClientConfiguration ().setSLDEnabled (true );
176+ } catch (Exception e ) {
177+ LOG .error ("Failed to enable second level domain." , e );
178+ throw new RuntimeException ("Failed to enable second level domain." , e );
179+ }
180+ }
181+
159182 private static class CacheKey {
160183
161184 private final Options options ;
0 commit comments