Skip to content

Commit e87710e

Browse files
committed
Support TiDB
1 parent 2f021d4 commit e87710e

File tree

3 files changed

+244
-0
lines changed

3 files changed

+244
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,228 @@ jobs:
17411741
name: db2_12.1_integration_test_reports_${{ matrix.mode.label }}
17421742
path: core/build/reports/tests/integrationTestJdbc
17431743

1744+
integration-test-for-tidb-v6-5:
1745+
name: TiDB v6.5 integration test (${{ matrix.mode.label }})
1746+
runs-on: ubuntu-latest
1747+
1748+
strategy:
1749+
matrix:
1750+
mode:
1751+
- label: default
1752+
group_commit_enabled: false
1753+
- label: with_group_commit
1754+
group_commit_enabled: true
1755+
1756+
steps:
1757+
- name: Install TiUP
1758+
run: |
1759+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
1760+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
1761+
1762+
- name: Start TiDB with TiUP Playground
1763+
timeout-minutes: 3
1764+
run: |
1765+
tiup playground v6.5 --db 1 --pd 1 --kv 1 --tiflash 0 --without-monitor > tiup.log 2>&1 &
1766+
# Check if TiDB is running
1767+
while true; do
1768+
if mysql -h 127.0.0.1 -P 4000 -u root -e "SELECT 1" > /dev/null 2>&1; then
1769+
echo "TiDB is ready"
1770+
break
1771+
fi
1772+
echo "Waiting for TiDB to be ready..."
1773+
sleep 5
1774+
done
1775+
1776+
- uses: actions/checkout@v5
1777+
1778+
- name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }})
1779+
uses: actions/setup-java@v5
1780+
with:
1781+
java-version: ${{ env.JAVA_VERSION }}
1782+
distribution: ${{ env.JAVA_VENDOR }}
1783+
1784+
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}) to run integration test
1785+
uses: actions/setup-java@v5
1786+
if: ${{ env.SET_UP_INT_TEST_RUNTIME_NON_ORACLE_JDK == 'true'}}
1787+
with:
1788+
java-version: ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}
1789+
distribution: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}
1790+
1791+
- name: Login to Oracle container registry
1792+
uses: docker/login-action@v3
1793+
if: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR == 'oracle' }}
1794+
with:
1795+
registry: container-registry.oracle.com
1796+
username: ${{ secrets.OCR_USERNAME }}
1797+
password: ${{ secrets.OCR_TOKEN }}
1798+
1799+
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (oracle) to run the integration test
1800+
if: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR == 'oracle' }}
1801+
run: |
1802+
container_id=$(docker create "container-registry.oracle.com/java/jdk:${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}")
1803+
docker cp -L "$container_id:/usr/java/default" /usr/lib/jvm/oracle-jdk && docker rm "$container_id"
1804+
1805+
- name: Setup Gradle
1806+
uses: gradle/actions/setup-gradle@v4
1807+
1808+
- name: Execute Gradle 'integrationTestJdbc' task
1809+
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:mysql://localhost:4000 -Dscalardb.jdbc.username=root -Dscalardb.jdbc.password= -Dscalardb.jdbc.isolation_level=REPEATABLE_READ ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}
1810+
1811+
- name: Upload Gradle test reports
1812+
if: always()
1813+
uses: actions/upload-artifact@v4
1814+
with:
1815+
name: tidb_v6_5_integration_test_reports_${{ matrix.mode.label }}
1816+
path: core/build/reports/tests/integrationTestJdbc
1817+
1818+
integration-test-for-tidb-v7-5:
1819+
name: TiDB v7.5 integration test (${{ matrix.mode.label }})
1820+
runs-on: ubuntu-latest
1821+
1822+
strategy:
1823+
matrix:
1824+
mode:
1825+
- label: default
1826+
group_commit_enabled: false
1827+
- label: with_group_commit
1828+
group_commit_enabled: true
1829+
1830+
steps:
1831+
- name: Install TiUP
1832+
run: |
1833+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
1834+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
1835+
1836+
- name: Start TiDB with TiUP Playground
1837+
timeout-minutes: 3
1838+
run: |
1839+
tiup playground v7.5 --db 1 --pd 1 --kv 1 --tiflash 0 --without-monitor > tiup.log 2>&1 &
1840+
# Check if TiDB is running
1841+
while true; do
1842+
if mysql -h 127.0.0.1 -P 4000 -u root -e "SELECT 1" > /dev/null 2>&1; then
1843+
echo "TiDB is ready"
1844+
break
1845+
fi
1846+
echo "Waiting for TiDB to be ready..."
1847+
sleep 5
1848+
done
1849+
1850+
- uses: actions/checkout@v5
1851+
1852+
- name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }})
1853+
uses: actions/setup-java@v5
1854+
with:
1855+
java-version: ${{ env.JAVA_VERSION }}
1856+
distribution: ${{ env.JAVA_VENDOR }}
1857+
1858+
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}) to run integration test
1859+
uses: actions/setup-java@v5
1860+
if: ${{ env.SET_UP_INT_TEST_RUNTIME_NON_ORACLE_JDK == 'true'}}
1861+
with:
1862+
java-version: ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}
1863+
distribution: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}
1864+
1865+
- name: Login to Oracle container registry
1866+
uses: docker/login-action@v3
1867+
if: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR == 'oracle' }}
1868+
with:
1869+
registry: container-registry.oracle.com
1870+
username: ${{ secrets.OCR_USERNAME }}
1871+
password: ${{ secrets.OCR_TOKEN }}
1872+
1873+
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (oracle) to run the integration test
1874+
if: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR == 'oracle' }}
1875+
run: |
1876+
container_id=$(docker create "container-registry.oracle.com/java/jdk:${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}")
1877+
docker cp -L "$container_id:/usr/java/default" /usr/lib/jvm/oracle-jdk && docker rm "$container_id"
1878+
1879+
- name: Setup Gradle
1880+
uses: gradle/actions/setup-gradle@v4
1881+
1882+
- name: Execute Gradle 'integrationTestJdbc' task
1883+
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:mysql://localhost:4000 -Dscalardb.jdbc.username=root -Dscalardb.jdbc.password= -Dscalardb.jdbc.isolation_level=REPEATABLE_READ ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}
1884+
1885+
- name: Upload Gradle test reports
1886+
if: always()
1887+
uses: actions/upload-artifact@v4
1888+
with:
1889+
name: tidb_v7_5_integration_test_reports_${{ matrix.mode.label }}
1890+
path: core/build/reports/tests/integrationTestJdbc
1891+
1892+
integration-test-for-tidb-v8-5:
1893+
name: TiDB v8.5 integration test (${{ matrix.mode.label }})
1894+
runs-on: ubuntu-latest
1895+
1896+
strategy:
1897+
matrix:
1898+
mode:
1899+
- label: default
1900+
group_commit_enabled: false
1901+
- label: with_group_commit
1902+
group_commit_enabled: true
1903+
1904+
steps:
1905+
- name: Install TiUP
1906+
run: |
1907+
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
1908+
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
1909+
1910+
- name: Start TiDB with TiUP Playground
1911+
timeout-minutes: 3
1912+
run: |
1913+
tiup playground v8.5 --db 1 --pd 1 --kv 1 --tiflash 0 --without-monitor > tiup.log 2>&1 &
1914+
# Check if TiDB is running
1915+
while true; do
1916+
if mysql -h 127.0.0.1 -P 4000 -u root -e "SELECT 1" > /dev/null 2>&1; then
1917+
echo "TiDB is ready"
1918+
break
1919+
fi
1920+
echo "Waiting for TiDB to be ready..."
1921+
sleep 5
1922+
done
1923+
1924+
- uses: actions/checkout@v5
1925+
1926+
- name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }})
1927+
uses: actions/setup-java@v5
1928+
with:
1929+
java-version: ${{ env.JAVA_VERSION }}
1930+
distribution: ${{ env.JAVA_VENDOR }}
1931+
1932+
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}) to run integration test
1933+
uses: actions/setup-java@v5
1934+
if: ${{ env.SET_UP_INT_TEST_RUNTIME_NON_ORACLE_JDK == 'true'}}
1935+
with:
1936+
java-version: ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}
1937+
distribution: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}
1938+
1939+
- name: Login to Oracle container registry
1940+
uses: docker/login-action@v3
1941+
if: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR == 'oracle' }}
1942+
with:
1943+
registry: container-registry.oracle.com
1944+
username: ${{ secrets.OCR_USERNAME }}
1945+
password: ${{ secrets.OCR_TOKEN }}
1946+
1947+
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (oracle) to run the integration test
1948+
if: ${{ env.INT_TEST_JAVA_RUNTIME_VENDOR == 'oracle' }}
1949+
run: |
1950+
container_id=$(docker create "container-registry.oracle.com/java/jdk:${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}")
1951+
docker cp -L "$container_id:/usr/java/default" /usr/lib/jvm/oracle-jdk && docker rm "$container_id"
1952+
1953+
- name: Setup Gradle
1954+
uses: gradle/actions/setup-gradle@v4
1955+
1956+
- name: Execute Gradle 'integrationTestJdbc' task
1957+
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:mysql://localhost:4000 -Dscalardb.jdbc.username=root -Dscalardb.jdbc.password= -Dscalardb.jdbc.isolation_level=REPEATABLE_READ ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}
1958+
1959+
- name: Upload Gradle test reports
1960+
if: always()
1961+
uses: actions/upload-artifact@v4
1962+
with:
1963+
name: tidb_v8_5_integration_test_reports_${{ matrix.mode.label }}
1964+
path: core/build/reports/tests/integrationTestJdbc
1965+
17441966
integration-test-for-multi-storage:
17451967
name: Multi-storage integration test (${{ matrix.mode.label }})
17461968
runs-on: ubuntu-latest

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,13 @@ private List<TestData> createExistingMysqlDatabaseWithAllDataTypes(String namesp
603603
UNSUPPORTED_DATA_TYPES_MYSQL.stream()
604604
.filter(type -> !type.equalsIgnoreCase("JSON"))
605605
.collect(Collectors.toList())));
606+
} else if (isTiDB()) {
607+
data.addAll(
608+
prepareCreateNonImportableTableSql(
609+
namespace,
610+
UNSUPPORTED_DATA_TYPES_MYSQL.stream()
611+
.filter(type -> !type.equalsIgnoreCase("GEOMETRY"))
612+
.collect(Collectors.toList())));
606613
} else {
607614
data.addAll(prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_MYSQL));
608615
}
@@ -763,6 +770,15 @@ private boolean isMariaDB() {
763770
}
764771
}
765772

