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 opaque records in Raft append entries message #10825

Merged

Conversation

mmaslankaprv
Copy link
Member

@mmaslankaprv mmaslankaprv commented May 17, 2023

Introduced new append entries request type and endpoint. The new type
leverages serde based serialization of model::record_batch in
request record_batch_reader. The new serialization does not
materialize batch records but uses an opaque iobuf to serialize batch
payload.

Fixes: #10743

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.1.x
  • v22.3.x
  • v22.2.x

Release Notes

Improvements

  • fixed large allocations when replicating batches with large number of records

@mmaslankaprv mmaslankaprv force-pushed the append-entries-allocation branch 5 times, most recently from 2884642 to f56356e Compare May 17, 2023 20:13
@mmaslankaprv mmaslankaprv changed the title Append entries allocation Use opaque records in Raft append entries message May 18, 2023
@mmaslankaprv mmaslankaprv force-pushed the append-entries-allocation branch 2 times, most recently from 91b7c31 to d3d398b Compare May 20, 2023 15:30
@mmaslankaprv mmaslankaprv marked this pull request as ready for review May 20, 2023 20:53
@dotnwat
Copy link
Member

dotnwat commented May 20, 2023

Introduced new append entries request type and endpoint. The new type
leverages serde based serialization of model::record_batch in
request record_batch_reader. The new serialization does not
materialize batch records but uses an opaque iobuf to serialize batch
payload.

In addition to using serde, is this a performance boost too?

@mmaslankaprv
Copy link
Member Author

Introduced new append entries request type and endpoint. The new type
leverages serde based serialization of model::record_batch in
request record_batch_reader. The new serialization does not
materialize batch records but uses an opaque iobuf to serialize batch
payload.

In addition to using serde, is this a performance boost too?

Outside of using serde, this limits large allocations (records vector). I think it will provide a boost for workloads involving not compressed batches, haven't measure that yet.

Copy link
Contributor

@bharathv bharathv left a comment

Choose a reason for hiding this comment

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

nits but lgtm otherwise..

@@ -1158,6 +1158,10 @@ class remote_segment_batch_consumer : public storage::batch_consumer {
// redpanda offset.
batch.header().base_offset = kafka::offset_cast(
rp_to_kafka(batch.base_offset()));
// since base offset isn't accounted into Kafka crc we need to only
// update header_crc
batch.header().header_crc = model::internal_header_only_crc(
Copy link
Contributor

Choose a reason for hiding this comment

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

is this related to this patch?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it is as i changed the operator==(record_batch_header) to compare the header_crc

src/v/model/record.h Show resolved Hide resolved
src/v/model/record.h Outdated Show resolved Hide resolved
auto serde_fields() { return std::tie(_header, _records); }

static model::record_batch
serde_direct_read(iobuf_parser& in, size_t const bytes_left_limit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL, didn't know about *direct*

Copy link
Member Author

Choose a reason for hiding this comment

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

me neither, i like it

src/v/raft/types.h Outdated Show resolved Hide resolved
@mmaslankaprv mmaslankaprv force-pushed the append-entries-allocation branch from d3d398b to 38984af Compare May 23, 2023 06:49
@mmaslankaprv mmaslankaprv requested a review from bharathv May 23, 2023 06:49
bharathv
bharathv previously approved these changes May 23, 2023
@mmaslankaprv mmaslankaprv force-pushed the append-entries-allocation branch from 38984af to dd7b1f4 Compare May 25, 2023 14:59
@mmaslankaprv mmaslankaprv force-pushed the append-entries-allocation branch 3 times, most recently from 8d49c31 to c2d8193 Compare May 30, 2023 07:08
@mmaslankaprv mmaslankaprv requested a review from bharathv May 30, 2023 11:58
Signed-off-by: Michal Maslanka <michal@redpanda.com>
After batch base offset is updated in remote segment parser we must
update the header crc for it to be consistent with current state.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
Serde now supports types without default constructors. Leveraged that
and refactored `raft::append_entries_request` type.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
Introduced a type wrapping append entries request and defining a new
serialization logic for the `append_entries_request`. Leveraging the
wrapper approach allow us to decouple type change from its usage and as
a result reduce the code churn.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
@mmaslankaprv mmaslankaprv force-pushed the append-entries-allocation branch from c2d8193 to 36def36 Compare May 31, 2023 07:40
static ss::future<model::record_batch>
serde_async_direct_read(iobuf_parser& in, size_t const bytes_left_limit) {
using serde::read_async_nested;
// TODO: change to coroutine after we upgrade to clang-16
Copy link
Contributor

Choose a reason for hiding this comment

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

comment is stale :-D, what are the odds.

@mmaslankaprv mmaslankaprv merged commit af6853a into redpanda-data:dev Jun 1, 2023
@mmaslankaprv mmaslankaprv deleted the append-entries-allocation branch June 1, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Oversized allocation: 1122304 bytes in reflection::adl<model::record_batch>::from(iobuf_parser&)
3 participants