Support Firebird Wire Protocol packets: Common responses
Feature Request
For English only, other languages will not be accepted.
Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot make decision by current information, we will close it.
Please answer these questions before submitting your issue. Thanks!
Is your feature request related to a problem?
Currently, ShardingSphere-Proxy supports the basic packets required to perform transactions with Firebird. However, for full compatibility with the Firebird drivers, ShardingSphere-Proxy must support all Wire Protocol packets.
Describe the feature you would like.
Add support for the Firebird Wire protocol packages listed below.
-
[x] Generic response Pull request: #35937
-
[x] SQL response Pull request: #35937
-
[x] Fetch response Pull request: #35937
-
[ ] Slice response
-
[ ] Dummy response
Steps to implement Wire Protocol packet
- Add packet to org.apache.shardingsphere.database.protocol.firebird module
- Add executor for created packet to org.apache.shardingsphere.proxy.frontend.firebird module
- Add exceptions to org.apache.shardingsphere.database.exception.firebird module if needed
- Add unit tests for created classes.
I would like to work on this issue.
I've implemented the four remaining common response packets for this issue.
@bhaskars2904 — you noted earlier that you'd like to work on this issue. I've since opened the PR below, so no problem if you'd already started on something: feel free to review it, and the sibling issues (#39936 - #39943) are still open and unassigned if you'd like to pick one of those up instead. Happy to coordinate either way.
PR: #40013
Scope
Generic, SQL and Fetch responses are already covered by #35937, so this PR picks up the four unchecked items in the issue:
| Spec section | Class added | Op code |
|---|---|---|
| 3.4 Inline blob response | FirebirdInlineBlobResponsePacket |
op_inline_blob (114) |
| 3.5 Slice response | FirebirdSliceResponsePacket |
op_slice (60) |
| 3.6 Dummy response | FirebirdDummyResponsePacket |
op_dummy (71) |
| 3.7 Exit or disconnect command (aux connection) | FirebirdExitResponsePacket, FirebirdDisconnectResponsePacket |
op_exit (2), op_disconnect (6) |
All five classes live in org.apache.shardingsphere.database.protocol.firebird.packet.generic and follow the pattern of the already-merged response packets (FirebirdGenericResponsePacket, FirebirdSQLResponsePacket, FirebirdFetchResponsePacket): final class ... extends FirebirdPacket, with Lombok @RequiredArgsConstructor / @Getter on the three packets that carry fields, and a protected void write(FirebirdPacketPayload payload) that writes the operation code followed by the fields defined in the spec.
I also added INLINE_BLOB(114) to FirebirdCommandPacketType, which was not yet present.
Against the implementation steps in the issue
- Packet added to
database.protocol.firebird— done, as listed above. - Executor in
proxy.frontend.firebird— not applicable for this PR. All four packets are server-to-client only:op_inline_blobis emitted inside a fetch/SQL response,op_dummyis the server keep-alive packet, andop_exit/op_disconnectare sent by the server on the aux connection. None of them is triggered by a client request, so there is nothing to dispatch. For the slice response this is worth spelling out: it is the response toop_get_slice(58), but there is no get-slice request packet yet —FirebirdCommandPacketFactoryhas noGET_SLICEcase — so no executor can be attached until that request is implemented. This matches how the merged generic/SQL/fetch response packets were added, as packet classes plus unit tests. - Exceptions in
database.exception.firebird— none needed. These packets only serialize a server payload and raise no vendor errors. - Unit tests — added, one test class per new class.
Implementation notes
Inline blob response. Per the spec, the blob information buffer uses "the same encoding as p_resp_data in response to a blob information request with all blob information items", and the blob data buffer uses "the same encoding as p_resp_data in response to Get segment". Rather than duplicating those encodings, both fields are typed as FirebirdPacket and framed as length-prefixed, 4-byte-aligned buffers — the same composition FirebirdGenericResponsePacket already uses for its data field. A FirebirdBlobInfoReturnPacket and a FirebirdGetBlobSegmentResponsePacket can therefore be passed in directly.
Slice response — one point I would like feedback on. The specification is explicitly uncertain about this one. Section 3.5 states "This might not reflect actual encoding in the protocol", and the second field is documented as "Slice length (possibly a buffer?, needs verification)". I implemented the documented layout literally: operation code, slice length as a 4-byte integer, the slice length again, then the slice data as a length-prefixed buffer. I have flagged the caveat in the packet Javadoc as well. If the actual server-side encoding differs — for example if the second field is reserved padding rather than a repeated length — that is the one place this PR would need adjusting, and I would be glad to correct it.
Exit vs disconnect. The spec describes exit and disconnect as a single packet form carrying either op_exit or op_disconnect. I implemented them as two small classes, since each is a distinct wire operation and one-class-per-packet is the prevailing convention in this module. Happy to collapse them into one parameterized class if that is preferred.
Tests
New test classes: FirebirdDummyResponsePacketTest, FirebirdExitResponsePacketTest, FirebirdDisconnectResponsePacketTest, FirebirdSliceResponsePacketTest, FirebirdInlineBlobResponsePacketTest — 10 tests in total.
The slice test is parameterized over an empty, a 4-byte aligned and an unaligned slice; the inline blob test covers both aligned and unaligned buffer framing. The tests assert against real serialized bytes on an UnpooledByteBuf rather than only verifying mock interactions, so the operation code, field order, buffer length prefixes and padding alignment are all actually checked.
mvn -P check -pl database/protocol/dialect/firebird test
Tests run: 542, Failures: 0, Errors: 0, Skipped: 0
mvn -P check -pl proxy/frontend/dialect/firebird test
Tests run: 282, Failures: 0, Errors: 0, Skipped: 0
All four Firebird modules (protocol, proxy frontend, proxy backend, proxy dialect) build successfully, the two modules with tests were run as shown above, and spotless:apply reports all files clean.
AI disclosure
Per AI_POLICY.md: this work was AI-assisted. I used the MiniMax Code (MCode) AI coding agent to draft the packet classes and unit tests; I reviewed, ran and own every change. The affected files are the five new packet classes, the five new test classes, and the INLINE_BLOB(114) constant in FirebirdCommandPacketType — all in database/protocol/dialect/firebird. The packet layouts were implemented from the official Firebird wire protocol documentation and the existing packet classes in this module; no third-party code was copied.