-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fault Tolerant Execution for PostgreSQL and MySQL connectors
- Loading branch information
Showing
33 changed files
with
965 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/trino-main/src/main/java/io/trino/split/PageSinkId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.split; | ||
|
||
import io.trino.execution.TaskId; | ||
import io.trino.spi.connector.ConnectorPageSinkId; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
public class PageSinkId | ||
implements ConnectorPageSinkId | ||
{ | ||
private final long id; | ||
|
||
public static PageSinkId fromTaskId(TaskId taskId) | ||
{ | ||
long stageId = taskId.getStageId().getId(); | ||
long partitionId = taskId.getPartitionId(); | ||
checkArgument(partitionId == (partitionId & 0x00FFFFFF), "partitionId is out of allowable range"); | ||
long attemptId = taskId.getAttemptId(); | ||
checkArgument(attemptId == (attemptId & 0xFF), "attemptId is out of allowable range"); | ||
long id = (stageId << 32) + (partitionId << 8) + attemptId; | ||
return new PageSinkId(id); | ||
} | ||
|
||
private PageSinkId(long id) | ||
{ | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public long getId() | ||
{ | ||
return this.id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/trino-main/src/test/java/io/trino/split/TestPageSinkId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.split; | ||
|
||
import io.trino.execution.StageId; | ||
import io.trino.execution.TaskId; | ||
import io.trino.spi.QueryId; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
public class TestPageSinkId | ||
{ | ||
private PageSinkId fromTaskId(int stageId, int partitionId, int attemptId) | ||
{ | ||
return PageSinkId.fromTaskId(new TaskId(new StageId(new QueryId("query"), stageId), partitionId, attemptId)); | ||
} | ||
|
||
@Test | ||
public void testFromTaskId() | ||
{ | ||
PageSinkId pageSinkId = fromTaskId(1, 2, 3); | ||
long expected = (1L << 32) + (2L << 8) + 3L; | ||
assertEquals(pageSinkId.getId(), expected); | ||
} | ||
|
||
@Test | ||
public void testFromTaskIdChecks() | ||
{ | ||
assertThatThrownBy(() -> { | ||
fromTaskId(1, 1 << 24, 3); | ||
}).hasMessageContaining("partitionId is out of allowable range"); | ||
|
||
assertThatThrownBy(() -> { | ||
fromTaskId(1, -1, 3); | ||
}).hasMessageContaining("partitionId is negative"); | ||
|
||
assertThatThrownBy(() -> { | ||
fromTaskId(1, 2, 256); | ||
}).hasMessageContaining("attemptId is out of allowable range"); | ||
|
||
assertThatThrownBy(() -> { | ||
fromTaskId(1, 2, -1); | ||
}).hasMessageContaining("attemptId is negative"); | ||
} | ||
} |
Oops, something went wrong.