-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-5023] Consuming records from Iterator directly instead of using inner message queue #7174
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
Changes from 13 commits
5c1c1fd
1e99dac
37a6e2d
cc37167
1e966be
b4f4135
7a1e171
ec0c804
0cd32cd
7ed45ff
178bf76
27316e8
e2e9203
a5c5fa8
bca3774
8f2f3a5
c734cef
db06b33
be53e07
783a5cd
74e0742
b0c2730
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.hudi.execution; | ||
|
|
||
| import static org.apache.hudi.execution.HoodieLazyInsertIterable.getTransformFunction; | ||
|
|
||
| import org.apache.avro.generic.IndexedRecord; | ||
| import org.apache.hudi.common.model.HoodieRecord; | ||
| import org.apache.hudi.common.table.timeline.HoodieActiveTimeline; | ||
| import org.apache.hudi.common.testutils.HoodieTestDataGenerator; | ||
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.common.util.queue.IteratorBasedQueueConsumer; | ||
| import org.apache.hudi.common.util.queue.SimpleHoodieExecutor; | ||
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.exception.HoodieException; | ||
| import org.apache.hudi.testutils.HoodieClientTestHarness; | ||
| import org.apache.spark.TaskContext; | ||
| import org.apache.spark.TaskContext$; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.Timeout; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import scala.Tuple2; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class TestSimpleExecutionInSpark extends HoodieClientTestHarness { | ||
|
|
||
| private final String instantTime = HoodieActiveTimeline.createNewInstantTime(); | ||
|
|
||
| @BeforeEach | ||
| public void setUp() throws Exception { | ||
| initTestDataGenerator(); | ||
| initExecutorServiceWithFixedThreadPool(2); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() throws Exception { | ||
| cleanupResources(); | ||
| } | ||
|
|
||
| private Runnable getPreExecuteRunnable() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
| final TaskContext taskContext = TaskContext.get(); | ||
| return () -> TaskContext$.MODULE$.setTaskContext(taskContext); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExecutor() { | ||
|
|
||
| final List<HoodieRecord> hoodieRecords = dataGen.generateInserts(instantTime, 128); | ||
| final List<HoodieRecord> consumedRecords = new ArrayList<>(); | ||
|
|
||
| HoodieWriteConfig hoodieWriteConfig = mock(HoodieWriteConfig.class); | ||
| when(hoodieWriteConfig.getDisruptorWriteBufferSize()).thenReturn(Option.of(8)); | ||
| IteratorBasedQueueConsumer<HoodieLazyInsertIterable.HoodieInsertValueGenResult<HoodieRecord>, Integer> consumer = | ||
| new IteratorBasedQueueConsumer<HoodieLazyInsertIterable.HoodieInsertValueGenResult<HoodieRecord>, Integer>() { | ||
|
|
||
| private int count = 0; | ||
|
|
||
| @Override | ||
| public void consumeOneRecord(HoodieLazyInsertIterable.HoodieInsertValueGenResult<HoodieRecord> record) { | ||
| consumedRecords.add(record.record); | ||
| count++; | ||
| } | ||
|
|
||
| @Override | ||
| protected Integer getResult() { | ||
| return count; | ||
| } | ||
| }; | ||
| SimpleHoodieExecutor<HoodieRecord, Tuple2<HoodieRecord, Option<IndexedRecord>>, Integer> exec = null; | ||
|
|
||
| try { | ||
| exec = new SimpleHoodieExecutor(hoodieRecords.iterator(), consumer, getTransformFunction(HoodieTestDataGenerator.AVRO_SCHEMA), getPreExecuteRunnable()); | ||
|
|
||
|
|
||
| int result = exec.execute(); | ||
| // It should buffer and write 100 records | ||
| assertEquals(128, result); | ||
| // There should be no remaining records in the buffer | ||
| assertFalse(exec.isRemaining()); | ||
|
|
||
| // collect all records and assert that consumed records are identical to produced ones | ||
| // assert there's no tampering, and that the ordering is preserved | ||
| assertEquals(hoodieRecords, consumedRecords); | ||
| for (int i = 0; i < hoodieRecords.size(); i++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this for-loop, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeap. Removed. Sorry for missing this one. |
||
| assertEquals(hoodieRecords.get(i), consumedRecords.get(i)); | ||
| } | ||
|
|
||
| } finally { | ||
| if (exec != null) { | ||
| exec.shutdownNow(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Timeout(value = 60) | ||
| public void testInterruptExecutor() { | ||
| final List<HoodieRecord> hoodieRecords = dataGen.generateInserts(instantTime, 100); | ||
|
|
||
| HoodieWriteConfig hoodieWriteConfig = mock(HoodieWriteConfig.class); | ||
| when(hoodieWriteConfig.getDisruptorWriteBufferSize()).thenReturn(Option.of(1024)); | ||
| IteratorBasedQueueConsumer<HoodieLazyInsertIterable.HoodieInsertValueGenResult<HoodieRecord>, Integer> consumer = | ||
| new IteratorBasedQueueConsumer<HoodieLazyInsertIterable.HoodieInsertValueGenResult<HoodieRecord>, Integer>() { | ||
|
|
||
| int count = 0; | ||
|
|
||
| @Override | ||
| public void consumeOneRecord(HoodieLazyInsertIterable.HoodieInsertValueGenResult<HoodieRecord> record) { | ||
| count++; | ||
| } | ||
|
|
||
| @Override | ||
| protected Integer getResult() { | ||
| return count; | ||
| } | ||
| }; | ||
|
|
||
| SimpleHoodieExecutor<HoodieRecord, Tuple2<HoodieRecord, Option<IndexedRecord>>, Integer> executor = | ||
| new SimpleHoodieExecutor(hoodieRecords.iterator(), consumer, getTransformFunction(HoodieTestDataGenerator.AVRO_SCHEMA), getPreExecuteRunnable()); | ||
|
|
||
| try { | ||
| Thread.currentThread().interrupt(); | ||
| assertThrows(HoodieException.class, executor::execute); | ||
| assertTrue(Thread.interrupted()); | ||
| } catch (Exception e) { | ||
| // ignore here | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @@alexeykudinkin
Not involved testInterruptExecutor in this SimpleExecutionSpark Test.
Bcz there is no inner Thread pool in this new SimpleExecutor so there is nothing to interrupt right?
Is that looks good to u ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense