This is an automated email from the ASF dual-hosted git repository. jiangmaolin pushed a commit to branch dev-5.5.1 in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit 7b14796d28ad591f29f6b132991b7f17e3ea3cda Author: Haoran Meng <[email protected]> AuthorDate: Mon Oct 28 15:47:43 2024 +0800 Refactor MetaDataContextManager --- .../DialectCharacterLengthCalculator.java | 119 ++++++++++++++++ .../event/LoadTableMetaDataChangedEvent.java | 40 ++++++ .../process/TableMetaDataReportingProcessor.java | 68 +++++++++ .../core/metadata/type/ProcessScenarioType.java | 26 ++++ .../metadata/persist/node/RoutineMetaDataNode.java | 156 +++++++++++++++++++++ .../process/scenario/ConvertTableProcessData.java | 48 +++++++ .../process/scenario/LoadMetaDataProcessData.java | 38 +++++ .../process/scenario/ScenarioProcessData.java | 24 ++++ .../transaction/TransactionPersistService.java | 71 ++++++++++ .../metadata/persist/MetaDataPersistService.java | 5 - .../spi/TransactionConfigurationGenerator.java | 49 +++++++ .../transaction/spi/TransactionRecoveryJob.java | 35 +++++ .../mode/metadata/MetaDataContextManager.java | 16 --- 13 files changed, 674 insertions(+), 21 deletions(-) diff --git a/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/database/character/DialectCharacterLengthCalculator.java b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/database/character/DialectCharacterLengthCalculator.java new file mode 100644 index 00000000000..50c3e6e428f --- /dev/null +++ b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/database/character/DialectCharacterLengthCalculator.java @@ -0,0 +1,119 @@ +/* + * 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 com.sphereex.dbplusengine.infra.database.core.metadata.database.character; + +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI; +import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Dialect character length calculator. + */ +@SingletonSPI +public interface DialectCharacterLengthCalculator extends DatabaseTypedSPI { + + /** + * Whether need calculate column and row character length or not. + * + * @return whether need calculate or not + */ + boolean isNeedCalculate(); + + /** + * Get charset char to byte ratio. + * + * @param charset charset + * @return charset char to byte ratio + */ + int getCharsetCharToByteRatio(String charset); + + /** + * Get charset name by collation. + * + * @param collation collation + * @return charset name + */ + String getCharsetNameByCollation(String collation); + + /** + * Judge whether type is character type or not. + * + * @param type type + * @return whether is character type or not + */ + boolean isCharacterType(String type); + + /** + * Get default charset name. + * + * @return default charset name + */ + String getDefaultCharsetName(); + + /** + * Check column byte length. + * + * @param columnByteLength column byte length + * @param columnName column name + */ + void checkColumnByteLength(int columnByteLength, String columnName); + + /** + * Check row byte length. + * + * @param columnByteLength column byte length + */ + void checkRowByteLength(int columnByteLength); + + /** + * Calculate column byte length by column char length. + * + * @param columnCharLength column char length + * @param notNull not null + * @param dataType data type + * @param columnName column name + * @param columnCharset column charset + * @param isNullCalculated is null calculated + * @return column byte length + */ + int calculateColumnByteLength(int columnCharLength, boolean notNull, String dataType, String columnName, String columnCharset, AtomicBoolean isNullCalculated); + + /** + * Convert byte length to character length. + * + * @param byteLength byte length + * @param charset charset + * @return character length + */ + int toCharacterLength(int byteLength, String charset); + + /** + * Whether supported column character set definition or not. + * + * @return whether supported column character set definition or not + */ + boolean isSupportedColumnCharacterSetDefinition(); + + /** + * Get default column length unit type. + * + * @return default column length unit type + */ + String getDefaultColumnLengthUnit(); +} diff --git a/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/event/LoadTableMetaDataChangedEvent.java b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/event/LoadTableMetaDataChangedEvent.java new file mode 100644 index 00000000000..729f8d5fb4d --- /dev/null +++ b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/event/LoadTableMetaDataChangedEvent.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 com.sphereex.dbplusengine.infra.database.core.metadata.event; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +// TODO Consider extract event module for unified management. +/** + * Load table meta data changed event. + */ +@RequiredArgsConstructor +@Getter +public final class LoadTableMetaDataChangedEvent { + + private final String instanceId; + + private final String databaseName; + + private final String storageUnitName; + + private final int totalCount; + + private final int completed; +} diff --git a/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/process/TableMetaDataReportingProcessor.java b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/process/TableMetaDataReportingProcessor.java new file mode 100644 index 00000000000..7deffd4d60a --- /dev/null +++ b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/process/TableMetaDataReportingProcessor.java @@ -0,0 +1,68 @@ +/* + * 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 com.sphereex.dbplusengine.infra.database.core.metadata.process; + +import com.sphereex.dbplusengine.infra.database.core.metadata.event.LoadTableMetaDataChangedEvent; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; + +/** + * Table meta data reporting processor. + */ +@RequiredArgsConstructor +public final class TableMetaDataReportingProcessor { + + private static final int BATCH_REPORT_SIZE = 10; + + private final EventBusContext eventBusContext; + + private final String instanceId; + + private final String schemaName; + + private final String storageUnitName; + + private int totalCount; + + private int completed; + + private int reported; + + /** + * Collect total count. + * + * @param totalCount total count + */ + public void collect(final int totalCount) { + this.totalCount = totalCount; + } + + /** + * Complete once. + */ + public void completeOnce() { + if (null == eventBusContext) { + return; + } + completed++; + if (completed == totalCount || 0 == completed % BATCH_REPORT_SIZE) { + eventBusContext.post(new LoadTableMetaDataChangedEvent(instanceId, schemaName, storageUnitName, totalCount, completed - reported)); + reported = completed; + } + } +} diff --git a/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/type/ProcessScenarioType.java b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/type/ProcessScenarioType.java new file mode 100644 index 00000000000..b44ae04c69a --- /dev/null +++ b/infra/database/core/src/main/java/com/sphereex/dbplusengine/infra/database/core/metadata/type/ProcessScenarioType.java @@ -0,0 +1,26 @@ +/* + * 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 com.sphereex.dbplusengine.infra.database.core.metadata.type; + +/** + * Process scenario type. + */ +public enum ProcessScenarioType { + + LOAD_METADATA, CONVERT_TABLE +} diff --git a/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/node/RoutineMetaDataNode.java b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/node/RoutineMetaDataNode.java new file mode 100644 index 00000000000..ba6e97132be --- /dev/null +++ b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/node/RoutineMetaDataNode.java @@ -0,0 +1,156 @@ +/* + * 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 com.sphereex.dbplusengine.metadata.persist.node; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Routine meta data node. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class RoutineMetaDataNode { + + private static final String ROOT_NODE = "metadata"; + + private static final String SCHEMAS_NODE = "schemas"; + + private static final String ROUTINES_NODE = "routines"; + + private static final String ACTIVE_VERSION = "active_version"; + + private static final String VERSIONS = "versions"; + + private static final String ROUTINES_PATTERN = "/([\\w\\-]+)/schemas/([\\w\\-]+)/routines"; + + private static final String ACTIVE_VERSION_SUFFIX = "/([\\w\\-]+)/active_version"; + + private static final String ROUTINES_SUFFIX = "/([\\w\\-]+)$"; + + /** + * Get meta data routines path. + * + * @param databaseName database name + * @param schemaName schema name + * @return routines path + */ + public static String getMetaDataRoutinesPath(final String databaseName, final String schemaName) { + return String.join("/", getMetaDataNode(), databaseName, SCHEMAS_NODE, schemaName, ROUTINES_NODE); + } + + /** + * Get routine active version node. + * + * @param databaseName database name + * @param schemaName schema name + * @param routineName routine name + * @return routine active version node + */ + public static String getRoutineActiveVersionNode(final String databaseName, final String schemaName, final String routineName) { + return String.join("/", getMetaDataNode(), databaseName, SCHEMAS_NODE, schemaName, ROUTINES_NODE, routineName, ACTIVE_VERSION); + } + + /** + * Get routine versions node. + * + * @param databaseName database name + * @param schemaName schema name + * @param routineName routine name + * @return routine active version node + */ + public static String getRoutineVersionsNode(final String databaseName, final String schemaName, final String routineName) { + return String.join("/", getMetaDataNode(), databaseName, SCHEMAS_NODE, schemaName, ROUTINES_NODE, routineName, VERSIONS); + } + + /** + * Get routine version node. + * + * @param databaseName database name + * @param schemaName schema name + * @param routineName routine name + * @param version version + * @return routine version node + */ + public static String getRoutineVersionNode(final String databaseName, final String schemaName, final String routineName, final String version) { + return String.join("/", getRoutineVersionsNode(databaseName, schemaName, routineName), version); + } + + /** + * Get routine node. + * + * @param databaseName database name + * @param schemaName schema name + * @param routineName routine name + * @return routine path + */ + public static String getRoutineNode(final String databaseName, final String schemaName, final String routineName) { + return String.join("/", getMetaDataNode(), databaseName, SCHEMAS_NODE, schemaName, ROUTINES_NODE, routineName); + } + + /** + * Get routine name by active version node. + * + * @param path path + * @return routine name + */ + public static Optional<String> getRoutineNameByActiveVersionNode(final String path) { + Pattern pattern = Pattern.compile(getMetaDataNode() + ROUTINES_PATTERN + ACTIVE_VERSION_SUFFIX, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(path); + return matcher.find() ? Optional.of(matcher.group(3)) : Optional.empty(); + } + + /** + * Get routine name. + * + * @param path path + * @return routine name + */ + public static Optional<String> getRoutineName(final String path) { + Pattern pattern = Pattern.compile(getMetaDataNode() + ROUTINES_PATTERN + "/([\\w\\-]+)$", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(path); + return matcher.find() ? Optional.of(matcher.group(3)) : Optional.empty(); + } + + /** + * Is routine active version node. + * + * @param path path + * @return true or false + */ + public static boolean isRoutineActiveVersionNode(final String path) { + return Pattern.compile(getMetaDataNode() + ROUTINES_PATTERN + ACTIVE_VERSION_SUFFIX, Pattern.CASE_INSENSITIVE).matcher(path).find(); + } + + /** + * Is routine node. + * + * @param path path + * @return true or false + */ + public static boolean isRoutineNode(final String path) { + return Pattern.compile(getMetaDataNode() + ROUTINES_PATTERN + ROUTINES_SUFFIX, Pattern.CASE_INSENSITIVE).matcher(path).find(); + } + + private static String getMetaDataNode() { + return String.join("/", "", ROOT_NODE); + } +} diff --git a/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/ConvertTableProcessData.java b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/ConvertTableProcessData.java new file mode 100644 index 00000000000..c4f508cc86a --- /dev/null +++ b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/ConvertTableProcessData.java @@ -0,0 +1,48 @@ +/* + * 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 com.sphereex.dbplusengine.metadata.persist.service.process.scenario; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration; + +/** + * Convert table process data. + */ +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public final class ConvertTableProcessData implements YamlConfiguration, ScenarioProcessData { + + private int total; + + private int completed; + + private ConvertProcessScenarioNodeType type; + + /** + * Convert process scenario node type. + */ + public enum ConvertProcessScenarioNodeType { + + DDL, UDF, PROCEDURE, ROLLBACK_DDL + } +} diff --git a/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/LoadMetaDataProcessData.java b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/LoadMetaDataProcessData.java new file mode 100644 index 00000000000..7cf2806b761 --- /dev/null +++ b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/LoadMetaDataProcessData.java @@ -0,0 +1,38 @@ +/* + * 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 com.sphereex.dbplusengine.metadata.persist.service.process.scenario; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration; + +/** + * Load meta data process data. + */ +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public final class LoadMetaDataProcessData implements YamlConfiguration, ScenarioProcessData { + + private int total; + + private int completed; +} diff --git a/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/ScenarioProcessData.java b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/ScenarioProcessData.java new file mode 100644 index 00000000000..3b8df0cf16c --- /dev/null +++ b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/process/scenario/ScenarioProcessData.java @@ -0,0 +1,24 @@ +/* + * 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 com.sphereex.dbplusengine.metadata.persist.service.process.scenario; + +/** + * Scenario process data. + */ +public interface ScenarioProcessData { +} diff --git a/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/transaction/TransactionPersistService.java b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/transaction/TransactionPersistService.java new file mode 100644 index 00000000000..69c68f4533d --- /dev/null +++ b/kernel/metadata/core/src/main/java/com/sphereex/dbplusengine/metadata/persist/service/transaction/TransactionPersistService.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 com.sphereex.dbplusengine.metadata.persist.service.transaction; + +import com.google.common.base.Preconditions; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.metadata.persist.node.ComputeNode; +import org.apache.shardingsphere.metadata.persist.service.config.global.GlobalRulePersistService; +import org.apache.shardingsphere.mode.spi.PersistRepository; +import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; + +import java.util.*; + +/** + * Transaction persist service. + */ +@RequiredArgsConstructor +@Getter +public final class TransactionPersistService { + + private final PersistRepository repository; + + private final GlobalRulePersistService globalRuleService; + + /** + * Get all XA recovery ids. + * + * @return all XA recovery ids + */ + public Collection<List<String>> getAllXARecoveryIds() { + Collection<List<String>> result = new LinkedList<>(); + for (String each : repository.getChildrenKeys(ComputeNode.getXaRecoveryIdNodePath())) { + List<String> instances = repository.getChildrenKeys(ComputeNode.getXaRecoveryIdNodePath() + "/" + each); + result.add(instances.isEmpty() ? Arrays.asList(each, "") : Arrays.asList(each, instances.get(0))); + } + return result; + } + + /** + * Persist transaction rule without consistency. + * + * @param props transaction props + */ + public void persistTransactionRuleWithoutConsistency(final Properties props) { + Optional<TransactionRuleConfiguration> transactionRuleConfig = globalRuleService.load().stream() + .filter(TransactionRuleConfiguration.class::isInstance).map(each -> (TransactionRuleConfiguration) each).findFirst(); + Preconditions.checkState(transactionRuleConfig.isPresent()); + if (props.equals(transactionRuleConfig.get().getProps())) { + return; + } + transactionRuleConfig.get().getProps().clear(); + transactionRuleConfig.get().getProps().putAll(props); + globalRuleService.persistWithoutConsistency(Collections.singletonList(transactionRuleConfig.get())); + } +} diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java index 1697984e60e..e9fdc1faff2 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java @@ -18,7 +18,6 @@ package org.apache.shardingsphere.metadata.persist; import com.sphereex.dbplusengine.SphereEx; -import com.sphereex.dbplusengine.metadata.persist.service.process.ConvertTableProcessPersistService; import com.sphereex.dbplusengine.metadata.persist.service.transaction.TransactionPersistService; import lombok.Getter; import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration; @@ -71,9 +70,6 @@ public final class MetaDataPersistService { private final ShardingSphereDataPersistService shardingSphereDataPersistService; - @SphereEx - private final ConvertTableProcessPersistService scenarioProcessPersistService; - @SphereEx private final TransactionPersistService transactionService; @@ -88,7 +84,6 @@ public final class MetaDataPersistService { propsService = new PropertiesPersistService(repository, metaDataVersionPersistService); shardingSphereDataPersistService = new ShardingSphereDataPersistService(repository); // SPEX ADDED: BEGIN - scenarioProcessPersistService = new ConvertTableProcessPersistService(repository); transactionService = new TransactionPersistService(repository, globalRuleService); // SPEX ADDED: END } diff --git a/kernel/transaction/api/src/main/java/com/sphereex/dbplusengine/transaction/spi/TransactionConfigurationGenerator.java b/kernel/transaction/api/src/main/java/com/sphereex/dbplusengine/transaction/spi/TransactionConfigurationGenerator.java new file mode 100644 index 00000000000..fe8d2db31bf --- /dev/null +++ b/kernel/transaction/api/src/main/java/com/sphereex/dbplusengine/transaction/spi/TransactionConfigurationGenerator.java @@ -0,0 +1,49 @@ +/* + * 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 com.sphereex.dbplusengine.transaction.spi; + +import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration; +import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; +import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; + +import java.util.Properties; + +/** + * Transaction configuration generator. + */ +@SingletonSPI +public interface TransactionConfigurationGenerator extends TypedSPI { + + /** + * Set transaction properties. + * + * @param transactionProps transaction properties + */ + void setTransactionProperties(Properties transactionProps); + + /** + * Get transaction rule properties. + * + * @param originTransactionProps origin transaction properties + * @param databaseConfig database configuration + * @param computeNodeInstanceContext compute node instance context + * @return transaction rule props + */ + Properties getTransactionProperties(Properties originTransactionProps, DatabaseConfiguration databaseConfig, ComputeNodeInstanceContext computeNodeInstanceContext); +} diff --git a/kernel/transaction/api/src/main/java/com/sphereex/dbplusengine/transaction/spi/TransactionRecoveryJob.java b/kernel/transaction/api/src/main/java/com/sphereex/dbplusengine/transaction/spi/TransactionRecoveryJob.java new file mode 100644 index 00000000000..a5e53a5c9cf --- /dev/null +++ b/kernel/transaction/api/src/main/java/com/sphereex/dbplusengine/transaction/spi/TransactionRecoveryJob.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 com.sphereex.dbplusengine.transaction.spi; + +import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; + +/** + * Transaction recovery job. + */ +@SingletonSPI +public interface TransactionRecoveryJob extends TypedSPI { + + /** + * Execute. + * + * @param xaRecoveryNode xa recovery node + */ + void execute(String xaRecoveryNode); +} diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java index 6fae4ff1eb7..fa4ccfe7433 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java @@ -18,8 +18,6 @@ package org.apache.shardingsphere.mode.metadata; import com.sphereex.dbplusengine.SphereEx; -import com.sphereex.dbplusengine.infra.database.core.metadata.data.model.SphereExTableStatus; -import com.sphereex.dbplusengine.infra.database.core.metadata.type.ProcessScenarioType; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; @@ -30,10 +28,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilder; -import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial; import org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericSchemaManager; -import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.metadata.decorator.RuleConfigurationPersistDecorateEngine; @@ -42,7 +37,6 @@ import org.apache.shardingsphere.mode.spi.PersistRepository; import java.sql.SQLException; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -118,9 +112,6 @@ public class MetaDataContextManager { public void forceRefreshDatabaseMetaData(final ShardingSphereDatabase database) { try { MetaDataContexts reloadedMetaDataContexts = createMetaDataContexts(database); - // SPEX ADDED: BEGIN - cleanProcessNode(database); - // SPEX ADDED: END metaDataContexts.set(reloadedMetaDataContexts); metaDataContexts.get().getMetaData().getDatabase(database.getName()).getSchemas() .forEach((schemaName, schema) -> { @@ -143,7 +134,6 @@ public class MetaDataContextManager { public void refreshDatabaseMetaData(final ShardingSphereDatabase database) { try { MetaDataContexts reloadedMetaDataContexts = createMetaDataContexts(database); - cleanProcessNode(database); dropSchemas(database.getName(), reloadedMetaDataContexts.getMetaData().getDatabase(database.getName()), database); metaDataContexts.set(reloadedMetaDataContexts); metaDataContexts.get().getMetaData().getDatabase(database.getName()).getSchemas() @@ -187,10 +177,4 @@ public class MetaDataContextManager { switchingResource.closeStaleDataSources(); return result; } - - @SphereEx - private void cleanProcessNode(final ShardingSphereDatabase database) { - database.getResourceMetaData().getStorageUnits() - .forEach((key, value) -> metaDataPersistService.getScenarioProcessPersistService().clean(ProcessScenarioType.LOAD_METADATA, database.getName(), key)); - } }