773+
private boolean isTiDB() {
774+
try (Connection connection = dataSource.getConnection()) {
775+
String version = connection.getMetaData().getDatabaseProductVersion();
776+
return version.contains("TiDB");
777+
} catch (SQLException e) {
778+
throw new RuntimeException("Get database product version failed");
779+
}
780+
}
781+
766782
private int getMajorVersion() {
767783
try (Connection connection = dataSource.getConnection()) {
768784
return connection.getMetaData().getDatabaseMajorVersion();

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcEnv.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import com.scalar.db.config.DatabaseConfig;
44
import java.util.Properties;
5+
import org.assertj.core.util.Strings;
56

67
public final class JdbcEnv {
78
private static final String PROP_JDBC_URL = "scalardb.jdbc.url";
89
private static final String PROP_JDBC_USERNAME = "scalardb.jdbc.username";
910
private static final String PROP_JDBC_PASSWORD = "scalardb.jdbc.password";
1011
private static final String PROP_JDBC_NORMAL_USERNAME = "scalardb.jdbc.normal_username";
1112
private static final String PROP_JDBC_NORMAL_PASSWORD = "scalardb.jdbc.normal_password";
13+
private static final String PROP_JDBC_ISOLATION_LEVEL = "scalardb.jdbc.isolation_level";
1214

1315
private static final String DEFAULT_JDBC_URL = "jdbc:postgresql://localhost:5432/";
1416
private static final String DEFAULT_JDBC_USERNAME = "postgres";
@@ -22,6 +24,7 @@ public static Properties getProperties(String testName) {
2224
String jdbcUrl = System.getProperty(PROP_JDBC_URL, DEFAULT_JDBC_URL);
2325
String username = System.getProperty(PROP_JDBC_USERNAME, DEFAULT_JDBC_USERNAME);
2426
String password = System.getProperty(PROP_JDBC_PASSWORD, DEFAULT_JDBC_PASSWORD);
27+
String isolationLevel = System.getProperty(PROP_JDBC_ISOLATION_LEVEL);
2528

2629
Properties properties = new Properties();
2730
properties.setProperty(DatabaseConfig.CONTACT_POINTS, jdbcUrl);
@@ -31,6 +34,9 @@ public static Properties getProperties(String testName) {
3134
properties.setProperty(DatabaseConfig.CROSS_PARTITION_SCAN, "true");
3235
properties.setProperty(DatabaseConfig.CROSS_PARTITION_SCAN_FILTERING, "true");
3336
properties.setProperty(DatabaseConfig.CROSS_PARTITION_SCAN_ORDERING, "true");
37+
if (!Strings.isNullOrEmpty(isolationLevel)) {
38+
properties.setProperty(JdbcConfig.ISOLATION_LEVEL, isolationLevel);
39+
}
3440

3541
// Add testName as a metadata schema suffix
3642
properties.setProperty(

0 commit comments

Comments
 (0)