You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/21 10:30:57 UTC

[shardingsphere] branch master updated: Remove PipelineSimpleLock (#19431)

This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new af298a72012 Remove PipelineSimpleLock (#19431)
af298a72012 is described below

commit af298a720123491e0690060bf6eccab81b66b6f1
Author: azexcy <10...@users.noreply.github.com>
AuthorDate: Thu Jul 21 18:30:48 2022 +0800

    Remove PipelineSimpleLock (#19431)
---
 .../pipeline/core/lock/PipelineSimpleLock.java     | 97 ----------------------
 .../pipeline/core/lock/PipelineSimpleLockTest.java | 49 -----------
 2 files changed, 146 deletions(-)

diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java
deleted file mode 100644
index f7cbcb8955e..00000000000
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.shardingsphere.data.pipeline.core.lock;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.data.pipeline.core.constant.DataPipelineConstants;
-import org.apache.shardingsphere.data.pipeline.core.context.PipelineContext;
-import org.apache.shardingsphere.infra.lock.LockContext;
-import org.apache.shardingsphere.infra.lock.LockScope;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Pipeline simple lock.
- */
-@Slf4j
-// TODO extract interface and factory
-public final class PipelineSimpleLock {
-    
-    private static volatile PipelineSimpleLock instance;
-    
-    private final LockContext lockContext;
-    
-    private final Map<String, Boolean> lockNameLockedMap;
-    
-    private PipelineSimpleLock() {
-        lockNameLockedMap = new ConcurrentHashMap<>();
-        lockContext = PipelineContext.getContextManager().getInstanceContext().getLockContext();
-    }
-    
-    /**
-     * Get instance.
-     *
-     * @return instance
-     */
-    public static PipelineSimpleLock getInstance() {
-        if (null == instance) {
-            synchronized (PipelineSimpleLock.class) {
-                if (null == instance) {
-                    instance = new PipelineSimpleLock();
-                }
-            }
-        }
-        return instance;
-    }
-    
-    /**
-     * Try to lock.
-     *
-     * @param lockName lock name
-     * @param timeoutMills the maximum time in milliseconds to acquire lock
-     * @return true if lock got, else false
-     */
-    public boolean tryLock(final String lockName, final long timeoutMills) {
-        String realLockName = decorateLockName(lockName);
-        boolean result = lockContext.getLock(LockScope.GLOBAL).tryLock(realLockName, timeoutMills);
-        if (result) {
-            lockNameLockedMap.put(realLockName, true);
-        }
-        log.info("tryLock, lockName={}, timeoutMills={}, result={}", realLockName, timeoutMills, result);
-        return result;
-    }
-    
-    /**
-     * Release lock.
-     *
-     * @param lockName lock name
-     */
-    public void releaseLock(final String lockName) {
-        String realLockName = decorateLockName(lockName);
-        log.info("releaseLock, lockName={}", realLockName);
-        if (lockNameLockedMap.getOrDefault(realLockName, false)) {
-            lockNameLockedMap.remove(realLockName);
-            lockContext.getLock(LockScope.GLOBAL).releaseLock(realLockName);
-        }
-    }
-    
-    private String decorateLockName(final String lockName) {
-        return DataPipelineConstants.DATA_PIPELINE_NODE_NAME + "-" + lockName;
-    }
-}
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLockTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLockTest.java
deleted file mode 100644
index a81e729f3a3..00000000000
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLockTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.shardingsphere.data.pipeline.core.lock;
-
-import org.apache.shardingsphere.data.pipeline.core.util.PipelineContextUtil;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.junit.Assert.assertTrue;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class PipelineSimpleLockTest {
-    
-    @BeforeClass
-    public static void beforeClass() {
-        PipelineContextUtil.mockModeConfigAndContextManager();
-    }
-    
-    @Test
-    public void assertTryLockAndReleaseLock() {
-        PipelineSimpleLock pipelineSimpleLock = PipelineSimpleLock.getInstance();
-        String lockName = "test";
-        long timeoutMillis = 50L;
-        boolean locked = pipelineSimpleLock.tryLock(lockName, timeoutMillis);
-        assertTrue(locked);
-        pipelineSimpleLock.releaseLock(lockName);
-        locked = pipelineSimpleLock.tryLock(lockName, timeoutMillis);
-        assertTrue(locked);
-        pipelineSimpleLock.releaseLock(lockName);
-    }
-    
-}