This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 2efac8447e5 Remove standalone lock service (#20947)
2efac8447e5 is described below
commit 2efac8447e58dfb37836f039983e320963d4b347
Author: gin <[email protected]>
AuthorDate: Tue Sep 13 11:16:49 2022 +0800
Remove standalone lock service (#20947)
---
.../StandaloneContextManagerBuilder.java | 3 +-
.../lock/ShardingSphereStandaloneLock.java | 59 ----------------------
.../standalone/lock/StandaloneExclusiveLock.java | 56 --------------------
.../lock/StandaloneLockPersistService.java | 40 ---------------
4 files changed, 1 insertion(+), 157 deletions(-)
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index 698909d1ab5..a06857b3a67 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.mode.lock.ShardingSphereLockContext;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
-import
org.apache.shardingsphere.mode.manager.standalone.lock.StandaloneLockPersistService;
import
org.apache.shardingsphere.mode.manager.standalone.subscriber.ProcessStandaloneSubscriber;
import
org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -60,7 +59,7 @@ public final class StandaloneContextManagerBuilder implements
ContextManagerBuil
private InstanceContext buildInstanceContext(final
ContextManagerBuilderParameter parameter) {
return new InstanceContext(new
ComputeNodeInstance(parameter.getInstanceMetaData()),
- new StandaloneWorkerIdGenerator(),
parameter.getModeConfiguration(), new ShardingSphereLockContext(new
StandaloneLockPersistService()),
+ new StandaloneWorkerIdGenerator(),
parameter.getModeConfiguration(), new ShardingSphereLockContext(null),
new EventBusContext(),
ScheduleContextFactory.newInstance(parameter.getModeConfiguration()));
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/ShardingSphereStandaloneLock.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/ShardingSphereStandaloneLock.java
deleted file mode 100644
index e52f0395d01..00000000000
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/ShardingSphereStandaloneLock.java
+++ /dev/null
@@ -1,59 +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 com.google.common.base.Preconditions;
-import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Standalone lock of ShardingSphere.
- */
-public final class ShardingSphereStandaloneLock implements ShardingSphereLock {
-
- private final Map<String, ReentrantLock> locks = new ConcurrentHashMap<>();
-
- @Override
- public synchronized boolean tryLock(final String lockName, final long
timeoutMillis) {
- Preconditions.checkNotNull(lockName, "Try lock args lockName name can
not be null.");
- ReentrantLock lock = locks.get(lockName);
- if (null == lock) {
- lock = new StandaloneExclusiveLock();
- locks.put(lockName, lock);
- }
- return innerTryLock(lock, timeoutMillis);
- }
-
- private boolean innerTryLock(final ReentrantLock lock, final long
timeoutMillis) {
- try {
- return lock.tryLock(timeoutMillis, TimeUnit.MILLISECONDS);
- } catch (final InterruptedException ignored) {
- return false;
- }
- }
-
- @Override
- public void unlock(final String lockName) {
- Preconditions.checkNotNull(lockName, "Un-lock args lockName name can
not be null.");
- locks.get(lockName).unlock();
- }
-}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneExclusiveLock.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneExclusiveLock.java
deleted file mode 100644
index e08ed81f48e..00000000000
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneExclusiveLock.java
+++ /dev/null
@@ -1,56 +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 java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Standalone exclusive lock.
- */
-public final class StandaloneExclusiveLock extends ReentrantLock {
-
- private final AtomicReference<LockState> lockState = new
AtomicReference<>(LockState.UNLOCKED);
-
- @Override
- public boolean tryLock(final long timeout, final TimeUnit unit) throws
InterruptedException {
- if (!lockState.compareAndSet(LockState.UNLOCKED, LockState.LOCKING)) {
- return false;
- }
- boolean isLocked = super.tryLock(timeout, unit);
- if (isLocked && lockState.compareAndSet(LockState.LOCKING,
LockState.LOCKED)) {
- return true;
- }
- lockState.compareAndSet(LockState.LOCKING, LockState.UNLOCKED);
- return false;
- }
-
- @Override
- public void unlock() {
- if (LockState.LOCKED == lockState.get()) {
- super.unlock();
- lockState.compareAndSet(LockState.LOCKED, LockState.UNLOCKED);
- }
- }
-
- private enum LockState {
-
- LOCKED, UNLOCKED, LOCKING
- }
-}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockPersistService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockPersistService.java
deleted file mode 100644
index 524bfc6d423..00000000000
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockPersistService.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.manager.standalone.lock;
-
-import org.apache.shardingsphere.infra.lock.LockDefinition;
-import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
-import org.apache.shardingsphere.mode.lock.LockPersistService;
-
-/**
- * Standalone lock persist service.
- */
-public final class StandaloneLockPersistService implements LockPersistService {
-
- private final ShardingSphereLock standaloneLock = new
ShardingSphereStandaloneLock();
-
- @Override
- public boolean tryLock(final LockDefinition lockDefinition, final long
timeoutMillis) {
- return standaloneLock.tryLock(lockDefinition.getLockKey(),
timeoutMillis);
- }
-
- @Override
- public void unlock(final LockDefinition lockDefinition) {
- standaloneLock.unlock(lockDefinition.getLockKey());
- }
-}