Skip to content

HIVE-29762: Synchronization logic added as a part of HIVE-24428 is having hash collision issue - #6651

Merged
dengzhhu653 merged 1 commit into
apache:masterfrom
mdayakar:HIVE-29762_HashCollisionIssue
Aug 3, 2026
Merged

HIVE-29762: Synchronization logic added as a part of HIVE-24428 is having hash collision issue#6651
dengzhhu653 merged 1 commit into
apache:masterfrom
mdayakar:HIVE-29762_HashCollisionIssue

Conversation

@mdayakar

Copy link
Copy Markdown
Contributor

HIVE-29762: Synchronization logic added as a part of HIVE-24428 is having hash collision issue

What changes were proposed in this pull request?

Here hash collisions are happening for unrelated(db.tablename) keys with stripe size of 32 so increased the stripe size to 65536 which will increase memory footprint as 65536 lock objects will get created upfront. To reduce the memory footprint, used Striped.lazyWeakLock() API in which lock objects are lazily allocated and weakly referenced.

Why are the changes needed?

To remove/minimize the hash collisions for the unrelated db.tablename keys.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Existing testcases.

@@ -2017,8 +2007,10 @@ public enum ConfVars {
+ "e.g. javax.net.ssl.trustStore=/tmp/truststore,javax.net.ssl.trustStorePassword=pwd.\n " +
"If both this and the metastore.dbaccess.ssl.* properties are set, then the latter properties \n" +
"will overwrite what was set in the deprecated property."),
METASTORE_NUM_STRIPED_TABLE_LOCKS("metastore.num.striped.table.locks", "hive.metastore.num.striped.table.locks", 32,
"Number of striped locks available to provide exclusive operation support for critical table operations like add_partitions."),
METASTORE_NUM_STRIPED_TABLE_LOCKS("metastore.num.striped.table.locks", "hive.metastore.num.striped.table.locks", 65536,

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.

any particular reason why 65536 was chosen?

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.

There is no reason, I feel 65536(2^16) is not too high and not too low value and minimizes the hash collisions. If required we can increase this value.

@thomasrebele thomasrebele 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.

Thank you for the PR! I've read the ticket description in HIVE-29762, and it's not clear to me whether the concurrency issue is a performance bug or a deadlock problem. If the issue is a performance bug, then the PR looks good to me as-is. If the issue is a deadlock, then the PR would just make the deadlock less likely, making it more difficult to debug in the future. If there's a deadlock, another ticket should be created to find a permanent fix. Could you clarify this in the ticket description, please?

// lazyWeakLock: lock objects are allocated on first use and held via weak references,
// so unused stripes are GC'd. A large stripe count keeps hash collisions between
// unrelated (db, tbl) keys without paying permanent memory cost.
tablelocks = Striped.lazyWeakLock(numTableLocks);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mdayakar
mdayakar force-pushed the HIVE-29762_HashCollisionIssue branch from 061fed4 to 08a447b Compare July 28, 2026 16:11
@mdayakar

Copy link
Copy Markdown
Contributor Author

Thank you for the PR! I've read the ticket description in HIVE-29762, and it's not clear to me whether the concurrency issue is a performance bug or a deadlock problem. If the issue is a performance bug, then the PR looks good to me as-is. If the issue is a deadlock, then the PR would just make the deadlock less likely, making it more difficult to debug in the future. If there's a deadlock, another ticket should be created to find a permanent fix. Could you clarify this in the ticket description, please?

@thomasrebele thanks for the review. Its a performance issue, here for the unrelated table names(keys) like a.AA and b.BB for example, it was giving same lock object due to hash collision issue because of that one thread is is waiting to lock and other thread got the lock and working on adding partition. But here partition is getting added to different tables so here both threads can work concurrently. This issue got fixed as a part of current fix.

@sonarqubecloud

Copy link
Copy Markdown

@dengzhhu653

dengzhhu653 commented Jul 30, 2026

Copy link
Copy Markdown
Member

Check the context of HIVE-24428, the Metastore server won't delete the created directory upon dynamic partitions from different clients collide, and this seems to be a in-process lock, do we really need it to coordinate clients?

@mdayakar

Copy link
Copy Markdown
Contributor Author

Check the context of HIVE-24428, the Metastore server won't delete the created directory upon dynamic partitions from different clients collide, and this seems to be a in-process lock, do we really need it to coordinate clients?

Thanks for the review @dengzhhu653. As per my understanding, here partition folder in the storage is getting created and they maintain Map<PartValEqWrapperLite, Boolean> to store whether the partition folder is successfully created or not (value attribute in the map). In case of any exception while adding the partition, here the directory is getting cleaned based on the boolean value present in the map for that particular partition.

There will be below two scenarios,

  1. If multiple clients connecting to different HMS instances, in this case only the client which created the data folder can delete it in case of any errors/exceptions.
  2. If multiple clients connecting to same HMS instance, in this case if don't provide synchronization logic then there can be a chance that one client can delete the data folder even though partition is added successfully.

Please let me know whether my understanding is correct or I am missing something. Thanks.

@dengzhhu653

Copy link
Copy Markdown
Member

here the directory is getting cleaned based on the boolean value present in the map for that particular partition.

I see

If multiple clients connecting to different HMS instances, in this case only the client which created the data folder can delete it in case of any errors/exceptions.

We still have the same issue in this case, image A and B client add the same partition p1;
A, create the p1 directory(true) -> B create the p1 directory(false) -> B commits p1 since B has only a few partitions to be added -> A throws errors and removes the data inserted by B

@dengzhhu653 dengzhhu653 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This mitigates the hash collision somehow, while we should come up with a better way to coordinate different clients

@mdayakar

mdayakar commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

This mitigates the hash collision somehow, while we should come up with a better way to coordinate different clients

@dengzhhu653 I raised a followup JIRA (HIVE-29789) to fix the issue related to multiple HMS instances involved.

@dengzhhu653
dengzhhu653 merged commit 569c064 into apache:master Aug 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants