Make Stress exit with non-zero status after failure

patch by Stefania Alborghetti; reviewed by Benjamin Lerer for CASSANDRA-10340
This commit is contained in:
Stefania Alborghetti 2016-03-17 15:35:08 +01:00 committed by Benjamin Lerer
parent 2ab6299370
commit 7043744085
4 changed files with 52 additions and 37 deletions

View File

@ -1,4 +1,5 @@
3.6
* Stress should exit with non-zero status after failure (CASSANDRA-10340)
* Add client to cqlsh SHOW_SESSION (CASSANDRA-8958)
* Fix nodetool tablestats keyspace level metrics (CASSANDRA-11226)
* Store repair options in parent_repair_history (CASSANDRA-11244)

View File

@ -58,19 +58,31 @@ public final class Stress
if (FBUtilities.isWindows())
WindowsTimer.startTimerPeriod(1);
int exitCode = run(arguments);
if (FBUtilities.isWindows())
WindowsTimer.endTimerPeriod(1);
System.exit(exitCode);
}
private static int run(String[] arguments)
{
try
{
final StressSettings settings;
try
{
settings = StressSettings.parse(arguments);
if (settings == null)
return 0; // special settings action
}
catch (IllegalArgumentException e)
{
System.out.printf("%s\n", e.getMessage());
printHelpMessage();
e.printStackTrace();
return;
return 1;
}
MultiPrintStream logout = settings.log.getOutput();
@ -128,14 +140,10 @@ public final class Stress
catch (Throwable t)
{
t.printStackTrace();
}
finally
{
if (FBUtilities.isWindows())
WindowsTimer.endTimerPeriod(1);
System.exit(0);
return 1;
}
return 0;
}
/**

View File

@ -79,6 +79,9 @@ public class StressAction implements Runnable
output.println("FAILURE");
settings.disconnect();
if (!success)
throw new RuntimeException("Failed to execute stress action");
}
// type provided separately to support recursive call for mixed command with each command type it is performing
@ -101,8 +104,11 @@ public class StressAction implements Runnable
// we need to warm up all the nodes in the cluster ideally, but we may not be the only stress instance;
// so warm up all the nodes we're speaking to only.
output.println(String.format("Warming up %s with %d iterations...", single.desc(), iterations));
run(single, threads, iterations, 0, null, null, warmupOutput, true);
boolean success = null != run(single, threads, iterations, 0, null, null, warmupOutput, true);
if (!success)
throw new RuntimeException("Failed to execute warmup");
}
}
// TODO : permit varying more than just thread count
@ -332,13 +338,10 @@ public class StressAction implements Runnable
catch (Exception e)
{
if (output == null)
{
System.err.println(e.getMessage());
success = false;
System.exit(-1);
}
else
e.printStackTrace(output);
e.printStackTrace(output);
success = false;
workManager.stop();
metrics.cancel();
@ -346,6 +349,11 @@ public class StressAction implements Runnable
}
}
}
catch (Exception e)
{
System.err.println(e.getMessage());
success = false;
}
finally
{
done.countDown();

View File

@ -184,6 +184,8 @@ public class StressSettings implements Serializable
}
private static volatile JavaDriverClient client;
private static volatile int numFailures;
private static int MAX_NUM_FAILURES = 10;
public JavaDriverClient getJavaDriverClient()
{
@ -195,9 +197,12 @@ public class StressSettings implements Serializable
if (client != null)
return client;
try
synchronized (this)
{
synchronized (this)
if (numFailures >= MAX_NUM_FAILURES)
throw new RuntimeException("Failed to create client too many times");
try
{
String currentNode = node.randomNode();
if (client != null)
@ -211,10 +216,11 @@ public class StressSettings implements Serializable
return client = c;
}
}
catch (Exception e)
{
throw new RuntimeException(e);
catch (Exception e)
{
numFailures +=1;
throw new RuntimeException(e);
}
}
}
@ -228,22 +234,14 @@ public class StressSettings implements Serializable
public static StressSettings parse(String[] args)
{
try
{
args = repairParams(args);
final Map<String, String[]> clArgs = parseMap(args);
if (clArgs.containsKey("legacy"))
return Legacy.build(Arrays.copyOfRange(args, 1, args.length));
if (SettingsMisc.maybeDoSpecial(clArgs))
System.exit(1);
return get(clArgs);
}
catch (IllegalArgumentException e)
{
System.out.println(e.getMessage());
System.exit(1);
throw new AssertionError();
}
args = repairParams(args);
final Map<String, String[]> clArgs = parseMap(args);
if (clArgs.containsKey("legacy"))
return Legacy.build(Arrays.copyOfRange(args, 1, args.length));
if (SettingsMisc.maybeDoSpecial(clArgs))
return null;
return get(clArgs);
}
private static String[] repairParams(String[] args)