Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do data validation when undo. #1060

Merged
merged 12 commits into from
May 21, 2019
Merged

Do data validation when undo. #1060

merged 12 commits into from
May 21, 2019

Conversation

ujjboy
Copy link
Contributor

@ujjboy ujjboy commented May 17, 2019

Ⅰ. Describe what this PR did

  • Add logic:
    • compare current data in the database with destination image, if they are not equal, it means have dirty data,
    • then compare current data in the database and the original image, if they are equal, also no need to execute undo
    • else will throw an exception
  • Add some test case

Ⅱ. Does this pull request fix one issue?

Part of #1049

@ujjboy
Copy link
Contributor Author

ujjboy commented May 17, 2019

I will add more test case which uses h2 database later.

@codecov-io
Copy link

codecov-io commented May 17, 2019

Codecov Report

Merging #1060 into develop will increase coverage by 0.49%.
The diff coverage is 81.66%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #1060      +/-   ##
=============================================
+ Coverage      39.44%   39.94%   +0.49%     
- Complexity      1138     1153      +15     
=============================================
  Files            222      222              
  Lines           8872     8929      +57     
  Branches        1143     1158      +15     
=============================================
+ Hits            3500     3567      +67     
+ Misses          4931     4914      -17     
- Partials         441      448       +7
Impacted Files Coverage Δ Complexity Δ
...seata/rm/datasource/undo/AbstractUndoExecutor.java 82.79% <81.66%> (-0.54%) 20 <16> (+11)
...o/seata/rm/datasource/sql/struct/TableRecords.java 73.68% <0%> (+35.08%) 13% <0%> (+4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 415e5c8...18ea10c. Read the comment docs.

@ujjboy ujjboy changed the title [WIP] Do data validation when undo. Do data validation when undo. May 17, 2019
@ujjboy ujjboy requested a review from zhangthen May 17, 2019 15:42
Copy link
Contributor

@zhangthen zhangthen left a comment

Choose a reason for hiding this comment

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

LGTM

// parese pk values
Object[] pkValues = parsePkValues(getUndoRows());

PreparedStatement statement = conn.prepareStatement(checkSQL);
Copy link
Contributor

Choose a reason for hiding this comment

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

The statement should close in finally .

*/
protected void dataValidation(Connection conn) throws SQLException {
protected boolean dataValidation(Connection conn) throws SQLException {

Copy link
Contributor

Choose a reason for hiding this comment

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

It ‘s better to add a switcher to close the dirty data check manually, the switcher is open default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will add it in the next standalone PR.

Copy link
Contributor

@leizhiyuan leizhiyuan left a comment

Choose a reason for hiding this comment

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

I left some comments

executor.executeOn(new MockConnection());
// skip data validation
Mockito.doReturn(true).when(spy).dataValidation(connection);
spy.executeOn(connection);
} catch (SQLException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use e.printTrace()

executor.executeOn(new MockConnection());
// skip data validation
Mockito.doReturn(true).when(spy).dataValidation(connection);
spy.executeOn(connection);
} catch (SQLException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use e.printTrace()

@ujjboy ujjboy requested a review from leizhiyuan May 20, 2019 03:45
// no need undo if the before data snapshot is equivalent to the after data snapshot.
if (DataCompareUtils.isRecordsEquals(sqlUndoLog.getBeforeImage(), sqlUndoLog.getAfterImage())) {
// when the data validation is not ok
if (!dataValidation(conn)) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we throw some exception explicitly for the code change later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don’t get your point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add some log and change the method name for more explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

as communicated offline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leizhiyuan done.

@leizhiyuan leizhiyuan merged commit f6ee500 into apache:develop May 21, 2019
@leizhiyuan leizhiyuan added this to the 0.6.0 milestone May 21, 2019
@ujjboy ujjboy deleted the undo_check branch May 21, 2019 12:30
nick-tan pushed a commit to nick-tan/seata that referenced this pull request Jul 12, 2019
* Do data validation when undo.

* Run test case use h2 database.

* fix as review.

* Add log.
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.

None yet

5 participants