Skip to content

Commit

Permalink
Cleanup logic in JavaInstanceRunnable close method (apache#3932)
Browse files Browse the repository at this point in the history
* Cleanup logic in JavaInstanceRunnable close method

* Added comments
  • Loading branch information
srkukarni authored Mar 28, 2019
1 parent c11c48f commit 5740699
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,20 +456,25 @@ record = this.source.read();
return record;
}

/**
* NOTE: this method is be syncrhonized because it is potentially called by two different places
* one inside the run/finally clause and one inside the ThreadRuntime::stop
*/
@Override
public void close() {
synchronized public void close() {

if (stats != null) {
stats.close();
stats = null;
}

if (source != null) {
try {
source.close();
} catch (Throwable e) {
log.error("Failed to close source {}", instanceConfig.getFunctionDetails().getSource().getClassName(), e);

}
source = null;
}

if (sink != null) {
Expand All @@ -478,10 +483,12 @@ public void close() {
} catch (Throwable e) {
log.error("Failed to close sink {}", instanceConfig.getFunctionDetails().getSource().getClassName(), e);
}
sink = null;
}

if (null != javaInstance) {
javaInstance.close();
javaInstance = null;
}

// kill the state table
Expand All @@ -495,13 +502,17 @@ public void close() {
log.warn("Failed to close state storage client", cause);
return null;
});
storageClient = null;
}

// once the thread quits, clean up the instance
fnCache.unregisterFunctionInstance(
instanceConfig.getFunctionId(),
instanceConfig.getInstanceName());
log.info("Unloading JAR files for function {}", instanceConfig);
if (instanceCache != null) {
// once the thread quits, clean up the instance
fnCache.unregisterFunctionInstance(
instanceConfig.getFunctionId(),
instanceConfig.getInstanceName());
log.info("Unloading JAR files for function {}", instanceConfig);
instanceCache = null;
}
}

public InstanceCommunication.MetricsData getAndResetMetrics() {
Expand Down

0 comments on commit 5740699

Please sign in to comment.