Skip to content

Commit 72ea366

Browse files
virajjasanianoopsjohn
authored andcommitted
HBASE-22760 : Pause/Resume/Query Snapshot Auto Cleanup Activity (#619)
1 parent de9b1d4 commit 72ea366

File tree

23 files changed

+3278
-159
lines changed

23 files changed

+3278
-159
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,4 +1658,28 @@ public enum MasterSwitchType {
16581658
* @return List of servers that not cleared
16591659
*/
16601660
List<ServerName> clearDeadServers(final List<ServerName> servers) throws IOException;
1661+
1662+
1663+
/**
1664+
* Turn on or off the auto snapshot cleanup based on TTL.
1665+
*
1666+
* @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1667+
* @param synchronous If <code>true</code>, it waits until current snapshot cleanup is completed,
1668+
* if outstanding.
1669+
* @return Previous auto snapshot cleanup value
1670+
* @throws IOException if a remote or network exception occurs
1671+
*/
1672+
boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous)
1673+
throws IOException;
1674+
1675+
/**
1676+
* Query the current state of the auto snapshot cleanup based on TTL.
1677+
*
1678+
* @return <code>true</code> if the auto snapshot cleanup is enabled,
1679+
* <code>false</code> otherwise.
1680+
* @throws IOException if a remote or network exception occurs
1681+
*/
1682+
boolean isSnapshotCleanupEnabled() throws IOException;
1683+
1684+
16611685
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,20 @@ public ListNamespacesResponse listNamespaces(RpcController controller,
21322132
return stub.listNamespaces(controller, request);
21332133
}
21342134

2135+
@Override
2136+
public MasterProtos.SetSnapshotCleanupResponse switchSnapshotCleanup(
2137+
RpcController controller, MasterProtos.SetSnapshotCleanupRequest request)
2138+
throws ServiceException {
2139+
return stub.switchSnapshotCleanup(controller, request);
2140+
}
2141+
2142+
@Override
2143+
public MasterProtos.IsSnapshotCleanupEnabledResponse isSnapshotCleanupEnabled(
2144+
RpcController controller, MasterProtos.IsSnapshotCleanupEnabledRequest request)
2145+
throws ServiceException {
2146+
return stub.isSnapshotCleanupEnabled(controller, request);
2147+
}
2148+
21352149
@Override
21362150
public ListNamespaceDescriptorsResponse listNamespaceDescriptors(RpcController controller,
21372151
ListNamespaceDescriptorsRequest request) throws ServiceException {

hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsProcedureDoneResponse;
137137
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsRestoreSnapshotDoneRequest;
138138
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsRestoreSnapshotDoneResponse;
139+
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSnapshotCleanupEnabledRequest;
139140
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSnapshotDoneRequest;
140141
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSnapshotDoneResponse;
141142
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest;
@@ -154,6 +155,7 @@
154155
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SecurityCapabilitiesRequest;
155156
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetBalancerRunningRequest;
156157
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetNormalizerRunningRequest;
158+
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetSnapshotCleanupRequest;
157159
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ShutdownRequest;
158160
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SnapshotRequest;
159161
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SnapshotResponse;
@@ -5053,4 +5055,38 @@ public List<ServerName> call(int callTimeout) throws Exception {
50535055
private RpcControllerFactory getRpcControllerFactory() {
50545056
return rpcControllerFactory;
50555057
}
5058+
5059+
@Override
5060+
public boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous)
5061+
throws IOException {
5062+
return executeCallable(new MasterCallable<Boolean>(getConnection()) {
5063+
5064+
@Override
5065+
public Boolean call(int callTimeout) throws Exception {
5066+
HBaseRpcController controller = rpcControllerFactory.newController();
5067+
controller.setCallTimeout(callTimeout);
5068+
SetSnapshotCleanupRequest req =
5069+
RequestConverter.buildSetSnapshotCleanupRequest(on, synchronous);
5070+
return master.switchSnapshotCleanup(controller, req).getPrevSnapshotCleanup();
5071+
}
5072+
});
5073+
5074+
}
5075+
5076+
@Override
5077+
public boolean isSnapshotCleanupEnabled() throws IOException {
5078+
return executeCallable(new MasterCallable<Boolean>(getConnection()) {
5079+
5080+
@Override
5081+
public Boolean call(int callTimeout) throws Exception {
5082+
HBaseRpcController controller = rpcControllerFactory.newController();
5083+
controller.setCallTimeout(callTimeout);
5084+
IsSnapshotCleanupEnabledRequest req =
5085+
RequestConverter.buildIsSnapshotCleanupEnabledRequest();
5086+
return master.isSnapshotCleanupEnabled(controller, req).getEnabled();
5087+
}
5088+
});
5089+
5090+
}
5091+
50565092
}

hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsCleanerChoreEnabledRequest;
101101
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
102102
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsNormalizerEnabledRequest;
103+
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos
104+
.IsSnapshotCleanupEnabledRequest;
103105
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSplitOrMergeEnabledRequest;
104106
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyColumnRequest;
105107
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyTableRequest;
@@ -110,6 +112,7 @@
110112
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.RunCleanerChoreRequest;
111113
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetBalancerRunningRequest;
112114
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetNormalizerRunningRequest;
115+
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetSnapshotCleanupRequest;
113116
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetSplitOrMergeEnabledRequest;
114117
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.TruncateTableRequest;
115118
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.UnassignRegionRequest;
@@ -1830,4 +1833,31 @@ private static MasterProtos.MasterSwitchType convert(Admin.MasterSwitchType swit
18301833
}
18311834
throw new UnsupportedOperationException("Unsupport switch type:" + switchType);
18321835
}
1836+
1837+
1838+
/**
1839+
* Creates SetSnapshotCleanupRequest for turning on/off auto snapshot cleanup
1840+
*
1841+
* @param enabled Set to <code>true</code> to enable,
1842+
* <code>false</code> to disable.
1843+
* @param synchronous If <code>true</code>, it waits until current snapshot cleanup is completed,
1844+
* if outstanding.
1845+
* @return a SetSnapshotCleanupRequest
1846+
*/
1847+
public static SetSnapshotCleanupRequest buildSetSnapshotCleanupRequest(
1848+
final boolean enabled, final boolean synchronous) {
1849+
return SetSnapshotCleanupRequest.newBuilder().setEnabled(enabled).setSynchronous(synchronous)
1850+
.build();
1851+
}
1852+
1853+
/**
1854+
* Creates IsSnapshotCleanupEnabledRequest to determine if auto snapshot cleanup
1855+
* based on TTL expiration is turned on
1856+
*
1857+
* @return IsSnapshotCleanupEnabledRequest
1858+
*/
1859+
public static IsSnapshotCleanupEnabledRequest buildIsSnapshotCleanupEnabledRequest() {
1860+
return IsSnapshotCleanupEnabledRequest.newBuilder().build();
1861+
}
1862+
18331863
}

hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
122122
private String switchZNode;
123123
// znode containing the lock for the tables
124124
public String tableLockZNode;
125+
// znode containing the state of the snapshot auto-cleanup
126+
String snapshotCleanupZNode;
125127
// znode containing the state of recovering regions
126128
public String recoveringRegionsZNode;
127129
// znode containing namespace descriptors
@@ -137,6 +139,7 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
137139
}};
138140

139141
public final static String META_ZNODE_PREFIX = "meta-region-server";
142+
private static final String DEFAULT_SNAPSHOT_CLEANUP_ZNODE = "snapshot-cleanup";
140143

141144
private final Configuration conf;
142145

@@ -456,6 +459,8 @@ private void setNodeNames(Configuration conf) {
456459
switchZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.switch", "switch"));
457460
tableLockZNode = ZKUtil.joinZNode(baseZNode,
458461
conf.get("zookeeper.znode.tableLock", "table-lock"));
462+
snapshotCleanupZNode = ZKUtil.joinZNode(baseZNode,
463+
conf.get("zookeeper.znode.snapshot.cleanup", DEFAULT_SNAPSHOT_CLEANUP_ZNODE));
459464
recoveringRegionsZNode = ZKUtil.joinZNode(baseZNode,
460465
conf.get("zookeeper.znode.recovering.regions", "recovering-regions"));
461466
namespaceZNode = ZKUtil.joinZNode(baseZNode,

hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,6 @@ public static enum Modify {
13381338
// User defined Default TTL config key
13391339
public static final String DEFAULT_SNAPSHOT_TTL_CONFIG_KEY = "hbase.master.snapshot.ttl";
13401340

1341-
public static final String SNAPSHOT_CLEANER_DISABLE = "hbase.master.cleaner.snapshot.disable";
1342-
13431341
/**
13441342
* Configurations for master executor services.
13451343
*/

hbase-protocol/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<include>RSGroupAdmin.proto</include>
200200
<include>SecureBulkLoad.proto</include>
201201
<include>Snapshot.proto</include>
202+
<include>SnapshotCleanup.proto</include>
202203
<include>Table.proto</include>
203204
<include>Tracing.proto</include>
204205
<include>VisibilityLabels.proto</include>

0 commit comments

Comments
 (0)