Skip to content
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

Use RecordBatch to write follow up records #10163

Merged
merged 8 commits into from
Aug 25, 2022

Conversation

Zelldon
Copy link
Member

@Zelldon Zelldon commented Aug 24, 2022

Description

In order to determine the maximum record batch size, we use a new method on the batch writer. This method allows us to check whether we would be able to write a specific event count and batch size to the writer.

During processing a RecordBatch is built up in the ProcessingResultBuilder and given as ImmutableRecordBatch inside the ProcessingResult to the PrcoessingStateMachine. Here we tried to not change the interfaces, which causes us to cast on certain places, this is similar to how it currently is done in the LegacyWriter.

The RecordBatch is consumed by the ProcessingStateMachine in order to write the records. A follow-up PR will clean up other parts, like the unused writer in the ProcessingResult, etc.

Some StreamProcessor tests relied on the writer usage, which has been disabled/removed for now. We will soon rewrite them.

Related issues

related #9724
related #10001

Definition of Done

Not all items need to be done depending on the issue and the pull request.

Code changes:

  • The changes are backwards compatibility with previous versions
  • If it fixes a bug then PRs are created to backport the fix to the last two minor versions. You can trigger a backport by assigning labels (e.g. backport stable/1.3) to the PR, in case that fails you need to create backports manually.

Testing:

  • There are unit/integration tests that verify all acceptance criterias of the issue
  • New tests are written to ensure backwards compatibility with further versions
  • The behavior is tested manually
  • The change has been verified by a QA run
  • The impact of the changes is verified by a benchmark

Documentation:

  • The documentation is updated (e.g. BPMN reference, configuration, examples, get-started guides, etc.)
  • New content is added to the release announcement
  • If the PR changes how BPMN processes are validated (e.g. support new BPMN element) then the Camunda modeling team should be informed to adjust the BPMN linting.

Please refer to our review guidelines.

We have some use case where we want to verify whether we could potentially write certain event count and event batch size to the LogStreamBatchWriter, without already adding it to the batch.
This commit adds a new method to check whether the event count and batch size could potentially written.
* Add a new method to return a RecordBatch from the ProcessingResult
* Existing ResultBuilder implementation now also writes to a record batch, not only to the streamWriter
* ResultBuilder creates a result with ImmutableRecordBatch
* RecordBatch is created with new writer check method, in order to verify whether certain entries can be added to the batch
Some of them need to be restored after refactoring, but in a different way.
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2022

Test Results

   852 files  ±  0     852 suites  ±0   1h 37m 54s ⏱️ - 1m 53s
6 465 tests +40  6 453 ✔️ +39  12 💤 +1  0 ±0 
6 649 runs  +40  6 637 ✔️ +39  12 💤 +1  0 ±0 

Results for commit 503bdbc. ± Comparison against base commit ce79272.

♻️ This comment has been updated with latest results.

@Zelldon Zelldon marked this pull request as ready for review August 24, 2022 11:36
Comment on lines +72 to +76
final ValueType valueType = typeRegistry.get(value.getClass());
if (valueType == null) {
// usually happens when the record is not registered at the TypedStreamEnvironment
throw new IllegalStateException("Missing value type mapping for record: " + value.getClass());
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +78 to +84
if (value instanceof UnifiedRecordValue unifiedRecordValue) {
mutableRecordBatch.appendRecord(
key, -1, type, intent, rejectionType, rejectionReason, valueType, unifiedRecordValue);
} else {
throw new IllegalStateException(
String.format("The record value %s is not a UnifiedRecordValue", value));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do a similar thing in the Legacy writer see https://github.com/camunda/zeebe/blob/main/engine/src/main/java/io/camunda/zeebe/streamprocessor/LegacyTypedStreamWriterImpl.java#L85-L89

We could change the interface to accept only UnifiedRecordValue, but this would cause more changes on other interfaces which I didn't wanted to do in this PR.

Comment on lines -81 to -82
@Test
public void shouldMarkUnhealthyWhenOnErrorHandlingWriteEventFails() {
Copy link
Member Author

@Zelldon Zelldon Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a follow-up issue to either restore/rewrite the tests. Lets see whether we find a good way. Right now the writing shouldn't fail anymore.

Copy link
Contributor

@deepthidevaki deepthidevaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one question - I don't understand how this works because it seems like we are writing the followup records twice. Once via RecordBatch in ProcessingStateMachine and one directly via streamWriter in DirectProcessingResultBuilder.

If I understood this correctly, you can already

  • Remove streamWriter from DirectProcessingResultBuilder
  • Use the RecordBatch to verify instead of StreamWriter in DirectProcessingResultBuilder::canWriteEventOfLength

Let me know what you think, and I will approve the PR after that.

throw new IllegalStateException(
String.format("The record value %s is not a UnifiedRecordValue", value));
}

streamWriter.appendRecord(key, type, intent, rejectionType, rejectionReason, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Doesn't the record gets written twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the streamWriter is reseted in the ProcessingStateMachine. The problem here is I can't yet remove it because I have to migrate the TaskResult first to the RecordBatch, then I can remove that part.

Co-authored-by: Deepthi Devaki Akkoorath <deepthidevaki@users.noreply.github.com>
Copy link
Contributor

@deepthidevaki deepthidevaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@Zelldon
Copy link
Member Author

Zelldon commented Aug 25, 2022

Thanks for your review :) :bors r+

@Zelldon
Copy link
Member Author

Zelldon commented Aug 25, 2022

bors r-

@Zelldon
Copy link
Member Author

Zelldon commented Aug 25, 2022

bors r+

@zeebe-bors-camunda
Copy link
Contributor

Build succeeded:

@zeebe-bors-camunda zeebe-bors-camunda bot merged commit 82f7212 into main Aug 25, 2022
@zeebe-bors-camunda zeebe-bors-camunda bot deleted the zell-use-recordbatch branch August 25, 2022 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants