You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "rishi-rana (via GitHub)" <gi...@apache.org> on 2026/09/08 17:07:10 UTC
[PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
rishi-rana opened a new pull request, #39773:
URL: https://github.com/apache/shardingsphere/pull/39773
Fixes 4 of the 5 sub-cases in #39052. The 5th (isc_blobtoobig) is split off to #39772, per makssent's suggestion, since it needs a buffered-size-limit design decision rather than just wiring an existing signal to an error.
Changes proposed in this pull request:
- `FirebirdOpenBlobCommandExecutor`: throw `InvalidSegstrIdException` on an unknown BLOB id instead of registering an empty BLOB.
- `FirebirdPutBlobSegmentCommandExecutor` / `FirebirdBatchBlobSegmentsCommandExecutor`: check `appendSegment()`'s `OptionalInt` result and throw `InvalidSegstrHandleException` on an unknown or already-closed handle instead of silently reporting success. This covers both the "unknown handle" and "put after close" cases from the issue, since `closeWrite()` removes the cache entry either way, so both hit the same signal.
- `FirebirdExecuteStatementCommandExecutor.bindBlobParameters()`: throw `InvalidSegstrIdException` for an unknown or unclosed BLOB parameter instead of silently binding `null`.
- Adds `InvalidSegstrHandleException`/`InvalidSegstrIdException` and their `FirebirdVendorError`/`FirebirdDialectExceptionMapper` wiring, following the error-handling pattern established in #38927. The gdscodes and SQL states (`isc_bad_segstr_handle` / `isc_bad_segstr_id`, both SQLSTATE 42000) were verified against the `jaybird` client jar's `isc_error_sqlstates.properties`/`isc_error_msg.properties`, not guessed.
- Fixed `FirebirdOpenBlobCommandExecutorTest`'s existing `assertExecute` test, which was unintentionally exercising the bug (an unregistered blob id) and asserting success; it now seeds real content via `FirebirdBlobBinaryProtocolValue`. Added unknown-id/unknown-handle/put-after-close regression tests across all four executors.
This pull request was drafted with assistance from Claude Code (Anthropic). Affected scope: the two new exception classes, the `FirebirdVendorError`/`FirebirdDialectExceptionMapper` wiring, the four executor fixes listed above, and their corresponding unit tests. I reviewed and verified all changes myself.
---
Before committing this PR, I'm sure that I have checked the following options:
- [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
- [x] I have self-reviewed the commit code.
- [ ] I have (or in comment I request) added corresponding labels for the pull request.
- [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
- [ ] I have made corresponding changes to the documentation.
- [x] I have added corresponding unit tests for my changes.
- [x] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5600789065
```markdown
### Result
**Review Result: Not Mergeable**
**Blocking Issues: 3**
### Blocking Issues
#### 1. The new handle check is skipped for an empty batch
**Evidence:** `FirebirdBatchBlobSegmentsCommandExecutor.java:51-57`.
The PR adds a check of the `appendSegment()` result inside the loop. When `packet.getSegments()` is empty, the loop is skipped. For an unknown handle, `getBlobId()` returns an empty result, and a success response with `id=0` is sent.
Firebird validates the handle before entering the loop:
https://github.com/FirebirdSQL/firebird/blob/v5.0.3/src/remote/server/server.cpp#L5448-L5494
**Required Change:** validate the existence of the handle regardless of whether the request contains segments. Add tests for empty batches with unknown and closed handles.
#### 2. The new OpenBlob check incorrectly rejects BLOB ID = 0
**Evidence:** `FirebirdOpenBlobCommandExecutor.java:46-49`.
The PR replaces the previous empty-content fallback for IDs missing from the cache with `InvalidSegstrIdException`.
For ID = 0, this turns a valid operation into an error. Firebird treats a zero ID as an empty BLOB: `blobId.isEmpty()` sets `BLB_eof` rather than raising `isc_bad_segstr_id`.
https://github.com/FirebirdSQL/firebird/blob/v5.0.3/src/jrd/blb.cpp#L1373-L1377
**Relation to this PR:** the new check directly changes a previously successful empty-BLOB open into `invalid BLOB ID`.
**Impact:** the client receives a BLOB error for a value that Firebird accepts.
**Required Change:** preserve the valid handling of ID = 0 without weakening validation of genuinely unknown IDs. Add a dedicated test for opening a zero ID.
#### 3. The new check reports an unknown-handle error for a valid read handle
**Evidence:** `FirebirdPutBlobSegmentCommandExecutor.java:49-50`, `FirebirdBatchBlobSegmentsCommandExecutor.java:52-53`.
After OpenBlob, a valid read handle exists. If a segment write is requested using that handle, `appendSegment()` does not find it in the write cache and returns an empty result.
The check added by this PR interprets this as an unknown handle and raises `isc_bad_segstr_handle`.
In Firebird, this handle passes the existence check. The error occurs later, when the write is attempted. For Firebird 4.0.6 and 5.0.3, the error is:
- GDS: `isc_cannot_update_old_blob`;
- code: `335545262`;
- SQLSTATE: `42000`;
- message: `cannot update old BLOB`.
https://github.com/FirebirdSQL/firebird/blob/v5.0.3/src/jrd/blb.cpp#L1604-L1607
**Relation to this PR:** this finding concerns the exception selected by the new check, not the implementation of BLOB reading or storage.
**Impact:** an existing handle used for an invalid operation is incorrectly classified as unknown. The same issue affects non-empty batches.
**Required Change:** distinguish an unknown handle from a valid handle opened for reading. Verify the corresponding server error for the target Firebird version.
### Evidence
Tests for an unknown BLOB handle and an unknown BLOB ID were written and passed: errors returned directly by Firebird and through ShardingSphere Proxy matched in SQLSTATE, GDS code, and message.
Additional manual verification was performed in the debugger: replacing the BLOB handle before writing and the BLOB ID before opening caused Proxy to return the expected errors.
| Error | GDS code | SQLSTATE | Message |
|---|---|---|---|
| Unknown BLOB handle | `335544328`, `isc_bad_segstr_handle` | `42000` | `invalid BLOB handle` |
| Invalid BLOB ID | `335544329`, `isc_bad_segstr_id` | `42000` | `invalid BLOB ID` |
The basic scenarios are therefore confirmed by tests and manual verification. The added vendor codes and messages are correct.
The findings concern validation completeness and error selection in specific edge cases. These cases were analyzed against the source code but have not yet been reproduced separately against the database.
### Coverage
- Reviewed the diff and stated scope of PR #39773 at head `951391bca0d`.
- Reference implementations: Firebird 5.0.3 and Jaybird 5.0.6 source code.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "rishi-rana (via GitHub)" <gi...@apache.org>.
rishi-rana commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5672709992
The failing check is `E2E - pipeline on opengauss/opengauss:3.1.0` ([run 34869140487](https://github.com/apache/shardingsphere/actions/runs/34869140487)). It appears unrelated to this PR.
Two data-pipeline tests error:
- `CDCE2EIT.assertCDCDataImportSuccess` — `NullPointerException: Cannot invoke "org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable.getName()" because "each" is null`
- `PostgreSQLMigrationGeneralE2EIT.assertMigrationSuccess` — `IllegalStateException: Job status not reached: EXECUTE_INCREMENTAL_TASK`
The same job fails with the identical NPE on `dev` in [run 34866362193](https://github.com/apache/shardingsphere/actions/runs/34866362193), about 26 minutes before this one. The same job also failed on an unrelated PR branch in [run 34823301334](https://github.com/apache/shardingsphere/actions/runs/34823301334).
The NPE is in `infra.metadata.database.schema`, while this PR only touches `database/exception/dialect/firebird` and `proxy/frontend/dialect/firebird`, and the openGauss E2E does not load the Firebird frontend.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "rishi-rana (via GitHub)" <gi...@apache.org>.
rishi-rana commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5667282920
Fixed in 8a64e5f — you're right, and my earlier scoping of this was wrong.
When I first traced `bindBlobParameters()` I treated the negative-id branch as a separate mechanism (Proxy-generated result BLOBs held by `FirebirdBlobBinaryProtocolValue`) and deliberately left it alone, fixing only the positive write-cache path. But #39052 asks for an error on an unknown BLOB parameter without qualifying the sign, and a stale, cross-connection or fabricated negative id reaching the backend as `NULL` is exactly the silent behaviour the issue is about. The distinction I drew wasn't one the requirement makes.
`bindBlobParameters()` now checks the negative-id lookup before assigning the parameter and throws `InvalidSegstrIdException` when no content exists. `assertSkipBlobParameterWhenNegativeBlobId` is replaced by `assertRejectUnknownResultBlobParameter`, which asserts the exception; I verified it fails against the previous implementation. `assertBindResultBlobParameter` is untouched, so valid result-BLOB reuse stays covered.
Verification on this head: 32 tests in `database/exception/dialect/firebird` and 279 in `proxy/frontend/dialect/firebird`, zero failures; `spotless:check checkstyle:check -Pcheck` clean for both modules.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "rishi-rana (via GitHub)" <gi...@apache.org>.
rishi-rana commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5628660498
@makssent ready for your review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu merged PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "rishi-rana (via GitHub)" <gi...@apache.org>.
rishi-rana commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5588977901
Changes are ready for review @makssent
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "rishi-rana (via GitHub)" <gi...@apache.org>.
rishi-rana commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5611194858
Thanks for the detailed review — the Firebird source references made these easy to verify. All three blocking issues are fixed in 9b5f8a5.
**1. Handle check skipped for an empty batch.** `FirebirdBatchBlobSegmentsCommandExecutor` now validates the handle before iterating segments, so an empty batch on an unknown or closed handle raises the error instead of returning `id=0` with success — matching `rem_port::put_segment()`.
**2. BLOB ID = 0 incorrectly rejected.** `FirebirdOpenBlobCommandExecutor` now treats a zero id as the NULL BLOB quad and opens an empty BLOB, per `blb::open2()`. This also makes it consistent with `FirebirdExecuteStatementCommandExecutor.bindBlobParameters()`, which already had a `0L == blobId` case. Added `assertExecuteWithZeroBlobId`, and noted the convention in the class Javadoc so it doesn't read as a swallowed error.
**3. Valid read handle reported as unknown.** Added `CannotUpdateOldBlobException` -> `isc_cannot_update_old_blob` (335545262 / 42000 / `cannot update old BLOB`, confirmed against Jaybird's `isc_error_sqlstates.properties` and `isc_error_msg.properties`), and a shared `FirebirdBlobWriteHandleValidator` used by both put and batch.
One implementation note on 3 that's worth flagging: my first attempt detected the read handle via `FirebirdBlobReadCache`, but `readSegment()` removes the cursor once the BLOB is fully consumed, so a drained-but-unclosed read handle would still have reported `isc_bad_segstr_handle` — the same handle giving two different errors depending on how much had been read. The validator now checks allocation state in `FirebirdBlobHandleGenerator` instead, which is unaffected by read progress and is released by close/cancel (so a closed handle still correctly reports `isc_bad_segstr_handle`). `assertExecuteWithFullyReadHandle` covers this and fails against the cursor-based version.
Also added tests for the empty-batch and read-handle paths, direct tests for the new `isAllocated`, and removed two tests that became byte-identical duplicates once validation moved ahead of the loop — with the check now preceding segment iteration, `assertExecuteWithUnknownBlobHandle` / `assertExecuteAfterClose` already exercise the empty-batch path, since the packet mock yields no segments.
One item I deliberately did not change, in case you'd prefer otherwise: `appendSegment()`'s `OptionalInt` result is no longer consumed, since the up-front validation makes the empty case unreachable on a connection's serialized command path. Re-adding a post-append `checkState` would guard a `close_blob` interleaving mid-write, but it looked like duplicate validation of an invariant the validator already guarantees. Happy to add it back if you think the race is worth defending.
Local verification: 311 tests across `database/exception/dialect/firebird` and `proxy/frontend/dialect/firebird`, zero failures; Checkstyle and Spotless clean under `-Pcheck`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add error handling for unknown or closed BLOB handles and ids in Firebird Proxy [shardingsphere]
Posted by "rishi-rana (via GitHub)" <gi...@apache.org>.
rishi-rana commented on PR #39773:
URL: https://github.com/apache/shardingsphere/pull/39773#issuecomment-5685124366
Fixed in 2571d21.
`FirebirdOpenBlobCommandExecutor` now resolves content by id instead of only consulting the result BLOB store:
- zero — NULL BLOB quad, opens an empty BLOB (unchanged);
- negative — result BLOB store, rejected when the content is missing (unchanged);
- positive — `FirebirdBlobWriteCache`, returning the stored content of a created BLOB, rejected when the id is unknown or still open.
`isClosed()` returns false for both an unknown id and an open one, so a single check covers the "reject unknown or unclosed" requirement, and the content is then read through `getBlobData()` — the same pair `bindBlobParameters()` already uses, so no new cache API was needed.
On the test: my first attempt set up the write cache directly rather than running the commands, which would not have covered what you asked. A real `close_blob` also calls `FirebirdBlobReadCache.removeBlob()` and `FirebirdBlobHandleGenerator.releaseBlobHandle()`, so the handle is freed and reused by the following `open_blob`, and the id comes from `FirebirdBlobIdGenerator` rather than being hardcoded. `assertExecuteAfterCreatedBlobIsClosed` now drives `FirebirdCreateBlobCommandExecutor` -> `FirebirdPutBlobSegmentCommandExecutor` -> `FirebirdCloseBlobCommandExecutor` -> `FirebirdOpenBlobCommandExecutor` and asserts the stored bytes are returned through `readSegment()`. Against the previous implementation it fails with `InvalidSegstrIdException: Invalid BLOB id: 1`, reproducing the reported behaviour.
Also added `assertExecuteWhenCreatedBlobIsNotClosed` (same create and put sequence, no close) and `assertExecuteWithUnknownResultBlobId` for the negative-id branch, which had no direct coverage.
Verification on this head: 32 tests in `database/exception/dialect/firebird` and 282 in `proxy/frontend/dialect/firebird`, zero failures; `spotless:check checkstyle:check -Pcheck` clean for both modules.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org