-
Notifications
You must be signed in to change notification settings - Fork 180
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
fix: dynamically load BigtableAdmin and BigtableAsyncAdmin #3341
Conversation
new AbstractBigtableAdmin.UnsupportedOperationsHandler())) | ||
.make() | ||
.load(BigtableAdmin.class.getClassLoader()) | ||
.getLoaded() |
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.
I dont think we should be defining a new class for every invocation. Instead I think it would be better to move the class definition to BigtableAdmin, something along the lines of:
abstract class BIgtableAdmin {
private static Class<? extends BigtableAdmin> classDefinition = null;
private static synchronized Class<? extends BigtableAdmin> getSubclass() {
if (classDefinition == null) {
// byte buddy...
}
return classDefinition;
}
public static Admin createInstance(Connection connection) {
return getSubclass().newInstance()...;
}
...arent/bigtable-hbase-2.x/src/main/java/com/google/cloud/bigtable/hbase2_x/BigtableAdmin.java
Outdated
Show resolved
Hide resolved
...arent/bigtable-hbase-1.x/src/main/java/com/google/cloud/bigtable/hbase1_x/BigtableAdmin.java
Show resolved
Hide resolved
asyncAdmin = new BigtableAsyncAdmin(connection); | ||
try { | ||
asyncAdmin = BigtableAsyncAdmin.createInstance(connection); | ||
} catch (Exception e) { |
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.
I dont think the try catch necessary here
|
||
private static Class<? extends BigtableAdmin> adminClass = null; | ||
|
||
private static synchronized Class<? extends BigtableAdmin> getSubclass() { |
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 docs explaining what this is doing and why its necessary
return new BigtableAsyncAdmin(BigtableAsyncConnection.this); | ||
} catch (IOException e) { | ||
return BigtableAsyncAdmin.createInstance(BigtableAsyncConnection.this); | ||
} catch (Exception e) { |
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.
Is try catch necessary here?
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.
lgtm
When upgrading hbase from 1.4.x to 1.7.x, hbase added a method in the interface which depends on
ServerType
class that only exists after 1.7.0 (https://github.com/googleapis/java-bigtable-hbase/pull/3270/files#diff-5ec033f24f0ec19af948a12e09d84d70f8d9342c098cdca7cb1f6c2f71fe399dR334). This breaks hbase shell that's running with an older version of hbase because hbase shell (which is written in ruby) will try to load all the methods and won't be able to load theServerType
class because it doesn't exist in an older version of hbase. The error message looks like:This pr tries to workaround this issue by dynamically loading BigtableAdmin and BigtableAsyncAdmin classes so the backward incompatible methods won't be accessed unless the methods are called.