use of org.apache.cassandra.exceptions.OverloadedException in project cassandra by apache.
the class ClientResourceLimitsTest method testChangingLimitsAtRuntime.
@Test
public void testChangingLimitsAtRuntime() {
SimpleClient client = client(true);
try {
QueryMessage smallMessage = new QueryMessage(String.format("CREATE TABLE %s.atable (pk int PRIMARY KEY, v text)", KEYSPACE), V5_DEFAULT_OPTIONS);
client.execute(smallMessage);
try {
client.execute(queryMessage());
fail();
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof OverloadedException);
}
// change global limit, query will still fail because endpoint limit
ClientResourceLimits.setGlobalLimit(HIGH_LIMIT);
Assert.assertEquals("new global limit not returned by EndpointPayloadTrackers", HIGH_LIMIT, ClientResourceLimits.getGlobalLimit());
Assert.assertEquals("new global limit not returned by DatabaseDescriptor", HIGH_LIMIT, DatabaseDescriptor.getNativeTransportMaxConcurrentRequestsInBytes());
try {
client.execute(queryMessage());
fail();
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof OverloadedException);
}
// change endpoint limit, query will now succeed
ClientResourceLimits.setEndpointLimit(HIGH_LIMIT);
Assert.assertEquals("new endpoint limit not returned by EndpointPayloadTrackers", HIGH_LIMIT, ClientResourceLimits.getEndpointLimit());
Assert.assertEquals("new endpoint limit not returned by DatabaseDescriptor", HIGH_LIMIT, DatabaseDescriptor.getNativeTransportMaxConcurrentRequestsInBytesPerIp());
client.execute(queryMessage());
// ensure new clients also see the new raised limits
client.close();
client = client(true);
client.execute(queryMessage());
// lower the global limit and ensure the query fails again
ClientResourceLimits.setGlobalLimit(LOW_LIMIT);
Assert.assertEquals("new global limit not returned by EndpointPayloadTrackers", LOW_LIMIT, ClientResourceLimits.getGlobalLimit());
Assert.assertEquals("new global limit not returned by DatabaseDescriptor", LOW_LIMIT, DatabaseDescriptor.getNativeTransportMaxConcurrentRequestsInBytes());
try {
client.execute(queryMessage());
fail();
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof OverloadedException);
}
// lower the endpoint limit and ensure existing clients also have requests that fail
ClientResourceLimits.setEndpointLimit(60);
Assert.assertEquals("new endpoint limit not returned by EndpointPayloadTrackers", 60, ClientResourceLimits.getEndpointLimit());
Assert.assertEquals("new endpoint limit not returned by DatabaseDescriptor", 60, DatabaseDescriptor.getNativeTransportMaxConcurrentRequestsInBytesPerIp());
try {
client.execute(smallMessage);
fail();
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof OverloadedException);
}
// ensure new clients also see the new lowered limit
client.close();
client = client(true);
try {
client.execute(smallMessage);
fail();
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof OverloadedException);
}
// put the test state back
ClientResourceLimits.setEndpointLimit(LOW_LIMIT);
Assert.assertEquals("new endpoint limit not returned by EndpointPayloadTrackers", LOW_LIMIT, ClientResourceLimits.getEndpointLimit());
Assert.assertEquals("new endpoint limit not returned by DatabaseDescriptor", LOW_LIMIT, DatabaseDescriptor.getNativeTransportMaxConcurrentRequestsInBytesPerIp());
} finally {
client.close();
}
}
use of org.apache.cassandra.exceptions.OverloadedException in project cassandra by apache.
the class RateLimitingTest method testBytesInFlightOverload.
private void testBytesInFlightOverload(int payloadSize) throws Exception {
try (SimpleClient client = client().connect(false, true)) {
StorageService.instance.setNativeTransportRateLimitingEnabled(false);
QueryMessage queryMessage = new QueryMessage("CREATE TABLE IF NOT EXISTS " + KEYSPACE + ".atable (pk int PRIMARY KEY, v text)", queryOptions());
client.execute(queryMessage);
StorageService.instance.setNativeTransportRateLimitingEnabled(true);
ClientResourceLimits.GLOBAL_REQUEST_LIMITER.setRate(OVERLOAD_PERMITS_PER_SECOND, ticker);
ClientResourceLimits.setGlobalLimit(1);
try {
// The first query takes the one available permit, but should fail on the bytes in flight limit.
client.execute(queryMessage(payloadSize));
} catch (RuntimeException e) {
assertTrue(Throwables.anyCauseMatches(e, cause -> cause instanceof OverloadedException));
}
} finally {
// Sanity check bytes in flight limiter.
assertEquals(0, ClientResourceLimits.getCurrentGlobalUsage());
StorageService.instance.setNativeTransportRateLimitingEnabled(false);
}
}
Aggregations