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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import static org
.junit
.Assert
.assertEquals
;
22 import java
.io
.IOException
;
23 import java
.util
.List
;
24 import org
.apache
.hadoop
.hbase
.TableName
;
25 import org
.apache
.hadoop
.hbase
.master
.RegionState
;
26 import org
.apache
.hadoop
.hbase
.master
.assignment
.RegionStates
;
27 import org
.apache
.hadoop
.hbase
.snapshot
.SnapshotTestingUtils
;
28 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
29 import org
.apache
.hadoop
.hbase
.util
.EnvironmentEdgeManager
;
30 import org
.junit
.Test
;
32 public class CloneSnapshotFromClientAfterSplittingRegionTestBase
33 extends CloneSnapshotFromClientTestBase
{
35 private void splitRegion(final RegionInfo regionInfo
) throws IOException
{
36 byte[][] splitPoints
= Bytes
.split(regionInfo
.getStartKey(), regionInfo
.getEndKey(), 1);
37 admin
.split(regionInfo
.getTable(), splitPoints
[1]);
41 public void testCloneSnapshotAfterSplittingRegion() throws IOException
, InterruptedException
{
42 // Turn off the CatalogJanitor
43 admin
.catalogJanitorSwitch(false);
46 List
<RegionInfo
> regionInfos
= admin
.getRegions(tableName
);
47 RegionReplicaUtil
.removeNonDefaultRegions(regionInfos
);
49 // Split the first region
50 splitRegion(regionInfos
.get(0));
53 admin
.snapshot(snapshotName2
, tableName
);
55 // Clone the snapshot to another table
56 TableName clonedTableName
=
57 TableName
.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager
.currentTime());
58 admin
.cloneSnapshot(snapshotName2
, clonedTableName
);
59 SnapshotTestingUtils
.waitForTableToBeOnline(TEST_UTIL
, clonedTableName
);
61 verifyRowCount(TEST_UTIL
, clonedTableName
, snapshot1Rows
);
63 RegionStates regionStates
=
64 TEST_UTIL
.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
66 // The region count of the cloned table should be the same as the one of the original table
67 int openRegionCountOfOriginalTable
=
68 regionStates
.getRegionByStateOfTable(tableName
).get(RegionState
.State
.OPEN
).size();
69 int openRegionCountOfClonedTable
=
70 regionStates
.getRegionByStateOfTable(clonedTableName
).get(RegionState
.State
.OPEN
).size();
71 assertEquals(openRegionCountOfOriginalTable
, openRegionCountOfClonedTable
);
73 int splitRegionCountOfOriginalTable
=
74 regionStates
.getRegionByStateOfTable(tableName
).get(RegionState
.State
.SPLIT
).size();
75 int splitRegionCountOfClonedTable
=
76 regionStates
.getRegionByStateOfTable(clonedTableName
).get(RegionState
.State
.SPLIT
).size();
77 assertEquals(splitRegionCountOfOriginalTable
, splitRegionCountOfClonedTable
);
79 TEST_UTIL
.deleteTable(clonedTableName
);
81 admin
.catalogJanitorSwitch(true);
86 public void testCloneSnapshotBeforeSplittingRegionAndDroppingTable()
87 throws IOException
, InterruptedException
{
88 // Turn off the CatalogJanitor
89 admin
.catalogJanitorSwitch(false);
93 admin
.snapshot(snapshotName2
, tableName
);
95 // Clone the snapshot to another table
96 TableName clonedTableName
=
97 TableName
.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager
.currentTime());
98 admin
.cloneSnapshot(snapshotName2
, clonedTableName
);
99 SnapshotTestingUtils
.waitForTableToBeOnline(TEST_UTIL
, clonedTableName
);
101 // Split the first region of the original table
102 List
<RegionInfo
> regionInfos
= admin
.getRegions(tableName
);
103 RegionReplicaUtil
.removeNonDefaultRegions(regionInfos
);
104 splitRegion(regionInfos
.get(0));
106 // Drop the original table
107 admin
.disableTable(tableName
);
108 admin
.deleteTable(tableName
);
110 // Disable and enable the cloned table. This should be successful
111 admin
.disableTable(clonedTableName
);
112 admin
.enableTable(clonedTableName
);
113 SnapshotTestingUtils
.waitForTableToBeOnline(TEST_UTIL
, clonedTableName
);
115 verifyRowCount(TEST_UTIL
, clonedTableName
, snapshot1Rows
);
117 admin
.catalogJanitorSwitch(true);