Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor InventoryDumper #32636

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.data.pipeline.core.util;
package org.apache.shardingsphere.infra.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 org.apache.shardingsphere.infra.util;

import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class DatabaseTypeUtilsTest {

@Test
void assertIsMySQL() {
DatabaseType actual = TypedSPILoader.getService(DatabaseType.class, "MySQL");
assertTrue(DatabaseTypeUtils.isMySQL(actual));
actual = TypedSPILoader.getService(DatabaseType.class, "MariaDB");
assertTrue(DatabaseTypeUtils.isMySQL(actual));
actual = TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
assertFalse(DatabaseTypeUtils.isMySQL(actual));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.apache.shardingsphere.data.pipeline.core.query.JDBCStreamQueryBuilder;
import org.apache.shardingsphere.data.pipeline.core.ratelimit.JobRateLimitAlgorithm;
import org.apache.shardingsphere.data.pipeline.core.sqlbuilder.sql.PipelineInventoryDumpSQLBuilder;
import org.apache.shardingsphere.data.pipeline.core.util.DatabaseTypeUtils;
import org.apache.shardingsphere.infra.util.DatabaseTypeUtils;
import org.apache.shardingsphere.data.pipeline.core.util.PipelineJdbcUtils;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
Expand Down Expand Up @@ -108,10 +108,10 @@ protected void runBlocking() {
}
init();
try (Connection connection = dataSource.getConnection()) {
if (!Strings.isNullOrEmpty(dumperContext.getQuerySQL()) || !dumperContext.hasUniqueKey() || isPrimaryKeyWithoutRanged(position)) {
dumpWithStreamingQuery(connection);
} else {
if (Strings.isNullOrEmpty(dumperContext.getQuerySQL()) && dumperContext.hasUniqueKey() && !isPrimaryKeyWithoutRange(position)) {
dumpPageByPage(connection);
} else {
dumpWithStreamingQuery(connection);
}
// CHECKSTYLE:OFF
} catch (final SQLException | RuntimeException ex) {
Expand All @@ -121,20 +121,17 @@ protected void runBlocking() {
}
}

private boolean isPrimaryKeyWithoutRanged(final IngestPosition position) {
return position instanceof PrimaryKeyIngestPosition && null == ((PrimaryKeyIngestPosition<?>) position).getBeginValue() && null == ((PrimaryKeyIngestPosition<?>) position).getEndValue();
}

/**
* Initialize.
*/
public void init() {
private void init() {
if (null == tableMetaData) {
tableMetaData = metaDataLoader.getTableMetaData(
dumperContext.getCommonContext().getTableAndSchemaNameMapper().getSchemaName(dumperContext.getLogicTableName()), dumperContext.getActualTableName());
}
}

private boolean isPrimaryKeyWithoutRange(final IngestPosition position) {
return position instanceof PrimaryKeyIngestPosition && null == ((PrimaryKeyIngestPosition<?>) position).getBeginValue() && null == ((PrimaryKeyIngestPosition<?>) position).getEndValue();
}

@SuppressWarnings("MagicConstant")
private void dumpWithStreamingQuery(final Connection connection) throws SQLException {
int batchSize = dumperContext.getBatchSize();
Expand Down