You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/08/25 04:08:36 UTC

[GitHub] [shardingsphere] soulasuna opened a new pull request #11995: Refactor shadow algorithm.

soulasuna opened a new pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995


   For #11661.
   Refactor shadow algorithm.
   
   Changes proposed in this pull request:
   - Add algorithm secondary interface.
   - Add check on shadow Algorithm.
   - Add  shadow Algorithm method.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tristaZero merged pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
tristaZero merged pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] soulasuna commented on a change in pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
soulasuna commented on a change in pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#discussion_r695579624



##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.shadow.algorithm.shadow.note;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * Simple note shadow algorithm.
+ */
+@Getter
+@Setter
+public final class SimpleSQLNoteShadowAlgorithm implements NoteShadowAlgorithm<String> {
+    
+    private static final String NOTE_SPACE = ",";
+    
+    private static final String NOTE_ELEMENT_SPACE = "=";
+    
+    private static final String NOTE_PREFIX = "/*";
+    
+    private static final String NOTE_SUFFIX = "*/";
+    
+    private Properties props = new Properties();
+    
+    @Override
+    public String getType() {
+        return "SIMPLE_NOTE";
+    }
+    
+    @Override
+    public void init() {
+        checkPropsSize();
+    }
+    
+    private void checkPropsSize() {
+        Preconditions.checkState(!props.isEmpty(), "Simple note shadow algorithm props cannot be empty.");
+    }
+    
+    @Override
+    public boolean isShadow(final Collection<String> shadowTableNames, final PreciseNoteShadowValue<String> noteShadowValue) {
+        if (!shadowTableNames.contains(noteShadowValue.getLogicTableName())) {
+            return false;
+        }
+        Optional<Map<String, String>> noteOptional = parseNote(noteShadowValue.getSqlNoteValue());
+        return noteOptional.filter(stringStringMap -> props.entrySet().stream().allMatch(entry -> Objects.equals(entry.getValue(), stringStringMap.get(String.valueOf(entry.getKey()))))).isPresent();
+    }
+    
+    private Optional<Map<String, String>> parseNote(final String sqlNoteValue) {

Review comment:
       I will fix it.

##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
##########
@@ -15,24 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.api.shadow.note;
 
 import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-import java.util.Properties;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
 
-/**
- * Simple note shadow algorithm.
- */
+@RequiredArgsConstructor
 @Getter
-@Setter
-public final class SimpleSQLNoteShadowAlgorithm implements ShadowAlgorithm {
+@ToString
+public class PreciseNoteShadowValue<T extends Comparable<?>> implements ShadowValue {

Review comment:
       I will fix it.

##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.shadow.api.shadow.column;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
+
+/**
+ * Shadow value for precise column.
+ */
+@RequiredArgsConstructor
+@Getter
+@ToString
+public class PreciseColumnShadowValue<T extends Comparable<?>> implements ShadowValue {

Review comment:
       I will fix it.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] soulasuna commented on a change in pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
soulasuna commented on a change in pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#discussion_r695638266



##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.shadow.api.shadow.column;
+
+import lombok.NoArgsConstructor;
+
+import java.util.Optional;
+
+/**
+ * Operation types supported by shadow.
+ */
+@NoArgsConstructor
+public enum ShadowOperationType {
+    
+    /**
+     * The shadow operation is insert.
+     */
+    INSERT,
+    
+    /**
+     * The shadow operation is delete.
+     */
+    DELETE,
+    
+    /**
+     * The shadow operation is update.
+     */
+    UPDATE,
+    
+    /**
+     * The shadow operation is select.
+     */
+    SELECT;
+    
+    /**
+     * Create shadow operation type.
+     *
+     * @param operationType operation type
+     * @return shadow operation type
+     */
+    public static Optional<ShadowOperationType> newInstance(final String operationType) {

Review comment:
       OK.I will optimization method name.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] soulasuna commented on a change in pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
soulasuna commented on a change in pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#discussion_r695579238



##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/ShadowAlgorithmType.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.shadow.algorithm.shadow;
+
+import java.util.Optional;
+
+/**
+ * Shadow algorithm type.
+ */
+public enum ShadowAlgorithmType {
+    
+    /**
+     * Shadow algorithm use column match with regular expression.
+     */
+    COLUMN_REGEX_MATCH,
+    
+    /**
+     * Shadow algorithm use simple sql note.
+     */
+    SIMPLE_NOTE;
+    
+    /**
+     * Create shadow algorithm type.
+     *
+     * @param shadowAlgorithmType shadow algorithm type
+     * @return shadow operation type
+     */
+    public static Optional<ShadowAlgorithmType> newInstance(final String shadowAlgorithmType) {

Review comment:
       OK. This class will be removed.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#issuecomment-905195359


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#11995](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4bca8b8) into [master](https://codecov.io/gh/apache/shardingsphere/commit/ed71fb20f3fce018a38da050a9a6f68b9df16229?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (ed71fb2) will **increase** coverage by `0.06%`.
   > The diff coverage is `55.62%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/11995/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #11995      +/-   ##
   ============================================
   + Coverage     63.13%   63.20%   +0.06%     
   + Complexity     1235     1230       -5     
   ============================================
     Files          2293     2297       +4     
     Lines         34869    34911      +42     
     Branches       6063     6080      +17     
   ============================================
   + Hits          22015    22065      +50     
   + Misses        11074    11061      -13     
   - Partials       1780     1785       +5     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...cs/prometheus/collector/MetaDataInfoCollector.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtYWdlbnQvc2hhcmRpbmdzcGhlcmUtYWdlbnQtcGx1Z2lucy9zaGFyZGluZ3NwaGVyZS1hZ2VudC1wbHVnaW4tbWV0cmljcy9zaGFyZGluZ3NwaGVyZS1hZ2VudC1tZXRyaWNzLXByb21ldGhldXMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2FnZW50L21ldHJpY3MvcHJvbWV0aGV1cy9jb2xsZWN0b3IvTWV0YURhdGFJbmZvQ29sbGVjdG9yLmphdmE=) | `53.84% <ø> (ø)` | |
   | [.../shadow/api/shadow/column/ShadowOperationType.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhZG93L3NoYXJkaW5nc3BoZXJlLXNoYWRvdy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NoYWRvdy9hcGkvc2hhZG93L2NvbHVtbi9TaGFkb3dPcGVyYXRpb25UeXBlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...dow/algorithm/shadow/ShadowAlgorithmException.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhZG93L3NoYXJkaW5nc3BoZXJlLXNoYWRvdy1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zaGFkb3cvYWxnb3JpdGhtL3NoYWRvdy9TaGFkb3dBbGdvcml0aG1FeGNlcHRpb24uamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...te/token/generator/impl/OrderByTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9PcmRlckJ5VG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...uthority/listener/PrivilegeNodeChangedWatcher.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvbnRleHQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29udGV4dC9hdXRob3JpdHkvbGlzdGVuZXIvUHJpdmlsZWdlTm9kZUNoYW5nZWRXYXRjaGVyLmphdmE=) | `50.00% <ø> (ø)` | |
   | [...rnance/core/lock/ShardingSphereDistributeLock.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9sb2NrL1NoYXJkaW5nU3BoZXJlRGlzdHJpYnV0ZUxvY2suamF2YQ==) | `32.00% <ø> (ø)` | |
   | [...ernance/core/lock/service/LockRegistryService.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9sb2NrL3NlcnZpY2UvTG9ja1JlZ2lzdHJ5U2VydmljZS5qYXZh) | `37.14% <ø> (ø)` | |
   | [...vernance/core/lock/watcher/LockChangedWatcher.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9sb2NrL3dhdGNoZXIvTG9ja0NoYW5nZWRXYXRjaGVyLmphdmE=) | `22.22% <ø> (ø)` | |
   | [...core/registry/ClusterPersistRepositoryFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9yZWdpc3RyeS9DbHVzdGVyUGVyc2lzdFJlcG9zaXRvcnlGYWN0b3J5LmphdmE=) | `100.00% <ø> (ø)` | |
   | [...rnance/core/registry/GovernanceWatcherFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9yZWdpc3RyeS9Hb3Zlcm5hbmNlV2F0Y2hlckZhY3RvcnkuamF2YQ==) | `0.00% <ø> (ø)` | |
   | ... and [143 more](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [4bf7077...4bca8b8](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter commented on pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#issuecomment-905195359


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#11995](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e5628c6) into [master](https://codecov.io/gh/apache/shardingsphere/commit/ed71fb20f3fce018a38da050a9a6f68b9df16229?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (ed71fb2) will **increase** coverage by `0.16%`.
   > The diff coverage is `57.86%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/11995/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #11995      +/-   ##
   ============================================
   + Coverage     63.13%   63.30%   +0.16%     
   + Complexity     1235     1231       -4     
   ============================================
     Files          2293     2297       +4     
     Lines         34869    34964      +95     
     Branches       6063     6085      +22     
   ============================================
   + Hits          22015    22133     +118     
   + Misses        11074    11045      -29     
   - Partials       1780     1786       +6     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...cs/prometheus/collector/MetaDataInfoCollector.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtYWdlbnQvc2hhcmRpbmdzcGhlcmUtYWdlbnQtcGx1Z2lucy9zaGFyZGluZ3NwaGVyZS1hZ2VudC1wbHVnaW4tbWV0cmljcy9zaGFyZGluZ3NwaGVyZS1hZ2VudC1tZXRyaWNzLXByb21ldGhldXMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2FnZW50L21ldHJpY3MvcHJvbWV0aGV1cy9jb2xsZWN0b3IvTWV0YURhdGFJbmZvQ29sbGVjdG9yLmphdmE=) | `53.84% <ø> (ø)` | |
   | [.../shadow/api/shadow/column/ShadowOperationType.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhZG93L3NoYXJkaW5nc3BoZXJlLXNoYWRvdy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NoYWRvdy9hcGkvc2hhZG93L2NvbHVtbi9TaGFkb3dPcGVyYXRpb25UeXBlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...dow/algorithm/shadow/ShadowAlgorithmException.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhZG93L3NoYXJkaW5nc3BoZXJlLXNoYWRvdy1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zaGFkb3cvYWxnb3JpdGhtL3NoYWRvdy9TaGFkb3dBbGdvcml0aG1FeGNlcHRpb24uamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...te/token/generator/impl/OrderByTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9PcmRlckJ5VG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...uthority/listener/PrivilegeNodeChangedWatcher.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvbnRleHQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29udGV4dC9hdXRob3JpdHkvbGlzdGVuZXIvUHJpdmlsZWdlTm9kZUNoYW5nZWRXYXRjaGVyLmphdmE=) | `50.00% <ø> (ø)` | |
   | [...rnance/core/lock/ShardingSphereDistributeLock.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9sb2NrL1NoYXJkaW5nU3BoZXJlRGlzdHJpYnV0ZUxvY2suamF2YQ==) | `32.00% <ø> (ø)` | |
   | [...ernance/core/lock/service/LockRegistryService.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9sb2NrL3NlcnZpY2UvTG9ja1JlZ2lzdHJ5U2VydmljZS5qYXZh) | `37.14% <ø> (ø)` | |
   | [...vernance/core/lock/watcher/LockChangedWatcher.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9sb2NrL3dhdGNoZXIvTG9ja0NoYW5nZWRXYXRjaGVyLmphdmE=) | `22.22% <ø> (ø)` | |
   | [...core/registry/ClusterPersistRepositoryFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9yZWdpc3RyeS9DbHVzdGVyUGVyc2lzdFJlcG9zaXRvcnlGYWN0b3J5LmphdmE=) | `100.00% <ø> (ø)` | |
   | [...rnance/core/registry/GovernanceWatcherFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9yZWdpc3RyeS9Hb3Zlcm5hbmNlV2F0Y2hlckZhY3RvcnkuamF2YQ==) | `0.00% <ø> (ø)` | |
   | ... and [118 more](https://codecov.io/gh/apache/shardingsphere/pull/11995/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [4bf7077...e5628c6](https://codecov.io/gh/apache/shardingsphere/pull/11995?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tristaZero commented on a change in pull request #11995: Refactor shadow algorithm.

Posted by GitBox <gi...@apache.org>.
tristaZero commented on a change in pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#discussion_r695554146



##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.shadow.api.shadow.column;
+
+import lombok.NoArgsConstructor;
+
+import java.util.Optional;
+
+/**
+ * Operation types supported by shadow.
+ */
+@NoArgsConstructor
+public enum ShadowOperationType {
+    
+    /**
+     * The shadow operation is insert.
+     */
+    INSERT,
+    
+    /**
+     * The shadow operation is delete.
+     */
+    DELETE,
+    
+    /**
+     * The shadow operation is update.
+     */
+    UPDATE,
+    
+    /**
+     * The shadow operation is select.
+     */
+    SELECT;
+    
+    /**
+     * Create shadow operation type.
+     *
+     * @param operationType operation type
+     * @return shadow operation type
+     */
+    public static Optional<ShadowOperationType> newInstance(final String operationType) {

Review comment:
       Could your refer to `MySQLAuthenticationMethod`?

##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.shadow.algorithm.shadow.note;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * Simple note shadow algorithm.
+ */
+@Getter
+@Setter
+public final class SimpleSQLNoteShadowAlgorithm implements NoteShadowAlgorithm<String> {
+    
+    private static final String NOTE_SPACE = ",";
+    
+    private static final String NOTE_ELEMENT_SPACE = "=";
+    
+    private static final String NOTE_PREFIX = "/*";
+    
+    private static final String NOTE_SUFFIX = "*/";
+    
+    private Properties props = new Properties();
+    
+    @Override
+    public String getType() {
+        return "SIMPLE_NOTE";
+    }
+    
+    @Override
+    public void init() {
+        checkPropsSize();
+    }
+    
+    private void checkPropsSize() {
+        Preconditions.checkState(!props.isEmpty(), "Simple note shadow algorithm props cannot be empty.");
+    }
+    
+    @Override
+    public boolean isShadow(final Collection<String> shadowTableNames, final PreciseNoteShadowValue<String> noteShadowValue) {
+        if (!shadowTableNames.contains(noteShadowValue.getLogicTableName())) {
+            return false;
+        }
+        Optional<Map<String, String>> noteOptional = parseNote(noteShadowValue.getSqlNoteValue());
+        return noteOptional.filter(stringStringMap -> props.entrySet().stream().allMatch(entry -> Objects.equals(entry.getValue(), stringStringMap.get(String.valueOf(entry.getKey()))))).isPresent();
+    }
+    
+    private Optional<Map<String, String>> parseNote(final String sqlNoteValue) {

Review comment:
       It is suggested to extract this logic to a util class for other `note algorithms`.

##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/ShadowAlgorithmType.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.shadow.algorithm.shadow;
+
+import java.util.Optional;
+
+/**
+ * Shadow algorithm type.
+ */
+public enum ShadowAlgorithmType {
+    
+    /**
+     * Shadow algorithm use column match with regular expression.
+     */
+    COLUMN_REGEX_MATCH,
+    
+    /**
+     * Shadow algorithm use simple sql note.
+     */
+    SIMPLE_NOTE;
+    
+    /**
+     * Create shadow algorithm type.
+     *
+     * @param shadowAlgorithmType shadow algorithm type
+     * @return shadow operation type
+     */
+    public static Optional<ShadowAlgorithmType> newInstance(final String shadowAlgorithmType) {

Review comment:
       Do you think `instanceof` is suitable to replace this class?

##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
##########
@@ -15,24 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.api.shadow.note;
 
 import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-import java.util.Properties;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
 
-/**
- * Simple note shadow algorithm.
- */
+@RequiredArgsConstructor
 @Getter
-@Setter
-public final class SimpleSQLNoteShadowAlgorithm implements ShadowAlgorithm {
+@ToString
+public class PreciseNoteShadowValue<T extends Comparable<?>> implements ShadowValue {

Review comment:
       Is it supposed to be a final class?

##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.shadow.api.shadow.column;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
+
+/**
+ * Shadow value for precise column.
+ */
+@RequiredArgsConstructor
+@Getter
+@ToString
+public class PreciseColumnShadowValue<T extends Comparable<?>> implements ShadowValue {

Review comment:
       Is it supposed to be a final class?




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org