Skip to content

Ensure that batchParamValues is cleared in all cases when using bulk update mode#1768

Closed
ianroberts wants to merge 1 commit intomicrosoft:mainfrom
ianroberts:clear-batch-on-fail
Closed

Ensure that batchParamValues is cleared in all cases when using bulk update mode#1768
ianroberts wants to merge 1 commit intomicrosoft:mainfrom
ianroberts:clear-batch-on-fail

Conversation

@ianroberts
Copy link
Copy Markdown
Contributor

Closes #1767

@ghost
Copy link
Copy Markdown

ghost commented Mar 10, 2022

CLA assistant check
All CLA requirements met.

@Jeffery-Wasty
Copy link
Copy Markdown
Contributor

Hi @ianroberts,

Thank you for the report and for the potential fix in the pull request. We'll take a look at both and get back to you as soon as we can.

@Jeffery-Wasty Jeffery-Wasty self-assigned this Mar 10, 2022
@Jeffery-Wasty Jeffery-Wasty added the Under Investigation Used for issues under investigation label Mar 10, 2022
@Jeffery-Wasty Jeffery-Wasty self-requested a review March 11, 2022 18:56
Copy link
Copy Markdown
Contributor

@Jeffery-Wasty Jeffery-Wasty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianroberts We'll be taking a closer look at this at a later date.

@Jeffery-Wasty Jeffery-Wasty removed their assignment Mar 15, 2022
for (int i = 0; i < batchParamValues.size(); ++i) {
updateCounts[i] = 1;
}
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply adding batchParamValues = null to a finally clause should be enough, no need for an additional try block.

return updateCounts;
loggerExternal.exiting(getClassNameLogging(), "executeBatch", updateCounts);
return updateCounts;
} finally {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to 2133, batchParamValues = null should be executed in all cases so it makes sense for it to be in a finally block belonging to the initial try block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there are a number of checks inside the outer try block that can throw IllegalArgumentException in order to abort the bulk copy and fall back to the regular batch insert method. I introduced the inner try in order to avoid clearing out batchParamValues until we know for sure that we're committed to the bulk copy code path and won't be backing out to try again with a batch insert.

Copy link
Copy Markdown
Contributor Author

@ianroberts ianroberts Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative approach could be to remove both the additional inner try I've added here and the one at line 2296 in the "old style batch insert" branch, and instead wrap the whole method body in an outer try/finally that ensures batchParamValues is cleared in all cases immediately before the method returns. That's a bigger diff with all the indentation changes but might be clearer overall.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a separate PR #1869 for the alternative approach, which is also rebased against the latest main.

for (int i = 0; i < batchParamValues.size(); ++i) {
updateCounts[i] = 1;
}
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above.

return updateCounts;
loggerExternal.exiting(getClassNameLogging(), "executeLargeBatch", updateCounts);
return updateCounts;
} finally {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@Jeffery-Wasty
Copy link
Copy Markdown
Contributor

Let's just keep all changes in one PR, #1869 , even if they're 'alternate scenarios' we can just choose which commit we'd like to merge.

@Jeffery-Wasty Jeffery-Wasty removed the Under Investigation Used for issues under investigation label Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch not cleared on failure when using bulk update

2 participants