You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2025/09/19 05:33:30 UTC

(shardingsphere) branch master updated: Remove LockContext and LockDefinition (#36628)

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

menghaoran 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 1b3d8bd340a Remove LockContext and LockDefinition (#36628)
1b3d8bd340a is described below

commit 1b3d8bd340af0bd3eaf35c3ab05bad81034d863d
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Fri Sep 19 13:33:24 2025 +0800

    Remove LockContext and LockDefinition (#36628)
---
 .../executor/GlobalClockTransactionHookTest.java   |  9 ----
 .../shardingsphere/mode/lock/LockContext.java      | 40 ------------------
 .../shardingsphere/mode/lock/LockDefinition.java   | 31 --------------
 .../standalone/lock/StandaloneLockContext.java     | 43 -------------------
 .../standalone/lock/StandaloneLockContextTest.java | 48 ----------------------
 5 files changed, 171 deletions(-)

diff --git a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java
index 037dc53acee..a945b7cdfa2 100644
--- a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java
+++ b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.globalclock.provider.GlobalClockProvider;
 import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
 import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.mode.lock.LockContext;
 import org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
 import org.apache.shardingsphere.test.infra.framework.mock.AutoMockExtension;
 import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
@@ -41,7 +40,6 @@ import java.util.Optional;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -145,13 +143,6 @@ class GlobalClockTransactionHookTest {
         verify(globalClockTransactionExecutor).sendSnapshotTimestamp(Collections.emptyList(), 10L);
     }
     
-    @Test
-    void assertBeforeCommitWhenDisabledGlobalClockRule() throws SQLException {
-        LockContext lockContext = mock(LockContext.class);
-        transactionHook.beforeCommit(rule, databaseType, Collections.emptyList(), transactionContext);
-        verify(lockContext, times(0)).tryLock(any(), anyLong());
-    }
-    
     @Test
     void assertBeforeCommit() throws SQLException {
         when(rule.getConfiguration().isEnabled()).thenReturn(true);
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockContext.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockContext.java
deleted file mode 100644
index 96cd850eed1..00000000000
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockContext.java
+++ /dev/null
@@ -1,40 +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.mode.lock;
-
-/**
- * Lock context.
- */
-public interface LockContext {
-    
-    /**
-     * Try Lock.
-     *
-     * @param lockDefinition lock definition
-     * @param timeoutMillis timeout milliseconds
-     * @return is locked or not
-     */
-    boolean tryLock(LockDefinition lockDefinition, long timeoutMillis);
-    
-    /**
-     * Unlock.
-     *
-     * @param lockDefinition lock definition
-     */
-    void unlock(LockDefinition lockDefinition);
-}
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockDefinition.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockDefinition.java
deleted file mode 100644
index 19505dc38cc..00000000000
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockDefinition.java
+++ /dev/null
@@ -1,31 +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.mode.lock;
-
-/**
- * Lock definition.
- */
-public interface LockDefinition {
-    
-    /**
-     * Get lock key.
-     *
-     * @return lock key
-     */
-    String getLockKey();
-}
diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java
deleted file mode 100644
index dedc0208ef8..00000000000
--- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java
+++ /dev/null
@@ -1,43 +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.mode.manager.standalone.lock;
-
-import org.apache.shardingsphere.mode.lock.LockContext;
-import org.apache.shardingsphere.mode.lock.LockDefinition;
-import org.apache.shardingsphere.mode.retry.RetryExecutor;
-
-import java.util.Collection;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * Standalone lock context.
- */
-public final class StandaloneLockContext implements LockContext {
-    
-    private final Collection<String> lockedKeys = new CopyOnWriteArraySet<>();
-    
-    @Override
-    public boolean tryLock(final LockDefinition lockDefinition, final long timeoutMillis) {
-        return new RetryExecutor(timeoutMillis, 50L).execute(arg -> lockedKeys.add(lockDefinition.getLockKey()), null);
-    }
-    
-    @Override
-    public void unlock(final LockDefinition lockDefinition) {
-        lockedKeys.remove(lockDefinition.getLockKey());
-    }
-}
diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContextTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContextTest.java
deleted file mode 100644
index 9a109ab3117..00000000000
--- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContextTest.java
+++ /dev/null
@@ -1,48 +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.mode.manager.standalone.lock;
-
-import org.apache.shardingsphere.mode.lock.LockDefinition;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class StandaloneLockContextTest {
-    
-    private final StandaloneLockContext lockContext = new StandaloneLockContext();
-    
-    @Test
-    void assertTryLock() {
-        LockDefinition lockDefinition = mock(LockDefinition.class);
-        when(lockDefinition.getLockKey()).thenReturn("foo_key");
-        assertTrue(lockContext.tryLock(lockDefinition, 100L));
-        assertFalse(lockContext.tryLock(lockDefinition, 100L));
-    }
-    
-    @Test
-    void assertUnlock() {
-        LockDefinition lockDefinition = mock(LockDefinition.class);
-        when(lockDefinition.getLockKey()).thenReturn("foo_key");
-        lockContext.tryLock(lockDefinition, 100L);
-        lockContext.unlock(lockDefinition);
-        assertTrue(lockContext.tryLock(lockDefinition, 100L));
-    }
-}