Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-207

RemoteRepository does not CANCEL a SPARQL UPDATE if there is a client error.

    Details

      Description

      SPARQL UPDATE does not automatically submit a CANCEL while the boolean, graph, and tuple query forms all do attempt that CANCEL.

      I suggest that the same CANCEL behavior should exist in the Java client for SPARQL UPDATE.

      The evaluate() method on the client for SPARQL UPDATE is:

              @Override
              public void evaluate(final IPreparedQueryListener listener) 
                      throws Exception {
               
              	JettyResponseListener response = null;
                  try {
      
                      setupConnectOptions();
      
                      // Note: No response body is expected.
                      
                      checkResponseCode(response = doConnect(opts));
      
                  } finally {
                      
                  	if (response != null)
                  		response.abort();
      	                            
                  }
                  
              }
      

      The evaluate method on the client for SPARQL query delegates to code that has the following general form. This includes some logic that is not relevant for SPARQL UPDATE, but note that a SPARQL QUERY that is not known to be done (fully drained) is CANCELed by the client in the finally {} clause.

        GraphQueryResult graphResults(final ConnectOptions opts,
                 final UUID queryId, final IPreparedQueryListener listener) throws Exception {
      
           // The listener handling the http response.
           JettyResponseListener response = null;
           // Incrementally parse the response in another thread.  
             BackgroundGraphResult result = null;
             try {
      
                 response = doConnect(opts);
      
                 checkResponseCode(response);
                 
                 final String baseURI = "";
      
                 final String contentType = response.getContentType();
      
                 if (contentType == null)
                     throw new RuntimeException("Not found: Content-Type");
                 
                 final MiniMime mimeType = new MiniMime(contentType);
                 
                 final RDFFormat format = RDFFormat
                         .forMIMEType(mimeType.getMimeType());
      
                 if (format == null)
                     throw new IOException(
                             "Could not identify format for service response: serviceURI="
                                     + opts.getBestRequestURL() + ", contentType=" + contentType
                                     + " : response=" + response.getResponseBody());
      
                 final RDFParserFactory factory = RDFParserRegistry.getInstance().get(format);
      
                 if (factory == null)
                     throw new RuntimeException(
                             "RDFParserFactory not found: Content-Type="
                                     + contentType + ", format=" + format);
      
                 final RDFParser parser = factory.getParser();
                 
                 // TODO See BLZG-1106 (Make RDFParserOptions configurable)
                 parser.setValueFactory(new ValueFactoryImpl());
      
                 parser.setVerifyData(true);
      
                 parser.setStopAtFirstError(true);
      
                 parser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);
                 /**
                  * Note: The default charset depends on the MIME Type. The [charset]
                  * MUST be [null] if the MIME Type is binary since this effects
                  * whether a Reader or InputStream will be used to construct and
                  * apply the RDF parser.
                  * 
                  * @see <a href="http://trac.blazegraph.com/ticket/920" > Content
                  *      negotiation orders accept header scores in reverse </a>
                  */
                 Charset charset = format.getCharset();//Charset.forName(UTF8);
                 try {
                    
                    final String encoding = response.getContentEncoding();
                     if (encoding != null)
                         charset = Charset.forName(encoding);
                 } catch (IllegalCharsetNameException e) {
                     // work around for Joseki-3.2
                     // Content-Type: application/rdf+xml;
                     // charset=application/rdf+xml
                 }
                 
                 final BackgroundGraphResult tmp = new BackgroundGraphResult(
                         parser, response.getInputStream(), charset, baseURI) {
                    
                    final AtomicBoolean notDone = new AtomicBoolean(true);
                    
                    @Override
                    public boolean hasNext() throws QueryEvaluationException {
                    
                       final boolean hasNext = super.hasNext();
                       
                       if (hasNext == false) {
                          
                          notDone.set(false);
                          
                       }
                       
                       return hasNext;
                       
                    }
                    
                    @Override
                    public void close() throws QueryEvaluationException {
                       
                       try {
                    
                          super.close();
                    
                       } finally {
                          
                       if (notDone.compareAndSet(true, false)) {
                          
                          try {
                             cancel(queryId);
                          } catch (Exception ex) {log.warn(ex); }
                          
                       }
                       
                       if (listener != null) {
                           listener.closed(queryId);
                       }
                       
                       }
                    
                    };
                    
                 };
                 
              /*
               * Note: Asynchronous execution. Typically does not even start
               * running until after we leave this method!
               */
                 executor.execute(tmp);
                 
                 // The executor accepted the task for execution (at some point).
                 result = tmp;
      
                 /*
               * Result will be asynchronously produced.
               * 
               * Note: At this point the caller is responsible for calling close()
               * on this object to clean up the resources associated with this
               * request.
               */
                 return result;
      
             } finally {
      
                 if (response != null && result == null) {
                 /*
                  * This code path only handles errors. We have a response, but
                  * we were not able to generate the asynchronous [result]
                  * object.
                  */
                    response.abort();
                    
                     try {
                    /*
                     * POST back to the server in an attempt to cancel the
                     * request if already executing on the server.
                     */
                       cancel(queryId);
                     } catch (Exception ex) {log.warn(ex); }
                 
                     if (listener != null) {
                    listener.closed(queryId);
                 }
              }
      
             }
      
         }
      

        Activity

        beebs Brad Bebee created issue -
        Hide
        bryanthompson bryanthompson added a comment -

        Fixed in commit 072bbb604819bb99afc5e6056a952d04f4eea411 to github branch TICKET_1156d

        Show
        bryanthompson bryanthompson added a comment - Fixed in commit 072bbb604819bb99afc5e6056a952d04f4eea411 to github branch TICKET_1156d
        bryanthompson bryanthompson made changes -
        Field Original Value New Value
        Fix Version/s BLAZEGRAPH_RELEASE_1_5_2 [ 10164 ]
        beebs Brad Bebee made changes -
        Workflow Trac Import v2 [ 12043 ] Trac Import v3 [ 13653 ]
        beebs Brad Bebee made changes -
        Workflow Trac Import v3 [ 13653 ] Trac Import v4 [ 14982 ]
        beebs Brad Bebee made changes -
        Status Closed - Won't Fix [ 6 ] Open [ 1 ]
        beebs Brad Bebee made changes -
        Status Open [ 1 ] Accepted [ 10101 ]
        beebs Brad Bebee made changes -
        Status Accepted [ 10101 ] In Progress [ 3 ]
        Priority Highest [ 1 ]
        beebs Brad Bebee made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        beebs Brad Bebee made changes -
        Status Resolved [ 5 ] In Review [ 10100 ]
        beebs Brad Bebee made changes -
        Status In Review [ 10100 ] Done [ 10000 ]
        beebs Brad Bebee made changes -
        Workflow Trac Import v4 [ 14982 ] Trac Import v5 [ 16042 ]
        beebs Brad Bebee made changes -
        Workflow Trac Import v5 [ 16042 ] Trac Import v6 [ 17629 ]
        beebs Brad Bebee made changes -
        Workflow Trac Import v6 [ 17629 ] Trac Import v7 [ 19026 ]
        beebs Brad Bebee made changes -
        Workflow Trac Import v7 [ 19026 ] Trac Import v8 [ 20647 ]

          People

          • Assignee:
            bryanthompson bryanthompson
            Reporter:
            bryanthompson bryanthompson
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: