Skip to content

Commit 27cc167

Browse files
authored
Do not reload table schema when update catalog cache (#2667) (#2676)
1 parent 776313f commit 27cc167

File tree

8 files changed

+44
-21
lines changed

8 files changed

+44
-21
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ jobs:
6060

6161
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
6262
# If this step fails, then you should remove it and run the build manually (see below)
63-
- name: Autobuild
64-
uses: github/codeql-action/autobuild@v1
63+
# - name: Autobuild
64+
# uses: github/codeql-action/autobuild@v1
65+
- name: build
66+
run: |
67+
mvn clean package -Dmaven.test.skip=true -B
6568
6669
# ℹ️ Command-line programs to run using the OS shell.
6770
# 📚 https://git.io/JvXDl

core/src/main/scala/com/pingcap/tispark/TiConfigConst.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,7 @@ object TiConfigConst {
8585
val DEFAULT_GC_MAX_WAIT_TIME: Long = 24 * 60 * 60
8686
val DEFAULT_GC_SAFE_POINT_TTL: Int = 5 * 60
8787

88+
// cache load
89+
val LOAD_TABLES: String = "spark.tispark.load_tables"
90+
val DEFAULT_LOAD_TABLES: Boolean = true
8891
}

core/src/main/scala/com/pingcap/tispark/utils/TiUtil.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ object TiUtil {
237237
tiConf.setNewCollationEnable(conf.get(TiConfigConst.NEW_COLLATION_ENABLE).toBoolean)
238238
}
239239

240+
tiConf.setLoadTables(
241+
conf.get(TiConfigConst.LOAD_TABLES, TiConfigConst.DEFAULT_LOAD_TABLES.toString).toBoolean)
240242
tiConf
241243
}
242244

