Closed muga closed 7 years ago
@muga Some questions:
finish()
there can finally make finish()
called twice. It's from how PreviewExecutor
works?For 1, this is required for both of preview
and run
. finish()
is called when the input plugin correctly finishes operations for Page objects like addRecord()
. The addRecord
method is called when the plugin correctly finishes writing rows to the Page object.
For 2, this doesn't have any impacts for run
and guess
. PreviewExecutor
only has the logic that uses the spec of finish()
. Other executors don't have it for now but they might be able to to have it.
For 3, This is the scenario that finish()
is called twice:
PreviewExecutor
creates SamplingPageOutput
object and passes it to input plugin (PreviewExecutor.java#L122)finish()
when Input plugin finishes writing data to Page object. (PreviewExecutor.java#L170)finish()
method. (PreviewExecutor.java#L182)finish()
is called within finally block. (RestClientInputPluginBaseUnsafe.java#L118)@muga Sorry, I don't understand yet. That finish()
in your step 2 is PageOutput#finish
, and the other finish()
in your step 4 is PageBuilder#finish
. They're different?
@dmikurube PageBuilder#finish
calls PageOutput#finish
. Sorry, I should've commented it as 5.
@muga Okay. Then, sounds it is very exceptional in PreviewExecutor
that SamplingPageOutput#add
calls its own finish
by itself. I thought that PageBuidler#finish ==> PageOutput#finish
is designed to be called from outside at last. Other plugins look like that. PreviewExecutor
seems an exception.
It seems to me that the right fix is to change how to escape from preview
in PreviewExecutor
when the specified number of rows have been read. What do you think?
The library is designed under the assumption above that finish
is designed to be called from outside.
@muga I'm just wondering if you could add a comment there such as
// When failing around |PageBuidler| in |ingestServiceData|, |pageBuilder.finish()| should not be called.
(No need to be as-is.)
@dmikurube Thank you for reviewing.
It seems to me that the right fix is to change how to escape from preview in PreviewExecutor when the specified number of rows have been read. What do you think?
Agree. As talked on 1on1, we should fix 2 things:
PageOutput#add
in SamplingPageOutput
and not call the finish
.RestClientInputPluginBaseUnsafe#run
and not call pageBuilder.finish
when failing ingestServiceData method call. (this PR) I will file a ticket for 1.
PageBuilder#finish() is called when ingestServiceData failed. The finish() needs to be called when PageBuilder finishes writing Page objects.
As background, when PreviewExecutor executes my plugin that uses this library, it throws NullPointerException reported on https://github.com/embulk/embulk/issues/570. The cause of the issue is that PageBuilder#finish method is called twice within preview. I'm trying to fix Embulk itself to avoid this situation https://github.com/embulk/embulk/pull/571. This PR fixes the cause that the finish() is called twice within PreviewExecutor.