Search in sources :

Example 1 with PagesSerde

use of io.hetu.core.transport.execution.buffer.PagesSerde in project hetu-core by openlookeng.

the class StreamingAggregationOperator method capture.

@Override
public Object capture(BlockEncodingSerdeProvider serdeProvider) {
    StreamingAggregationOperatorState myState = new StreamingAggregationOperatorState();
    myState.operatorContext = operatorContext.capture(serdeProvider);
    myState.systemMemoryContext = systemMemoryContext.getBytes();
    myState.userMemoryContext = userMemoryContext.getBytes();
    myState.aggregates = new Object[aggregates.size()];
    for (int i = 0; i < aggregates.size(); i++) {
        myState.aggregates[i] = aggregates.get(i).capture(serdeProvider);
    }
    myState.pageBuilder = pageBuilder.capture(serdeProvider);
    if (currentGroup != null) {
        SerializedPage serializedPage = ((PagesSerde) serdeProvider).serialize(currentGroup);
        myState.currentGroup = serializedPage.capture(serdeProvider);
    }
    myState.finishing = finishing;
    return myState;
}
Also used : PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage)

Example 2 with PagesSerde

use of io.hetu.core.transport.execution.buffer.PagesSerde in project hetu-core by openlookeng.

the class TestPagesIndex method testEstimatedSizeSnapshot.

@Test
public void testEstimatedSizeSnapshot() {
    List<Type> types = ImmutableList.of(BIGINT, VARCHAR);
    PagesSerde serde = TestingPagesSerdeFactory.testingPagesSerde();
    Page input = somePage(types);
    PagesIndex pagesIndex = newPagesIndex(types, 30, false);
    long initialEstimatedSize = pagesIndex.getEstimatedSize().toBytes();
    assertTrue(initialEstimatedSize > 0, format("Initial estimated size must be positive, got %s", initialEstimatedSize));
    pagesIndex.addPage(input);
    long estimatedSizeWithOnePage = pagesIndex.getEstimatedSize().toBytes();
    assertTrue(estimatedSizeWithOnePage > initialEstimatedSize, "Estimated size should grow after adding a page");
    Object snapshot = pagesIndex.capture(serde);
    assertEquals(SnapshotTestUtil.toSimpleSnapshotMapping(snapshot), createExpectedMapping());
    pagesIndex.addPage(input);
    long estimatedSizeWithTwoPages = pagesIndex.getEstimatedSize().toBytes();
    assertEquals(estimatedSizeWithTwoPages, initialEstimatedSize + (estimatedSizeWithOnePage - initialEstimatedSize) * 2, "Estimated size should grow linearly as long as we don't pass expectedPositions");
    pagesIndex.compact();
    long estimatedSizeAfterCompact = pagesIndex.getEstimatedSize().toBytes();
    // We can expect compact to reduce size because VARCHAR sequence pages are compactable.
    assertTrue(estimatedSizeAfterCompact < estimatedSizeWithTwoPages, format("Compact should reduce (or retain) size, but changed from %s to %s", estimatedSizeWithTwoPages, estimatedSizeAfterCompact));
}
Also used : Type(io.prestosql.spi.type.Type) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) Page(io.prestosql.spi.Page) SequencePageBuilder.createSequencePage(io.prestosql.SequencePageBuilder.createSequencePage) Test(org.testng.annotations.Test)

Example 3 with PagesSerde

use of io.hetu.core.transport.execution.buffer.PagesSerde in project hetu-core by openlookeng.

the class TestBinaryFileSpiller method testSpillerUnCommit.

