Gaffer icon indicating copy to clipboard operation
Gaffer copied to clipboard

Merge Function misconfiguration handling

Open GCHQDeveloper314 opened this issue 1 year ago • 0 comments

Describe the bug The Federated Store allows an unsuitable merge function to be configured and an error only occurs when there is an attempt to use the merge function. The resulting stack trace doesn't clearly state that there's a merge function misconfiguration.

To Reproduce Steps to reproduce the behaviour:

  1. Configure an incompatible merge function, e.g. using MergeSchema with GetAllElements.
  2. Run the configured operation on a federated store which has a graph.

Expected behaviour Ideally, if the merge functions configured are incompatible, an error should be printed on startup and the invalid configuration ignored. Alternately, a more helpful error could be thrown.

Stack trace and errors With Spring REST:

core.exception.ErrorFactory ERROR  - Error: Error executing opChain: Error federating operation:class uk.gov.gchq.gaffer.operation.impl.get.GetAllElements
uk.gov.gchq.gaffer.core.exception.GafferRuntimeException: Error executing opChain: Error federating operation:class uk.gov.gchq.gaffer.operation.impl.get.GetAllElements
	at uk.gov.gchq.gaffer.rest.service.v2.AbstractOperationService._execute(AbstractOperationService.java:112)
	at uk.gov.gchq.gaffer.rest.controller.OperationController.execute(OperationController.java:137)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at uk.gov.gchq.gaffer.rest.filter.GafferHeaderFilter.doFilterInternal(GafferHeaderFilter.java:41)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:750)
Caused by: uk.gov.gchq.gaffer.operation.OperationException: Error federating operation:class uk.gov.gchq.gaffer.operation.impl.get.GetAllElements
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOutputHandler.doOperation(FederatedOutputHandler.java:72)
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOutputHandler.doOperation(FederatedOutputHandler.java:38)
	at uk.gov.gchq.gaffer.store.Store.handleOperation(Store.java:961)
	at uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler.doOperation(OperationChainHandler.java:49)
	at uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler.doOperation(OperationChainHandler.java:37)
	at uk.gov.gchq.gaffer.store.Store.handleOperation(Store.java:961)
	at uk.gov.gchq.gaffer.store.Store.execute(Store.java:373)
	at uk.gov.gchq.gaffer.store.Store.execute(Store.java:367)
	at uk.gov.gchq.gaffer.graph.Graph._execute(Graph.java:341)
	at uk.gov.gchq.gaffer.graph.Graph.execute(Graph.java:192)
	at uk.gov.gchq.gaffer.rest.service.v2.AbstractOperationService._execute(AbstractOperationService.java:108)
	... 55 more
Caused by: uk.gov.gchq.gaffer.operation.OperationException: Error while merging results. uk.gov.gchq.gaffer.mapstore.impl.GetAllElementsHandler$AllElementsIterable cannot be cast to uk.gov.gchq.gaffer.store.schema.Schema
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOperationHandler.mergeResults(FederatedOperationHandler.java:108)
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOperationHandler.doOperation(FederatedOperationHandler.java:57)
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOperationHandler.doOperation(FederatedOperationHandler.java:48)
	at uk.gov.gchq.gaffer.store.Store.handleOperation(Store.java:961)
	at uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler.doOperation(OperationChainHandler.java:49)
	at uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler.doOperation(OperationChainHandler.java:37)
	at uk.gov.gchq.gaffer.store.Store.handleOperation(Store.java:961)
	at uk.gov.gchq.gaffer.store.Store.execute(Store.java:373)
	at uk.gov.gchq.gaffer.store.Store.execute(Store.java:367)
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOutputHandler.doOperation(FederatedOutputHandler.java:62)
	... 65 more
Caused by: java.lang.ClassCastException: uk.gov.gchq.gaffer.mapstore.impl.GetAllElementsHandler$AllElementsIterable cannot be cast to uk.gov.gchq.gaffer.store.schema.Schema
	at uk.gov.gchq.gaffer.federatedstore.util.MergeSchema.apply(MergeSchema.java:34)
	at uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOperationHandler.mergeResults(FederatedOperationHandler.java:103)
	... 74 more

Platform

  • OS: Linux
  • Gaffer Version: 2.0.0

Additional context Potential solutions could include a refactor of the code for merge functions to ensure that Generics are fully used for checking the types which merge functions accept. As seen in the stack trace, the error is caused by a ClassCastException which happens because of raw types in the code which allow invalid combinations of merge functions.

GCHQDeveloper314 avatar Oct 19 '23 16:10 GCHQDeveloper314