Java Code Examples for org.apache.solr.common.SolrException#getMetadata()

The following examples show how to use org.apache.solr.common.SolrException#getMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseCloudSolrClient.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public RouteException(ErrorCode errorCode, NamedList<Throwable> throwables, Map<String, ? extends LBSolrClient.Req> routes){
  super(errorCode, throwables.getVal(0).getMessage(), throwables.getVal(0));
  this.throwables = throwables;
  this.routes = routes;

  // create a merged copy of the metadata from all wrapped exceptions
  NamedList<String> metadata = new NamedList<String>();
  for (int i = 0; i < throwables.size(); i++) {
    Throwable t = throwables.getVal(i);
    if (t instanceof SolrException) {
      SolrException e = (SolrException) t;
      NamedList<String> eMeta = e.getMetadata();
      if (null != eMeta) {
        metadata.addAll(eMeta);
      }
    }
  }
  if (0 < metadata.size()) {
    this.setMetadata(metadata);
  }
}
 
Example 2
Source File: ResponseUtils.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Adds the given Throwable's message to the given NamedList.
 * <p>
 * If the response code is not a regular code, the Throwable's
 * stack trace is both logged and added to the given NamedList.
 * <p>
 * Status codes less than 100 are adjusted to be 500.
 */
@SuppressWarnings({"unchecked"})
public static int getErrorInfo(Throwable ex, @SuppressWarnings({"rawtypes"})NamedList info, Logger log) {
  int code = 500;
  if (ex instanceof SolrException) {
    SolrException solrExc = (SolrException)ex;
    code = solrExc.code();
    NamedList<String> errorMetadata = solrExc.getMetadata();
    if (errorMetadata == null) {
      errorMetadata = new NamedList<>();
    }
    errorMetadata.add(SolrException.ERROR_CLASS, ex.getClass().getName());
    errorMetadata.add(SolrException.ROOT_ERROR_CLASS, SolrException.getRootCause(ex).getClass().getName());
    info.add("metadata", errorMetadata);
    if (ex instanceof ApiBag.ExceptionWithErrObject) {
      ApiBag.ExceptionWithErrObject exception = (ApiBag.ExceptionWithErrObject) ex;
      info.add("details", exception.getErrs() );
    }
  }
  
  for (Throwable th = ex; th != null; th = th.getCause()) {
    String msg = th.getMessage();
    if (msg != null) {
      info.add("msg", msg);
      break;
    }
  }
  
  // For any regular code, don't include the stack trace
  if (code == 500 || code < 100) {
    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    SolrException.log(log, null, ex);
    info.add("trace", sw.toString());

    // non standard codes have undefined results with various servers
    if (code < 100) {
      log.warn("invalid return code: {}", code);
      code = 500;
    }
  }
  
  info.add("code", code);
  return code;
}
 
Example 3
Source File: TolerantUpdateProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void finish() throws IOException {

  // even if processAdd threw an error, this.finish() is still called and we might have additional
  // errors from other remote leaders that we need to check for from the finish method of downstream processors
  // (like DUP)

  try {
    super.finish();
  } catch (DistributedUpdateProcessor.DistributedUpdatesAsyncException duae) {
    firstErrTracker.caught(duae);


    // adjust our stats based on each of the distributed errors
    for (Error error : duae.errors) {
      // we can't trust the req info from the Error, because multiple original requests might have been
      // lumped together
      //
      // instead we trust the metadata that the TolerantUpdateProcessor running on the remote node added
      // to the exception when it failed.
      if ( ! (error.e instanceof SolrException) ) {
        log.error("async update exception is not SolrException, no metadata to process", error.e);
        continue;
      }
      SolrException remoteErr = (SolrException) error.e;
      NamedList<String> remoteErrMetadata = remoteErr.getMetadata();

      if (null == remoteErrMetadata) {
        log.warn("remote error has no metadata to aggregate: {} {}", remoteErr.getMessage(), remoteErr);
        continue;
      }

      for (int i = 0; i < remoteErrMetadata.size(); i++) {
        ToleratedUpdateError err =
          ToleratedUpdateError.parseMetadataIfToleratedUpdateError(remoteErrMetadata.getName(i),
                                                                   remoteErrMetadata.getVal(i));
        if (null == err) {
          // some metadata unrelated to this update processor
          continue;
        }

        if (CmdType.DELQ.equals(err.getType())) {
          if (knownDBQErrors.contains(err)) {
            // we've already seen this identical error, probably a dup from another shard
            continue;
          } else {
            knownDBQErrors.add(err);
          }
        }

        knownErrors.add(err);
      }
    }
  }

  header.add("errors", ToleratedUpdateError.formatForResponseHeader(knownErrors));
  // include in response so client knows what effective value was (may have been server side config)
  header.add("maxErrors", ToleratedUpdateError.getUserFriendlyMaxErrors(maxErrors));

  // annotate any error that might be thrown (or was already thrown)
  firstErrTracker.annotate(knownErrors);

  // decide if we have hit a situation where we know an error needs to be thrown.

  if ((DistribPhase.TOLEADER.equals(distribPhase) ? 0 : maxErrors) < knownErrors.size()) {
    // NOTE: even if maxErrors wasn't exceeded, we need to throw an error when we have any errors if we're
    // a leader that was forwarded to by another node so that the forwarding node knows we encountered some
    // problems and can aggregate the results

    firstErrTracker.throwFirst();
  }
}