This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 8d7d442 Add proxy lock context (#8444)
8d7d442 is described below
commit 8d7d442c24e842f42e7204ac66b8b0936ab7cb0d
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Dec 1 18:17:27 2020 +0800
Add proxy lock context (#8444)
---
.../impl/AbstractBootstrapInitializer.java | 3 ++
.../impl/GovernanceBootstrapInitializer.java | 9 +++-
.../impl/StandardBootstrapInitializer.java | 7 +++
.../proxy/lock/GovernanceLockStrategy.java | 42 ++++++++++++++++++
.../proxy/lock/ProxyLockContext.java | 50 ++++++++++++++++++++++
.../proxy/lock/ProxyLockStrategy.java | 36 ++++++++++++++++
.../proxy/lock/StandardLockStrategy.java | 35 +++++++++++++++
7 files changed, 181 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
index 841ed83..e28c453 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
@@ -65,6 +65,7 @@ public abstract class AbstractBootstrapInitializer implements
BootstrapInitializ
ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
initOpenTracing();
setDatabaseServerInfo();
+ initProxyLockContext();
shardingSphereProxy.start(port);
}
@@ -127,4 +128,6 @@ public abstract class AbstractBootstrapInitializer
implements BootstrapInitializ
protected abstract MetaDataContexts
decorateMetaDataContexts(MetaDataContexts metaDataContexts);
protected abstract TransactionContexts
decorateTransactionContexts(TransactionContexts transactionContexts);
+
+ protected abstract void initProxyLockContext();
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
index 241fb67..94508bb 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
@@ -26,8 +26,8 @@ import
org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfig
import
org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
+import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.ProxyConfigurationUpdater;
@@ -35,6 +35,8 @@ import
org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
import
org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter;
import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
import
org.apache.shardingsphere.proxy.config.yaml.YamlProxyServerConfiguration;
+import org.apache.shardingsphere.proxy.lock.GovernanceLockStrategy;
+import org.apache.shardingsphere.proxy.lock.ProxyLockContext;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import java.util.Collection;
@@ -121,4 +123,9 @@ public final class GovernanceBootstrapInitializer extends
AbstractBootstrapIniti
protected TransactionContexts decorateTransactionContexts(final
TransactionContexts transactionContexts) {
return new GovernanceTransactionContexts(transactionContexts);
}
+
+ @Override
+ protected void initProxyLockContext() {
+ ProxyLockContext.init(new GovernanceLockStrategy(governanceFacade));
+ }
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
index de82b7d..aff566c 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
@@ -21,6 +21,8 @@ import
org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
import
org.apache.shardingsphere.proxy.config.yaml.swapper.YamlProxyConfigurationSwapper;
+import org.apache.shardingsphere.proxy.lock.ProxyLockContext;
+import org.apache.shardingsphere.proxy.lock.StandardLockStrategy;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
/**
@@ -42,4 +44,9 @@ public final class StandardBootstrapInitializer extends
AbstractBootstrapInitial
protected TransactionContexts decorateTransactionContexts(final
TransactionContexts transactionContexts) {
return transactionContexts;
}
+
+ @Override
+ protected void initProxyLockContext() {
+ ProxyLockContext.init(new StandardLockStrategy());
+ }
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/GovernanceLockStrategy.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/GovernanceLockStrategy.java
new file mode 100644
index 0000000..ca03b01
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/GovernanceLockStrategy.java
@@ -0,0 +1,42 @@
+/*
+ * 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.proxy.lock;
+
+import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
+
+/**
+ * Governance proxy lock strategy.
+ */
+public final class GovernanceLockStrategy implements ProxyLockStrategy {
+
+ private final GovernanceFacade governanceFacade;
+
+ public GovernanceLockStrategy(final GovernanceFacade governanceFacade) {
+ this.governanceFacade = governanceFacade;
+ }
+
+ @Override
+ public boolean tryLock() {
+ return governanceFacade.getLockCenter().tryGlobalLock();
+ }
+
+ @Override
+ public void releaseLock() {
+ governanceFacade.getLockCenter().releaseGlobalLock();
+ }
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/ProxyLockContext.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/ProxyLockContext.java
new file mode 100644
index 0000000..afbffe3
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/ProxyLockContext.java
@@ -0,0 +1,50 @@
+/*
+ * 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.proxy.lock;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Proxy lock context.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ProxyLockContext {
+
+ private static final AtomicReference<ProxyLockStrategy>
PROXY_LOCK_STRATEGY = new AtomicReference<>();
+
+ /**
+ * Init proxy lock strategy.
+ *
+ * @param proxyLockStrategy proxy lock strategy
+ */
+ public static void init(final ProxyLockStrategy proxyLockStrategy) {
+ PROXY_LOCK_STRATEGY.set(proxyLockStrategy);
+ }
+
+ /**
+ * Get proxy lock strategy.
+ *
+ * @return proxy lock strategy
+ */
+ public static ProxyLockStrategy getProxyLockStrategy() {
+ return PROXY_LOCK_STRATEGY.get();
+ }
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/ProxyLockStrategy.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/ProxyLockStrategy.java
new file mode 100644
index 0000000..1090736
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/ProxyLockStrategy.java
@@ -0,0 +1,36 @@
+/*
+ * 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.proxy.lock;
+
+/**
+ * Proxy lock strategy.
+ */
+public interface ProxyLockStrategy {
+
+ /**
+ * Try to get lock.
+ *
+ * @return true if get the lock, false if not
+ */
+ boolean tryLock();
+
+ /**
+ * Release lock.
+ */
+ void releaseLock();
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/StandardLockStrategy.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/StandardLockStrategy.java
new file mode 100644
index 0000000..d6503ac
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/lock/StandardLockStrategy.java
@@ -0,0 +1,35 @@
+/*
+ * 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.proxy.lock;
+
+/**
+ * Standard lock strategy.
+ */
+public final class StandardLockStrategy implements ProxyLockStrategy {
+
+ @Override
+ public boolean tryLock() {
+ // TODO
+ return false;
+ }
+
+ @Override
+ public void releaseLock() {
+ // TODO
+ }
+}