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
PHOENIX-6129 : Optimize tableExists() call while retrieving correct MUTEX table #920
PHOENIX-6129 : Optimize tableExists() call while retrieving correct MUTEX table #920
Conversation
Since it is not allowed to mutate SYSTEM tables, providing corresponding IT test seems difficult. |
…cquireUpgradeMutex()
…) from acquireUpgradeMutex()" This reverts commit 9aafabf.
: SchemaUtil.getTableKey(tenantId, schemaName, tableName); | ||
byte[] rowKey = columnName != null ? | ||
SchemaUtil.getColumnKey(tenantId, schemaName, tableName, columnName, familyName) : | ||
SchemaUtil.getTableKey(tenantId, schemaName, tableName); | ||
// at this point the system mutex table should have been created or | ||
// an exception thrown | ||
byte[] sysMutexPhysicalTableNameBytes = getSysMutexPhysicalTableNameBytes(); |
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.
byte[] sysMutexPhysicalTableNameBytes = getSysMutexPhysicalTableNameBytes();
If I understand correctly what @ChinmaySKulkarni described in the ticket, this call will still result to an admin.tableExists call to check the existance of SYSTEM.MUTEX/SYSTEM:MUTEX and you didn't changed that.
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.
try (Table sysMutexTable = getTable(sysMutexPhysicalTableNameBytes)) {
Instead We could try the Table sysMutexTable =getTable() call with one of them and catch HBase TableNotFoundException, in that case try with the other one.
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.
If getSysMutexPhysicalTableNameBytes()
start throwing TableNotFoundException
, then at this point the Exception would be thrown and caught, so we would not go ahead with next getTable()
call.
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.
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.
@virajjasani I think there is some confusion here. The aim of this Jira is to reduce the HBase calls to get the table. Currently, the call to writeMutexCell()
calls getSysMutexPhysicalTableNameBytes()
which does 1 or 2 HBase admin calls (tableExists()) and then we still do a getTable()
call here.
The same happens for deleteMutexCell()
.
Instead of calling getSysMutexPhysicalTableNameBytes()
, we can do 1 getTable()
call with SYSTEM.MUTEX
and if that throws a TNFE, try again with SYSTEM:MUTEX
thus eliminating the tableExists()
calls.
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.
My bad for this misunderstanding. Addressed concerns, updated the PR.
💔 -1 overall
This message was automatically generated. |
Test failures don't seem relevant, tried locally, all passed. Fixed checkstyle issues relevant to this PR. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@ChinmaySKulkarni IMHO we can not live without Admin.tableExists is the only thread safe way to identify if table already exists:
&
I checked implementation also, and getTable() internally uses We can do one improvement though, we can utilize same connection to perform both: tableExists() and getTable(). |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
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.
Added some comments. One generic question regarding your finding:
Connection.getTable() has no guarantee that it will throw TableNotFoundException if table doesn't exist.
CQSI.getTable() depends on HBaseFactoryProvider.getHTableFactory().getTable()
which internally also uses connection.getTable()
. As you can see from the CQSI.getTable() code, it tries to catch TableNotFoundException and probably expects one to be thrown if the table doesn't exist. As per your findings however, this is not guaranteed. This is a problem right? Do we need a separate Jira for this (if yes, can you please open one and mention your findings there)
phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
Show resolved
Hide resolved
} else if (admin.tableExists(TableName.valueOf( | ||
SchemaUtil.getPhysicalTableName(SYSTEM_MUTEX_NAME, props).getName()))) { | ||
sysMutexPhysicalTableNameBytes = SchemaUtil.getPhysicalTableName(SYSTEM_MUTEX_NAME, props).getName(); | ||
private Table getSysMutexTable() throws SQLException, IOException { |
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.
Please add a unit test for this new method.
phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
Show resolved
Hide resolved
@virajjasani please also make the commit message the same as the Jira (or update the Jira if you think this is more appropriate). |
@ChinmaySKulkarni I have addressed your comments, updated Jira message and created Jira PHOENIX-6203 for TNFE issue. Thanks for the review! |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@ChinmaySKulkarni please take a look when you get time. Failed tests are not relevant. |
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. Thanks for fixing this @virajjasani !
No description provided.