private void testSpillerUnCommit(List<Type> types, List<Page>... spills) throws ExecutionException, InterruptedException, IOException {
    long spilledBytesBefore = spillerStats.getTotalSpilledBytes();
    long spilledBytes = 0;
    assertEquals(memoryContext.getBytes(), 0);
    List<Runnable> runners = new ArrayList<>();
    PagesSerde serde = TestingPagesSerdeFactory.testingPagesSerde();
    Spiller spiller = factory.create(TYPES, bytes -> {
    }, memoryContext);
    spilledBytes = doSpill(spiller, spilledBytes, runners, spills, 0);
    spillUploadPath.mkdirs();
    int counter = 1;
    int runCount = runners.size();
    List<Path> uploadedFile = new ArrayList<>();
    for (counter = 1; counter <= runCount; counter++) {
        runners.remove(0).run();
        assertEquals(spiller.getSpilledFilePaths().size(), counter);
        assertEquals(runners.size(), runCount - counter);
        Object snapshot = spiller.capture(serde);
        spiller.getSpilledFilePaths().stream().forEach(path -> {
            try {
                Files.copy(path, Paths.get(spillUploadPath.getPath(), path.getFileName().toString()), REPLACE_EXISTING);
                uploadedFile.add(Paths.get(spillUploadPath.getPath(), path.getFileName().toString()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        spiller.close();
        spiller = factory.create(TYPES, bytes -> {
        }, memoryContext);
        spiller.restore(snapshot, serde);
        uploadedFile.stream().forEach(path -> {
            try {
                Files.move(path, Paths.get(spillPath.getPath(), path.getFileName().toString()), REPLACE_EXISTING);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        uploadedFile.clear();
        doSpill(spiller, spilledBytes, runners, spills, counter);
    }
    // assertEquals(spillerStats.getTotalSpilledBytes() - spilledBytesBefore, spilledBytes);
    // At this point, the buffers should still be accounted for in the memory context, because
    // the spiller (FileSingleStreamSpiller) doesn't release its memory reservation until it's closed.
    // assertEquals(memoryContext.getBytes(), spills.length * FileSingleStreamSpiller.BUFFER_SIZE);
    List<Iterator<Page>> actualSpills = spiller.getSpills();
    assertEquals(actualSpills.size(), spills.length);
    for (int i = 0; i < actualSpills.size(); i++) {
        List<Page> actualSpill = ImmutableList.copyOf(actualSpills.get(i));
        List<Page> expectedSpill = spills[i];
        assertEquals(actualSpill.size(), expectedSpill.size());
        for (int j = 0; j < actualSpill.size(); j++) {
            assertPageEquals(types, actualSpill.get(j), expectedSpill.get(j));
        }
    }
    spiller.close();
    assertEquals(memoryContext.getBytes(), 0);
}
Also used : Path(java.nio.file.Path) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MoreFiles.deleteRecursively(com.google.common.io.MoreFiles.deleteRecursively) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) AfterMethod(org.testng.annotations.AfterMethod) HetuLocalFileSystemClient(io.hetu.core.filesystem.HetuLocalFileSystemClient) TestingPagesSerdeFactory(io.prestosql.testing.TestingPagesSerdeFactory) ArrayList(java.util.ArrayList) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.commons.lang3.tuple.Pair) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) AggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) Path(java.nio.file.Path) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) PagesSerdeFactory(io.hetu.core.transport.execution.buffer.PagesSerdeFactory) Properties(java.util.Properties) Iterator(java.util.Iterator) Files(java.nio.file.Files) BlockBuilder(io.prestosql.spi.block.BlockBuilder) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) BeforeMethod(org.testng.annotations.BeforeMethod) Page(io.prestosql.spi.Page) IOException(java.io.IOException) LocalConfig(io.hetu.core.filesystem.LocalConfig) Mockito.when(org.mockito.Mockito.when) Metadata(io.prestosql.metadata.Metadata) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Matchers.any(org.mockito.Matchers.any) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) List(java.util.List) Paths(java.nio.file.Paths) RowPagesBuilder(io.prestosql.RowPagesBuilder) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) Double.doubleToLongBits(java.lang.Double.doubleToLongBits) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) PageAssertions.assertPageEquals(io.prestosql.operator.PageAssertions.assertPageEquals) Mockito.mock(org.mockito.Mockito.mock) ArrayList(java.util.ArrayList) Page(io.prestosql.spi.Page) IOException(java.io.IOException) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) Iterator(java.util.Iterator)

Example 4 with PagesSerde

use of io.hetu.core.transport.execution.buffer.PagesSerde in project hetu-core by openlookeng.

