Skip to content

Commit 6555fc1

Browse files
authored
avoid clearing server in cache when scanner closed and interrupted (apache#5313)
When the thread running an accumulo scanner is interrupted it may cause the server the scanner was reading from to be cleared from the cache. This can be disruptive in the case where the server is fine. This change makes a narrow exception to clearing the server from the cache for the case where the scanner was closed and an interrupt was seen. The reason this is so narrow is to avoid failing to invalidate the cache in the case where there is actually a problem with the server.
1 parent de53324 commit 6555fc1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

core/src/main/java/org/apache/accumulo/core/clientImpl/ScannerIterator.java

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public Entry<Key,Value> next() {
124124
}
125125

126126
void close() {
127+
// setting this so that some errors can be ignored
128+
scanState.closeInitiated = true;
127129
// run actual close operation in the background so this does not block.
128130
context.executeCleanupTask(() -> {
129131
synchronized (scanState) {

core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftScanner.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static java.util.concurrent.TimeUnit.SECONDS;
2323

2424
import java.io.IOException;
25+
import java.io.InterruptedIOException;
2526
import java.security.SecureRandom;
2627
import java.time.Duration;
2728
import java.util.ArrayList;
@@ -212,6 +213,8 @@ public static class ScanState {
212213

213214
Duration busyTimeout;
214215

216+
volatile boolean closeInitiated = false;
217+
215218
TabletLocation getErrorLocation() {
216219
return prevLoc;
217220
}
@@ -508,8 +511,13 @@ public static List<KeyValue> scan(ClientContext context, ScanState scanState, Du
508511
TraceUtil.setException(child2, e, false);
509512
sleepMillis = pause(sleepMillis, maxSleepTime, scanState.runOnScanServer);
510513
} catch (TException e) {
511-
TabletLocator.getLocator(context, scanState.tableId).invalidateCache(context,
512-
loc.tablet_location);
514+
boolean wasInterruptedAfterClose =
515+
e.getCause() != null && e.getCause().getClass().equals(InterruptedIOException.class)
516+
&& scanState.closeInitiated;
517+
if (!wasInterruptedAfterClose) {
518+
TabletLocator.getLocator(context, scanState.tableId).invalidateCache(context,
519+
loc.tablet_location);
520+
}
513521
error = "Scan failed, thrift error " + e.getClass().getName() + " " + e.getMessage()
514522
+ " " + scanState.getErrorLocation();
515523
if (!error.equals(lastError)) {

0 commit comments

Comments
 (0)