Skip to content

Commit 97d88cf

Browse files
misterjpapatdcmeehan
authored andcommitted
Make TaskUpdate size exceeded message succinct
Improve the exception message for EXCEEDED_TASK_UPDATE_SIZE_LIMIT by using the DataSize class to produce better human readable succinct values for byte values. A message like "TaskUpdate size of 860492511 Bytes has exceeded the limit of 524288000 Bytes" becomes "TaskUpdate size of 820.63MB has exceeded the limit of 500MB". Add unit tests in the TestHttpRemoteTask class to check for the correctly formatted exception message.
1 parent 0902cb3 commit 97d88cf

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

presto-main/src/main/java/com/facebook/presto/server/remotetask/HttpRemoteTask.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.google.common.util.concurrent.ListenableFuture;
7676
import com.google.common.util.concurrent.SettableFuture;
7777
import com.sun.management.ThreadMXBean;
78+
import io.airlift.units.DataSize;
7879
import io.airlift.units.Duration;
7980
import it.unimi.dsi.fastutil.longs.LongArrayList;
8081
import org.joda.time.DateTime;
@@ -226,6 +227,7 @@ public final class HttpRemoteTask
226227
private final HandleResolver handleResolver;
227228
private final int maxTaskUpdateSizeInBytes;
228229
private final int maxUnacknowledgedSplits;
230+
private final DataSize maxTaskUpdateDataSize;
229231

230232
private final TableWriteInfo tableWriteInfo;
231233

@@ -325,6 +327,7 @@ public HttpRemoteTask(
325327
this.handleResolver = handleResolver;
326328
this.tableWriteInfo = tableWriteInfo;
327329
this.maxTaskUpdateSizeInBytes = maxTaskUpdateSizeInBytes;
330+
this.maxTaskUpdateDataSize = DataSize.succinctBytes(this.maxTaskUpdateSizeInBytes);
328331
this.maxUnacknowledgedSplits = getMaxUnacknowledgedSplitsPerTask(session);
329332
checkArgument(maxUnacknowledgedSplits > 0, "maxUnacknowledgedSplits must be > 0, found: %s", maxUnacknowledgedSplits);
330333

@@ -882,7 +885,7 @@ private synchronized void sendUpdate()
882885
taskUpdateRequestSize.add(taskUpdateRequestJson.length);
883886

884887
if (taskUpdateRequestJson.length > maxTaskUpdateSizeInBytes) {
885-
failTask(new PrestoException(EXCEEDED_TASK_UPDATE_SIZE_LIMIT, format("TaskUpdate size of %d Bytes has exceeded the limit of %d Bytes", taskUpdateRequestJson.length, maxTaskUpdateSizeInBytes)));
888+
failTask(new PrestoException(EXCEEDED_TASK_UPDATE_SIZE_LIMIT, getExceededTaskUpdateSizeMessage(taskUpdateRequestJson)));
886889
}
887890

888891
if (fragment.isPresent()) {
@@ -928,6 +931,12 @@ private synchronized void sendUpdate()
928931
executor);
929932
}
930933

934+
private String getExceededTaskUpdateSizeMessage(byte[] taskUpdateRequestJson)
935+
{
936+
DataSize taskUpdateSize = DataSize.succinctBytes(taskUpdateRequestJson.length);
937+
return format("TaskUpdate size of %s has exceeded the limit of %s", taskUpdateSize.toString(), this.maxTaskUpdateDataSize.toString());
938+
}
939+
931940
private synchronized List<TaskSource> getSources()
932941
{
933942
return Stream.concat(tableScanPlanNodeIds.stream(), remoteSourcePlanNodeIds.stream())

presto-main/src/test/java/com/facebook/presto/server/remotetask/TestHttpRemoteTask.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.google.inject.Injector;
7373
import com.google.inject.Module;
7474
import com.google.inject.Provides;
75+
import io.airlift.units.DataSize;
7576
import io.airlift.units.Duration;
7677
import org.testng.annotations.DataProvider;
7778
import org.testng.annotations.Test;
@@ -90,6 +91,7 @@
9091
import javax.ws.rs.core.MediaType;
9192
import javax.ws.rs.core.UriInfo;
9293

94+
import java.lang.reflect.Method;
9395
import java.net.URI;
9496
import java.util.HashMap;
9597
import java.util.Map;
@@ -222,6 +224,66 @@ public void testHTTPRemoteTaskSize()
222224
assertTrue(httpRemoteTaskFactory.getTaskUpdateRequestSize() > 0);
223225
}
224226

