-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-28578: Concurrency issue in updateTableColumnStatistics #6159
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
Conversation
c26894e to
65ac4a0
Compare
7472b31 to
c729ea1
Compare
|
It is still using pessimistic locking. how about Transaction A: UPDATE version = version + 1 (starts at v=5) Database MVCC: |
|
Thank you @deniskuzZ for the comment. String updateSQL = "UPDATE \"TABLE_PARAMS\" " + "SET \"PARAM_VALUE\" = '" + newVersion + "' " +
"WHERE \"TBL_ID\" = " + tblId + " AND \"PARAM_KEY\" = '" + versionParamKey + "' " +
AND \"PARAM_VALUE\" = '" + expectedVersion + "'"; // ✅ CHECK SNAPSHOT!The result of this query seems important to the example, let's say there is a row( If there are more transactions to update this row, then they are piled up to get a change to take over the row lock. In my opinion, this is similar to the s4u way I proposed in the old PR. |
|
in any case, solution in this PR is acceptable and OK to merge, but please consider using MVCC (i.e. Another question: since we’re adding |
IMO in the MVCC the transaction still holds the row lock in case of affected rows = 1, it might be rolled back in the middle of the transaction, so other updates need this transaction to commit or rollback to get the right version of this row(avoid to read dirty). |
Performance Comparison (Updates Only)
|
| private boolean areTxnStatsSupported = false; | ||
| private PropertyStore propertyStore; | ||
|
|
||
| private static Striped<Lock> tablelocks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this optimization? it can safe some resources when concurrency happens on HMS process level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we can depend on a shared outer lock solely, if we worry about the CPU overhead it brought to the database, I can add it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another point is the retry is random but at least 30ms, and the row is located by the primary key, so I guess the CPU overhead might not be so high as we think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably you are right
...e-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
Show resolved
Hide resolved
| return selectStatement + " for update NOWAIT"; | ||
| } else { | ||
| int selectLength = "select".length(); | ||
| return selectStatement.trim().substring(0, selectLength) + " /*+ MAX_EXECUTION_TIME(300) */ " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how reliable is that? it won't take row-level lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it takes the row-level lock as well, and maximum wait time for the lock is 300ms, otherwise throws:
Caused by: java.sql.SQLException: Query execution was interrupted, maximum statement execution time exceeded
Checked MySQL 5.7, using mysql-connector-j-8.0.32.jar and mysql-connector-java-5.1.49.jar
deniskuzZ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, pending tests
...e-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
Outdated
Show resolved
Hide resolved
|
Since the retries are handled by server-side via RetryingExecutor, do we actually need |
This is a more optimistic way compared to S4U, NOWAIT helps prevent the long hang for waiting for the lock, reduce the hot contention, personally I like this way. |
c729ea1 to
4911fd7
Compare
|
|
Filed another jira HIVE-29316 to fix the similar issue on updatePartitionColumnStatistics |
|
Thank you @deniskuzZ for the review! |





What changes were proposed in this pull request?
Why are the changes needed?
Does this PR introduce any user-facing change?
How was this patch tested?
Tested on Postgres 17.2, MariaDB 10.3.39-MariaDB-1, MySQL 9.1.0-1.el9 and 5.7.44 and Oracle 23