the class TestSpillCipherPagesSerde method test.

@Test
public void test() {
    SpillCipher cipher = new AesSpillCipher();
    PagesSerde serde = TESTING_SERDE_FACTORY.createPagesSerdeForSpill(Optional.of(cipher), false, false);
    List<Type> types = ImmutableList.of(VARCHAR);
    Page emptyPage = new Page(VARCHAR.createBlockBuilder(null, 0).build());
    assertPageEquals(types, serde.deserialize(serde.serialize(emptyPage)), emptyPage);
    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, 2);
    VARCHAR.writeString(blockBuilder, "hello");
    VARCHAR.writeString(blockBuilder, "world");
    Page helloWorldPage = new Page(blockBuilder.build());
    SerializedPage serialized = serde.serialize(helloWorldPage);
    assertPageEquals(types, serde.deserialize(serialized), helloWorldPage);
    assertTrue(serialized.isEncrypted(), "page should be encrypted");
    cipher.close();
    assertFailure(() -> serde.serialize(helloWorldPage), "Spill cipher already closed");
    assertFailure(() -> serde.deserialize(serialized), "Spill cipher already closed");
}
Also used : Type(io.prestosql.spi.type.Type) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) Page(io.prestosql.spi.Page) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) SpillCipher(io.prestosql.spi.spiller.SpillCipher) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 5 with PagesSerde

use of io.hetu.core.transport.execution.buffer.PagesSerde in project hetu-core by openlookeng.

the class TestMarkerPage method testStaticSerde.

@Test
public void testStaticSerde() {
    PagesSerde serde = TESTING_SERDE_FACTORY.createPagesSerde();
    MarkerPage marker1 = MarkerPage.snapshotPage(1);
    SerializedPage serializedPage = serde.serialize(marker1);
    Page deserializedPage = serde.deserialize(serializedPage);
    Assert.assertTrue(deserializedPage instanceof MarkerPage);
    marker1 = (MarkerPage) deserializedPage;
    Assert.assertEquals(marker1.getSnapshotId(), 1);
    Assert.assertFalse(marker1.isResuming());
    MarkerPage resume1 = MarkerPage.resumePage(1);
    serializedPage = serde.serialize(resume1);
    deserializedPage = serde.deserialize(serializedPage);
    Assert.assertTrue(deserializedPage instanceof MarkerPage);
    resume1 = (MarkerPage) deserializedPage;
    Assert.assertEquals(resume1.getSnapshotId(), 1);
    Assert.assertTrue(resume1.isResuming());
    Page regular = new Page(1);
    serializedPage = serde.serialize(regular);
    deserializedPage = serde.deserialize(serializedPage);
    Assert.assertFalse(deserializedPage instanceof MarkerPage);
}
Also used : MarkerPage(io.prestosql.spi.snapshot.MarkerPage) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) Page(io.prestosql.spi.Page) Test(org.testng.annotations.Test)

Aggregations

PagesSerde (io.hetu.core.transport.execution.buffer.PagesSerde)18 Page (io.prestosql.spi.Page)12 Test (org.testng.annotations.Test)10 SerializedPage (io.hetu.core.transport.execution.buffer.SerializedPage)8 Type (io.prestosql.spi.type.Type)6 BlockBuilder (io.prestosql.spi.block.BlockBuilder)5 TestingPagesSerdeFactory (io.prestosql.testing.TestingPagesSerdeFactory)3 ImmutableList (com.google.common.collect.ImmutableList)2 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)2 Block (io.prestosql.spi.block.Block)2 MarkerPage (io.prestosql.spi.snapshot.MarkerPage)2 SpillCipher (io.prestosql.spi.spiller.SpillCipher)2 ArrayList (java.util.ArrayList)2 MoreFiles.deleteRecursively (com.google.common.io.MoreFiles.deleteRecursively)1 ALLOW_INSECURE (com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 HttpClient (io.airlift.http.client.HttpClient)1 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)1 Slice (io.airlift.slice.Slice)1 DataSize (io.airlift.units.DataSize)1