[SCRIPTS] GetIndexedScript call can deadlock

GetIndexedScript can deadlock since they perform blocking operation
on the network thread. This commit moves the blocking to an async operation
This commit is contained in:
Simon Willnauer 2014-10-29 09:54:42 +01:00
parent e3a09e1933
commit bf1aed14db
2 changed files with 15 additions and 5 deletions

View File

@ -49,8 +49,18 @@ public class TransportGetIndexedScriptAction extends HandledTransportAction<GetI
}
@Override
public void doExecute(GetIndexedScriptRequest request, ActionListener<GetIndexedScriptResponse> listener){
GetResponse scriptResponse = scriptService.queryScriptIndex(request);
listener.onResponse(new GetIndexedScriptResponse(scriptResponse));
public void doExecute(GetIndexedScriptRequest request, final ActionListener<GetIndexedScriptResponse> listener){
// forward the handling to the script service we are running on a network thread here...
scriptService.queryScriptIndex(request,new ActionListener<GetResponse>() {
@Override
public void onResponse(GetResponse getFields) {
listener.onResponse(new GetIndexedScriptResponse(getFields));
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
});
}
}

View File

@ -354,12 +354,12 @@ public class ScriptService extends AbstractComponent {
}
}
public GetResponse queryScriptIndex(GetIndexedScriptRequest request) {
public void queryScriptIndex(GetIndexedScriptRequest request, final ActionListener<GetResponse> listener) {
String scriptLang = validateScriptLanguage(request.scriptLang());
GetRequest getRequest = new GetRequest(request, SCRIPT_INDEX).type(scriptLang).id(request.id())
.version(request.version()).versionType(request.versionType())
.operationThreaded(false).preference("_local"); //Set preference for no forking
return client.get(getRequest).actionGet();
client.get(getRequest, listener);
}
private String validateScriptLanguage(String scriptLang) {