public AttemptId nextAttempt() { return new AttemptId(externalId, attempt + 1); } }
/** * Convert an external id to an attempt id, assuming this is its first attempt * @param externalId * @return */ public static AttemptId of(final ExternalId externalId) { return new AttemptId(externalId, 0); }
@Override public QueryContext get() { final UserSession session = systemSession(getOptionManager()); return new QueryContext(session, sabotContext.get(), new AttemptId().toQueryId()); } };
/** * Convert a query id to an attemp id * @param queryId * @return */ public static AttemptId of(final QueryId queryId) { ExternalId externalId = ExternalIdHelper.toExternal(queryId); int attempt = (int) (queryId.getPart2() & MASK); return new AttemptId(externalId, attempt); }
public static AttemptId fromString(final String attemptIdStr) { final UUID uuid = UUID.fromString(attemptIdStr); final long part1 = uuid.getMostSignificantBits(); final long part2 = uuid.getLeastSignificantBits(); final ExternalId externalId = ExternalId.newBuilder() .setPart1(part1) .setPart2(part2 & ExternalIdHelper.MASK) .build(); final int attempt = (int) part2 & 0xFF; return new AttemptId(externalId, attempt); } }
@Override public QueryProfile getProfile(JobId jobId, int attempt) throws JobNotFoundException { Job job = getJob(jobId); final AttemptId attemptId = new AttemptId(JobsServiceUtil.getJobIdAsExternalId(jobId), attempt); if(jobIsDone(job.getJobAttempt())){ return profileStore.get(attemptId); } // Check if the profile for given attempt already exists. Even if the job is not done, it is possible that // profile exists for previous attempts final QueryProfile queryProfile = profileStore.get(attemptId); if (queryProfile != null) { return queryProfile; } final NodeEndpoint endpoint = job.getJobAttempt().getEndpoint(); if(endpoint.equals(identity)){ final ForemenTool tool = this.foremenTool.get(); Optional<QueryProfile> profile = tool.getProfile(attemptId.getExternalId()); return profile.orNull(); } try{ CoordTunnel tunnel = coordTunnelCreator.get().getTunnel(JobsServiceUtil.toPB(endpoint)); return tunnel.requestQueryProfile(attemptId.getExternalId()).checkedGet(15, TimeUnit.SECONDS); }catch(TimeoutException | RpcException | RuntimeException e){ logger.info("Unable to retrieve remote query profile for external id: {}", ExternalIdHelper.toString(attemptId.getExternalId()), e); return null; } }
@Test public void testCTAS() { OptionManager options = Mockito.mock(OptionManager.class); ReAttemptHandler attemptHandler = new ExternalAttemptHandler(options); AttemptId id = new AttemptId(); final UserException userException = UserException.memoryError(null).build(NoOutputLogger.INSTANCE); assertEquals(AttemptReason.NONE, attemptHandler.isRecoverable(new ReAttemptContext(id, userException, false, true))); }
.setQueryId(new AttemptId().toQueryId()) .setMinorFragmentId(0) .setMajorFragmentId(0)
@Test public void testSingleCompletedAttempt() throws Exception { final String attemptId = AttemptIdUtils.toString(new AttemptId()); Job job = createJob("A1", Arrays.asList("space1", "ds1"), "v1", "A", "space1", JobState.COMPLETED, "select * from LocalFS1.\"dac-sample1.json\"", 100L, 110L, QueryType.UI_RUN); job.getJobAttempt().setDetails(new JobDetails()); job.getJobAttempt().setAttemptId(attemptId); JobDetailsUI detailsUI = new JobDetailsUI(job.getJobId(), job.getJobAttempt().getDetails(), JobResource.getPaginationURL(job.getJobId()), job.getAttempts(), JobResource.getDownloadURL(job), null, null, null, true, null, null); assertEquals("", detailsUI.getAttemptsSummary()); assertEquals(1, detailsUI.getAttemptDetails().size()); AttemptDetailsUI attemptDetailsUI = detailsUI.getAttemptDetails().get(0); assertEquals("", attemptDetailsUI.getReason()); assertEquals(JobState.COMPLETED, attemptDetailsUI.getResult()); assertEquals("/profiles/" + job.getJobId().getId() + "?attempt=0", attemptDetailsUI.getProfileUrl()); }
@Test public void testSingleFailedAttempt() throws Exception { final String attemptId = AttemptIdUtils.toString(new AttemptId()); Job job = createJob("A1", Arrays.asList("space1", "ds1"), "v1", "A", "space1", JobState.FAILED, "select * from LocalFS1.\"dac-sample1.json\"", 100L, 110L, QueryType.UI_RUN); job.getJobAttempt().setDetails(new JobDetails()); job.getJobAttempt().setAttemptId(attemptId); JobDetailsUI detailsUI = new JobDetailsUI(job.getJobId(), job.getJobAttempt().getDetails(), JobResource.getPaginationURL(job.getJobId()), job.getAttempts(), JobResource.getDownloadURL(job), new JobFailureInfo("Some error message", JobFailureType.UNKNOWN, null), null, null, false, null, null); assertEquals("", detailsUI.getAttemptsSummary()); assertEquals(1, detailsUI.getAttemptDetails().size()); AttemptDetailsUI attemptDetailsUI = detailsUI.getAttemptDetails().get(0); assertEquals("", attemptDetailsUI.getReason()); assertEquals(JobState.FAILED, attemptDetailsUI.getResult()); assertEquals("/profiles/" + job.getJobId().getId() + "?attempt=0", attemptDetailsUI.getProfileUrl()); }
.setQueryId(new AttemptId().toQueryId()) .setMinorFragmentId(0) .setMajorFragmentId(0)
.setQueryId(new AttemptId().toQueryId()) .setMinorFragmentId(0) .setMajorFragmentId(0)