Merge pull request #14827 from MaineC/bug-fix/10021-error-listeners

Adds exception objects to log messages.
This commit is contained in:
Isabel Drost-Fromm 2015-11-25 10:42:38 +01:00
commit 473b19400f
19 changed files with 78 additions and 35 deletions

View File

@ -51,9 +51,13 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
private static final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE; private static final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE;
private final Map<String, List<String>> headers = new HashMap<>(); private final Map<String, List<String>> headers = new HashMap<>();
/**
* Construct a <code>ElasticsearchException</code> with the specified cause exception.
*/
public ElasticsearchException(Throwable cause) { public ElasticsearchException(Throwable cause) {
super(cause); super(cause);
} }
/** /**
* Construct a <code>ElasticsearchException</code> with the specified detail message. * Construct a <code>ElasticsearchException</code> with the specified detail message.
* *

View File

@ -191,7 +191,7 @@ class JNANatives {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("unable to install syscall filter", t); logger.debug("unable to install syscall filter", t);
} }
logger.warn("unable to install syscall filter: " + t.getMessage()); logger.warn("unable to install syscall filter: ", t);
} }
} }
} }

View File

@ -231,7 +231,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
} }
} catch (Exception ex) { } catch (Exception ex) {
// Wrap the inner exception so we have the index name in the exception message // Wrap the inner exception so we have the index name in the exception message
throw new IllegalStateException("unable to upgrade the mappings for the index [" + indexMetaData.getIndex() + "], reason: [" + ex.getMessage() + "]", ex); throw new IllegalStateException("unable to upgrade the mappings for the index [" + indexMetaData.getIndex() + "]", ex);
} }
} }

View File

@ -643,7 +643,8 @@ public class Base64 {
try { try {
encoded = encodeBytes(source, 0, source.length, NO_OPTIONS); encoded = encodeBytes(source, 0, source.length, NO_OPTIONS);
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
assert false : ex.getMessage(); // not sure why this was an assertion before, running with assertions disabled would mean swallowing this exception
throw new IllegalStateException(ex);
} // end catch } // end catch
assert encoded != null; assert encoded != null;
return encoded; return encoded;
@ -705,7 +706,7 @@ public class Base64 {
try { try {
encoded = encodeBytes(source, off, len, NO_OPTIONS); encoded = encodeBytes(source, off, len, NO_OPTIONS);
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
assert false : ex.getMessage(); throw new IllegalStateException(ex);
} // end catch } // end catch
assert encoded != null; assert encoded != null;
return encoded; return encoded;
@ -766,7 +767,7 @@ public class Base64 {
try { try {
encoded = encodeBytesToBytes(source, 0, source.length, Base64.NO_OPTIONS); encoded = encodeBytesToBytes(source, 0, source.length, Base64.NO_OPTIONS);
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); throw new IllegalStateException("IOExceptions only come from GZipping, which is turned off: ", ex);
} }
return encoded; return encoded;
} }

View File

@ -331,6 +331,6 @@ public abstract class Multibinder<T> {
NullPointerException npe = new NullPointerException(name); NullPointerException npe = new NullPointerException(name);
throw new ConfigurationException(singleton( throw new ConfigurationException(singleton(
new Message(emptyList(), npe.toString(), npe))); new Message(emptyList(), npe)));
} }
} }

View File

@ -58,6 +58,10 @@ public final class Message implements Serializable, Element {
this(Collections.singletonList(source), message, null); this(Collections.singletonList(source), message, null);
} }
public Message(Object source, Throwable cause) {
this(Collections.singletonList(source), null, cause);
}
public Message(String message) { public Message(String message) {
this(Collections.emptyList(), message, null); this(Collections.emptyList(), message, null);
} }

View File

@ -525,7 +525,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
} }
}); });
} else if (node.equals(nodes().masterNode())) { } else if (node.equals(nodes().masterNode())) {
handleMasterGone(node, "shut_down"); handleMasterGone(node, null, "shut_down");
} }
} }
@ -615,7 +615,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
}); });
} }
private void handleMasterGone(final DiscoveryNode masterNode, final String reason) { private void handleMasterGone(final DiscoveryNode masterNode, final Throwable cause, final String reason) {
if (lifecycleState() != Lifecycle.State.STARTED) { if (lifecycleState() != Lifecycle.State.STARTED) {
// not started, ignore a master failure // not started, ignore a master failure
return; return;
@ -625,7 +625,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
return; return;
} }
logger.info("master_left [{}], reason [{}]", masterNode, reason); logger.info("master_left [{}], reason [{}]", cause, masterNode, reason);
clusterService.submitStateUpdateTask("zen-disco-master_failed (" + masterNode + ")", Priority.IMMEDIATE, new ClusterStateUpdateTask() { clusterService.submitStateUpdateTask("zen-disco-master_failed (" + masterNode + ")", Priority.IMMEDIATE, new ClusterStateUpdateTask() {
@ -1078,8 +1078,8 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
private class MasterNodeFailureListener implements MasterFaultDetection.Listener { private class MasterNodeFailureListener implements MasterFaultDetection.Listener {
@Override @Override
public void onMasterFailure(DiscoveryNode masterNode, String reason) { public void onMasterFailure(DiscoveryNode masterNode, Throwable cause, String reason) {
handleMasterGone(masterNode, reason); handleMasterGone(masterNode, cause, reason);
} }
} }

View File

@ -49,7 +49,7 @@ public class MasterFaultDetection extends FaultDetection {
public static interface Listener { public static interface Listener {
/** called when pinging the master failed, like a timeout, transport disconnects etc */ /** called when pinging the master failed, like a timeout, transport disconnects etc */
void onMasterFailure(DiscoveryNode masterNode, String reason); void onMasterFailure(DiscoveryNode masterNode, Throwable cause, String reason);
} }
@ -117,7 +117,7 @@ public class MasterFaultDetection extends FaultDetection {
transportService.connectToNode(masterNode); transportService.connectToNode(masterNode);
} catch (final Exception e) { } catch (final Exception e) {
// notify master failure (which stops also) and bail.. // notify master failure (which stops also) and bail..
notifyMasterFailure(masterNode, "failed to perform initial connect [" + e.getMessage() + "]"); notifyMasterFailure(masterNode, e, "failed to perform initial connect ");
return; return;
} }
if (masterPinger != null) { if (masterPinger != null) {
@ -176,22 +176,22 @@ public class MasterFaultDetection extends FaultDetection {
threadPool.schedule(TimeValue.timeValueMillis(0), ThreadPool.Names.SAME, masterPinger); threadPool.schedule(TimeValue.timeValueMillis(0), ThreadPool.Names.SAME, masterPinger);
} catch (Exception e) { } catch (Exception e) {
logger.trace("[master] [{}] transport disconnected (with verified connect)", masterNode); logger.trace("[master] [{}] transport disconnected (with verified connect)", masterNode);
notifyMasterFailure(masterNode, "transport disconnected (with verified connect)"); notifyMasterFailure(masterNode, null, "transport disconnected (with verified connect)");
} }
} else { } else {
logger.trace("[master] [{}] transport disconnected", node); logger.trace("[master] [{}] transport disconnected", node);
notifyMasterFailure(node, "transport disconnected"); notifyMasterFailure(node, null, "transport disconnected");
} }
} }
} }
private void notifyMasterFailure(final DiscoveryNode masterNode, final String reason) { private void notifyMasterFailure(final DiscoveryNode masterNode, final Throwable cause, final String reason) {
if (notifiedMasterFailure.compareAndSet(false, true)) { if (notifiedMasterFailure.compareAndSet(false, true)) {
threadPool.generic().execute(new Runnable() { threadPool.generic().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.onMasterFailure(masterNode, reason); listener.onMasterFailure(masterNode, cause, reason);
} }
} }
}); });
@ -255,15 +255,15 @@ public class MasterFaultDetection extends FaultDetection {
return; return;
} else if (exp.getCause() instanceof NotMasterException) { } else if (exp.getCause() instanceof NotMasterException) {
logger.debug("[master] pinging a master {} that is no longer a master", masterNode); logger.debug("[master] pinging a master {} that is no longer a master", masterNode);
notifyMasterFailure(masterToPing, "no longer master"); notifyMasterFailure(masterToPing, exp, "no longer master");
return; return;
} else if (exp.getCause() instanceof ThisIsNotTheMasterYouAreLookingForException) { } else if (exp.getCause() instanceof ThisIsNotTheMasterYouAreLookingForException) {
logger.debug("[master] pinging a master {} that is not the master", masterNode); logger.debug("[master] pinging a master {} that is not the master", masterNode);
notifyMasterFailure(masterToPing, "not master"); notifyMasterFailure(masterToPing, exp,"not master");
return; return;
} else if (exp.getCause() instanceof NodeDoesNotExistOnMasterException) { } else if (exp.getCause() instanceof NodeDoesNotExistOnMasterException) {
logger.debug("[master] pinging a master {} but we do not exists on it, act as if its master failure", masterNode); logger.debug("[master] pinging a master {} but we do not exists on it, act as if its master failure", masterNode);
notifyMasterFailure(masterToPing, "do not exists on master, act as master failure"); notifyMasterFailure(masterToPing, exp,"do not exists on master, act as master failure");
return; return;
} }
@ -272,7 +272,7 @@ public class MasterFaultDetection extends FaultDetection {
if (retryCount >= pingRetryCount) { if (retryCount >= pingRetryCount) {
logger.debug("[master] failed to ping [{}], tried [{}] times, each with maximum [{}] timeout", masterNode, pingRetryCount, pingRetryTimeout); logger.debug("[master] failed to ping [{}], tried [{}] times, each with maximum [{}] timeout", masterNode, pingRetryCount, pingRetryTimeout);
// not good, failure // not good, failure
notifyMasterFailure(masterToPing, "failed to ping, tried [" + pingRetryCount + "] times, each with maximum [" + pingRetryTimeout + "] timeout"); notifyMasterFailure(masterToPing, null, "failed to ping, tried [" + pingRetryCount + "] times, each with maximum [" + pingRetryTimeout + "] timeout");
} else { } else {
// resend the request, not reschedule, rely on send timeout // resend the request, not reschedule, rely on send timeout
transportService.sendRequest(masterToPing, MASTER_PING_ACTION_NAME, request, options, this); transportService.sendRequest(masterToPing, MASTER_PING_ACTION_NAME, request, options, this);

View File

@ -140,9 +140,9 @@ public class PublishClusterStateAction extends AbstractComponent {
throw t; throw t;
} catch (Throwable t) { } catch (Throwable t) {
// try to fail committing, in cause it's still on going // try to fail committing, in cause it's still on going
if (sendingController.markAsFailed("unexpected error [" + t.getMessage() + "]")) { if (sendingController.markAsFailed("unexpected error", t)) {
// signal the change should be rejected // signal the change should be rejected
throw new Discovery.FailedToCommitClusterStateException("unexpected error [{}]", t, t.getMessage()); throw new Discovery.FailedToCommitClusterStateException("unexpected error", t);
} else { } else {
throw t; throw t;
} }
@ -583,6 +583,21 @@ public class PublishClusterStateAction extends AbstractComponent {
return true; return true;
} }
/**
* tries marking the publishing as failed, if a decision wasn't made yet
*
* @return true if the publishing was failed and the cluster state is *not* committed
**/
synchronized private boolean markAsFailed(String details, Throwable reason) {
if (committedOrFailed()) {
return committed == false;
}
logger.trace("failed to commit version [{}]. {}", reason, clusterState.version(), details);
committed = false;
committedOrFailedLatch.countDown();
return true;
}
/** /**
* tries marking the publishing as failed, if a decision wasn't made yet * tries marking the publishing as failed, if a decision wasn't made yet
* *

View File

@ -235,7 +235,7 @@ public class Analysis {
try (BufferedReader reader = FileSystemUtils.newBufferedReader(wordListFile.toUri().toURL(), StandardCharsets.UTF_8)) { try (BufferedReader reader = FileSystemUtils.newBufferedReader(wordListFile.toUri().toURL(), StandardCharsets.UTF_8)) {
return loadWordList(reader, "#"); return loadWordList(reader, "#");
} catch (IOException ioe) { } catch (IOException ioe) {
String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage()); String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix);
throw new IllegalArgumentException(message, ioe); throw new IllegalArgumentException(message, ioe);
} }
} }
@ -282,7 +282,7 @@ public class Analysis {
try { try {
return FileSystemUtils.newBufferedReader(path.toUri().toURL(), StandardCharsets.UTF_8); return FileSystemUtils.newBufferedReader(path.toUri().toURL(), StandardCharsets.UTF_8);
} catch (IOException ioe) { } catch (IOException ioe) {
String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage()); String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix);
throw new IllegalArgumentException(message, ioe); throw new IllegalArgumentException(message, ioe);
} }
} }

View File

@ -67,7 +67,7 @@ public class TranslogRecoveryPerformer {
numOps++; numOps++;
} }
} catch (Throwable t) { } catch (Throwable t) {
throw new BatchOperationException(shardId, "failed to apply batch translog operation [" + t.getMessage() + "]", numOps, t); throw new BatchOperationException(shardId, "failed to apply batch translog operation", numOps, t);
} }
return numOps; return numOps;
} }

View File

@ -33,6 +33,11 @@ public class IndexShardSnapshotException extends ElasticsearchException {
this(shardId, msg, null); this(shardId, msg, null);
} }
public IndexShardSnapshotException(ShardId shardId, Throwable cause) {
super(cause);
setShard(shardId);
}
public IndexShardSnapshotException(ShardId shardId, String msg, Throwable cause) { public IndexShardSnapshotException(ShardId shardId, String msg, Throwable cause) {
super(msg, cause); super(msg, cause);
setShard(shardId); setShard(shardId);

View File

@ -32,6 +32,10 @@ public class IndexShardSnapshotFailedException extends IndexShardSnapshotExcepti
super(shardId, msg); super(shardId, msg);
} }
public IndexShardSnapshotFailedException(ShardId shardId, Throwable cause) {
super(shardId, cause);
}
public IndexShardSnapshotFailedException(ShardId shardId, String msg, Throwable cause) { public IndexShardSnapshotFailedException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause); super(shardId, msg, cause);
} }

View File

@ -191,7 +191,7 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements
if (e instanceof IndexShardSnapshotFailedException) { if (e instanceof IndexShardSnapshotFailedException) {
throw (IndexShardSnapshotFailedException) e; throw (IndexShardSnapshotFailedException) e;
} else { } else {
throw new IndexShardSnapshotFailedException(shardId, e.getMessage(), e); throw new IndexShardSnapshotFailedException(shardId, e);
} }
} }
} }
@ -373,7 +373,7 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements
} catch (IOException e) { } catch (IOException e) {
// We cannot delete index file - this is fatal, we cannot continue, otherwise we might end up // We cannot delete index file - this is fatal, we cannot continue, otherwise we might end up
// with references to non-existing files // with references to non-existing files
throw new IndexShardSnapshotFailedException(shardId, "error deleting index files during cleanup, reason: " + e.getMessage(), e); throw new IndexShardSnapshotFailedException(shardId, "error deleting index files during cleanup", e);
} }
blobsToDelete = new ArrayList<>(); blobsToDelete = new ArrayList<>();

View File

@ -22,6 +22,7 @@ package org.elasticsearch.indices.recovery;
import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.IndexOutput;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
@ -175,7 +176,7 @@ public class RecoveryStatus extends AbstractRefCounted {
listener.onRecoveryFailure(state(), e, sendShardFailure); listener.onRecoveryFailure(state(), e, sendShardFailure);
} finally { } finally {
try { try {
cancellableThreads.cancel("failed recovery [" + e.getMessage() + "]"); cancellableThreads.cancel("failed recovery [" + ExceptionsHelper.stackTrace(e) + "]");
} finally { } finally {
// release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now // release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now
decRef(); decRef();

View File

@ -130,8 +130,17 @@ public class RecoveryTarget extends AbstractComponent implements IndexEventListe
} }
protected void retryRecovery(final RecoveryStatus recoveryStatus, final Throwable reason, TimeValue retryAfter, final StartRecoveryRequest currentRequest) {
logger.trace("will retry recovery with id [{}] in [{}]", reason, recoveryStatus.recoveryId(), retryAfter);
retryRecovery(recoveryStatus, retryAfter, currentRequest);
}
protected void retryRecovery(final RecoveryStatus recoveryStatus, final String reason, TimeValue retryAfter, final StartRecoveryRequest currentRequest) { protected void retryRecovery(final RecoveryStatus recoveryStatus, final String reason, TimeValue retryAfter, final StartRecoveryRequest currentRequest) {
logger.trace("will retrying recovery with id [{}] in [{}] (reason [{}])", recoveryStatus.recoveryId(), retryAfter, reason); logger.trace("will retry recovery with id [{}] in [{}] (reason [{}])", recoveryStatus.recoveryId(), retryAfter, reason);
retryRecovery(recoveryStatus, retryAfter, currentRequest);
}
private void retryRecovery(final RecoveryStatus recoveryStatus, TimeValue retryAfter, final StartRecoveryRequest currentRequest) {
try { try {
recoveryStatus.resetRecovery(); recoveryStatus.resetRecovery();
} catch (Throwable e) { } catch (Throwable e) {
@ -224,7 +233,7 @@ public class RecoveryTarget extends AbstractComponent implements IndexEventListe
} }
if (cause instanceof DelayRecoveryException) { if (cause instanceof DelayRecoveryException) {
retryRecovery(recoveryStatus, cause.getMessage(), recoverySettings.retryDelayStateSync(), request); retryRecovery(recoveryStatus, cause, recoverySettings.retryDelayStateSync(), request);
return; return;
} }

View File

@ -69,7 +69,7 @@ public class SharedFSRecoverySourceHandler extends RecoverySourceHandler {
// create a new IndexWriter // create a new IndexWriter
logger.info("recovery failed for primary shadow shard, failing shard"); logger.info("recovery failed for primary shadow shard, failing shard");
// pass the failure as null, as we want to ensure the store is not marked as corrupted // pass the failure as null, as we want to ensure the store is not marked as corrupted
shard.failShard("primary relocation failed on shared filesystem caused by: [" + t.getMessage() + "]", null); shard.failShard("primary relocation failed on shared filesystem", t);
} else { } else {
logger.info("recovery failed on shared filesystem", t); logger.info("recovery failed on shared filesystem", t);
} }

View File

@ -484,7 +484,7 @@ public class TransportService extends AbstractLifecycleComponent<TransportServic
} }
protected void traceResponseSent(long requestId, String action, Throwable t) { protected void traceResponseSent(long requestId, String action, Throwable t) {
tracerLog.trace("[{}][{}] sent error response (error: [{}])", requestId, action, t.getMessage()); tracerLog.trace("[{}][{}] sent error response", t, requestId, action);
} }
@Override @Override

View File

@ -193,7 +193,7 @@ public class ZenFaultDetectionTests extends ESTestCase {
masterFD.addListener(new MasterFaultDetection.Listener() { masterFD.addListener(new MasterFaultDetection.Listener() {
@Override @Override
public void onMasterFailure(DiscoveryNode masterNode, String reason) { public void onMasterFailure(DiscoveryNode masterNode, Throwable cause, String reason) {
failureNode[0] = masterNode; failureNode[0] = masterNode;
failureReason[0] = reason; failureReason[0] = reason;
notified.countDown(); notified.countDown();
@ -211,4 +211,4 @@ public class ZenFaultDetectionTests extends ESTestCase {
assertThat(failureReason[0], matcher); assertThat(failureReason[0], matcher);
} }
} }