Skip to content

Commit

Permalink
minor, add more logs to troubleshot a mysterious NPE in ScannerWorker…
Browse files Browse the repository at this point in the history
….java (#3361)
  • Loading branch information
liyang-kylin authored Nov 28, 2017
1 parent fbd83ce commit 924c667
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.kylin.storage.gtrecord;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Iterator;

import org.apache.kylin.cube.cuboid.Cuboid;
Expand All @@ -39,10 +39,15 @@
public class ScannerWorker {

private static final Logger logger = LoggerFactory.getLogger(ScannerWorker.class);
private IGTScanner internal = null;

private final IGTScanner internal;
private final Object[] inputArgs;

public ScannerWorker(ISegment segment, Cuboid cuboid, GTScanRequest scanRequest, String gtStorage,
StorageContext context) {

inputArgs = new Object[] { segment, cuboid, scanRequest, gtStorage, context };

try (TraceScope scope = Trace.startSpan("visit segment " + segment.getName())) {

if (scanRequest == null) {
Expand All @@ -58,21 +63,30 @@ public ScannerWorker(ISegment segment, Cuboid cuboid, GTScanRequest scanRequest,
.getConstructor(ISegment.class, Cuboid.class, GTInfo.class, StorageContext.class)
.newInstance(segment, cuboid, info, context); // default behavior
internal = rpc.getGTScanner(scanRequest);
} catch (IOException | InstantiationException | InvocationTargetException | IllegalAccessException
| ClassNotFoundException | NoSuchMethodException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}

checkNPE();
}

public boolean isSegmentSkipped() {
return internal instanceof EmptyGTScanner;
}

public Iterator<GTRecord> iterator() {
// to troubleshoot a myth NPE on line: return internal.iterator()
checkNPE();
return internal.iterator();
}

private void checkNPE() {
if (internal == null) {
logger.error("Caught an impossible NPE, args are " + Arrays.toString(inputArgs), new Exception());
}
}

public void close() throws IOException {
internal.close();
}
Expand Down

0 comments on commit 924c667

Please sign in to comment.