Skip to content

Commit

Permalink
Merge branch 'release-3.1' into cherry-pick-2675-to-release-3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanyu66 authored Apr 25, 2023
2 parents ae86d21 + eeca35a commit 840f6b5
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 31 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# - name: Autobuild
# uses: github/codeql-action/autobuild@v1
- name: build
run: |
mvn clean package -Dmaven.test.skip=true -B
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand Down
2 changes: 1 addition & 1 deletion assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/com/pingcap/tispark/TiConfigConst.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ object TiConfigConst {
val DEFAULT_GC_MAX_WAIT_TIME: Long = 24 * 60 * 60
val DEFAULT_GC_SAFE_POINT_TTL: Int = 5 * 60

// cache load
val LOAD_TABLES: String = "spark.tispark.load_tables"
val DEFAULT_LOAD_TABLES: Boolean = true
}
2 changes: 2 additions & 0 deletions core/src/main/scala/com/pingcap/tispark/utils/TiUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ object TiUtil {
tiConf.setNewCollationEnable(conf.get(TiConfigConst.NEW_COLLATION_ENABLE).toBoolean)
}

tiConf.setLoadTables(
conf.get(TiConfigConst.LOAD_TABLES, TiConfigConst.DEFAULT_LOAD_TABLES.toString).toBoolean)
tiConf
}

