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

[C++] Support protobuf native schema #11388

Merged

Conversation

BewareMyPower
Copy link
Contributor

Motivation

It's a feature catchup of #8372, which implemented protobuf native schema in Java client. This PR is to support protobuf native schema in C++ client.

Modifications

Since the protobuf native schema is based on protobuf-v3, we need to upgrade the protobuf to 3.x.y in build/docker/Dockerfile. From #9046 and PIP-75, the patched protobuf 2.4.1 were replaced by lightproto, so this PR removes protobuf.patch and install protobuf 3.17.1 instead of 2.4.1.

In addition, when I installed the rvm in docker image, it failed to download GPG keys from remote server. So I adopted another way to download keys, see https://rvm.io/rvm/security#alternatives. The updated image has already been uploaded as apachepulsar/pulsar-build:ubuntu-16.04-pb3 so the related scripts are updated as well.

For C++ source code, the modifications are:

  • Add the PROTOBUF_NATIVE schema and make methods of Commands recognize it so that the schema can be serialized to the actual CommandXXX struct.
  • Add a dependent header, which contains the createProtobufNativeSchema function to create a protobuf native SchemaInfo based on a protobuf descriptor. It's not included in pulsar/Client.h because it depends on protobuf header. If users don't want to use protobuf native schema, they need no extra protobuf dependency.
  • Change the dependency from protobuf-lite to protobuf because the implementation relies on the protobuf descriptor, which is not supported in protobuf-lite.
  • Add tests for protobuf native schema, which uses the same proto files with Java client's unit tests.

Since the depended protobuf version has been upgraded, the related documents are updated as well.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests ProtobufNativeSchemaTests.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)
  • The rest endpoints: (yes / no)
  • The admin cli options: (yes / no)
  • Anything that affects deployment: (yes / no / don't know)

@BewareMyPower BewareMyPower added doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. component/c++ labels Jul 20, 2021
@BewareMyPower BewareMyPower self-assigned this Jul 20, 2021
@BewareMyPower BewareMyPower changed the title [C++] Support protobuf native schema [WIP][C++] Support protobuf native schema Jul 20, 2021
@BewareMyPower
Copy link
Contributor Author

Run CI first to expose some test failures because some Dockerfiles may need changes.

@BewareMyPower BewareMyPower changed the title [WIP][C++] Support protobuf native schema [C++] Support protobuf native schema Jul 21, 2021
@BewareMyPower
Copy link
Contributor Author

Now all tests passed.

@BewareMyPower BewareMyPower added doc-required Your PR changes impact docs and you will update later. and removed doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. labels Jul 21, 2021
@merlimat merlimat merged commit 992760e into apache:master Jul 21, 2021
@codelipenghui codelipenghui added this to the 2.9.0 milestone Jul 22, 2021
Technoboy- pushed a commit to Technoboy-/pulsar that referenced this pull request Jul 22, 2021
* Add C++ ProtobufNativeSchema implementation

* Add tests for ProtobufNativeSchema

* Fix schema type error and add tests for protobuf native schema

* Upgrade pulsar-build image's protobuf to 3.17.1

* Update protobuf dependency version in documents

* Add missed comments

* Fix CentOS 7 build
@BewareMyPower BewareMyPower deleted the bewaremypower/cpp-protobuf-native-schema branch July 29, 2021 04:00
codelipenghui pushed a commit that referenced this pull request Jul 30, 2021
…#11492)

### Motivation

#11388 added support for protobuf native schema in C++ client. The implementation serializes a protobuf generated class' descriptor to a Base64 encoded string. However, it doesn't add the padding characters while the broker side requires the padding characters. Therefore, if the Base64 encoded string needs the padding characters, the broker will fail to deserialize:

> com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `byte[]` from String "": Unexpected end of base64-encoded String: base64 variant 'MIME-NO-LINEFEEDS' expects padding (one or more '=' characters) at the end. This Base64Variant might have been incorrectly configured

See https://en.wikipedia.org/wiki/Base64#Decoding_Base64_with_padding for the Base64 with padding.

### Modifications

- Add the padding `=` characters if the Base64 encoded string's length is not a multiple of four.
- Add a `PaddingDemo.proto` to test the above case to ensure that broker can validate the schema string.
@Anonymitaet Anonymitaet removed the doc-required Your PR changes impact docs and you will update later. label Aug 17, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
* Add C++ ProtobufNativeSchema implementation

* Add tests for ProtobufNativeSchema

* Fix schema type error and add tests for protobuf native schema

* Upgrade pulsar-build image's protobuf to 3.17.1

* Update protobuf dependency version in documents

* Add missed comments

* Fix CentOS 7 build
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…apache#11492)

### Motivation

apache#11388 added support for protobuf native schema in C++ client. The implementation serializes a protobuf generated class' descriptor to a Base64 encoded string. However, it doesn't add the padding characters while the broker side requires the padding characters. Therefore, if the Base64 encoded string needs the padding characters, the broker will fail to deserialize:

> com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `byte[]` from String "": Unexpected end of base64-encoded String: base64 variant 'MIME-NO-LINEFEEDS' expects padding (one or more '=' characters) at the end. This Base64Variant might have been incorrectly configured

See https://en.wikipedia.org/wiki/Base64#Decoding_Base64_with_padding for the Base64 with padding.

### Modifications

- Add the padding `=` characters if the Base64 encoded string's length is not a multiple of four.
- Add a `PaddingDemo.proto` to test the above case to ensure that broker can validate the schema string.
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.

4 participants