Commit Graph

83 Commits

Author SHA1 Message Date
Jason Gustafson 3a189ad868
KAFKA-10386; Fix flexible version support for `records` type (#9163)
This patch fixes the generated serde logic for the 'records' type so that it uses the compact byte array representation consistently when flexible versions are enabled.

Reviewers: David Arthur <mumrah@gmail.com>
2020-08-13 09:52:23 -07:00
Jason Gustafson 89e12f3c6b
KAFKA-10388; Fix struct conversion logic for tagged structures (#9166)
The message generator was missing conversion logic for tagged structures. This led to casting errors when either `fromStruct` or `toStruct` were invoked. This patch also adds missing null checks in the serialization of tagged byte arrays, which was found from improved test coverage.

Reviewers: Colin P. McCabe <cmccabe@apache.org>
2020-08-12 08:29:59 -07:00
David Arthur 4cd2396db3
KAFKA-9629 Use generated protocol for Fetch API (#9008)
Refactored FetchRequest and FetchResponse to use the generated message classes for serialization and deserialization. This allows us to bypass unnecessary Struct conversion in a few places. A new "records" type was added to the message protocol which uses BaseRecords as the field type. When sending, we can set a FileRecords instance on the message, and when receiving the message class will use MemoryRecords. 

Also included a few JMH benchmarks which indicate a small performance improvement for requests with high partition counts or small record sizes.

Reviewers: Jason Gustafson <jason@confluent.io>, Boyang Chen <boyang@confluent.io>, David Jacot <djacot@confluent.io>, Lucas Bradstreet <lucas@confluent.io>, Ismael Juma <ismael@juma.me.uk>, Colin P. McCabe <cmccabe@apache.org>
2020-07-30 13:29:39 -04:00
Colin Patrick McCabe e5335bcb58
MINOR: Add ApiMessageTypeGenerator (#9002)
Previously, we had some code hard-coded to generate message type classes
for RPCs.  We might want to generate message type classes for other
things as well, so make it more generic.

Reviewers: Boyang Chen <boyang@confluent.io>
2020-07-15 09:03:50 -07:00
David Jacot c0bcabcc9a
MINOR; Provide static constants with lowest and highest supported versions alongside with the schema (#8916)
Reviewers: Colin P. McCabe <cmccabe@apache.org>
2020-07-13 08:30:09 -07:00
Colin Patrick McCabe 6a30b4e385
MINOR: equals() should check _unknownTaggedFields (#8640)
_unknownTaggedFields contains tagged fields which we don't understand
with the current schema.  However, we still want to keep the data around
for various purposes. For example, if we are printing out a JSON form of
the message we received, we want to include a section containing the
tagged fields that couldn't be parsed. To leave these out would give an
incorrect impression of what was sent over the wire.  Since the unknown
tagged fields represent real data, they should be included in the fields
checked by equals().

Reviewers: Ismael Juma <ismael@juma.me.uk>, Boyang Chen <boyang@confluent.io>
2020-06-08 12:57:48 -07:00
David Jacot 21362ad7f7
KAFKA-9514; The protocol generator generated useless condition when a field is made nullable and flexible version is used (#8793)
Reviewers: Colin P. McCabe <cmccabe@apache.org>
2020-06-03 17:06:22 -07:00
Colin Patrick McCabe 14e426c9a8
MINOR: Add a duplicate() method to Message classes (#8556)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Jason Gustafson <jason@confluent.io>
2020-05-13 15:26:50 -07:00
Jason Gustafson c15cd5cfeb
MINOR: Only add 'Data' suffix for generated request/response/header types (#8625)
Currently we add "Data" to all generated classnames in order to avoid naming collisions with existing Request/Response objects. Generated classes for other persistent schema definitions (such as those used in `GroupCoordinator` and `TransactionCoordinator`) will not necessarily have the same problem, so it would be nice if the generated types could use the name defined in the schema directly.

Reviewers: Boyang Chen <boyang@confluent.io>, Colin P. McCabe <cmccabe@apache.org>
2020-05-06 15:30:13 -07:00
Chia-Ping Tsai 07e14e9cc5
MINOR: Fix unused arguments used in formatted string and log messages (#8036)
Reviewers: Ron Dagostino <rdagostino@confluent.io>, Ismael Juma <ismael@juma.me.uk>, Konstantine Karantasis <konstantine@confluent.io>
2020-04-29 22:37:05 -07:00
Colin Patrick McCabe 1d55127d97
MINOR: equals() should compare all fields for generated classes (#8539)
Reviewers: Jason Gustafson <jason@confluent.io>
2020-04-23 21:11:42 -07:00
Vikas Singh a276c54637
MINOR: Allow a single struct to be a field in the protocol spec (#8413)
Remove the restriction in the protocol generation code that a structure
field needs to be part of an array.

Reviewers: Colin P. McCabe <cmccabe@apache.org>
2020-04-10 13:15:05 -07:00
Colin Patrick McCabe bf6dffe93b
KAFKA-9309: Add the ability to translate Message classes to and from JSON (#7844)
Reviewers: David Arthur <mumrah@gmail.com>, Ron Dagostino <rdagostino@confluent.io>
2020-04-09 13:11:36 -07:00
Dominic Evans ddd3dfbfae
MINOR: comment apikey types in generated switch (#8201)
As a developer, it would be convenient if the generated
{request,response}HeaderVersion case statements in ApiMessageType.java
included a comment to remind me which type each of them is so I don't
need to manually cross-reference the newer/rarer ones.

Also include commented lines for the two special cases around
ApiVersionsResponse and ControllerShutdownRequest which are hardcoded in
the ApiMessageTypeGenerator.java and not covered by the message format
json files.

Before:
```java
    public short requestHeaderVersion(short _version) {
        switch (apiKey) {
            case 0:
                return (short) 1;
            case 1:
                return (short) 1;
            case 2:
                return (short) 1;
            case 3:
                if (_version >= 9) {
                    return (short) 2;
                } else {
                    return (short) 1;
                }
            // ...etc
```

After:
```java
    public short requestHeaderVersion(short _version) {
        switch (apiKey) {
            case 0: // Produce
                return (short) 1;
            case 1: // Fetch
                return (short) 1;
            case 2: // ListOffset
                return (short) 1;
            case 3: // Metadata
                if (_version >= 9) {
                    return (short) 2;
                } else {
                    return (short) 1;
                }
            // ...etc
```

Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>

Reviewers: Mickael Maison <mickael.maison@gmail.com>
2020-03-15 10:46:09 +00:00
Brian Byrne 57cef765f5
KAFKA-9474: Adds 'float64' to the RPC protocol types (#8012)
Reviewers: Jason Gustafson <jason@confluent.io>, Ismael Juma <ismael@juma.me.uk>
2020-01-30 04:54:27 -08:00
Colin Patrick McCabe 4fea3e4f1a
KAFKA-9288: Do not allow the same object to be inserted multiple times into ImplicitLinkedHashCollection (#7809)
Reviewers: Jason Gustafson <jason@confluent.io>
2019-12-10 16:27:16 -08:00
Jason Gustafson b94c7f479b
MINOR: Add ignorable field check to `toStruct` and fix usage (#7710)
If a field is not marked as ignorable, we should raise an exception if it has been set to a non-default value. This check already exists in `Message.write`, so this patch adds it to `Message.toStruct`. Additionally, we fix several fields which should have been marked ignorable and we fix some related test assertions.

Reviewers: Ismael Juma <ismael@juma.me.uk>, Manikumar Reddy <manikumar.reddy@gmail.com>, Colin Patrick McCabe <cmccabe@apache.org>
2019-11-22 22:05:03 -08:00
Colin Patrick McCabe 02df8e1496
KAFKA-8986: Allow null as a valid default for tagged fields. (#7585)
Allow null as a valid default for tagged fields.  Fix a bunch of cases where this would previously result in null pointer dereferences.

Also allow inferring FieldSpec#versions based on FieldSpec#taggedVersions.  Prefix 'key' with an underscore when it is used in the generated code, to avoid potential name collisions if someone names an RPC field "key".

Allow setting setting hexadecimal constants and 64-bit contstants.

Add a lot more test cases to SimpleExampleMessage.json.

Reviewers: Jason Gustafson <jason@confluent.io>
2019-11-20 16:40:18 -08:00
John Roesler 4a5155c934 KAFKA-8868: Generate SubscriptionInfo protocol message (#7248)
Rather than maintain hand coded protocol serialization code, Streams could use the same code-generation framework as Clients/Core.

There isn't a perfect match, since the code generation framework includes an assumption that you're generating "protocol messages", rather than just arbitrary blobs, but I think it's close enough to justify using it, and improving it over time.

Using the code generation allows us to drop a lot of detail-oriented, brittle, and hard-to-maintain serialization logic in favor of a schema spec.

Reviewers: Colin P. McCabe <cmccabe@apache.org>, Boyang Chen <boyang@confluent.io>, Bill Bejeck <bill@confluent.io>, Guozhang Wang <wangguoz@gmail.com>
2019-11-01 10:03:55 -07:00
Nikolay adb2bdb122 KAFKA-8584: The RPC code generator should support ByteBuffer. (#7342)
The RPC code generator should support using the ByteBuffer class in addition to byte arrays. By using the ByteBuffer class, we can avoid performing a copy in many situations. Also modify TestByteBufferDataTest to test the new feature.

Reviewers: Colin P. McCabe <cmccabe@apache.org>, Guozhang Wang <wangguoz@gmail.com>
2019-10-23 12:39:12 -07:00
Colin Patrick McCabe 0de61a4683 KAFKA-8885; The Kafka Protocol should Support Optional Tagged Fields (#7325)
This patch implements support for optional (tagged) fields in the Kafka protocol as documented in KIP-482: https://cwiki.apache.org/confluence/display/KAFKA/KIP-482%3A+The+Kafka+Protocol+should+Support+Optional+Tagged+Fields#KIP-482:TheKafkaProtocolshouldSupportOptionalTaggedFields-TypeClasses.

Reviewers: David Jacot <djacot@confluent.io>, Ismael Juma <ismael@juma.me.uk>, Jason Gustafson <jason@confluent.io>
2019-10-06 21:13:23 -07:00
Colin Patrick McCabe 92688ef82c MINOR: improve the Kafka RPC code generator (#7340)
Move the generator checkstyle suppressions to a special section, rather
than mixing them in with the other sections.  For generated code, do not
complain about variable names or cyclic complexity.

FieldType.java: remove isInteger since it isn't used anywhere.  This way, we
don't have to decide whether a UUID is an integer or not (there are arguments
for both choices).  Add FieldType#serializationIsDifferentInFlexibleVersions
and FieldType#isVariableLength.

HeaderGenerator: add the ability to generate static imports.  Add
IsNullConditional, VersionConditional, and ClauseGenerator as easier ways of
generating "if" statements.
2019-09-25 11:58:54 -04:00
John Roesler c955828095 MINOR: the code generator should be able to set the java package (#7355)
Reviewers: Colin P. McCabe <cmcabe@apache.org>
2019-09-20 09:25:19 -07:00
John Roesler 6530600e6b MINOR: Add UUID type to Kafka API code generation (#7291)
Reviewers: Colin P. McCabe <cmccabe@apache.org>
2019-09-13 11:36:58 -07:00
Colin P. Mccabe d70fe5ed2d KAFKA-8644; The Kafka protocol generator should allow null defaults for bytes and array fields
Author: Colin P. Mccabe <cmccabe@confluent.io>

Reviewers: Stanislav Kozlovski, Gwen Shapira

Closes #7059 from cmccabe/KAFKA-8644
2019-07-11 09:52:01 -07:00
Colin P. Mccabe 711c817254 KAFKA-8560; The Kafka protocol generator should support common structures
Author: Colin P. Mccabe <cmccabe@confluent.io>

Reviewers: Gwen Shapira

Closes #6966 from cmccabe/KAFKA-8560
2019-07-02 09:40:54 -07:00
Jason Gustafson 4f11090597
HOTFIX: Fix recent protocol breakage from KIP-345 and KIP-392 (#6780)
KIP-345 and KIP-392 introduced a couple breaking changes for old versions of bumped protocols. This patch fixes them.

Reviewers: Colin Patrick McCabe <cmccabe@confluent.io>, Ismael Juma <ismael@juma.me.uk>, Boyang Chen <bchen11@outlook.com>, Guozhang Wang <wangguoz@gmail.com>
2019-05-21 22:51:56 -07:00
Bob Barrett a97e55b838 KAFKA-8332: Refactor ImplicitLinkedHashSet to avoid losing ordering when converting to Scala
Because of how conversions between Java collections and Scala collections work, ImplicitLinkedHashMultiSet objects were being treated as unordered in some contexts where they shouldn't be.  This broke JOIN_GROUP handling.  

This patch renames ImplicitLinkedHashMultiSet to ImplicitLinkedHashMultCollection.  The order of Collection objects will be preserved when converting to scala.  Adding Set and List "views" to the Collection gives us a more elegant way of accessing that functionality when needed.

Reviewers: Colin P. McCabe <cmccabe@apache.org>
2019-05-09 11:08:22 -07:00
Colin Patrick McCabe 5144660040
KAFKA-8158: Add EntityType for Kafka RPC fields (#6503)
Reviewers: Jason Gustafson <jason@confluent.io>
2019-05-07 21:35:17 -07:00
Colin P. Mccabe 62381bd915 KAFKA-8168; Add a generated ApiMessageType class
Author: Colin P. Mccabe <cmccabe@confluent.io>

Reviewers: Gwen Shapira

Closes #6510 from cmccabe/KAFKA-8168
2019-04-05 15:27:34 -07:00
Colin Patrick McCabe e0d028bf6c
KAFKA-8150: Fix bugs in handling null arrays in generated RPC code (#6489)
ToString functions must not get a NullPointException.  read() functions
must properly translate a negative array length to a null field.

Reviewers: Manikumar Reddy <manikumar.reddy@gmail.com>
2019-03-25 09:43:44 -07:00
Colin P. Mccabe 027cbbaec5 KAFKA-8060: The Kafka protocol generator should allow null defaults
Author: Colin P. Mccabe <cmccabe@confluent.io>

Reviewers: Manikumar Reddy <manikumar.reddy@gmail.com>

Closes #6387 from cmccabe/KAFKA-8060
2019-03-08 09:25:28 +05:30
Stanislav Kozlovski fb0db7602a KAFKA-7844: Use regular subproject for generator to fix *All targets (#6182)
The presence of the buildSrc subproject is causing problems when we try
to run installAll, jarAll, and the other "all" targets. It's easier
just to make the generator code a regular subproject and use the
JavaExec gradle task to run the code. This also makes it more
straightforward to run the generator unit tests.

Reviewers: David Arthur <mumrah@gmail.com>, Ismael Juma <ismael@juma.me.uk>

Co-authored-by: Colin P. Mccabe <cmccabe@confluent.io>
Co-authored-by: Stanislav Kozlovski <stanislav_kozlovski@outlook.com>
2019-01-21 21:06:37 -08:00