SEPURI-SAI-KRISHNA opened a new pull request, #13362:
URL: https://github.com/apache/seatunnel/pull/13362
Yes, glad to contribute to Apache SeaTunnel.
### Purpose of this pull request
Closes #13318 (the `SinkFlowLifeCycle` part).
`SinkFlowLifeCycle` creates its writer only in `restoreState`. A task can be
closed before that: it is cancelled while it waits for its restore, for example
when another task group of the pipeline failed first, or `createWriter` /
`restoreWriter` throws. `close()` then called `writer.close()` with `writer`
still null and threw a `NullPointerException`, which `SeaTunnelTask.close()`
does not catch, so the lifecycles after the sink were not closed either.
A second leak sits on the same path. In `LOG` or `ROUTE` error handling
mode, `restoreState` creates the `ErrorHandler` (and, for `ROUTE`, opens its
error sink writer) before it creates the writer. Only
`ErrorHandlingSinkWriter.close()` closes that handler, so when the writer could
not be created, the handler and its error sink writer stayed open.
Changes, in `SinkFlowLifeCycle.close()` only:
- `super.close()` still completes the flow first.
- Without a writer, the flow closes the error handler if the restore created
one, and returns. Nothing was written, so no terminal write outcome is emitted
and no `WriterCloseEvent` is sent.
- With a writer, nothing changes.
Scope: making `SeaTunnelTask.close()` keep closing the other lifecycles when
one close throws is the other half of #13318, and #12391 (for #12231) already
does that, so this PR does not touch `SeaTunnelTask`. The two changes are
independent: with this PR the sink close no longer throws in these cases, and
with #12391 any other close failure no longer skips the rest.
I checked the open PRs that touch `SinkFlowLifeCycle`: #13120 (restore error
message) and #12014 (TRUNCATE TABLE events) change other methods, and their
patches apply cleanly on top of this one, including the test class #13120 also
extends.
### Does this PR introduce _any_ user-facing change?
Yes. A sink task closed before its writer exists no longer fails its close
with a `NullPointerException`, so the original error stays the one in the
worker log, and an error sink opened for that task is closed. No option,
default or API changes.
### How was this patch tested?
Two new cases in `SinkFlowLifeCycleErrorOutcomeTest`, which build a real
`SinkFlowLifeCycle` with a mocked sink:
- `closeBeforeRestoreNeedsNoWriter`: `init()` then `close()` without a
restore. The close does not throw and completes the flow.
- `closeAfterFailedWriterCreationClosesTheErrorHandler`: `LOG` mode,
`createWriter` throws, `restoreState` fails with that error, then `close()`
does not throw and closes the `ErrorHandler` that the restore created.
With the `SinkFlowLifeCycle` of dev, both fail with `NullPointerException:
Cannot invoke "SinkWriter.close()" because "this.writer" is null`. With the
guard but without closing the handler, the second fails (`Wanted but not
invoked: close()`).
- `SinkFlowLifeCycleErrorOutcomeTest` (15), `SinkFlowLifeCycleMetricsTest`,
`FlushSignalMetricsFlowTest`, `StainTraceFlowTest` and
`TransformFlowLifeCycleCloseTest`: 26 tests pass.
- `spotless:check`, `git diff --check`.
### Check list
* [x] If any new Jar binary package adding in your PR, please add License
Notice according
[New License
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
(no new jar)
* [x] If necessary, please update the documentation to describe the new
feature. https://github.com/apache/seatunnel/tree/dev/docs (not needed: no
option or documented behaviour changes)
* [x] If necessary, please update `incompatible-changes.md` to describe the
incompatibility caused by this PR. (not needed: no incompatible change)
* [ ] If you are contributing the connector code, please check that the
following files are updated: (not a connector change)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]