-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-28716: Users of QuotaRetriever should pass an existing connection (master) #6065
Changes from 1 commit
a247c98
dd42a14
80dd227
6caf25e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,7 @@ | |
import java.util.Iterator; | ||
import java.util.Objects; | ||
import java.util.Queue; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.client.Connection; | ||
import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
import org.apache.hadoop.hbase.client.Result; | ||
import org.apache.hadoop.hbase.client.ResultScanner; | ||
import org.apache.hadoop.hbase.client.Scan; | ||
|
@@ -52,21 +50,9 @@ public class QuotaRetriever implements Closeable, Iterable<QuotaSettings> { | |
private Connection connection; | ||
private Table table; | ||
|
||
/** | ||
* Should QutoaRetriever manage the state of the connection, or leave it be. | ||
*/ | ||
private boolean isManagedConnection = false; | ||
|
||
QuotaRetriever() { | ||
} | ||
|
||
void init(final Configuration conf, final Scan scan) throws IOException { | ||
// Set this before creating the connection and passing it down to make sure | ||
// it's cleaned up if we fail to construct the Scanner. | ||
this.isManagedConnection = true; | ||
init(ConnectionFactory.createConnection(conf), scan); | ||
} | ||
|
||
void init(final Connection conn, final Scan scan) throws IOException { | ||
this.connection = Objects.requireNonNull(conn); | ||
this.table = this.connection.getTable(QuotaTableUtil.QUOTA_TABLE_NAME); | ||
|
@@ -88,13 +74,8 @@ public void close() throws IOException { | |
this.table.close(); | ||
this.table = null; | ||
} | ||
// Null out the connection on close() even if we didn't explicitly close it | ||
// Null out the connection on close() even though we don't explicitly close it | ||
// to maintain typical semantics. | ||
if (isManagedConnection) { | ||
if (this.connection != null) { | ||
this.connection.close(); | ||
} | ||
} | ||
this.connection = null; | ||
} | ||
|
||
|
@@ -156,26 +137,26 @@ public void remove() { | |
|
||
/** | ||
* Open a QuotaRetriever with no filter, all the quota settings will be returned. | ||
* @param conf Configuration object to use. | ||
* @param conn Connection object to use. | ||
* @return the QuotaRetriever | ||
* @throws IOException if a remote or network exception occurs | ||
*/ | ||
public static QuotaRetriever open(final Configuration conf) throws IOException { | ||
return open(conf, null); | ||
public static QuotaRetriever open(final Connection conn) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is We document this in depth over on https://hbase.apache.org/book.html#hbase.versioning If we're going through the trouble to make breaking changes, let's push RAII and do away with the parameterless constructor + init method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for the deprecation cycle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since we're opening this worm-can, how about we get rid of these static constructor methods and use constructors like a normal object? |
||
return open(conn, null); | ||
} | ||
|
||
/** | ||
* Open a QuotaRetriever with the specified filter. | ||
* @param conf Configuration object to use. | ||
* Open a QuotaRetriever with the specified filter using an existing Connection | ||
* @param conn Connection object to use. | ||
* @param filter the QuotaFilter | ||
* @return the QuotaRetriever | ||
* @throws IOException if a remote or network exception occurs | ||
*/ | ||
public static QuotaRetriever open(final Configuration conf, final QuotaFilter filter) | ||
public static QuotaRetriever open(final Connection conn, final QuotaFilter filter) | ||
throws IOException { | ||
Scan scan = QuotaTableUtil.makeScan(filter); | ||
QuotaRetriever scanner = new QuotaRetriever(); | ||
scanner.init(conf, scan); | ||
scanner.init(conn, scan); | ||
return scanner; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ Multimap<TableName, String> getSnapshotsToComputeSize() throws IOException { | |
filter.addTypeFilter(QuotaType.SPACE); | ||
try (Admin admin = conn.getAdmin()) { | ||
// Pull all of the tables that have quotas (direct, or from namespace) | ||
for (QuotaSettings qs : QuotaRetriever.open(conf, filter)) { | ||
for (QuotaSettings qs : QuotaRetriever.open(conn, filter)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind also promoting uses of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, you got it! |
||
if (qs.getQuotaType() == QuotaType.SPACE) { | ||
String ns = qs.getNamespace(); | ||
TableName tn = qs.getTableName(); | ||
|
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.
What a weird API. This class is decorated as
IA.Public
but it's only created via these static factory method? Any what's with using the default constructor + aninit
method -- what happened to RAII ?’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.
Are non-public methods of an IA.Public class required to go through a deprecation cycle, or only public methods?
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.
Only public methods.
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.
Okay, then this PR is complying with the deprecation policy now