227+
@Test(timeOut = 50000)
228+
public void testHTTPRemoteBadTaskSize()
229+
throws Exception
230+
{
231+
AtomicLong lastActivityNanos = new AtomicLong(System.nanoTime());
232+
TestingTaskResource testingTaskResource = new TestingTaskResource(lastActivityNanos, FailureScenario.NO_FAILURE);
233+
boolean useThriftEncoding = false;
234+
DataSize maxDataSize = DataSize.succinctBytes(1024);
235+
InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig()
236+
.setThriftTransportEnabled(useThriftEncoding)
237+
.setMaxTaskUpdateSize(maxDataSize);
238+
239+
HttpRemoteTaskFactory httpRemoteTaskFactory = createHttpRemoteTaskFactory(testingTaskResource, useThriftEncoding, internalCommunicationConfig);
240+
241+
RemoteTask remoteTask = createRemoteTask(httpRemoteTaskFactory);
242+
testingTaskResource.setInitialTaskInfo(remoteTask.getTaskInfo());
243+
remoteTask.start();
244+
waitUntilIdle(lastActivityNanos);
245+
httpRemoteTaskFactory.stop();
246+
247+
assertTrue(remoteTask.getTaskStatus().getState().isDone(), format("TaskStatus is not in a done state: %s", remoteTask.getTaskStatus()));
248+
assertEquals(getOnlyElement(remoteTask.getTaskStatus().getFailures()).getMessage(), "TaskUpdate size of 1.97kB has exceeded the limit of 1kB");
249+
}
250+
251+
@Test(dataProvider = "getUpdateSize")
252+
public void testGetExceededTaskUpdateSizeListMessage(int updateSizeInBytes, int maxDataSizeInBytes,
253+
String expectedMessage) throws Exception
254+
{
255+
AtomicLong lastActivityNanos = new AtomicLong(System.nanoTime());
256+
TestingTaskResource testingTaskResource = new TestingTaskResource(lastActivityNanos, FailureScenario.NO_FAILURE);
257+
boolean useThriftEncoding = false;
258+
DataSize maxDataSize = DataSize.succinctBytes(maxDataSizeInBytes);
259+
InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig()
260+
.setThriftTransportEnabled(useThriftEncoding)
261+
.setMaxTaskUpdateSize(maxDataSize);
262+
HttpRemoteTaskFactory httpRemoteTaskFactory = createHttpRemoteTaskFactory(testingTaskResource, useThriftEncoding, internalCommunicationConfig);
263+
RemoteTask remoteTask = createRemoteTask(httpRemoteTaskFactory);
264+
265+
Method targetMethod = HttpRemoteTask.class.getDeclaredMethod("getExceededTaskUpdateSizeMessage", new Class[]{byte[].class});
266+
targetMethod.setAccessible(true);
267+
byte[] taskUpdateRequestJson = new byte[updateSizeInBytes];
268+
String message = (String) targetMethod.invoke(remoteTask, new Object[]{taskUpdateRequestJson});
269+
assertEquals(message, expectedMessage);
270+
}
271+
272+
@DataProvider(name = "getUpdateSize")
273+
protected Object[][] getUpdateSize()
274+
{
275+
return new Object[][] {
276+
{2000, 1000, "TaskUpdate size of 1.95kB has exceeded the limit of 1000B"},
277+
{2000, 1024, "TaskUpdate size of 1.95kB has exceeded the limit of 1kB"},
278+
{5000, 4 * 1024, "TaskUpdate size of 4.88kB has exceeded the limit of 4kB"},
279+
{2 * 1024, 1024, "TaskUpdate size of 2kB has exceeded the limit of 1kB"},
280+
{1024 * 1024, 512 * 1024, "TaskUpdate size of 1MB has exceeded the limit of 512kB"},
281+
{16 * 1024 * 1024, 8 * 1024 * 1024, "TaskUpdate size of 16MB has exceeded the limit of 8MB"},
282+
{485 * 1000 * 1000, 1024 * 1024 * 512, "TaskUpdate size of 462.53MB has exceeded the limit of 512MB"},
283+
{1024 * 1024 * 1024, 1024 * 1024 * 512, "TaskUpdate size of 1GB has exceeded the limit of 512MB"},
284+
{860492511, 524288000, "TaskUpdate size of 820.63MB has exceeded the limit of 500MB"}};
285+
}
286+
225287
private void runTest(FailureScenario failureScenario, boolean useThriftEncoding)
226288
throws Exception
227289
{
@@ -272,6 +334,13 @@ private RemoteTask createRemoteTask(HttpRemoteTaskFactory httpRemoteTaskFactory)
272334

273335
private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource, boolean useThriftEncoding)
274336
throws Exception
337+
{
338+
InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig().setThriftTransportEnabled(useThriftEncoding);
339+
return createHttpRemoteTaskFactory(testingTaskResource, useThriftEncoding, internalCommunicationConfig);
340+
}
341+
342+
private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource, boolean useThriftEncoding, InternalCommunicationConfig internalCommunicationConfig)
343+
throws Exception
275344
{
276345
Bootstrap app = new Bootstrap(
277346
new JsonModule(),
@@ -347,7 +416,7 @@ private HttpRemoteTaskFactory createHttpRemoteTaskFactory(
347416
metadataUpdatesJsonCodec,
348417
metadataUpdatesSmileCodec,
349418
new RemoteTaskStats(),
350-
new InternalCommunicationConfig().setThriftTransportEnabled(useThriftEncoding),
419+
internalCommunicationConfig,
351420
createTestMetadataManager(),
352421
new TestQueryManager(),
353422
new HandleResolver(),

0 commit comments

Comments
 (0)