Expand Down
2 changes: 1 addition & 1 deletion db-random-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
9 changes: 6 additions & 3 deletions docs/userguide_3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ spark.sql("select t1.id,t2.id from spark_catalog.default.t t1 left join tidb_cat
| `spark.tispark.replica_read.label` | "" | Only select TiKV store match specified labels. Format: label_x=value_x,label_y=value_y |
| `spark.tispark.replica_read.address_whitelist` | "" | Only select TiKV store with given ip addresses. Split mutil addresses by `,` |
| `spark.tispark.replica_read.address_blacklist` | "" | Do not select TiKV store with given ip addresses. Split mutil addresses by `,` |
| `spark.tispark.load_tables` | true | (experimental) Whether load all tables when we reload catalog cache. Disable it may cause table not find in scenarios where the table changes frequently. |

### TLS Configuration

Expand Down Expand Up @@ -385,13 +386,15 @@ TiSpark reads the range and hash partition table from TiDB.

Currently, TiSpark doesn't support a MySQL/TiDB partition table syntax `select col_name from table_name partition(partition_name)`, but you can still use `where` condition to filter the partitions.

TiSpark decides whether to apply partition pruning according to the partition type and the partition expression associated with the table. Currently, TiSpark partially apply partition pruning on range partition.
TiSpark decides whether to apply partition pruning according to the partition type and the partition expression associated with the table.

Currently, TiSpark partially apply partition pruning on range partition.

The partition pruning is applied when the partition expression of the range partition is one of the following:

+ column expression
+ `YEAR(col)` and its type is datetime/string/date literal that can be parsed as datetime.
+ `TO_DAYS(col)` and its type is datetime/string/date literal that can be parsed as datetime.
+ `YEAR($argument)` where the argument is a column and its type is datetime or string literal
that can be parsed as datetime.

If partition pruning is not applied, TiSpark's reading is equivalent to doing a table scan over all partitions.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<packaging>pom</packaging>
<name>TiSpark Project Parent POM</name>
<url>http://github.copm/pingcap/tispark</url>
Expand Down
2 changes: 1 addition & 1 deletion spark-wrapper/spark-3.0/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spark-wrapper/spark-3.1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spark-wrapper/spark-3.2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spark-wrapper/spark-3.3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion tikv-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-parent</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public class TiConfiguration implements Serializable {
private static final boolean DEF_IGNORE_TRUNCATE = true;
private static final boolean DEF_TRUNCATE_AS_WARNING = false;
private static final int DEF_MAX_FRAME_SIZE = 2147483647; // 2 GB
private boolean loadTables = true;

public boolean getLoadTables() {
return loadTables;
}

private static final int DEF_INDEX_SCAN_BATCH_SIZE = 20000;
private static final int DEF_REGION_SCAN_DOWNGRADE_THRESHOLD = 10000000;
// if keyRange size per request exceeds this limit, the request might be too large to be accepted
Expand Down
13 changes: 10 additions & 3 deletions tikv-client/src/main/java/com/pingcap/tikv/TiSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ public synchronized Catalog getOrCreateSnapShotCatalog(TiTimestamp ts) {
if (snapshotCatalog == null) {
snapshotCatalog =
new Catalog(
this::createSnapshotWithSnapshotTimestamp, conf.isShowRowId(), conf.getDBPrefix());
this::createSnapshotWithSnapshotTimestamp,
conf.isShowRowId(),
conf.getDBPrefix(),
conf.getLoadTables());
}
snapshotCatalog.reloadCache(true);
return snapshotCatalog;
}

Expand All @@ -208,7 +210,12 @@ public Catalog getCatalog() {
if (res == null) {
synchronized (this) {
if (catalog == null) {
catalog = new Catalog(this::createSnapshot, conf.isShowRowId(), conf.getDBPrefix());
catalog =
new Catalog(
this::createSnapshot,
conf.isShowRowId(),
conf.getDBPrefix(),
conf.getLoadTables());
}
res = catalog;
}
Expand Down
21 changes: 10 additions & 11 deletions tikv-client/src/main/java/com/pingcap/tikv/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ public class Catalog implements AutoCloseable {
private final Supplier<Snapshot> snapshotProvider;
private CatalogCache metaCache;
private static final AtomicLong lastUpdateTime = new AtomicLong(0);
private final boolean loadTables;

public Catalog(Supplier<Snapshot> snapshotProvider, boolean showRowId, String dbPrefix) {
public Catalog(
Supplier<Snapshot> snapshotProvider, boolean showRowId, String dbPrefix, boolean loadTables) {
this.snapshotProvider = Objects.requireNonNull(snapshotProvider, "Snapshot Provider is null");
this.showRowId = showRowId;
this.dbPrefix = dbPrefix;
metaCache = new CatalogCache(new CatalogTransaction(snapshotProvider.get()), dbPrefix, false);
reloadCache(true);
this.loadTables = loadTables;
metaCache =
new CatalogCache(new CatalogTransaction(snapshotProvider.get()), dbPrefix, loadTables);
}

@Override
Expand All @@ -67,18 +70,14 @@ public void reloadCache(boolean loadTables) {
}
}

private void reloadCache() {
reloadCache(false);
}

public List<TiDBInfo> listDatabases() {
reloadCache();
reloadCache(false);
return metaCache.listDatabases();
}

public List<TiTableInfo> listTables(TiDBInfo database) {
Objects.requireNonNull(database, "database is null");
reloadCache(true);
reloadCache(loadTables);
if (showRowId) {
return metaCache
.listTables(database)
Expand Down Expand Up @@ -133,7 +132,7 @@ public TiTableInfo getTableFromCache(TiDBInfo database, String tableName) {

public TiDBInfo getDatabase(String dbName) {
Objects.requireNonNull(dbName, "dbName is null");
reloadCache();
reloadCache(false);
return metaCache.getDatabase(dbName);
}

Expand All @@ -148,7 +147,7 @@ public TiTableInfo getTable(String dbName, String tableName) {
public TiTableInfo getTable(TiDBInfo database, String tableName) {
Objects.requireNonNull(database, "database is null");
Objects.requireNonNull(tableName, "tableName is null");
reloadCache(true);
reloadCache(loadTables);
TiTableInfo table = metaCache.getTable(database, tableName);
if (showRowId && table != null) {
return table.copyTableWithRowId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void listDatabasesTest() {
helper.addDatabase(265, "other");
helper.setSchemaVersion(667);

ReflectionWrapper wrapper = new ReflectionWrapper(cat);
wrapper.call("reloadCache");
ReflectionWrapper wrapper = new ReflectionWrapper(cat, boolean.class);
wrapper.call("reloadCache", false);

dbs = cat.listDatabases();
assertEquals(3, dbs.size());
Expand Down

0 comments on commit 840f6b5

Please sign in to comment.