Search in sources :

Example 1 with SerializedPage

use of io.hetu.core.transport.execution.buffer.SerializedPage 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 SerializedPage

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

the class TestPartitionedOutputOperator method testPartitionedOutputOperatorSnapshot.

@Test
public void testPartitionedOutputOperatorSnapshot() throws Exception {
    SnapshotUtils snapshotUtils = mock(SnapshotUtils.class);
    PartitionedOutputBuffer buffer = mock(PartitionedOutputBuffer.class);
    PartitionedOutputOperator operator = createPartitionedOutputOperator(snapshotUtils, buffer);
    operator.getOperatorContext().getDriverContext().getPipelineContext().getTaskContext().getSnapshotManager().setTotalComponents(1);
    List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(1, 1).addSequencePage(2, 4).build();
    MarkerPage marker = MarkerPage.snapshotPage(1);
    MarkerPage marker2 = MarkerPage.snapshotPage(2);
    MarkerPage marker3 = MarkerPage.snapshotPage(3);
    MarkerPage resume = MarkerPage.resumePage(1);
    // Add first page, then capture and compare, then add second page, then restore, then compare, then add second page, then finish, then compare
    operator.addInput(input.get(0));
    operator.addInput(marker);
    ArgumentCaptor<Object> stateArgument = ArgumentCaptor.forClass(Object.class);
    verify(snapshotUtils, times(1)).storeState(anyObject(), stateArgument.capture(), anyObject());
    Object snapshot = stateArgument.getValue();
    when(snapshotUtils.loadState(anyObject(), anyObject())).thenReturn(Optional.of(snapshot));
    operator.addInput(input.get(1));
    operator.addInput(resume);
    operator.addInput(marker2);
    verify(snapshotUtils, times(2)).storeState(anyObject(), stateArgument.capture(), anyObject());
    snapshot = stateArgument.getValue();
    Object snapshotEntry = ((Map<String, Object>) snapshot).get("query/2/1/1/0/0/0");
    assertEquals(SnapshotTestUtil.toFullSnapshotMapping(snapshotEntry), createExpectedMappingBeforeFinish());
    operator.addInput(input.get(1));
    operator.finish();
    operator.addInput(marker3);
    verify(snapshotUtils, times(3)).storeState(anyObject(), stateArgument.capture(), anyObject());
    snapshot = stateArgument.getValue();
    snapshotEntry = ((Map<String, Object>) snapshot).get("query/3/1/1/0/0/0");
    assertEquals(SnapshotTestUtil.toFullSnapshotMapping(snapshotEntry), createExpectedMappingAfterFinish());
    ArgumentCaptor<List> pagesArgument = ArgumentCaptor.forClass(List.class);
    verify(buffer, times(9)).enqueue(anyInt(), pagesArgument.capture(), anyString());
    List<List> pages = pagesArgument.getAllValues();
    // 9 pages:
    // 1 (page 1 partitioned)
    // 1 (marker 1)
    // 2 (page 2 before resume)
    // 1 (resume marker)
    // 1 (marker 2)
    // 2 (page 2 after resume)
    // 1 (marker 3)
    assertEquals(pages.size(), 9);
    assertTrue(((SerializedPage) pages.get(1).get(0)).isMarkerPage());
    assertTrue(((SerializedPage) pages.get(4).get(0)).isMarkerPage());
    assertTrue(((SerializedPage) pages.get(5).get(0)).isMarkerPage());
    assertTrue(((SerializedPage) pages.get(8).get(0)).isMarkerPage());
}
Also used : MarkerPage(io.prestosql.spi.snapshot.MarkerPage) PartitionedOutputBuffer(io.prestosql.execution.buffer.PartitionedOutputBuffer) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) Page(io.prestosql.spi.Page) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) Matchers.anyString(org.mockito.Matchers.anyString) SnapshotUtils(io.prestosql.snapshot.SnapshotUtils) Matchers.anyObject(org.mockito.Matchers.anyObject) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 3 with SerializedPage

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

the class PartitionedOutputBuffer method enqueue.

@Override
public void enqueue(int partitionNumber, List<SerializedPage> pages, String origin) {
    requireNonNull(pages, "pages is null");
    // this can happen with a limit query
    if (!state.get().canAddPages()) {
        return;
    }
    if (!isSnapshotEnabled) {
        doEnqueue(partitionNumber, pages);
        return;
    }
    // but still arrives at the buffer *before* the marker. These pages are potentially used twice, if we resume from this marker.
    if (pages.size() == 1 && pages.get(0).isMarkerPage()) {
        // Broadcast marker to all clients
        for (int i = 0; i < partitions.size(); i++) {
            MultiInputSnapshotState snapshotState = snapshotStates.get(i);
            synchronized (snapshotState) {
                // All marker related processing is handled by this utility method
                List<SerializedPage> processedPages = snapshotState.processSerializedPages(pages, origin);
                doEnqueue(i, processedPages);
            }
        }
    } else {
        MultiInputSnapshotState snapshotState = snapshotStates.get(partitionNumber);
        synchronized (snapshotState) {
            List<SerializedPage> processedPages = snapshotState.processSerializedPages(pages, origin);
            doEnqueue(partitionNumber, processedPages);
        }
    }
}
Also used : MultiInputSnapshotState(io.prestosql.snapshot.MultiInputSnapshotState) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage)

Example 4 with SerializedPage

use of io.hetu.core.transport.execution.buffer.SerializedPage 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 SerializedPage

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

the class TestMarkerPage method testSerde.

@Test
public void testSerde() {
    MarkerPage page = new MarkerPage(100, true);
    SerializedPage spage = SerializedPage.forMarker(page);
    page = spage.toMarker();
    Assert.assertEquals(page.getSnapshotId(), 100);
    Assert.assertTrue(page.isResuming());
}
Also used : MarkerPage(io.prestosql.spi.snapshot.MarkerPage) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) Test(org.testng.annotations.Test)

Aggregations

SerializedPage (io.hetu.core.transport.execution.buffer.SerializedPage)32 Page (io.prestosql.spi.Page)17 Test (org.testng.annotations.Test)10 PagesSerde (io.hetu.core.transport.execution.buffer.PagesSerde)9 MarkerPage (io.prestosql.spi.snapshot.MarkerPage)8 ImmutableList (com.google.common.collect.ImmutableList)5 URI (java.net.URI)5 List (java.util.List)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 BlockEncodingSerdeProvider (io.prestosql.spi.snapshot.BlockEncodingSerdeProvider)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 DataSize (io.airlift.units.DataSize)2 Duration (io.airlift.units.Duration)2 DataCenterQueryResults (io.prestosql.client.DataCenterQueryResults)2 QueryInfo (io.prestosql.execution.QueryInfo)2 PageBuilder (io.prestosql.spi.PageBuilder)2 BlockBuilder (io.prestosql.spi.block.BlockBuilder)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2