-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix worker OOM #9949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix worker OOM #9949
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
lib/trino-orc/src/test/java/io/trino/orc/TestSliceDictionaryColumnReader.java
This file contains hidden or 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,133 @@ | ||
| /* | ||
| * 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.orc; | ||
|
|
||
| import com.google.common.collect.ImmutableSet; | ||
| import io.airlift.slice.Slices; | ||
| import io.trino.memory.context.AggregatedMemoryContext; | ||
| import io.trino.orc.metadata.Footer; | ||
| import io.trino.orc.metadata.OrcMetadataReader; | ||
| import io.trino.orc.metadata.StripeInformation; | ||
| import io.trino.orc.reader.SliceDictionaryColumnReader; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Random; | ||
|
|
||
| import static com.google.common.io.Files.createTempDir; | ||
| import static io.trino.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext; | ||
| import static io.trino.orc.OrcTester.writeOrcColumnTrino; | ||
| import static io.trino.orc.metadata.CompressionKind.NONE; | ||
| import static io.trino.orc.metadata.PostScript.HiveWriterVersion.ORIGINAL; | ||
| import static io.trino.spi.type.VarcharType.VARCHAR; | ||
| import static java.nio.file.Files.readAllBytes; | ||
| import static java.time.ZoneOffset.UTC; | ||
| import static java.util.UUID.randomUUID; | ||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| public class TestSliceDictionaryColumnReader | ||
| { | ||
| public static final int ROWS = 100_000; | ||
| private static final int DICTIONARY = 22; | ||
| private static final int MAX_STRING = 19; | ||
|
|
||
| @Test | ||
| public void testDictionaryReaderUpdatesRetainedSize() | ||
| throws Exception | ||
| { | ||
| // create orc file | ||
| List<String> values = createValues(); | ||
| File temporaryDirectory = createTempDir(); | ||
| File orcFile = new File(temporaryDirectory, randomUUID().toString()); | ||
| writeOrcColumnTrino(orcFile, NONE, VARCHAR, values.iterator(), new OrcWriterStats()); | ||
|
|
||
| // prepare for read | ||
| OrcDataSource dataSource = new MemoryOrcDataSource(new OrcDataSourceId(orcFile.getPath()), Slices.wrappedBuffer(readAllBytes(orcFile.toPath()))); | ||
| OrcReader orcReader = OrcReader.createOrcReader(dataSource, new OrcReaderOptions()) | ||
| .orElseThrow(() -> new RuntimeException("File is empty")); | ||
| Footer footer = orcReader.getFooter(); | ||
| List<OrcColumn> columns = orcReader.getRootColumn().getNestedColumns(); | ||
| assertTrue(columns.size() == 1); | ||
| StripeReader stripeReader = new StripeReader( | ||
| dataSource, | ||
| UTC, | ||
| Optional.empty(), | ||
| footer.getTypes(), | ||
| ImmutableSet.copyOf(columns), | ||
| footer.getRowsInRowGroup(), | ||
| OrcPredicate.TRUE, | ||
| ORIGINAL, | ||
| new OrcMetadataReader(), | ||
| Optional.empty()); | ||
| AggregatedMemoryContext memoryContext = newSimpleAggregatedMemoryContext(); | ||
| SliceDictionaryColumnReader columnReader = new SliceDictionaryColumnReader(columns.get(0), memoryContext.newLocalMemoryContext(TestSliceDictionaryColumnReader.class.getSimpleName()), -1, false); | ||
|
|
||
| List<StripeInformation> stripeInformations = footer.getStripes(); | ||
| for (StripeInformation stripeInformation : stripeInformations) { | ||
| Stripe stripe = stripeReader.readStripe(stripeInformation, newSimpleAggregatedMemoryContext()); | ||
| List<RowGroup> rowGroups = stripe.getRowGroups(); | ||
| columnReader.startStripe(stripe.getFileTimeZone(), stripe.getDictionaryStreamSources(), stripe.getColumnEncodings()); | ||
|
|
||
| for (RowGroup rowGroup : rowGroups) { | ||
| columnReader.startRowGroup(rowGroup.getStreamSources()); | ||
| columnReader.prepareNextRead(1000); | ||
| columnReader.readBlock(); | ||
| // memory usage check | ||
| assertEquals(memoryContext.getBytes(), columnReader.getRetainedSizeInBytes()); | ||
| } | ||
| } | ||
|
|
||
| columnReader.close(); | ||
| assertTrue(memoryContext.getBytes() == 0); | ||
| } | ||
|
|
||
| private List<String> createValues() | ||
| { | ||
| Random random = new Random(); | ||
| List<String> dictionary = createDictionary(random); | ||
|
|
||
| List<String> values = new ArrayList<>(); | ||
| for (int i = 0; i < ROWS; ++i) { | ||
| if (random.nextBoolean()) { | ||
| values.add(dictionary.get(random.nextInt(dictionary.size()))); | ||
| } | ||
| else { | ||
| values.add(null); | ||
| } | ||
| } | ||
| return values; | ||
| } | ||
|
|
||
| private List<String> createDictionary(Random random) | ||
| { | ||
| List<String> dictionary = new ArrayList<>(); | ||
| for (int dictionaryIndex = 0; dictionaryIndex < DICTIONARY; dictionaryIndex++) { | ||
| dictionary.add(randomAsciiString(random)); | ||
| } | ||
| return dictionary; | ||
| } | ||
|
|
||
| private String randomAsciiString(Random random) | ||
| { | ||
| char[] value = new char[random.nextInt(MAX_STRING)]; | ||
| for (int i = 0; i < value.length; i++) { | ||
| value[i] = (char) random.nextInt(Byte.MAX_VALUE); | ||
| } | ||
| return new String(value); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.