Skip to content

PHOENIX-6420 Wrong result when conditional and regular upserts are passed in the same commit batch - #1183

Merged
swaroopak merged 3 commits into
apache:4.xfrom
tkhurana:PHOENIX-6420
Apr 6, 2021
Merged

PHOENIX-6420 Wrong result when conditional and regular upserts are passed in the same commit batch#1183
swaroopak merged 3 commits into
apache:4.xfrom
tkhurana:PHOENIX-6420

Conversation

@tkhurana

Copy link
Copy Markdown
Contributor

No description provided.

@tkhurana

Copy link
Copy Markdown
ContributorAuthor

@stoty

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec1m 32sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
+1 💚test4tests0m 0sThe patch appears to include 1 new or modified test files.
_ 4.x Compile Tests _
+1 💚mvninstall17m 20s4.x passed
+1 💚compile1m 44s4.x passed
+1 💚checkstyle1m 15s4.x passed
+1 💚javadoc1m 24s4.x passed
+0 🆗spotbugs5m 18sphoenix-core in 4.x has 941 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall10m 6sthe patch passed
+1 💚compile1m 49sthe patch passed
+1 💚javac1m 49sthe patch passed
-1 ❌checkstyle1m 18sphoenix-core: The patch generated 123 new + 803 unchanged - 63 fixed = 926 total (was 866)
+1 💚whitespace0m 0sThe patch has no whitespace issues.
+1 💚javadoc1m 21sthe patch passed
+1 💚spotbugs5m 51sphoenix-core generated 0 new + 940 unchanged - 1 fixed = 940 total (was 941)
_ Other Tests _
+1 💚unit223m 26sphoenix-core in the patch passed.
+1 💚asflicense0m 9sThe patch does not generate ASF License warnings.
273m 52s
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/1/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1183
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile
unameLinux 63d6d7375042 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revision4.x / ee4ce9f
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/1/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/1/testReport/
Max. process+thread count5010 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/1/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

conn.createStatement().execute(String.format(
"UPSERT INTO %s VALUES('a',1,1) ON DUPLICATE KEY UPDATE counter1 = counter1 + 2", tableName));
conn.commit();
assertRow(conn, tableName, "a", 2, 1);

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.

Should not counter1 value be 3? We are upserting 1 for counter1 and counter1=1+2

@swaroopakswaroopakMar 25, 2021

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.

I think it's correct as counter1 in the row is 0 from line number 627 or did I confuse myself 💭

@tkhuranatkhuranaMar 25, 2021

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@gokceni@swaroopak if the key already exists, we ignore the values provided in upsert and evaluate the expression on the stored value. So in this the increment happens on '0' which was the previously stored value.

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.

Cool, that's what I meant with the value from line 627.

conn.createStatement().execute(String.format(
"UPSERT INTO %s (pk, counter2) VALUES ('a',125)", tableName));
conn.commit();
assertRow(conn, tableName, "a", 11, 125);

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.

Recommend adding a check that index row is updated as well

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.

Also how about adding a check for char type column updates?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

There is no index defined yet. This change addresses the problem on the data table.

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.

