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

Do not reload table schema when update catalog cache (#2667) #2677

Merged
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
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
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 @@ -97,4 +97,7 @@ object TiConfigConst {
val GC_MAX_WAIT_TIME: String = "spark.tispark.gc_max_wait_time"
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
}
3 changes: 3 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 @@ -255,6 +255,9 @@ object TiUtil {
if (conf.contains(TiConfigConst.ENABLE_GRPC_FORWARD)) {
tiConf.setEnableGrpcForward(conf.get(TiConfigConst.ENABLE_GRPC_FORWARD).toBoolean)
}

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

Expand Down
61 changes: 48 additions & 13 deletions docs/userguide_3.0.md

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions tikv-client/src/main/java/com/pingcap/tikv/ClientSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public Catalog getCatalog() {
synchronized (this) {
if (catalog == null) {
catalog =
new Catalog(this::createSnapshot, getConf().isShowRowId(), getConf().getDBPrefix());
new Catalog(
this::createSnapshot,
getConf().isShowRowId(),
getConf().getDBPrefix(),
getConf().getLoadTables());
}
res = catalog;
}
Expand Down Expand Up @@ -117,9 +121,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public Optional<Boolean> getNewCollationEnable() {
private int tikvRegionSplitSizeInMB = DEF_TIKV_REGION_SPLIT_SIZE_IN_MB;
private static final int DEF_PARTITION_PER_SPLIT = 10;
private int partitionPerSplit = DEF_PARTITION_PER_SPLIT;
private boolean loadTables = true;

public boolean getLoadTables() {
return loadTables;
}
// ---------- same with client-java ------------

public String getPdAddrsString() {
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