Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyuan2024 committed Jan 2, 2025
1 parent c1a4e63 commit 8f06b0d
Show file tree
Hide file tree
Showing 9 changed files with 1,401 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ public static int getDefaultReplica() {
return 3;
}
}
/* Plan cache related vars */

public static boolean enablePlanCache() {
String enablePlanCache = executorProp.getOrDefault("enable_plan_cache", "on").toString();
return enablePlanCache.equalsIgnoreCase("on");
}

public static long getPlanCacheExpiration() {
try {
String planCacheExpr = executorProp.getOrDefault("plan_cache_expiration", "3600000").toString();
return Long.parseLong(planCacheExpr);
} catch (Exception e) {
return 3600000;
}
}
public static long gePlanCacheSize() {
try {
String planCacheSize = executorProp.getOrDefault("plan_cache_size", "20480000").toString();
return Long.parseLong(planCacheSize);
} catch (Exception e) {
return 20480000;
}
}

public static synchronized void setExecutorProp(String key, String val) {
if ("rpc_batch_size".equalsIgnoreCase(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.dingodb.driver;

import com.google.common.collect.ImmutableList;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.dingodb.calcite.DingoParserContext;
import io.dingodb.calcite.schema.RootSnapshotSchema;
import io.dingodb.common.CommonId;
Expand All @@ -28,6 +29,7 @@
import io.dingodb.common.profile.CommitProfile;
import io.dingodb.common.util.Optional;
import io.dingodb.common.util.Utils;
import io.dingodb.driver.plancache.LRUPlanCache;
import io.dingodb.exec.transaction.base.ITransaction;
import io.dingodb.exec.transaction.base.TransactionType;
import io.dingodb.exec.transaction.impl.TransactionManager;
Expand Down Expand Up @@ -117,6 +119,10 @@ public class DingoConnection extends AvaticaConnection implements CalcitePrepare
@Getter
private Map<Long, Long> mdlLockJobMap = new ConcurrentHashMap<>();

@Getter
@Setter
private LRUPlanCache planCache;

protected DingoConnection(
DingoDriver driver,
AvaticaFactory factory,
Expand All @@ -134,11 +140,31 @@ protected DingoConnection(
context = new DingoParserContext(defaultSchema, info);
sessionVariables = new Properties();
String user = info.getProperty("user");
String host = info.getProperty("host");
String host = info.getProperty("host");
if (user != null && host != null) {
sessionVariables.setProperty("@user", user);
sessionVariables.setProperty("@host", host);
}

String enablePreparePlanCache = info.getProperty("enablePreparePlanCache");
String enableNonpreparePlanCache = info.getProperty("enableNonPreparedPlanCache");
String enableDMLPlanCache = info.getProperty("enableDMLPlanCache");
String planCacheCapacity = info.getProperty("planCacheCapacity");
if (enableNonpreparePlanCache != null) {
sessionVariables.setProperty("@enableNonpreparePlanCache", enableNonpreparePlanCache);
}
if (enablePreparePlanCache != null) {
sessionVariables.setProperty("@enablePreparePlanCache", enablePreparePlanCache);
}
if (enableDMLPlanCache != null) {
sessionVariables.setProperty("@enableDMLPlanCache", enableDMLPlanCache);
}
if (planCacheCapacity != null) {
sessionVariables.setProperty("@planCacheCapacity", planCacheCapacity);
}



try {
InfoSchemaService infoSchemaService = InfoSchemaService.root();
Map<String, String> globalVariableMap = infoSchemaService.getGlobalVariables();
Expand Down Expand Up @@ -228,6 +254,7 @@ public void unlockTables() {
lockTables = null;
}


public synchronized ITransaction createTransaction(TransactionType type, boolean autoCommit) {
if (transaction == null) {
long startTs = TransactionManager.getStartTs();
Expand Down Expand Up @@ -350,6 +377,11 @@ public void close() throws SQLException {
LogUtils.info(log, "call dingoConnection close..., txnId:" + transaction.getTxnId());
transaction.cancel();
}

if (planCache != null) {
LogUtils.info(log, "call dingoConnection close, clean up session plan cache");
planCache.close();
}
} finally {
getMeta().cleanTransaction();
unlockTables();
Expand Down Expand Up @@ -617,4 +649,23 @@ public static Map<Long, Long> str2LongMap(String ids) {
}
return res;
}

public LRUPlanCache createPlanCache() {
int capacity = 1000;
if (sessionVariables.getProperty("planCacheCapacity") != null) {
String cap = sessionVariables.getProperty("planCacheCapacity");
if (cap != null) {
capacity = Integer.parseInt(cap);
}
}

// String txIsolation;
// if (oneTimeTxIsolation != null) {
// txIsolation = oneTimeTxIsolation;
// } else {
// txIsolation = getClientInfo("transaction_isolation");
// }
LRUPlanCache lruPlanCache = LRUPlanCache.newLRUPlanCache(capacity, 0.75, 200000, context, false);
return lruPlanCache;
}
}
Loading

0 comments on commit 8f06b0d

Please sign in to comment.