I saw createIndex( on line 624 of this function, that is why I was checking.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

That is actually local index

conn.createStatement().execute(String.format(
"UPSERT INTO %s VALUES('a',1,1) ON DUPLICATE KEY UPDATE counter1 = counter1 + 2", tableName));
conn.commit();
assertRow(conn, tableName, "a", 9, 4);

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.

To see these switched could be nice like row 635 and 634 swapped so that we are sure they are in the same batch and the order doesn't matter in the batch.

} else {
boolean incrementRowCount = dstMutations == this.mutationsMap;
// we only need to check if the new mutation batch (srcRows) conflicts with the
// last mutation batch

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.

why? could you add it to the comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Because we only try to merge the new batch with the last one. That is why we only check for conflicts with the last one. All previous batches are not updated.

@stoty

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec1m 17sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
+1 💚test4tests0m 0sThe patch appears to include 1 new or modified test files.
_ 4.x Compile Tests _
+1 💚mvninstall15m 2s4.x passed
+1 💚compile1m 9s4.x passed
+1 💚checkstyle0m 43s4.x passed
+1 💚javadoc0m 56s4.x passed
+0 🆗spotbugs3m 56sphoenix-core in 4.x has 941 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall8m 8sthe patch passed
+1 💚compile1m 8sthe patch passed
+1 💚javac1m 8sthe patch passed
-1 ❌checkstyle0m 55sphoenix-core: The patch generated 123 new + 803 unchanged - 63 fixed = 926 total (was 866)
+1 💚whitespace0m 1sThe patch has no whitespace issues.
+1 💚javadoc1m 0sthe patch passed
+1 💚spotbugs4m 6sphoenix-core generated 0 new + 940 unchanged - 1 fixed = 940 total (was 941)
_ Other Tests _
+1 💚unit264m 56sphoenix-core in the patch passed.
+1 💚asflicense0m 11sThe patch does not generate ASF License warnings.
304m 27s
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/2/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1183
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile
unameLinux fb0938c38a17 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revision4.x / 3535708
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/2/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/2/testReport/
Max. process+thread count4784 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/2/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

@gokcenigokceni left a comment

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.

LGTM

@swaroopakswaroopak left a comment

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.

Non-binding +1

import java.util.List;
import java.util.Properties;

import com.google.common.collect.ImmutableList;

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.

good to use the shaded version of guava for easier porting to 5.x

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@gjacoby126 I opened this PR against apache 4.x. The version on master is already using the shaded version.

assertEquals(2, state.getNumRows());

int actualPairs = 0;
Iterator<Pair<byte[], List<Mutation>>> mutations = state.toMutations();

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.

A comment here on what you're checking would be helpful.

Comment threadphoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java Outdated
if (multiRowMutationState != null) {
final List<Mutation> deleteMutations = Lists.newArrayList();
generateMutations(key, mutationTimestamp, serverTimestamp, multiRowMutationState, deleteMutations, null);
// for index table there will only be 1 mutation batch in the list

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.

why only one mutation batch? What if there are conflicting batches for the index?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@gjacoby126 For indexes, the only time we see an entry in the map is in case of deletes and that too for immutable indexes. So I don't expect a conflicting update unless someone explicitly does a regular upsert and conditional upsert directly on index table which is theoretically possible but highly unlikely.

@tkhurana
tkhurana requested a review from gjacoby126April 5, 2021 16:51

@gjacoby126gjacoby126 left a comment

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.

+1, thanks @tkhurana

@stoty

stoty commented Apr 5, 2021

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec5m 33sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
+1 💚test4tests0m 0sThe patch appears to include 1 new or modified test files.
_ 4.x Compile Tests _
+1 💚mvninstall15m 13s4.x passed
+1 💚compile1m 3s4.x passed
+1 💚checkstyle0m 40s4.x passed
+1 💚javadoc0m 52s4.x passed
+0 🆗spotbugs3m 13sphoenix-core in 4.x has 941 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall6m 44sthe patch passed
+1 💚compile1m 3sthe patch passed
+1 💚javac1m 3sthe patch passed
-1 ❌checkstyle0m 43sphoenix-core: The patch generated 123 new + 803 unchanged - 63 fixed = 926 total (was 866)
+1 💚whitespace0m 0sThe patch has no whitespace issues.
+1 💚javadoc0m 47sthe patch passed
+1 💚spotbugs3m 27sphoenix-core generated 0 new + 940 unchanged - 1 fixed = 940 total (was 941)
_ Other Tests _
-1 ❌unit193m 2sphoenix-core in the patch failed.
+1 💚asflicense0m 36sThe patch does not generate ASF License warnings.
235m 40s
ReasonTests
Failed junit testsphoenix.end2end.index.PartialIndexRebuilderIT
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/3/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1183
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile
unameLinux 4aee66818618 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revision4.x / 5c57004
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/3/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
unithttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/3/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/3/testReport/
Max. process+thread count5304 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1183/3/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

@swaroopak
swaroopak merged commit d962363 into apache:4.xApr 6, 2021
jpisaac pushed a commit to jpisaac/phoenix that referenced this pull request Jun 10, 2022
* PHOENIX-6420 Wrong result when conditional and regular upserts are passed in the same commit batch (apache#1183)
* PHOENIX-6420 Wrong result when conditional and regular upserts are passed in the same commit batch
* Addressed feedback
* Added comments, rename variable
* PHOENIX-6387 Conditional updates on tables with indexes (apache#1215)
* PHOENIX-6387 Conditional updates on tables with indexes client side
* PHOENIX-6387 Conditional updates on tables with indexes server side
* Remove the extra read For regular upserts on tables with local index
* Addressed review comments
Sign up for freeto 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.

5 participants

@tkhurana@stoty@swaroopak@gjacoby126@gokceni