Skip to content

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

Open
mdayakar wants to merge 1 commit into
apache:masterfrom
mdayakar:HIVE-29762_HashCollisionIssue
Open

HIVE-29762: Synchronization logic added as a part of HIVE-24428 is having hash collision issue#6651
mdayakar wants to merge 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

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.

5 participants