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

adding recreate flag when create tisession #1064

Merged
merged 4 commits into from
Aug 26, 2019
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
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/sql/TiContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TiContext(val sparkSession: SparkSession, options: Option[TiDBOptions] = N
lazy val sqlContext: SQLContext = sparkSession.sqlContext
val conf: SparkConf = mergeWithDataSourceConfig(sparkSession.sparkContext.conf, options)
val tiConf: TiConfiguration = TiUtil.sparkConfToTiConf(conf)
val tiSession: TiSession = TiSession.getInstance(tiConf)
val tiSession: TiSession = TiSession.getInstance(tiConf, true)
val meta: MetaManager = new MetaManager(tiSession.getCatalog)

StatisticsManager.initStatisticsManager(tiSession)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class BaseDataSourceTest(val table: String,

protected def dropTable(): Unit = {
jdbcUpdate(s"drop table if exists $dbtable")
// If we reuse tiSession, cache in catalog will be outdated after dropping and creating table.
TiSession.clearCache()
}

protected def dropTable(tblName: String): Unit = {
Expand Down
18 changes: 8 additions & 10 deletions tikv-client/src/main/java/com/pingcap/tikv/TiSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ public class TiSession implements AutoCloseable {

private static final Map<String, TiSession> sessionCachedMap = new HashMap<>();

// Since we create session as singleton now, configuration change will not
// reflect change
public static TiSession getInstance(TiConfiguration conf) {
public static TiSession getInstance(TiConfiguration conf, boolean recreate) {
birdstorm marked this conversation as resolved.
Show resolved Hide resolved
synchronized (sessionCachedMap) {
String key = conf.getPdAddrsString();
if (sessionCachedMap.containsKey(key)) {
if (sessionCachedMap.containsKey(key) && !recreate) {
return sessionCachedMap.get(key);
}

Expand All @@ -60,6 +58,12 @@ public static TiSession getInstance(TiConfiguration conf) {
}
}

// Since we create session as singleton now, configuration change will not
// reflect change
public static TiSession getInstance(TiConfiguration conf) {
return getInstance(conf, false);
}

private TiSession(TiConfiguration conf) {
this.conf = conf;
this.channelFactory = new ChannelFactory(conf.getMaxFrameSize());
Expand Down Expand Up @@ -188,12 +192,6 @@ public void injectCallBackFunc(Function<CacheInvalidateEvent, Void> callBackFunc
this.cacheInvalidateCallback = callBackFunc;
}

public static void clearCache() {
synchronized (sessionCachedMap) {
sessionCachedMap.clear();
}
}

@Override
public synchronized void close() throws Exception {
synchronized (sessionCachedMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class LockResolverSITest extends LockResolverTest {
public void setUp() {
TiConfiguration conf = TiConfiguration.createDefault("127.0.0.1:2379");
conf.setIsolationLevel(IsolationLevel.SI);
TiSession.clearCache();
try {
session = TiSession.getInstance(conf);
this.builder = session.getRegionStoreClientBuilder();
Expand Down