docs/userguide_3.0.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ spark.sql("select t1.id,t2.id from spark_catalog.default.t t1 left join tidb_cat
277277
| `spark.tispark.replica_read.label` | "" | Only select TiKV store match specified labels. Format: label_x=value_x,label_y=value_y |
278278
| `spark.tispark.replica_read.address_whitelist` | "" | Only select TiKV store with given ip addresses. Split mutil addresses by `,` |
279279
| `spark.tispark.replica_read.address_blacklist` | "" | Do not select TiKV store with given ip addresses. Split mutil addresses by `,` |
280+
| `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. |
280281

281282
### TLS Configuration
282283

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

386387
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.
387388

388-
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.
389+
TiSpark decides whether to apply partition pruning according to the partition type and the partition expression associated with the table.
390+
391+
Currently, TiSpark partially apply partition pruning on range partition.
389392

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

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

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

tikv-client/src/main/java/com/pingcap/tikv/TiConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public class TiConfiguration implements Serializable {
4848
private static final boolean DEF_IGNORE_TRUNCATE = true;
4949
private static final boolean DEF_TRUNCATE_AS_WARNING = false;
5050
private static final int DEF_MAX_FRAME_SIZE = 2147483647; // 2 GB
51+
private boolean loadTables = true;
52+
53+
public boolean getLoadTables() {
54+
return loadTables;
55+
}
56+
5157
private static final int DEF_INDEX_SCAN_BATCH_SIZE = 20000;
5258
private static final int DEF_REGION_SCAN_DOWNGRADE_THRESHOLD = 10000000;
5359
// if keyRange size per request exceeds this limit, the request might be too large to be accepted

tikv-client/src/main/java/com/pingcap/tikv/TiSession.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ public synchronized Catalog getOrCreateSnapShotCatalog(TiTimestamp ts) {
197197
if (snapshotCatalog == null) {
198198
snapshotCatalog =
199199
new Catalog(
200-
this::createSnapshotWithSnapshotTimestamp, conf.isShowRowId(), conf.getDBPrefix());
200+
this::createSnapshotWithSnapshotTimestamp,
201+
conf.isShowRowId(),
202+
conf.getDBPrefix(),
203+
conf.getLoadTables());
201204
}
202-
snapshotCatalog.reloadCache(true);
203205
return snapshotCatalog;
204206
}
205207

@@ -208,7 +210,12 @@ public Catalog getCatalog() {
208210
if (res == null) {
209211
synchronized (this) {
210212
if (catalog == null) {
211-
catalog = new Catalog(this::createSnapshot, conf.isShowRowId(), conf.getDBPrefix());
213+
catalog =
214+
new Catalog(
215+
this::createSnapshot,
216+
conf.isShowRowId(),
217+
conf.getDBPrefix(),
218+
conf.getLoadTables());
212219
}
213220
res = catalog;
214221
}

tikv-client/src/main/java/com/pingcap/tikv/catalog/Catalog.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ public class Catalog implements AutoCloseable {
4141
private final Supplier<Snapshot> snapshotProvider;
4242
private CatalogCache metaCache;
4343
private static final AtomicLong lastUpdateTime = new AtomicLong(0);
44+
private final boolean loadTables;
4445

45-
public Catalog(Supplier<Snapshot> snapshotProvider, boolean showRowId, String dbPrefix) {
46+
public Catalog(
47+
Supplier<Snapshot> snapshotProvider, boolean showRowId, String dbPrefix, boolean loadTables) {
4648
this.snapshotProvider = Objects.requireNonNull(snapshotProvider, "Snapshot Provider is null");
4749
this.showRowId = showRowId;
4850
this.dbPrefix = dbPrefix;
49-
metaCache = new CatalogCache(new CatalogTransaction(snapshotProvider.get()), dbPrefix, false);
50-
reloadCache(true);
51+
this.loadTables = loadTables;
52+
metaCache =
53+
new CatalogCache(new CatalogTransaction(snapshotProvider.get()), dbPrefix, loadTables);
5154
}
5255

5356
@Override
@@ -67,18 +70,14 @@ public void reloadCache(boolean loadTables) {
6770
}
6871
}
6972

70-
private void reloadCache() {
71-
reloadCache(false);
72-
}
73-
7473
public List<TiDBInfo> listDatabases() {
75-
reloadCache();
74+
reloadCache(false);
7675
return metaCache.listDatabases();
7776
}
7877

7978
public List<TiTableInfo> listTables(TiDBInfo database) {
8079
Objects.requireNonNull(database, "database is null");
81-
reloadCache(true);
80+
reloadCache(loadTables);
8281
if (showRowId) {
8382
return metaCache
8483
.listTables(database)
@@ -133,7 +132,7 @@ public TiTableInfo getTableFromCache(TiDBInfo database, String tableName) {
133132

134133
public TiDBInfo getDatabase(String dbName) {
135134
Objects.requireNonNull(dbName, "dbName is null");
136-
reloadCache();
135+
reloadCache(false);
137136
return metaCache.getDatabase(dbName);
138137
}
139138

@@ -148,7 +147,7 @@ public TiTableInfo getTable(String dbName, String tableName) {
148147
public TiTableInfo getTable(TiDBInfo database, String tableName) {
149148
Objects.requireNonNull(database, "database is null");
150149
Objects.requireNonNull(tableName, "tableName is null");
151-
reloadCache(true);
150+
reloadCache(loadTables);
152151
TiTableInfo table = metaCache.getTable(database, tableName);
153152
if (showRowId && table != null) {
154153
return table.copyTableWithRowId();

tikv-client/src/test/java/com/pingcap/tikv/catalog/CatalogTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public void listDatabasesTest() {
7070
helper.addDatabase(265, "other");
7171
helper.setSchemaVersion(667);
7272

73-
ReflectionWrapper wrapper = new ReflectionWrapper(cat);
74-
wrapper.call("reloadCache");
73+
ReflectionWrapper wrapper = new ReflectionWrapper(cat, boolean.class);
74+
wrapper.call("reloadCache", false);
7575

7676
dbs = cat.listDatabases();
7777
assertEquals(3, dbs.size());

0 commit comments

Comments
 (0)