Skip to content

Commit 1dcc8ee

Browse files
virajjasanianoopsjohn
authored andcommitted
HBASE-22760 : Pause/Resume/Query Snapshot Auto Cleanup Activity (#617)
1 parent c0908d4 commit 1dcc8ee

File tree

24 files changed

+737
-23
lines changed

24 files changed

+737
-23
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,4 +2232,26 @@ List<Boolean> hasUserPermissions(String userName, List<Permission> permissions)
22322232
default List<Boolean> hasUserPermissions(List<Permission> permissions) throws IOException {
22332233
return hasUserPermissions(null, permissions);
22342234
}
2235+
2236+
/**
2237+
* Turn on or off the auto snapshot cleanup based on TTL.
2238+
*
2239+
* @param on Set to <code>true</code> to enable, <code>false</code> to disable.
2240+
* @param synchronous If <code>true</code>, it waits until current snapshot cleanup is completed,
2241+
* if outstanding.
2242+
* @return Previous auto snapshot cleanup value
2243+
* @throws IOException if a remote or network exception occurs
2244+
*/
2245+
boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous)
2246+
throws IOException;
2247+
2248+
/**
2249+
* Query the current state of the auto snapshot cleanup based on TTL.
2250+
*
2251+
* @return <code>true</code> if the auto snapshot cleanup is enabled,
2252+
* <code>false</code> otherwise.
2253+
* @throws IOException if a remote or network exception occurs
2254+
*/
2255+
boolean isSnapshotCleanupEnabled() throws IOException;
2256+
22352257
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,4 +942,16 @@ public List<Boolean> hasUserPermissions(String userName, List<Permission> permis
942942
throws IOException {
943943
return get(admin.hasUserPermissions(userName, permissions));
944944
}
945+
946+
@Override
947+
public boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous)
948+
throws IOException {
949+
return get(admin.snapshotCleanupSwitch(on, synchronous));
950+
}
951+
952+
@Override
953+
public boolean isSnapshotCleanupEnabled() throws IOException {
954+
return get(admin.isSnapshotCleanupEnabled());
955+
}
956+
945957
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,4 +1484,27 @@ CompletableFuture<List<Boolean>> hasUserPermissions(String userName,
14841484
default CompletableFuture<List<Boolean>> hasUserPermissions(List<Permission> permissions) {
14851485
return hasUserPermissions(null, permissions);
14861486
}
1487+
1488+
/**
1489+
* Turn on or off the auto snapshot cleanup based on TTL.
1490+
* <p/>
1491+
* Notice that, the method itself is always non-blocking, which means it will always return
1492+
* immediately. The {@code sync} parameter only effects when will we complete the returned
1493+
* {@link CompletableFuture}.
1494+
*
1495+
* @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1496+
* @param sync If <code>true</code>, it waits until current snapshot cleanup is completed,
1497+
* if outstanding.
1498+
* @return Previous auto snapshot cleanup value wrapped by a {@link CompletableFuture}.
1499+
*/
1500+
CompletableFuture<Boolean> snapshotCleanupSwitch(boolean on, boolean sync);
1501+
1502+
/**
1503+
* Query the current state of the auto snapshot cleanup based on TTL.
1504+
*
1505+
* @return true if the auto snapshot cleanup is enabled, false otherwise.
1506+
* The return value will be wrapped by a {@link CompletableFuture}.
1507+
*/
1508+
CompletableFuture<Boolean> isSnapshotCleanupEnabled();
1509+
14871510
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,4 +826,16 @@ public CompletableFuture<List<Boolean>> hasUserPermissions(String userName,
826826
List<Permission> permissions) {
827827
return wrap(rawAdmin.hasUserPermissions(userName, permissions));
828828
}
829+
830+
@Override
831+
public CompletableFuture<Boolean> snapshotCleanupSwitch(final boolean on,
832+
final boolean sync) {
833+
return wrap(rawAdmin.snapshotCleanupSwitch(on, sync));
834+
}
835+
836+
@Override
837+
public CompletableFuture<Boolean> isSnapshotCleanupEnabled() {
838+
return wrap(rawAdmin.isSnapshotCleanupEnabled());
839+
}
840+
829841
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsProcedureDoneResponse;
207207
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsRpcThrottleEnabledRequest;
208208
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsRpcThrottleEnabledResponse;
209+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos
210+
.IsSnapshotCleanupEnabledResponse;
209211
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest;
210212
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse;
211213
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSplitOrMergeEnabledRequest;
@@ -256,6 +258,8 @@
256258
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetNormalizerRunningResponse;
257259
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetQuotaRequest;
258260
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetQuotaResponse;
261+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos
262+
.SetSnapshotCleanupResponse;
259263
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetSplitOrMergeEnabledRequest;
260264
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetSplitOrMergeEnabledResponse;
261265
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ShutdownRequest;
@@ -3856,4 +3860,28 @@ public CompletableFuture<List<Boolean>> hasUserPermissions(String userName,
38563860
resp -> resp.getHasUserPermissionList()))
38573861
.call();
38583862
}
3863+
3864+
@Override
3865+
public CompletableFuture<Boolean> snapshotCleanupSwitch(final boolean on,
3866+
final boolean sync) {
3867+
return this.<Boolean>newMasterCaller()
3868+
.action((controller, stub) -> this
3869+
.call(controller, stub,
3870+
RequestConverter.buildSetSnapshotCleanupRequest(on, sync),
3871+
MasterService.Interface::switchSnapshotCleanup,
3872+
SetSnapshotCleanupResponse::getPrevSnapshotCleanup))
3873+
.call();
3874+
}
3875+
3876+
@Override
3877+
public CompletableFuture<Boolean> isSnapshotCleanupEnabled() {
3878+
return this.<Boolean>newMasterCaller()
3879+
.action((controller, stub) -> this
3880+
.call(controller, stub,
3881+
RequestConverter.buildIsSnapshotCleanupEnabledRequest(),
3882+
MasterService.Interface::isSnapshotCleanupEnabled,
3883+
IsSnapshotCleanupEnabledResponse::getEnabled))
3884+
.call();
3885+
}
3886+
38593887
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsCleanerChoreEnabledRequest;
122122
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningRequest;
123123
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsNormalizerEnabledRequest;
124+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos
125+
.IsSnapshotCleanupEnabledRequest;
124126
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSplitOrMergeEnabledRequest;
125127
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MergeTableRegionsRequest;
126128
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyColumnRequest;
@@ -135,6 +137,8 @@
135137
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetBalancerRunningRequest;
136138
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetCleanerChoreRunningRequest;
137139
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetNormalizerRunningRequest;
140+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos
141+
.SetSnapshotCleanupRequest;
138142
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetSplitOrMergeEnabledRequest;
139143
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetTableStateInMetaRequest;
140144
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SplitTableRegionRequest;
@@ -1900,4 +1904,30 @@ private static List<RegionSpecifier> toEncodedRegionNameRegionSpecifiers(
19001904
map(r -> buildRegionSpecifier(RegionSpecifierType.ENCODED_REGION_NAME, Bytes.toBytes(r))).
19011905
collect(Collectors.toList());
19021906
}
1907+
1908+
/**
1909+
* Creates SetSnapshotCleanupRequest for turning on/off auto snapshot cleanup
1910+
*
1911+
* @param enabled Set to <code>true</code> to enable,
1912+
* <code>false</code> to disable.
1913+
* @param synchronous If <code>true</code>, it waits until current snapshot cleanup is completed,
1914+
* if outstanding.
1915+
* @return a SetSnapshotCleanupRequest
1916+
*/
1917+
public static SetSnapshotCleanupRequest buildSetSnapshotCleanupRequest(
1918+
final boolean enabled, final boolean synchronous) {
1919+
return SetSnapshotCleanupRequest.newBuilder().setEnabled(enabled).setSynchronous(synchronous)
1920+
.build();
1921+
}
1922+
1923+
/**
1924+
* Creates IsSnapshotCleanupEnabledRequest to determine if auto snapshot cleanup
1925+
* based on TTL expiration is turned on
1926+
*
1927+
* @return IsSnapshotCleanupEnabledRequest
1928+
*/
1929+
public static IsSnapshotCleanupEnabledRequest buildIsSnapshotCleanupEnabledRequest() {
1930+
return IsSnapshotCleanupEnabledRequest.newBuilder().build();
1931+
}
1932+
19031933
}

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class ZNodePaths {
4141
public static final char ZNODE_PATH_SEPARATOR = '/';
4242

4343
public final static String META_ZNODE_PREFIX = "meta-region-server";
44+
private static final String DEFAULT_SNAPSHOT_CLEANUP_ZNODE = "snapshot-cleanup";
4445

4546
// base znode for this cluster
4647
public final String baseZNode;
@@ -89,6 +90,8 @@ public class ZNodePaths {
8990
public final String queuesZNode;
9091
// znode containing queues of hfile references to be replicated
9192
public final String hfileRefsZNode;
93+
// znode containing the state of the snapshot auto-cleanup
94+
final String snapshotCleanupZNode;
9295

9396
public ZNodePaths(Configuration conf) {
9497
baseZNode = conf.get(ZOOKEEPER_ZNODE_PARENT, DEFAULT_ZOOKEEPER_ZNODE_PARENT);
@@ -123,20 +126,35 @@ public ZNodePaths(Configuration conf) {
123126
queuesZNode = joinZNode(replicationZNode, conf.get("zookeeper.znode.replication.rs", "rs"));
124127
hfileRefsZNode = joinZNode(replicationZNode,
125128
conf.get("zookeeper.znode.replication.hfile.refs", "hfile-refs"));
129+
snapshotCleanupZNode = joinZNode(baseZNode,
130+
conf.get("zookeeper.znode.snapshot.cleanup", DEFAULT_SNAPSHOT_CLEANUP_ZNODE));
126131
}
127132

128133
@Override
129134
public String toString() {
130-
return "ZNodePaths [baseZNode=" + baseZNode + ", metaReplicaZNodes=" + metaReplicaZNodes
131-
+ ", rsZNode=" + rsZNode + ", drainingZNode=" + drainingZNode + ", masterAddressZNode="
132-
+ masterAddressZNode + ", backupMasterAddressesZNode=" + backupMasterAddressesZNode
133-
+ ", clusterStateZNode=" + clusterStateZNode + ", tableZNode=" + tableZNode
134-
+ ", clusterIdZNode=" + clusterIdZNode + ", splitLogZNode=" + splitLogZNode
135-
+ ", balancerZNode=" + balancerZNode + ", regionNormalizerZNode=" + regionNormalizerZNode
136-
+ ", switchZNode=" + switchZNode + ", tableLockZNode=" + tableLockZNode
137-
+ ", namespaceZNode=" + namespaceZNode + ", masterMaintZNode=" + masterMaintZNode
138-
+ ", replicationZNode=" + replicationZNode + ", peersZNode=" + peersZNode
139-
+ ", queuesZNode=" + queuesZNode + ", hfileRefsZNode=" + hfileRefsZNode + "]";
135+
return new StringBuilder()
136+
.append("ZNodePaths [baseZNode=").append(baseZNode)
137+
.append(", metaReplicaZNodes=").append(metaReplicaZNodes)
138+
.append(", rsZNode=").append(rsZNode)
139+
.append(", drainingZNode=").append(drainingZNode)
140+
.append(", masterAddressZNode=").append(masterAddressZNode)
141+
.append(", backupMasterAddressesZNode=").append(backupMasterAddressesZNode)
142+
.append(", clusterStateZNode=").append(clusterStateZNode)
143+
.append(", tableZNode=").append(tableZNode)
144+
.append(", clusterIdZNode=").append(clusterIdZNode)
145+
.append(", splitLogZNode=").append(splitLogZNode)
146+
.append(", balancerZNode=").append(balancerZNode)
147+
.append(", regionNormalizerZNode=").append(regionNormalizerZNode)
148+
.append(", switchZNode=").append(switchZNode)
149+
.append(", tableLockZNode=").append(tableLockZNode)
150+
.append(", namespaceZNode=").append(namespaceZNode)
151+
.append(", masterMaintZNode=").append(masterMaintZNode)
152+
.append(", replicationZNode=").append(replicationZNode)
153+
.append(", peersZNode=").append(peersZNode)
154+
.append(", queuesZNode=").append(queuesZNode)
155+
.append(", hfileRefsZNode=").append(hfileRefsZNode)
156+
.append(", snapshotCleanupZNode=").append(snapshotCleanupZNode)
157+
.append("]").toString();
140158
}
141159

142160
/**

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
@@ -1471,8 +1471,6 @@ public enum OperationStatusCode {
14711471
// User defined Default TTL config key
14721472
public static final String DEFAULT_SNAPSHOT_TTL_CONFIG_KEY = "hbase.master.snapshot.ttl";
14731473

1474-
public static final String SNAPSHOT_CLEANER_DISABLE = "hbase.master.cleaner.snapshot.disable";
1475-
14761474
/**
14771475
* Configurations for master executor services.
14781476
*/

hbase-protocol-shaded/src/main/protobuf/Master.proto

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,22 @@ enum MasterSwitchType {
318318
MERGE = 1;
319319
}
320320

321+
message SetSnapshotCleanupRequest {
322+
required bool enabled = 1;
323+
optional bool synchronous = 2;
324+
}
325+
326+
message SetSnapshotCleanupResponse {
327+
required bool prev_snapshot_cleanup = 1;
328+
}
329+
330+
message IsSnapshotCleanupEnabledRequest {
331+
}
332+
333+
message IsSnapshotCleanupEnabledResponse {
334+
required bool enabled = 1;
335+
}
336+
321337
message SetSplitOrMergeEnabledRequest {
322338
required bool enabled = 1;
323339
optional bool synchronous = 2;
@@ -896,6 +912,18 @@ service MasterService {
896912
*/
897913
rpc RestoreSnapshot(RestoreSnapshotRequest) returns(RestoreSnapshotResponse);
898914

915+
/**
916+
* Turn on/off snapshot auto-cleanup based on TTL expiration
917+
*/
918+
rpc SwitchSnapshotCleanup (SetSnapshotCleanupRequest)
919+
returns (SetSnapshotCleanupResponse);
920+
921+
/**
922+
* Determine if snapshot auto-cleanup based on TTL expiration is turned on
923+
*/
924+
rpc IsSnapshotCleanupEnabled (IsSnapshotCleanupEnabledRequest)
925+
returns (IsSnapshotCleanupEnabledResponse);
926+
899927
/**
900928
* Execute a distributed procedure.
901929
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
syntax = "proto2";
20+
21+
// This file contains protocol buffers to represent the state of the snapshot auto cleanup based on TTL
22+
package hbase.pb;
23+
24+
option java_package = "org.apache.hadoop.hbase.shaded.protobuf.generated";
25+
option java_outer_classname = "SnapshotCleanupProtos";
26+
option java_generate_equals_and_hash = true;
27+
option optimize_for = SPEED;
28+
29+
message SnapshotCleanupState {
30+
required bool snapshot_cleanup_enabled = 1;
31+
}

0 commit comments

Comments
 (0)