BsoBird commented on code in PR #10688: URL: https://github.com/apache/iceberg/pull/10688#discussion_r1675609730
########## core/src/main/java/org/apache/iceberg/lock/RedissonLockManager.java: ########## @@ -0,0 +1,174 @@ +/* + * 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. + */ +package org.apache.iceberg.lock; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.apache.iceberg.exceptions.BadRequestException; +import org.apache.iceberg.relocated.com.google.common.base.Strings; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.util.LockManagers; +import org.apache.iceberg.util.Tasks; +import org.redisson.Redisson; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; +import org.redisson.config.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RedissonLockManager extends LockManagers.BaseLockManager { + + public static final String REDISSON_LOCK_CONF = "lock.redisson.conf.yml.base64"; + public static final String REDISSON_LOCK_SINGLE_NODE_URL = "lock.redisson.conf.url"; + public static final String REDISSON_LOCK_KEY_PREFIX = "lock.redisson.key.prefix"; + public static final String REDISSON_LOCK_RETRY_MAX_TIMES = "lock.redisson.retry.max-times"; + public static final String REDISSON_LOCK_RETRY_MAX_TIMES_DEFAULT = "3"; + private static final Logger LOG = LoggerFactory.getLogger(RedissonLockManager.class); + + private final Map<String, RLock> lockCache = Maps.newHashMap(); + private RedissonClient redissonClient; + private String prefix = null; + private int maxRetryTimes = 10; + + public RedissonLockManager() {} + + public RedissonLockManager(String redisUrl) { + try { + init(redisUrl, null); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public RedissonLockManager(String redisUrl, String confYmlBase64) { + try { + init(redisUrl, confYmlBase64); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private synchronized void init(String redissonUrl, String redissonConfYmlBase64) + throws IOException { + if (redissonClient != null) { + return; + } + if (!Strings.isNullOrEmpty(redissonConfYmlBase64)) { + String ymlConfig = + new String(Base64.getDecoder().decode(redissonConfYmlBase64), StandardCharsets.UTF_8); + Config config = Config.fromYAML(ymlConfig); Review Comment: Base64 encrypted strings can be quite large, but I think we can ignore that for now. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org