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

Fix cacheInvalidateCallback does not work #2626

Merged
merged 1 commit into from
Feb 16, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
*
* Copyright 2022 PingCAP, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.pingcap.tispark.accumulator;

import org.apache.log4j.spi.LoggingEvent
import org.apache.log4j.{AppenderSkeleton, Logger}
import org.apache.spark.sql.BaseTiSparkTest

import java.util
import java.util.stream.Collectors;

class AccumulatorSuite extends BaseTiSparkTest {
test("cacheInvalidateCallback does not work") {
val listLogAppender = new ListLogAppender
val logger = Logger.getRootLogger
logger.addAppender(listLogAppender)
try {
tidbStmt.execute("DROP TABLE IF EXISTS `t1`")
tidbStmt.execute("""
|CREATE TABLE `t1` (
|`a` BIGINT(20) NOT NULL,
|`b` varchar(255) NOT NULL,
|`c` varchar(255) DEFAULT NULL
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
""".stripMargin)
spark.sql("SELECT * FROM t1").show()
tidbStmt.execute(
"SPLIT TABLE t1 BETWEEN (-9223372036854775808) AND (-8223372036854775808) REGIONS 300")
spark.sql("SELECT * FROM t1").show()
} finally {
logger.removeAppender(listLogAppender)
}
val cacheInvalidateListenerLog = listLogAppender.getLog
.stream()
.filter(e =>
e.getMessage.toString.contains(
"Failed to send notification back to driver since CacheInvalidateCallBack is null in executor node"))
.collect(Collectors.toList[LoggingEvent])
assert(cacheInvalidateListenerLog.size() == 0)
}

class ListLogAppender extends AppenderSkeleton {

final private val log = new util.ArrayList[LoggingEvent]()

override def requiresLayout = false

override protected def append(loggingEvent: LoggingEvent): Unit = {
log.add(loggingEvent)
}

override def close(): Unit = {}

def getLog = new util.ArrayList[LoggingEvent](log)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class LogicalPlanTestSuite extends BasePlanTest {
"insert into test3 values(1, 2, 3), (2, 1, 3), (2, 1, 4), (3, 2, 3), (4, 2, 1)")
refreshConnections()
val df =
spark.sql(
"""
spark.sql("""
|select t1.*, (
| select count(*)
| from test2
Expand Down
2 changes: 2 additions & 0 deletions tikv-client/src/main/java/com/pingcap/tikv/TiSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ public ExecutorService getThreadPoolForDeleteRange() {
*/
public void injectCallBackFunc(Function<CacheInvalidateEvent, Void> callBackFunc) {
this.cacheInvalidateCallback = callBackFunc;
RegionManager manager = this.getRegionManager();
manager.setCacheInvalidateCallback(callBackFunc);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RegionManager {
// https://github.com/pingcap/tispark/issues/1170
private final RegionCache cache;

private final Function<CacheInvalidateEvent, Void> cacheInvalidateCallback;
private Function<CacheInvalidateEvent, Void> cacheInvalidateCallback;

private AtomicInteger tiflashStoreIndex = new AtomicInteger(0);

Expand All @@ -67,6 +67,11 @@ public RegionManager(ReadOnlyPDClient pdClient) {
this.cacheInvalidateCallback = null;
}

public synchronized void setCacheInvalidateCallback(
Function<CacheInvalidateEvent, Void> cacheInvalidateCallback) {
this.cacheInvalidateCallback = cacheInvalidateCallback;
}

public Function<CacheInvalidateEvent, Void> getCacheInvalidateCallback() {
return cacheInvalidateCallback;
}
Expand Down