http://git-wip-us.apache.org/repos/asf/hbase-site/blob/ac54a6a8/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html ---------------------------------------------------------------------- diff --git a/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html b/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html index e8af18d..5a1361f 100644 --- a/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html +++ b/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html @@ -2643,1491 +2643,1490 @@ <span class="sourceLineNo">2635</span> * Expire a region server's session<a name="line.2635"></a> <span class="sourceLineNo">2636</span> * @param index which RS<a name="line.2636"></a> <span class="sourceLineNo">2637</span> */<a name="line.2637"></a> -<span class="sourceLineNo">2638</span> public HRegionServer expireRegionServerSession(int index) throws Exception {<a name="line.2638"></a> +<span class="sourceLineNo">2638</span> public void expireRegionServerSession(int index) throws Exception {<a name="line.2638"></a> <span class="sourceLineNo">2639</span> HRegionServer rs = getMiniHBaseCluster().getRegionServer(index);<a name="line.2639"></a> <span class="sourceLineNo">2640</span> expireSession(rs.getZooKeeper(), false);<a name="line.2640"></a> <span class="sourceLineNo">2641</span> decrementMinRegionServerCount();<a name="line.2641"></a> -<span class="sourceLineNo">2642</span> return rs;<a name="line.2642"></a> -<span class="sourceLineNo">2643</span> }<a name="line.2643"></a> -<span class="sourceLineNo">2644</span><a name="line.2644"></a> -<span class="sourceLineNo">2645</span> private void decrementMinRegionServerCount() {<a name="line.2645"></a> -<span class="sourceLineNo">2646</span> // decrement the count for this.conf, for newly spwaned master<a name="line.2646"></a> -<span class="sourceLineNo">2647</span> // this.hbaseCluster shares this configuration too<a name="line.2647"></a> -<span class="sourceLineNo">2648</span> decrementMinRegionServerCount(getConfiguration());<a name="line.2648"></a> -<span class="sourceLineNo">2649</span><a name="line.2649"></a> -<span class="sourceLineNo">2650</span> // each master thread keeps a copy of configuration<a name="line.2650"></a> -<span class="sourceLineNo">2651</span> for (MasterThread master : getHBaseCluster().getMasterThreads()) {<a name="line.2651"></a> -<span class="sourceLineNo">2652</span> decrementMinRegionServerCount(master.getMaster().getConfiguration());<a name="line.2652"></a> -<span class="sourceLineNo">2653</span> }<a name="line.2653"></a> -<span class="sourceLineNo">2654</span> }<a name="line.2654"></a> -<span class="sourceLineNo">2655</span><a name="line.2655"></a> -<span class="sourceLineNo">2656</span> private void decrementMinRegionServerCount(Configuration conf) {<a name="line.2656"></a> -<span class="sourceLineNo">2657</span> int currentCount = conf.getInt(<a name="line.2657"></a> -<span class="sourceLineNo">2658</span> ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1);<a name="line.2658"></a> -<span class="sourceLineNo">2659</span> if (currentCount != -1) {<a name="line.2659"></a> -<span class="sourceLineNo">2660</span> conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,<a name="line.2660"></a> -<span class="sourceLineNo">2661</span> Math.max(currentCount - 1, 1));<a name="line.2661"></a> -<span class="sourceLineNo">2662</span> }<a name="line.2662"></a> -<span class="sourceLineNo">2663</span> }<a name="line.2663"></a> -<span class="sourceLineNo">2664</span><a name="line.2664"></a> -<span class="sourceLineNo">2665</span> public void expireSession(ZKWatcher nodeZK) throws Exception {<a name="line.2665"></a> -<span class="sourceLineNo">2666</span> expireSession(nodeZK, false);<a name="line.2666"></a> -<span class="sourceLineNo">2667</span> }<a name="line.2667"></a> -<span class="sourceLineNo">2668</span><a name="line.2668"></a> -<span class="sourceLineNo">2669</span> /**<a name="line.2669"></a> -<span class="sourceLineNo">2670</span> * Expire a ZooKeeper session as recommended in ZooKeeper documentation<a name="line.2670"></a> -<span class="sourceLineNo">2671</span> * http://hbase.apache.org/book.html#trouble.zookeeper<a name="line.2671"></a> -<span class="sourceLineNo">2672</span> * There are issues when doing this:<a name="line.2672"></a> -<span class="sourceLineNo">2673</span> * [1] http://www.mail-archive.com/dev@zookeeper.apache.org/msg01942.html<a name="line.2673"></a> -<span class="sourceLineNo">2674</span> * [2] https://issues.apache.org/jira/browse/ZOOKEEPER-1105<a name="line.2674"></a> -<span class="sourceLineNo">2675</span> *<a name="line.2675"></a> -<span class="sourceLineNo">2676</span> * @param nodeZK - the ZK watcher to expire<a name="line.2676"></a> -<span class="sourceLineNo">2677</span> * @param checkStatus - true to check if we can create a Table with the<a name="line.2677"></a> -<span class="sourceLineNo">2678</span> * current configuration.<a name="line.2678"></a> -<span class="sourceLineNo">2679</span> */<a name="line.2679"></a> -<span class="sourceLineNo">2680</span> public void expireSession(ZKWatcher nodeZK, boolean checkStatus)<a name="line.2680"></a> -<span class="sourceLineNo">2681</span> throws Exception {<a name="line.2681"></a> -<span class="sourceLineNo">2682</span> Configuration c = new Configuration(this.conf);<a name="line.2682"></a> -<span class="sourceLineNo">2683</span> String quorumServers = ZKConfig.getZKQuorumServersString(c);<a name="line.2683"></a> -<span class="sourceLineNo">2684</span> ZooKeeper zk = nodeZK.getRecoverableZooKeeper().getZooKeeper();<a name="line.2684"></a> -<span class="sourceLineNo">2685</span> byte[] password = zk.getSessionPasswd();<a name="line.2685"></a> -<span class="sourceLineNo">2686</span> long sessionID = zk.getSessionId();<a name="line.2686"></a> -<span class="sourceLineNo">2687</span><a name="line.2687"></a> -<span class="sourceLineNo">2688</span> // Expiry seems to be asynchronous (see comment from P. Hunt in [1]),<a name="line.2688"></a> -<span class="sourceLineNo">2689</span> // so we create a first watcher to be sure that the<a name="line.2689"></a> -<span class="sourceLineNo">2690</span> // event was sent. We expect that if our watcher receives the event<a name="line.2690"></a> -<span class="sourceLineNo">2691</span> // other watchers on the same machine will get is as well.<a name="line.2691"></a> -<span class="sourceLineNo">2692</span> // When we ask to close the connection, ZK does not close it before<a name="line.2692"></a> -<span class="sourceLineNo">2693</span> // we receive all the events, so don't have to capture the event, just<a name="line.2693"></a> -<span class="sourceLineNo">2694</span> // closing the connection should be enough.<a name="line.2694"></a> -<span class="sourceLineNo">2695</span> ZooKeeper monitor = new ZooKeeper(quorumServers,<a name="line.2695"></a> -<span class="sourceLineNo">2696</span> 1000, new org.apache.zookeeper.Watcher(){<a name="line.2696"></a> -<span class="sourceLineNo">2697</span> @Override<a name="line.2697"></a> -<span class="sourceLineNo">2698</span> public void process(WatchedEvent watchedEvent) {<a name="line.2698"></a> -<span class="sourceLineNo">2699</span> LOG.info("Monitor ZKW received event="+watchedEvent);<a name="line.2699"></a> -<span class="sourceLineNo">2700</span> }<a name="line.2700"></a> -<span class="sourceLineNo">2701</span> } , sessionID, password);<a name="line.2701"></a> -<span class="sourceLineNo">2702</span><a name="line.2702"></a> -<span class="sourceLineNo">2703</span> // Making it expire<a name="line.2703"></a> -<span class="sourceLineNo">2704</span> ZooKeeper newZK = new ZooKeeper(quorumServers,<a name="line.2704"></a> -<span class="sourceLineNo">2705</span> 1000, EmptyWatcher.instance, sessionID, password);<a name="line.2705"></a> -<span class="sourceLineNo">2706</span><a name="line.2706"></a> -<span class="sourceLineNo">2707</span> //ensure that we have connection to the server before closing down, otherwise<a name="line.2707"></a> -<span class="sourceLineNo">2708</span> //the close session event will be eaten out before we start CONNECTING state<a name="line.2708"></a> -<span class="sourceLineNo">2709</span> long start = System.currentTimeMillis();<a name="line.2709"></a> -<span class="sourceLineNo">2710</span> while (newZK.getState() != States.CONNECTED<a name="line.2710"></a> -<span class="sourceLineNo">2711</span> && System.currentTimeMillis() - start < 1000) {<a name="line.2711"></a> -<span class="sourceLineNo">2712</span> Thread.sleep(1);<a name="line.2712"></a> -<span class="sourceLineNo">2713</span> }<a name="line.2713"></a> -<span class="sourceLineNo">2714</span> newZK.close();<a name="line.2714"></a> -<span class="sourceLineNo">2715</span> LOG.info("ZK Closed Session 0x" + Long.toHexString(sessionID));<a name="line.2715"></a> -<span class="sourceLineNo">2716</span><a name="line.2716"></a> -<span class="sourceLineNo">2717</span> // Now closing & waiting to be sure that the clients get it.<a name="line.2717"></a> -<span class="sourceLineNo">2718</span> monitor.close();<a name="line.2718"></a> -<span class="sourceLineNo">2719</span><a name="line.2719"></a> -<span class="sourceLineNo">2720</span> if (checkStatus) {<a name="line.2720"></a> -<span class="sourceLineNo">2721</span> getConnection().getTable(TableName.META_TABLE_NAME).close();<a name="line.2721"></a> -<span class="sourceLineNo">2722</span> }<a name="line.2722"></a> -<span class="sourceLineNo">2723</span> }<a name="line.2723"></a> -<span class="sourceLineNo">2724</span><a name="line.2724"></a> -<span class="sourceLineNo">2725</span> /**<a name="line.2725"></a> -<span class="sourceLineNo">2726</span> * Get the Mini HBase cluster.<a name="line.2726"></a> -<span class="sourceLineNo">2727</span> *<a name="line.2727"></a> -<span class="sourceLineNo">2728</span> * @return hbase cluster<a name="line.2728"></a> -<span class="sourceLineNo">2729</span> * @see #getHBaseClusterInterface()<a name="line.2729"></a> -<span class="sourceLineNo">2730</span> */<a name="line.2730"></a> -<span class="sourceLineNo">2731</span> public MiniHBaseCluster getHBaseCluster() {<a name="line.2731"></a> -<span class="sourceLineNo">2732</span> return getMiniHBaseCluster();<a name="line.2732"></a> -<span class="sourceLineNo">2733</span> }<a name="line.2733"></a> -<span class="sourceLineNo">2734</span><a name="line.2734"></a> -<span class="sourceLineNo">2735</span> /**<a name="line.2735"></a> -<span class="sourceLineNo">2736</span> * Returns the HBaseCluster instance.<a name="line.2736"></a> -<span class="sourceLineNo">2737</span> * <p>Returned object can be any of the subclasses of HBaseCluster, and the<a name="line.2737"></a> -<span class="sourceLineNo">2738</span> * tests referring this should not assume that the cluster is a mini cluster or a<a name="line.2738"></a> -<span class="sourceLineNo">2739</span> * distributed one. If the test only works on a mini cluster, then specific<a name="line.2739"></a> -<span class="sourceLineNo">2740</span> * method {@link #getMiniHBaseCluster()} can be used instead w/o the<a name="line.2740"></a> -<span class="sourceLineNo">2741</span> * need to type-cast.<a name="line.2741"></a> -<span class="sourceLineNo">2742</span> */<a name="line.2742"></a> -<span class="sourceLineNo">2743</span> public HBaseCluster getHBaseClusterInterface() {<a name="line.2743"></a> -<span class="sourceLineNo">2744</span> //implementation note: we should rename this method as #getHBaseCluster(),<a name="line.2744"></a> -<span class="sourceLineNo">2745</span> //but this would require refactoring 90+ calls.<a name="line.2745"></a> -<span class="sourceLineNo">2746</span> return hbaseCluster;<a name="line.2746"></a> -<span class="sourceLineNo">2747</span> }<a name="line.2747"></a> -<span class="sourceLineNo">2748</span><a name="line.2748"></a> -<span class="sourceLineNo">2749</span> /**<a name="line.2749"></a> -<span class="sourceLineNo">2750</span> * Get a Connection to the cluster.<a name="line.2750"></a> -<span class="sourceLineNo">2751</span> * Not thread-safe (This class needs a lot of work to make it thread-safe).<a name="line.2751"></a> -<span class="sourceLineNo">2752</span> * @return A Connection that can be shared. Don't close. Will be closed on shutdown of cluster.<a name="line.2752"></a> -<span class="sourceLineNo">2753</span> * @throws IOException<a name="line.2753"></a> -<span class="sourceLineNo">2754</span> */<a name="line.2754"></a> -<span class="sourceLineNo">2755</span> public Connection getConnection() throws IOException {<a name="line.2755"></a> -<span class="sourceLineNo">2756</span> if (this.connection == null) {<a name="line.2756"></a> -<span class="sourceLineNo">2757</span> this.connection = ConnectionFactory.createConnection(this.conf);<a name="line.2757"></a> -<span class="sourceLineNo">2758</span> }<a name="line.2758"></a> -<span class="sourceLineNo">2759</span> return this.connection;<a name="line.2759"></a> -<span class="sourceLineNo">2760</span> }<a name="line.2760"></a> -<span class="sourceLineNo">2761</span><a name="line.2761"></a> -<span class="sourceLineNo">2762</span> /**<a name="line.2762"></a> -<span class="sourceLineNo">2763</span> * Returns a Admin instance.<a name="line.2763"></a> -<span class="sourceLineNo">2764</span> * This instance is shared between HBaseTestingUtility instance users. Closing it has no effect,<a name="line.2764"></a> -<span class="sourceLineNo">2765</span> * it will be closed automatically when the cluster shutdowns<a name="line.2765"></a> -<span class="sourceLineNo">2766</span> *<a name="line.2766"></a> -<span class="sourceLineNo">2767</span> * @return HBaseAdmin instance which is guaranteed to support only {@link Admin} interface.<a name="line.2767"></a> -<span class="sourceLineNo">2768</span> * Functions in HBaseAdmin not provided by {@link Admin} interface can be changed/deleted<a name="line.2768"></a> -<span class="sourceLineNo">2769</span> * anytime.<a name="line.2769"></a> -<span class="sourceLineNo">2770</span> * @deprecated Since 2.0. Will be removed in 3.0. Use {@link #getAdmin()} instead.<a name="line.2770"></a> -<span class="sourceLineNo">2771</span> */<a name="line.2771"></a> -<span class="sourceLineNo">2772</span> @Deprecated<a name="line.2772"></a> -<span class="sourceLineNo">2773</span> public synchronized HBaseAdmin getHBaseAdmin()<a name="line.2773"></a> -<span class="sourceLineNo">2774</span> throws IOException {<a name="line.2774"></a> -<span class="sourceLineNo">2775</span> if (hbaseAdmin == null){<a name="line.2775"></a> -<span class="sourceLineNo">2776</span> this.hbaseAdmin = (HBaseAdmin) getConnection().getAdmin();<a name="line.2776"></a> -<span class="sourceLineNo">2777</span> }<a name="line.2777"></a> -<span class="sourceLineNo">2778</span> return hbaseAdmin;<a name="line.2778"></a> -<span class="sourceLineNo">2779</span> }<a name="line.2779"></a> -<span class="sourceLineNo">2780</span><a name="line.2780"></a> -<span class="sourceLineNo">2781</span> /**<a name="line.2781"></a> -<span class="sourceLineNo">2782</span> * Returns an Admin instance which is shared between HBaseTestingUtility instance users.<a name="line.2782"></a> -<span class="sourceLineNo">2783</span> * Closing it has no effect, it will be closed automatically when the cluster shutdowns<a name="line.2783"></a> -<span class="sourceLineNo">2784</span> */<a name="line.2784"></a> -<span class="sourceLineNo">2785</span> public synchronized Admin getAdmin() throws IOException {<a name="line.2785"></a> -<span class="sourceLineNo">2786</span> if (hbaseAdmin == null){<a name="line.2786"></a> -<span class="sourceLineNo">2787</span> this.hbaseAdmin = (HBaseAdmin) getConnection().getAdmin();<a name="line.2787"></a> -<span class="sourceLineNo">2788</span> }<a name="line.2788"></a> -<span class="sourceLineNo">2789</span> return hbaseAdmin;<a name="line.2789"></a> -<span class="sourceLineNo">2790</span> }<a name="line.2790"></a> -<span class="sourceLineNo">2791</span><a name="line.2791"></a> -<span class="sourceLineNo">2792</span> private HBaseAdmin hbaseAdmin = null;<a name="line.2792"></a> +<span class="sourceLineNo">2642</span> }<a name="line.2642"></a> +<span class="sourceLineNo">2643</span><a name="line.2643"></a> +<span class="sourceLineNo">2644</span> private void decrementMinRegionServerCount() {<a name="line.2644"></a> +<span class="sourceLineNo">2645</span> // decrement the count for this.conf, for newly spwaned master<a name="line.2645"></a> +<span class="sourceLineNo">2646</span> // this.hbaseCluster shares this configuration too<a name="line.2646"></a> +<span class="sourceLineNo">2647</span> decrementMinRegionServerCount(getConfiguration());<a name="line.2647"></a> +<span class="sourceLineNo">2648</span><a name="line.2648"></a> +<span class="sourceLineNo">2649</span> // each master thread keeps a copy of configuration<a name="line.2649"></a> +<span class="sourceLineNo">2650</span> for (MasterThread master : getHBaseCluster().getMasterThreads()) {<a name="line.2650"></a> +<span class="sourceLineNo">2651</span> decrementMinRegionServerCount(master.getMaster().getConfiguration());<a name="line.2651"></a> +<span class="sourceLineNo">2652</span> }<a name="line.2652"></a> +<span class="sourceLineNo">2653</span> }<a name="line.2653"></a> +<span class="sourceLineNo">2654</span><a name="line.2654"></a> +<span class="sourceLineNo">2655</span> private void decrementMinRegionServerCount(Configuration conf) {<a name="line.2655"></a> +<span class="sourceLineNo">2656</span> int currentCount = conf.getInt(<a name="line.2656"></a> +<span class="sourceLineNo">2657</span> ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1);<a name="line.2657"></a> +<span class="sourceLineNo">2658</span> if (currentCount != -1) {<a name="line.2658"></a> +<span class="sourceLineNo">2659</span> conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,<a name="line.2659"></a> +<span class="sourceLineNo">2660</span> Math.max(currentCount - 1, 1));<a name="line.2660"></a> +<span class="sourceLineNo">2661</span> }<a name="line.2661"></a> +<span class="sourceLineNo">2662</span> }<a name="line.2662"></a> +<span class="sourceLineNo">2663</span><a name="line.2663"></a> +<span class="sourceLineNo">2664</span> public void expireSession(ZKWatcher nodeZK) throws Exception {<a name="line.2664"></a> +<span class="sourceLineNo">2665</span> expireSession(nodeZK, false);<a name="line.2665"></a> +<span class="sourceLineNo">2666</span> }<a name="line.2666"></a> +<span class="sourceLineNo">2667</span><a name="line.2667"></a> +<span class="sourceLineNo">2668</span> /**<a name="line.2668"></a> +<span class="sourceLineNo">2669</span> * Expire a ZooKeeper session as recommended in ZooKeeper documentation<a name="line.2669"></a> +<span class="sourceLineNo">2670</span> * http://hbase.apache.org/book.html#trouble.zookeeper<a name="line.2670"></a> +<span class="sourceLineNo">2671</span> * There are issues when doing this:<a name="line.2671"></a> +<span class="sourceLineNo">2672</span> * [1] http://www.mail-archive.com/dev@zookeeper.apache.org/msg01942.html<a name="line.2672"></a> +<span class="sourceLineNo">2673</span> * [2] https://issues.apache.org/jira/browse/ZOOKEEPER-1105<a name="line.2673"></a> +<span class="sourceLineNo">2674</span> *<a name="line.2674"></a> +<span class="sourceLineNo">2675</span> * @param nodeZK - the ZK watcher to expire<a name="line.2675"></a> +<span class="sourceLineNo">2676</span> * @param checkStatus - true to check if we can create a Table with the<a name="line.2676"></a> +<span class="sourceLineNo">2677</span> * current configuration.<a name="line.2677"></a> +<span class="sourceLineNo">2678</span> */<a name="line.2678"></a> +<span class="sourceLineNo">2679</span> public void expireSession(ZKWatcher nodeZK, boolean checkStatus)<a name="line.2679"></a> +<span class="sourceLineNo">2680</span> throws Exception {<a name="line.2680"></a> +<span class="sourceLineNo">2681</span> Configuration c = new Configuration(this.conf);<a name="line.2681"></a> +<span class="sourceLineNo">2682</span> String quorumServers = ZKConfig.getZKQuorumServersString(c);<a name="line.2682"></a> +<span class="sourceLineNo">2683</span> ZooKeeper zk = nodeZK.getRecoverableZooKeeper().getZooKeeper();<a name="line.2683"></a> +<span class="sourceLineNo">2684</span> byte[] password = zk.getSessionPasswd();<a name="line.2684"></a> +<span class="sourceLineNo">2685</span> long sessionID = zk.getSessionId();<a name="line.2685"></a> +<span class="sourceLineNo">2686</span><a name="line.2686"></a> +<span class="sourceLineNo">2687</span> // Expiry seems to be asynchronous (see comment from P. Hunt in [1]),<a name="line.2687"></a> +<span class="sourceLineNo">2688</span> // so we create a first watcher to be sure that the<a name="line.2688"></a> +<span class="sourceLineNo">2689</span> // event was sent. We expect that if our watcher receives the event<a name="line.2689"></a> +<span class="sourceLineNo">2690</span> // other watchers on the same machine will get is as well.<a name="line.2690"></a> +<span class="sourceLineNo">2691</span> // When we ask to close the connection, ZK does not close it before<a name="line.2691"></a> +<span class="sourceLineNo">2692</span> // we receive all the events, so don't have to capture the event, just<a name="line.2692"></a> +<span class="sourceLineNo">2693</span> // closing the connection should be enough.<a name="line.2693"></a> +<span class="sourceLineNo">2694</span> ZooKeeper monitor = new ZooKeeper(quorumServers,<a name="line.2694"></a> +<span class="sourceLineNo">2695</span> 1000, new org.apache.zookeeper.Watcher(){<a name="line.2695"></a> +<span class="sourceLineNo">2696</span> @Override<a name="line.2696"></a> +<span class="sourceLineNo">2697</span> public void process(WatchedEvent watchedEvent) {<a name="line.2697"></a> +<span class="sourceLineNo">2698</span> LOG.info("Monitor ZKW received event="+watchedEvent);<a name="line.2698"></a> +<span class="sourceLineNo">2699</span> }<a name="line.2699"></a> +<span class="sourceLineNo">2700</span> } , sessionID, password);<a name="line.2700"></a> +<span class="sourceLineNo">2701</span><a name="line.2701"></a> +<span class="sourceLineNo">2702</span> // Making it expire<a name="line.2702"></a> +<span class="sourceLineNo">2703</span> ZooKeeper newZK = new ZooKeeper(quorumServers,<a name="line.2703"></a> +<span class="sourceLineNo">2704</span> 1000, EmptyWatcher.instance, sessionID, password);<a name="line.2704"></a> +<span class="sourceLineNo">2705</span><a name="line.2705"></a> +<span class="sourceLineNo">2706</span> //ensure that we have connection to the server before closing down, otherwise<a name="line.2706"></a> +<span class="sourceLineNo">2707</span> //the close session event will be eaten out before we start CONNECTING state<a name="line.2707"></a> +<span class="sourceLineNo">2708</span> long start = System.currentTimeMillis();<a name="line.2708"></a> +<span class="sourceLineNo">2709</span> while (newZK.getState() != States.CONNECTED<a name="line.2709"></a> +<span class="sourceLineNo">2710</span> && System.currentTimeMillis() - start < 1000) {<a name="line.2710"></a> +<span class="sourceLineNo">2711</span> Thread.sleep(1);<a name="line.2711"></a> +<span class="sourceLineNo">2712</span> }<a name="line.2712"></a> +<span class="sourceLineNo">2713</span> newZK.close();<a name="line.2713"></a> +<span class="sourceLineNo">2714</span> LOG.info("ZK Closed Session 0x" + Long.toHexString(sessionID));<a name="line.2714"></a> +<span class="sourceLineNo">2715</span><a name="line.2715"></a> +<span class="sourceLineNo">2716</span> // Now closing & waiting to be sure that the clients get it.<a name="line.2716"></a> +<span class="sourceLineNo">2717</span> monitor.close();<a name="line.2717"></a> +<span class="sourceLineNo">2718</span><a name="line.2718"></a> +<span class="sourceLineNo">2719</span> if (checkStatus) {<a name="line.2719"></a> +<span class="sourceLineNo">2720</span> getConnection().getTable(TableName.META_TABLE_NAME).close();<a name="line.2720"></a> +<span class="sourceLineNo">2721</span> }<a name="line.2721"></a> +<span class="sourceLineNo">2722</span> }<a name="line.2722"></a> +<span class="sourceLineNo">2723</span><a name="line.2723"></a> +<span class="sourceLineNo">2724</span> /**<a name="line.2724"></a> +<span class="sourceLineNo">2725</span> * Get the Mini HBase cluster.<a name="line.2725"></a> +<span class="sourceLineNo">2726</span> *<a name="line.2726"></a> +<span class="sourceLineNo">2727</span> * @return hbase cluster<a name="line.2727"></a> +<span class="sourceLineNo">2728</span> * @see #getHBaseClusterInterface()<a name="line.2728"></a> +<span class="sourceLineNo">2729</span> */<a name="line.2729"></a> +<span class="sourceLineNo">2730</span> public MiniHBaseCluster getHBaseCluster() {<a name="line.2730"></a> +<span class="sourceLineNo">2731</span> return getMiniHBaseCluster();<a name="line.2731"></a> +<span class="sourceLineNo">2732</span> }<a name="line.2732"></a> +<span class="sourceLineNo">2733</span><a name="line.2733"></a> +<span class="sourceLineNo">2734</span> /**<a name="line.2734"></a> +<span class="sourceLineNo">2735</span> * Returns the HBaseCluster instance.<a name="line.2735"></a> +<span class="sourceLineNo">2736</span> * <p>Returned object can be any of the subclasses of HBaseCluster, and the<a name="line.2736"></a> +<span class="sourceLineNo">2737</span> * tests referring this should not assume that the cluster is a mini cluster or a<a name="line.2737"></a> +<span class="sourceLineNo">2738</span> * distributed one. If the test only works on a mini cluster, then specific<a name="line.2738"></a> +<span class="sourceLineNo">2739</span> * method {@link #getMiniHBaseCluster()} can be used instead w/o the<a name="line.2739"></a> +<span class="sourceLineNo">2740</span> * need to type-cast.<a name="line.2740"></a> +<span class="sourceLineNo">2741</span> */<a name="line.2741"></a> +<span class="sourceLineNo">2742</span> public HBaseCluster getHBaseClusterInterface() {<a name="line.2742"></a> +<span class="sourceLineNo">2743</span> //implementation note: we should rename this method as #getHBaseCluster(),<a name="line.2743"></a> +<span class="sourceLineNo">2744</span> //but this would require refactoring 90+ calls.<a name="line.2744"></a> +<span class="sourceLineNo">2745</span> return hbaseCluster;<a name="line.2745"></a> +<span class="sourceLineNo">2746</span> }<a name="line.2746"></a> +<span class="sourceLineNo">2747</span><a name="line.2747"></a> +<span class="sourceLineNo">2748</span> /**<a name="line.2748"></a> +<span class="sourceLineNo">2749</span> * Get a Connection to the cluster.<a name="line.2749"></a> +<span class="sourceLineNo">2750</span> * Not thread-safe (This class needs a lot of work to make it thread-safe).<a name="line.2750"></a> +<span class="sourceLineNo">2751</span> * @return A Connection that can be shared. Don't close. Will be closed on shutdown of cluster.<a name="line.2751"></a> +<span class="sourceLineNo">2752</span> * @throws IOException<a name="line.2752"></a> +<span class="sourceLineNo">2753</span> */<a name="line.2753"></a> +<span class="sourceLineNo">2754</span> public Connection getConnection() throws IOException {<a name="line.2754"></a> +<span class="sourceLineNo">2755</span> if (this.connection == null) {<a name="line.2755"></a> +<span class="sourceLineNo">2756</span> this.connection = ConnectionFactory.createConnection(this.conf);<a name="line.2756"></a> +<span class="sourceLineNo">2757</span> }<a name="line.2757"></a> +<span class="sourceLineNo">2758</span> return this.connection;<a name="line.2758"></a> +<span class="sourceLineNo">2759</span> }<a name="line.2759"></a> +<span class="sourceLineNo">2760</span><a name="line.2760"></a> +<span class="sourceLineNo">2761</span> /**<a name="line.2761"></a> +<span class="sourceLineNo">2762</span> * Returns a Admin instance.<a name="line.2762"></a> +<span class="sourceLineNo">2763</span> * This instance is shared between HBaseTestingUtility instance users. Closing it has no effect,<a name="line.2763"></a> +<span class="sourceLineNo">2764</span> * it will be closed automatically when the cluster shutdowns<a name="line.2764"></a> +<span class="sourceLineNo">2765</span> *<a name="line.2765"></a> +<span class="sourceLineNo">2766</span> * @return HBaseAdmin instance which is guaranteed to support only {@link Admin} interface.<a name="line.2766"></a> +<span class="sourceLineNo">2767</span> * Functions in HBaseAdmin not provided by {@link Admin} interface can be changed/deleted<a name="line.2767"></a> +<span class="sourceLineNo">2768</span> * anytime.<a name="line.2768"></a> +<span class="sourceLineNo">2769</span> * @deprecated Since 2.0. Will be removed in 3.0. Use {@link #getAdmin()} instead.<a name="line.2769"></a> +<span class="sourceLineNo">2770</span> */<a name="line.2770"></a> +<span class="sourceLineNo">2771</span> @Deprecated<a name="line.2771"></a> +<span class="sourceLineNo">2772</span> public synchronized HBaseAdmin getHBaseAdmin()<a name="line.2772"></a> +<span class="sourceLineNo">2773</span> throws IOException {<a name="line.2773"></a> +<span class="sourceLineNo">2774</span> if (hbaseAdmin == null){<a name="line.2774"></a> +<span class="sourceLineNo">2775</span> this.hbaseAdmin = (HBaseAdmin) getConnection().getAdmin();<a name="line.2775"></a> +<span class="sourceLineNo">2776</span> }<a name="line.2776"></a> +<span class="sourceLineNo">2777</span> return hbaseAdmin;<a name="line.2777"></a> +<span class="sourceLineNo">2778</span> }<a name="line.2778"></a> +<span class="sourceLineNo">2779</span><a name="line.2779"></a> +<span class="sourceLineNo">2780</span> /**<a name="line.2780"></a> +<span class="sourceLineNo">2781</span> * Returns an Admin instance which is shared between HBaseTestingUtility instance users.<a name="line.2781"></a> +<span class="sourceLineNo">2782</span> * Closing it has no effect, it will be closed automatically when the cluster shutdowns<a name="line.2782"></a> +<span class="sourceLineNo">2783</span> */<a name="line.2783"></a> +<span class="sourceLineNo">2784</span> public synchronized Admin getAdmin() throws IOException {<a name="line.2784"></a> +<span class="sourceLineNo">2785</span> if (hbaseAdmin == null){<a name="line.2785"></a> +<span class="sourceLineNo">2786</span> this.hbaseAdmin = (HBaseAdmin) getConnection().getAdmin();<a name="line.2786"></a> +<span class="sourceLineNo">2787</span> }<a name="line.2787"></a> +<span class="sourceLineNo">2788</span> return hbaseAdmin;<a name="line.2788"></a> +<span class="sourceLineNo">2789</span> }<a name="line.2789"></a> +<span class="sourceLineNo">2790</span><a name="line.2790"></a> +<span class="sourceLineNo">2791</span> private HBaseAdmin hbaseAdmin = null;<a name="line.2791"></a> +<span class="sourceLineNo">2792</span><a name="line.2792"></a> <span class="sourceLineNo">2793</span><a name="line.2793"></a> <span class="sourceLineNo">2794</span><a name="line.2794"></a> -<span class="sourceLineNo">2795</span><a name="line.2795"></a> -<span class="sourceLineNo">2796</span> /**<a name="line.2796"></a> -<span class="sourceLineNo">2797</span> * Unassign the named region.<a name="line.2797"></a> -<span class="sourceLineNo">2798</span> *<a name="line.2798"></a> -<span class="sourceLineNo">2799</span> * @param regionName The region to unassign.<a name="line.2799"></a> -<span class="sourceLineNo">2800</span> */<a name="line.2800"></a> -<span class="sourceLineNo">2801</span> public void unassignRegion(String regionName) throws IOException {<a name="line.2801"></a> -<span class="sourceLineNo">2802</span> unassignRegion(Bytes.toBytes(regionName));<a name="line.2802"></a> -<span class="sourceLineNo">2803</span> }<a name="line.2803"></a> -<span class="sourceLineNo">2804</span><a name="line.2804"></a> -<span class="sourceLineNo">2805</span> /**<a name="line.2805"></a> -<span class="sourceLineNo">2806</span> * Unassign the named region.<a name="line.2806"></a> -<span class="sourceLineNo">2807</span> *<a name="line.2807"></a> -<span class="sourceLineNo">2808</span> * @param regionName The region to unassign.<a name="line.2808"></a> -<span class="sourceLineNo">2809</span> */<a name="line.2809"></a> -<span class="sourceLineNo">2810</span> public void unassignRegion(byte[] regionName) throws IOException {<a name="line.2810"></a> -<span class="sourceLineNo">2811</span> getAdmin().unassign(regionName, true);<a name="line.2811"></a> -<span class="sourceLineNo">2812</span> }<a name="line.2812"></a> -<span class="sourceLineNo">2813</span><a name="line.2813"></a> -<span class="sourceLineNo">2814</span> /**<a name="line.2814"></a> -<span class="sourceLineNo">2815</span> * Closes the region containing the given row.<a name="line.2815"></a> -<span class="sourceLineNo">2816</span> *<a name="line.2816"></a> -<span class="sourceLineNo">2817</span> * @param row The row to find the containing region.<a name="line.2817"></a> -<span class="sourceLineNo">2818</span> * @param table The table to find the region.<a name="line.2818"></a> -<span class="sourceLineNo">2819</span> */<a name="line.2819"></a> -<span class="sourceLineNo">2820</span> public void unassignRegionByRow(String row, RegionLocator table) throws IOException {<a name="line.2820"></a> -<span class="sourceLineNo">2821</span> unassignRegionByRow(Bytes.toBytes(row), table);<a name="line.2821"></a> -<span class="sourceLineNo">2822</span> }<a name="line.2822"></a> -<span class="sourceLineNo">2823</span><a name="line.2823"></a> -<span class="sourceLineNo">2824</span> /**<a name="line.2824"></a> -<span class="sourceLineNo">2825</span> * Closes the region containing the given row.<a name="line.2825"></a> -<span class="sourceLineNo">2826</span> *<a name="line.2826"></a> -<span class="sourceLineNo">2827</span> * @param row The row to find the containing region.<a name="line.2827"></a> -<span class="sourceLineNo">2828</span> * @param table The table to find the region.<a name="line.2828"></a> -<span class="sourceLineNo">2829</span> * @throws IOException<a name="line.2829"></a> -<span class="sourceLineNo">2830</span> */<a name="line.2830"></a> -<span class="sourceLineNo">2831</span> public void unassignRegionByRow(byte[] row, RegionLocator table) throws IOException {<a name="line.2831"></a> -<span class="sourceLineNo">2832</span> HRegionLocation hrl = table.getRegionLocation(row);<a name="line.2832"></a> -<span class="sourceLineNo">2833</span> unassignRegion(hrl.getRegionInfo().getRegionName());<a name="line.2833"></a> -<span class="sourceLineNo">2834</span> }<a name="line.2834"></a> -<span class="sourceLineNo">2835</span><a name="line.2835"></a> -<span class="sourceLineNo">2836</span> /*<a name="line.2836"></a> -<span class="sourceLineNo">2837</span> * Retrieves a splittable region randomly from tableName<a name="line.2837"></a> -<span class="sourceLineNo">2838</span> *<a name="line.2838"></a> -<span class="sourceLineNo">2839</span> * @param tableName name of table<a name="line.2839"></a> -<span class="sourceLineNo">2840</span> * @param maxAttempts maximum number of attempts, unlimited for value of -1<a name="line.2840"></a> -<span class="sourceLineNo">2841</span> * @return the HRegion chosen, null if none was found within limit of maxAttempts<a name="line.2841"></a> -<span class="sourceLineNo">2842</span> */<a name="line.2842"></a> -<span class="sourceLineNo">2843</span> public HRegion getSplittableRegion(TableName tableName, int maxAttempts) {<a name="line.2843"></a> -<span class="sourceLineNo">2844</span> List<HRegion> regions = getHBaseCluster().getRegions(tableName);<a name="line.2844"></a> -<span class="sourceLineNo">2845</span> int regCount = regions.size();<a name="line.2845"></a> -<span class="sourceLineNo">2846</span> Set<Integer> attempted = new HashSet<>();<a name="line.2846"></a> -<span class="sourceLineNo">2847</span> int idx;<a name="line.2847"></a> -<span class="sourceLineNo">2848</span> int attempts = 0;<a name="line.2848"></a> -<span class="sourceLineNo">2849</span> do {<a name="line.2849"></a> -<span class="sourceLineNo">2850</span> regions = getHBaseCluster().getRegions(tableName);<a name="line.2850"></a> -<span class="sourceLineNo">2851</span> if (regCount != regions.size()) {<a name="line.2851"></a> -<span class="sourceLineNo">2852</span> // if there was region movement, clear attempted Set<a name="line.2852"></a> -<span class="sourceLineNo">2853</span> attempted.clear();<a name="line.2853"></a> -<span class="sourceLineNo">2854</span> }<a name="line.2854"></a> -<span class="sourceLineNo">2855</span> regCount = regions.size();<a name="line.2855"></a> -<span class="sourceLineNo">2856</span> // There are chances that before we get the region for the table from an RS the region may<a name="line.2856"></a> -<span class="sourceLineNo">2857</span> // be going for CLOSE. This may be because online schema change is enabled<a name="line.2857"></a> -<span class="sourceLineNo">2858</span> if (regCount > 0) {<a name="line.2858"></a> -<span class="sourceLineNo">2859</span> idx = random.nextInt(regCount);<a name="line.2859"></a> -<span class="sourceLineNo">2860</span> // if we have just tried this region, there is no need to try again<a name="line.2860"></a> -<span class="sourceLineNo">2861</span> if (attempted.contains(idx))<a name="line.2861"></a> -<span class="sourceLineNo">2862</span> continue;<a name="line.2862"></a> -<span class="sourceLineNo">2863</span> try {<a name="line.2863"></a> -<span class="sourceLineNo">2864</span> regions.get(idx).checkSplit();<a name="line.2864"></a> -<span class="sourceLineNo">2865</span> return regions.get(idx);<a name="line.2865"></a> -<span class="sourceLineNo">2866</span> } catch (Exception ex) {<a name="line.2866"></a> -<span class="sourceLineNo">2867</span> LOG.warn("Caught exception", ex);<a name="line.2867"></a> -<span class="sourceLineNo">2868</span> attempted.add(idx);<a name="line.2868"></a> -<span class="sourceLineNo">2869</span> }<a name="line.2869"></a> -<span class="sourceLineNo">2870</span> }<a name="line.2870"></a> -<span class="sourceLineNo">2871</span> attempts++;<a name="line.2871"></a> -<span class="sourceLineNo">2872</span> } while (maxAttempts == -1 || attempts < maxAttempts);<a name="line.2872"></a> -<span class="sourceLineNo">2873</span> return null;<a name="line.2873"></a> -<span class="sourceLineNo">2874</span> }<a name="line.2874"></a> -<span class="sourceLineNo">2875</span><a name="line.2875"></a> -<span class="sourceLineNo">2876</span> public MiniDFSCluster getDFSCluster() {<a name="line.2876"></a> -<span class="sourceLineNo">2877</span> return dfsCluster;<a name="line.2877"></a> -<span class="sourceLineNo">2878</span> }<a name="line.2878"></a> -<span class="sourceLineNo">2879</span><a name="line.2879"></a> -<span class="sourceLineNo">2880</span> public void setDFSCluster(MiniDFSCluster cluster) throws IllegalStateException, IOException {<a name="line.2880"></a> -<span class="sourceLineNo">2881</span> setDFSCluster(cluster, true);<a name="line.2881"></a> -<span class="sourceLineNo">2882</span> }<a name="line.2882"></a> -<span class="sourceLineNo">2883</span><a name="line.2883"></a> -<span class="sourceLineNo">2884</span> /**<a name="line.2884"></a> -<span class="sourceLineNo">2885</span> * Set the MiniDFSCluster<a name="line.2885"></a> -<span class="sourceLineNo">2886</span> * @param cluster cluster to use<a name="line.2886"></a> -<span class="sourceLineNo">2887</span> * @param requireDown require the that cluster not be "up" (MiniDFSCluster#isClusterUp) before<a name="line.2887"></a> -<span class="sourceLineNo">2888</span> * it is set.<a name="line.2888"></a> -<span class="sourceLineNo">2889</span> * @throws IllegalStateException if the passed cluster is up when it is required to be down<a name="line.2889"></a> -<span class="sourceLineNo">2890</span> * @throws IOException if the FileSystem could not be set from the passed dfs cluster<a name="line.2890"></a> -<span class="sourceLineNo">2891</span> */<a name="line.2891"></a> -<span class="sourceLineNo">2892</span> public void setDFSCluster(MiniDFSCluster cluster, boolean requireDown)<a name="line.2892"></a> -<span class="sourceLineNo">2893</span> throws IllegalStateException, IOException {<a name="line.2893"></a> -<span class="sourceLineNo">2894</span> if (dfsCluster != null && requireDown && dfsCluster.isClusterUp()) {<a name="line.2894"></a> -<span class="sourceLineNo">2895</span> throw new IllegalStateException("DFSCluster is already running! Shut it down first.");<a name="line.2895"></a> -<span class="sourceLineNo">2896</span> }<a name="line.2896"></a> -<span class="sourceLineNo">2897</span> this.dfsCluster = cluster;<a name="line.2897"></a> -<span class="sourceLineNo">2898</span> this.setFs();<a name="line.2898"></a> -<span class="sourceLineNo">2899</span> }<a name="line.2899"></a> -<span class="sourceLineNo">2900</span><a name="line.2900"></a> -<span class="sourceLineNo">2901</span> public FileSystem getTestFileSystem() throws IOException {<a name="line.2901"></a> -<span class="sourceLineNo">2902</span> return HFileSystem.get(conf);<a name="line.2902"></a> -<span class="sourceLineNo">2903</span> }<a name="line.2903"></a> -<span class="sourceLineNo">2904</span><a name="line.2904"></a> -<span class="sourceLineNo">2905</span> /**<a name="line.2905"></a> -<span class="sourceLineNo">2906</span> * Wait until all regions in a table have been assigned. Waits default timeout before giving up<a name="line.2906"></a> -<span class="sourceLineNo">2907</span> * (30 seconds).<a name="line.2907"></a> -<span class="sourceLineNo">2908</span> * @param table Table to wait on.<a name="line.2908"></a> -<span class="sourceLineNo">2909</span> * @throws InterruptedException<a name="line.2909"></a> -<span class="sourceLineNo">2910</span> * @throws IOException<a name="line.2910"></a> -<span class="sourceLineNo">2911</span> */<a name="line.2911"></a> -<span class="sourceLineNo">2912</span> public void waitTableAvailable(TableName table)<a name="line.2912"></a> -<span class="sourceLineNo">2913</span> throws InterruptedException, IOException {<a name="line.2913"></a> -<span class="sourceLineNo">2914</span> waitTableAvailable(table.getName(), 30000);<a name="line.2914"></a> -<span class="sourceLineNo">2915</span> }<a name="line.2915"></a> -<span class="sourceLineNo">2916</span><a name="line.2916"></a> -<span class="sourceLineNo">2917</span> public void waitTableAvailable(TableName table, long timeoutMillis)<a name="line.2917"></a> -<span class="sourceLineNo">2918</span> throws InterruptedException, IOException {<a name="line.2918"></a> -<span class="sourceLineNo">2919</span> waitFor(timeoutMillis, predicateTableAvailable(table));<a name="line.2919"></a> -<span class="sourceLineNo">2920</span> }<a name="line.2920"></a> -<span class="sourceLineNo">2921</span><a name="line.2921"></a> -<span class="sourceLineNo">2922</span> /**<a name="line.2922"></a> -<span class="sourceLineNo">2923</span> * Wait until all regions in a table have been assigned<a name="line.2923"></a> -<span class="sourceLineNo">2924</span> * @param table Table to wait on.<a name="line.2924"></a> -<span class="sourceLineNo">2925</span> * @param timeoutMillis Timeout.<a name="line.2925"></a> -<span class="sourceLineNo">2926</span> * @throws InterruptedException<a name="line.2926"></a> -<span class="sourceLineNo">2927</span> * @throws IOException<a name="line.2927"></a> -<span class="sourceLineNo">2928</span> */<a name="line.2928"></a> -<span class="sourceLineNo">2929</span> public void waitTableAvailable(byte[] table, long timeoutMillis)<a name="line.2929"></a> -<span class="sourceLineNo">2930</span> throws InterruptedException, IOException {<a name="line.2930"></a> -<span class="sourceLineNo">2931</span> waitFor(timeoutMillis, predicateTableAvailable(TableName.valueOf(table)));<a name="line.2931"></a> -<span class="sourceLineNo">2932</span> }<a name="line.2932"></a> -<span class="sourceLineNo">2933</span><a name="line.2933"></a> -<span class="sourceLineNo">2934</span> public String explainTableAvailability(TableName tableName) throws IOException {<a name="line.2934"></a> -<span class="sourceLineNo">2935</span> String msg = explainTableState(tableName, TableState.State.ENABLED) + ", ";<a name="line.2935"></a> -<span class="sourceLineNo">2936</span> if (getHBaseCluster().getMaster().isAlive()) {<a name="line.2936"></a> -<span class="sourceLineNo">2937</span> Map<RegionInfo, ServerName> assignments =<a name="line.2937"></a> -<span class="sourceLineNo">2938</span> getHBaseCluster().getMaster().getAssignmentManager().getRegionStates()<a name="line.2938"></a> -<span class="sourceLineNo">2939</span> .getRegionAssignments();<a name="line.2939"></a> -<span class="sourceLineNo">2940</span> final List<Pair<RegionInfo, ServerName>> metaLocations =<a name="line.2940"></a> -<span class="sourceLineNo">2941</span> MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);<a name="line.2941"></a> -<span class="sourceLineNo">2942</span> for (Pair<RegionInfo, ServerName> metaLocation : metaLocations) {<a name="line.2942"></a> -<span class="sourceLineNo">2943</span> RegionInfo hri = metaLocation.getFirst();<a name="line.2943"></a> -<span class="sourceLineNo">2944</span> ServerName sn = metaLocation.getSecond();<a name="line.2944"></a> -<span class="sourceLineNo">2945</span> if (!assignments.containsKey(hri)) {<a name="line.2945"></a> -<span class="sourceLineNo">2946</span> msg += ", region " + hri<a name="line.2946"></a> -<span class="sourceLineNo">2947</span> + " not assigned, but found in meta, it expected to be on " + sn;<a name="line.2947"></a> -<span class="sourceLineNo">2948</span><a name="line.2948"></a> -<span class="sourceLineNo">2949</span> } else if (sn == null) {<a name="line.2949"></a> -<span class="sourceLineNo">2950</span> msg += ", region " + hri<a name="line.2950"></a> -<span class="sourceLineNo">2951</span> + " assigned, but has no server in meta";<a name="line.2951"></a> -<span class="sourceLineNo">2952</span> } else if (!sn.equals(assignments.get(hri))) {<a name="line.2952"></a> -<span class="sourceLineNo">2953</span> msg += ", region " + hri<a name="line.2953"></a> -<span class="sourceLineNo">2954</span> + " assigned, but has different servers in meta and AM ( " +<a name="line.2954"></a> -<span class="sourceLineNo">2955</span> sn + " <> " + assignments.get(hri);<a name="line.2955"></a> -<span class="sourceLineNo">2956</span> }<a name="line.2956"></a> -<span class="sourceLineNo">2957</span> }<a name="line.2957"></a> -<span class="sourceLineNo">2958</span> }<a name="line.2958"></a> -<span class="sourceLineNo">2959</span> return msg;<a name="line.2959"></a> -<span class="sourceLineNo">2960</span> }<a name="line.2960"></a> -<span class="sourceLineNo">2961</span><a name="line.2961"></a> -<span class="sourceLineNo">2962</span> public String explainTableState(final TableName table, TableState.State state)<a name="line.2962"></a> -<span class="sourceLineNo">2963</span> throws IOException {<a name="line.2963"></a> -<span class="sourceLineNo">2964</span> TableState tableState = MetaTableAccessor.getTableState(connection, table);<a name="line.2964"></a> -<span class="sourceLineNo">2965</span> if (tableState == null) {<a name="line.2965"></a> -<span class="sourceLineNo">2966</span> return "TableState in META: No table state in META for table " + table<a name="line.2966"></a> -<span class="sourceLineNo">2967</span> + " last state in meta (including deleted is " + findLastTableState(table) + ")";<a name="line.2967"></a> -<span class="sourceLineNo">2968</span> } else if (!tableState.inStates(state)) {<a name="line.2968"></a> -<span class="sourceLineNo">2969</span> return "TableState in META: Not " + state + " state, but " + tableState;<a name="line.2969"></a> -<span class="sourceLineNo">2970</span> } else {<a name="line.2970"></a> -<span class="sourceLineNo">2971</span> return "TableState in META: OK";<a name="line.2971"></a> -<span class="sourceLineNo">2972</span> }<a name="line.2972"></a> -<span class="sourceLineNo">2973</span> }<a name="line.2973"></a> -<span class="sourceLineNo">2974</span><a name="line.2974"></a> -<span class="sourceLineNo">2975</span> @Nullable<a name="line.2975"></a> -<span class="sourceLineNo">2976</span> public TableState findLastTableState(final TableName table) throws IOException {<a name="line.2976"></a> -<span class="sourceLineNo">2977</span> final AtomicReference<TableState> lastTableState = new AtomicReference<>(null);<a name="line.2977"></a> -<span class="sourceLineNo">2978</span> MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {<a name="line.2978"></a> -<span class="sourceLineNo">2979</span> @Override<a name="line.2979"></a> -<span class="sourceLineNo">2980</span> public boolean visit(Result r) throws IOException {<a name="line.2980"></a> -<span class="sourceLineNo">2981</span> if (!Arrays.equals(r.getRow(), table.getName()))<a name="line.2981"></a> -<span class="sourceLineNo">2982</span> return false;<a name="line.2982"></a> -<span class="sourceLineNo">2983</span> TableState state = MetaTableAccessor.getTableState(r);<a name="line.2983"></a> -<span class="sourceLineNo">2984</span> if (state != null)<a name="line.2984"></a> -<span class="sourceLineNo">2985</span> lastTableState.set(state);<a name="line.2985"></a> -<span class="sourceLineNo">2986</span> return true;<a name="line.2986"></a> -<span class="sourceLineNo">2987</span> }<a name="line.2987"></a> -<span class="sourceLineNo">2988</span> };<a name="line.2988"></a> -<span class="sourceLineNo">2989</span> MetaTableAccessor<a name="line.2989"></a> -<span class="sourceLineNo">2990</span> .scanMeta(connection, null, null,<a name="line.2990"></a> -<span class="sourceLineNo">2991</span> MetaTableAccessor.QueryType.TABLE,<a name="line.2991"></a> -<span class="sourceLineNo">2992</span> Integer.MAX_VALUE, visitor);<a name="line.2992"></a> -<span class="sourceLineNo">2993</span> return lastTableState.get();<a name="line.2993"></a> -<span class="sourceLineNo">2994</span> }<a name="line.2994"></a> -<span class="sourceLineNo">2995</span><a name="line.2995"></a> -<span class="sourceLineNo">2996</span> /**<a name="line.2996"></a> -<span class="sourceLineNo">2997</span> * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the<a name="line.2997"></a> -<span class="sourceLineNo">2998</span> * regions have been all assigned. Will timeout after default period (30 seconds)<a name="line.2998"></a> -<span class="sourceLineNo">2999</span> * Tolerates nonexistent table.<a name="line.2999"></a> -<span class="sourceLineNo">3000</span> * @param table Table to wait on.<a name="line.3000"></a> -<span class="sourceLineNo">3001</span> * @param table<a name="line.3001"></a> -<span class="sourceLineNo">3002</span> * @throws InterruptedException<a name="line.3002"></a> -<span class="sourceLineNo">3003</span> * @throws IOException<a name="line.3003"></a> -<span class="sourceLineNo">3004</span> */<a name="line.3004"></a> -<span class="sourceLineNo">3005</span> public void waitTableEnabled(TableName table)<a name="line.3005"></a> -<span class="sourceLineNo">3006</span> throws InterruptedException, IOException {<a name="line.3006"></a> -<span class="sourceLineNo">3007</span> waitTableEnabled(table, 30000);<a name="line.3007"></a> -<span class="sourceLineNo">3008</span> }<a name="line.3008"></a> -<span class="sourceLineNo">3009</span><a name="line.3009"></a> -<span class="sourceLineNo">3010</span> /**<a name="line.3010"></a> -<span class="sourceLineNo">3011</span> * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the<a name="line.3011"></a> -<span class="sourceLineNo">3012</span> * regions have been all assigned.<a name="line.3012"></a> -<span class="sourceLineNo">3013</span> * @see #waitTableEnabled(TableName, long)<a name="line.3013"></a> -<span class="sourceLineNo">3014</span> * @param table Table to wait on.<a name="line.3014"></a> -<span class="sourceLineNo">3015</span> * @param timeoutMillis Time to wait on it being marked enabled.<a name="line.3015"></a> -<span class="sourceLineNo">3016</span> * @throws InterruptedException<a name="line.3016"></a> -<span class="sourceLineNo">3017</span> * @throws IOException<a name="line.3017"></a> -<span class="sourceLineNo">3018</span> */<a name="line.3018"></a> -<span class="sourceLineNo">3019</span> public void waitTableEnabled(byte[] table, long timeoutMillis)<a name="line.3019"></a> -<span class="sourceLineNo">3020</span> throws InterruptedException, IOException {<a name="line.3020"></a> -<span class="sourceLineNo">3021</span> waitTableEnabled(TableName.valueOf(table), timeoutMillis);<a name="line.3021"></a> -<span class="sourceLineNo">3022</span> }<a name="line.3022"></a> -<span class="sourceLineNo">3023</span><a name="line.3023"></a> -<span class="sourceLineNo">3024</span> public void waitTableEnabled(TableName table, long timeoutMillis)<a name="line.3024"></a> -<span class="sourceLineNo">3025</span> throws IOException {<a name="line.3025"></a> -<span class="sourceLineNo">3026</span> waitFor(timeoutMillis, predicateTableEnabled(table));<a name="line.3026"></a> -<span class="sourceLineNo">3027</span> }<a name="line.3027"></a> -<span class="sourceLineNo">3028</span><a name="line.3028"></a> -<span class="sourceLineNo">3029</span> /**<a name="line.3029"></a> -<span class="sourceLineNo">3030</span> * Waits for a table to be 'disabled'. Disabled means that table is set as 'disabled'<a name="line.3030"></a> -<span class="sourceLineNo">3031</span> * Will timeout after default period (30 seconds)<a name="line.3031"></a> -<span class="sourceLineNo">3032</span> * @param table Table to wait on.<a name="line.3032"></a> -<span class="sourceLineNo">3033</span> * @throws InterruptedException<a name="line.3033"></a> -<span class="sourceLineNo">3034</span> * @throws IOException<a name="line.3034"></a> -<span class="sourceLineNo">3035</span> */<a name="line.3035"></a> -<span class="sourceLineNo">3036</span> public void waitTableDisabled(byte[] table)<a name="line.3036"></a> -<span class="sourceLineNo">3037</span> throws InterruptedException, IOException {<a name="line.3037"></a> -<span class="sourceLineNo">3038</span> waitTableDisabled(table, 30000);<a name="line.3038"></a> -<span class="sourceLineNo">3039</span> }<a name="line.3039"></a> -<span class="sourceLineNo">3040</span><a name="line.3040"></a> -<span class="sourceLineNo">3041</span> public void waitTableDisabled(TableName table, long millisTimeout)<a name="line.3041"></a> -<span class="sourceLineNo">3042</span> throws InterruptedException, IOException {<a name="line.3042"></a> -<span class="sourceLineNo">3043</span> waitFor(millisTimeout, predicateTableDisabled(table));<a name="line.3043"></a> -<span class="sourceLineNo">3044</span> }<a name="line.3044"></a> -<span class="sourceLineNo">3045</span><a name="line.3045"></a> -<span class="sourceLineNo">3046</span> /**<a name="line.3046"></a> -<span class="sourceLineNo">3047</span> * Waits for a table to be 'disabled'. Disabled means that table is set as 'disabled'<a name="line.3047"></a> -<span class="sourceLineNo">3048</span> * @param table Table to wait on.<a name="line.3048"></a> -<span class="sourceLineNo">3049</span> * @param timeoutMillis Time to wait on it being marked disabled.<a name="line.3049"></a> -<span class="sourceLineNo">3050</span> * @throws InterruptedException<a name="line.3050"></a> -<span class="sourceLineNo">3051</span> * @throws IOException<a name="line.3051"></a> -<span class="sourceLineNo">3052</span> */<a name="line.3052"></a> -<span class="sourceLineNo">3053</span> public void waitTableDisabled(byte[] table, long timeoutMillis)<a name="line.3053"></a> -<span class="sourceLineNo">3054</span> throws InterruptedException, IOException {<a name="line.3054"></a> -<span class="sourceLineNo">3055</span> waitTableDisabled(TableName.valueOf(table), timeoutMillis);<a name="line.3055"></a> -<span class="sourceLineNo">3056</span> }<a name="line.3056"></a> -<span class="sourceLineNo">3057</span><a name="line.3057"></a> -<span class="sourceLineNo">3058</span> /**<a name="line.3058"></a> -<span class="sourceLineNo">3059</span> * Make sure that at least the specified number of region servers<a name="line.3059"></a> -<span class="sourceLineNo">3060</span> * are running<a name="line.3060"></a> -<span class="sourceLineNo">3061</span> * @param num minimum number of region servers that should be running<a name="line.3061"></a> -<span class="sourceLineNo">3062</span> * @return true if we started some servers<a name="line.3062"></a> -<span class="sourceLineNo">3063</span> * @throws IOException<a name="line.3063"></a> -<span class="sourceLineNo">3064</span> */<a name="line.3064"></a> -<span class="sourceLineNo">3065</span> public boolean ensureSomeRegionServersAvailable(final int num)<a name="line.3065"></a> -<span class="sourceLineNo">3066</span> throws IOException {<a name="line.3066"></a> -<span class="sourceLineNo">3067</span> boolean startedServer = false;<a name="line.3067"></a> -<span class="sourceLineNo">3068</span> MiniHBaseCluster hbaseCluster = getMiniHBaseCluster();<a name="line.3068"></a> -<span class="sourceLineNo">3069</span> for (int i=hbaseCluster.getLiveRegionServerThreads().size(); i<num; ++i) {<a name="line.3069"></a> -<span class="sourceLineNo">3070</span> LOG.info("Started new server=" + hbaseCluster.startRegionServer());<a name="line.3070"></a> -<span class="sourceLineNo">3071</span> startedServer = true;<a name="line.3071"></a> -<span class="sourceLineNo">3072</span> }<a name="line.3072"></a> -<span class="sourceLineNo">3073</span><a name="line.3073"></a> -<span class="sourceLineNo">3074</span> return startedServer;<a name="line.3074"></a> -<span class="sourceLineNo">3075</span> }<a name="line.3075"></a> +<span class="sourceLineNo">2795</span> /**<a name="line.2795"></a> +<span class="sourceLineNo">2796</span> * Unassign the named region.<a name="line.2796"></a> +<span class="sourceLineNo">2797</span> *<a name="line.2797"></a> +<span class="sourceLineNo">2798</span> * @param regionName The region to unassign.<a name="line.2798"></a> +<span class="sourceLineNo">2799</span> */<a name="line.2799"></a> +<span class="sourceLineNo">2800</span> public void unassignRegion(String regionName) throws IOException {<a name="line.2800"></a> +<span class="sourceLineNo">2801</span> unassignRegion(Bytes.toBytes(regionName));<a name="line.2801"></a> +<span class="sourceLineNo">2802</span> }<a name="line.2802"></a> +<span class="sourceLineNo">2803</span><a name="line.2803"></a> +<span class="sourceLineNo">2804</span> /**<a name="line.2804"></a> +<span class="sourceLineNo">2805</span> * Unassign the named region.<a name="line.2805"></a> +<span class="sourceLineNo">2806</span> *<a name="line.2806"></a> +<span class="sourceLineNo">2807</span> * @param regionName The region to unassign.<a name="line.2807"></a> +<span class="sourceLineNo">2808</span> */<a name="line.2808"></a> +<span class="sourceLineNo">2809</span> public void unassignRegion(byte[] regionName) throws IOException {<a name="line.2809"></a> +<span class="sourceLineNo">2810</span> getAdmin().unassign(regionName, true);<a name="line.2810"></a> +<span class="sourceLineNo">2811</span> }<a name="line.2811"></a> +<span class="sourceLineNo">2812</span><a name="line.2812"></a> +<span class="sourceLineNo">2813</span> /**<a name="line.2813"></a> +<span class="sourceLineNo">2814</span> * Closes the region containing the given row.<a name="line.2814"></a> +<span class="sourceLineNo">2815</span> *<a name="line.2815"></a> +<span class="sourceLineNo">2816</span> * @param row The row to find the containing region.<a name="line.2816"></a> +<span class="sourceLineNo">2817</span> * @param table The table to find the region.<a name="line.2817"></a> +<span class="sourceLineNo">2818</span> */<a name="line.2818"></a> +<span class="sourceLineNo">2819</span> public void unassignRegionByRow(String row, RegionLocator table) throws IOException {<a name="line.2819"></a> +<span class="sourceLineNo">2820</span> unassignRegionByRow(Bytes.toBytes(row), table);<a name="line.2820"></a> +<span class="sourceLineNo">2821</span> }<a name="line.2821"></a> +<span class="sourceLineNo">2822</span><a name="line.2822"></a> +<span class="sourceLineNo">2823</span> /**<a name="line.2823"></a> +<span class="sourceLineNo">2824</span> * Closes the region containing the given row.<a name="line.2824"></a> +<span class="sourceLineNo">2825</span> *<a name="line.2825"></a> +<span class="sourceLineNo">2826</span> * @param row The row to find the containing region.<a name="line.2826"></a> +<span class="sourceLineNo">2827</span> * @param table The table to find the region.<a name="line.2827"></a> +<span class="sourceLineNo">2828</span> * @throws IOException<a name="line.2828"></a> +<span class="sourceLineNo">2829</span> */<a name="line.2829"></a> +<span class="sourceLineNo">2830</span> public void unassignRegionByRow(byte[] row, RegionLocator table) throws IOException {<a name="line.2830"></a> +<span class="sourceLineNo">2831</span> HRegionLocation hrl = table.getRegionLocation(row);<a name="line.2831"></a> +<span class="sourceLineNo">2832</span> unassignRegion(hrl.getRegionInfo().getRegionName());<a name="line.2832"></a> +<span class="sourceLineNo">2833</span> }<a name="line.2833"></a> +<span class="sourceLineNo">2834</span><a name="line.2834"></a> +<span class="sourceLineNo">2835</span> /*<a name="line.2835"></a> +<span class="sourceLineNo">2836</span> * Retrieves a splittable region randomly from tableName<a name="line.2836"></a> +<span class="sourceLineNo">2837</span> *<a name="line.2837"></a> +<span class="sourceLineNo">2838</span> * @param tableName name of table<a name="line.2838"></a> +<span class="sourceLineNo">2839</span> * @param maxAttempts maximum number of attempts, unlimited for value of -1<a name="line.2839"></a> +<span class="sourceLineNo">2840</span> * @return the HRegion chosen, null if none was found within limit of maxAttempts<a name="line.2840"></a> +<span class="sourceLineNo">2841</span> */<a name="line.2841"></a> +<span class="sourceLineNo">2842</span> public HRegion getSplittableRegion(TableName tableName, int maxAttempts) {<a name="line.2842"></a> +<span class="sourceLineNo">2843</span> List<HRegion> regions = getHBaseCluster().getRegions(tableName);<a name="line.2843"></a> +<span class="sourceLineNo">2844</span> int regCount = regions.size();<a name="line.2844"></a> +<span class="sourceLineNo">2845</span> Set<Integer> attempted = new HashSet<>();<a name="line.2845"></a> +<span class="sourceLineNo">2846</span> int idx;<a name="line.2846"></a> +<span class="sourceLineNo">2847</span> int attempts = 0;<a name="line.2847"></a> +<span class="sourceLineNo">2848</span> do {<a name="line.2848"></a> +<span class="sourceLineNo">2849</span> regions = getHBaseCluster().getRegions(tableName);<a name="line.2849"></a> +<span class="sourceLineNo">2850</span> if (regCount != regions.size()) {<a name="line.2850"></a> +<span class="sourceLineNo">2851</span> // if there was region movement, clear attempted Set<a name="line.2851"></a> +<span class="sourceLineNo">2852</span> attempted.clear();<a name="line.2852"></a> +<span class="sourceLineNo">2853</span> }<a name="line.2853"></a> +<span class="sourceLineNo">2854</span> regCount = regions.size();<a name="line.2854"></a> +<span class="sourceLineNo">2855</span> // There are chances that before we get the region for the table from an RS the region may<a name="line.2855"></a> +<span class="sourceLineNo">2856</span> // be going for CLOSE. This may be because online schema change is enabled<a name="line.2856"></a> +<span class="sourceLineNo">2857</span> if (regCount > 0) {<a name="line.2857"></a> +<span class="sourceLineNo">2858</span> idx = random.nextInt(regCount);<a name="line.2858"></a> +<span class="sourceLineNo">2859</span> // if we have just tried this region, there is no need to try again<a name="line.2859"></a> +<span class="sourceLineNo">2860</span> if (attempted.contains(idx))<a name="line.2860"></a> +<span class="sourceLineNo">2861</span> continue;<a name="line.2861"></a> +<span class="sourceLineNo">2862</span> try {<a name="line.2862"></a> +<span class="sourceLineNo">2863</span> regions.get(idx).checkSplit();<a name="line.2863"></a> +<span class="sourceLineNo">2864</span> return regions.get(idx);<a name="line.2864"></a> +<span class="sourceLineNo">2865</span> } catch (Exception ex) {<a name="line.2865"></a> +<span class="sourceLineNo">2866</span> LOG.warn("Caught exception", ex);<a name="line.2866"></a> +<span class="sourceLineNo">2867</span> attempted.add(idx);<a name="line.2867"></a> +<span class="sourceLineNo">2868</span> }<a name="line.2868"></a> +<span class="sourceLineNo">2869</span> }<a name="line.2869"></a> +<span class="sourceLineNo">2870</span> attempts++;<a name="line.2870"></a> +<span class="sourceLineNo">2871</span> } while (maxAttempts == -1 || attempts < maxAttempts);<a name="line.2871"></a> +<span class="sourceLineNo">2872</span> return null;<a name="line.2872"></a> +<span class="sourceLineNo">2873</span> }<a name="line.2873"></a> +<span class="sourceLineNo">2874</span><a name="line.2874"></a> +<span class="sourceLineNo">2875</span> public MiniDFSCluster getDFSCluster() {<a name="line.2875"></a> +<span class="sourceLineNo">2876</span> return dfsCluster;<a name="line.2876"></a> +<span class="sourceLineNo">2877</span> }<a name="line.2877"></a> +<span class="sourceLineNo">2878</span><a name="line.2878"></a> +<span class="sourceLineNo">2879</span> public void setDFSCluster(MiniDFSCluster cluster) throws IllegalStateException, IOException {<a name="line.2879"></a> +<span class="sourceLineNo">2880</span> setDFSCluster(cluster, true);<a name="line.2880"></a> +<span class="sourceLineNo">2881</span> }<a name="line.2881"></a> +<span class="sourceLineNo">2882</span><a name="line.2882"></a> +<span class="sourceLineNo">2883</span> /**<a name="line.2883"></a> +<span class="sourceLineNo">2884</span> * Set the MiniDFSCluster<a name="line.2884"></a> +<span class="sourceLineNo">2885</span> * @param cluster cluster to use<a name="line.2885"></a> +<span class="sourceLineNo">2886</span> * @param requireDown require the that cluster not be "up" (MiniDFSCluster#isClusterUp) before<a name="line.2886"></a> +<span class="sourceLineNo">2887</span> * it is set.<a name="line.2887"></a> +<span class="sourceLineNo">2888</span> * @throws IllegalStateException if the passed cluster is up when it is required to be down<a name="line.2888"></a> +<span class="sourceLineNo">2889</span> * @throws IOException if the FileSystem could not be set from the passed dfs cluster<a name="line.2889"></a> +<span class="sourceLineNo">2890</span> */<a name="line.2890"></a> +<span class="sourceLineNo">2891</span> public void setDFSCluster(MiniDFSCluster cluster, boolean requireDown)<a name="line.2891"></a> +<span class="sourceLineNo">2892</span> throws IllegalStateException, IOException {<a name="line.2892"></a> +<span class="sourceLineNo">2893</span> if (dfsCluster != null && requireDown && dfsCluster.isClusterUp()) {<a name="line.2893"></a> +<span class="sourceLineNo">2894</span> throw new IllegalStateException("DFSCluster is already running! Shut it down first.");<a name="line.2894"></a> +<span class="sourceLineNo">2895</span> }<a name="line.2895"></a> +<span class="sourceLineNo">2896</span> this.dfsCluster = cluster;<a name="line.2896"></a> +<span class="sourceLineNo">2897</span> this.setFs();<a name="line.2897"></a> +<span class="sourceLineNo">2898</span> }<a name="line.2898"></a> +<span class="sourceLineNo">2899</span><a name="line.2899"></a> +<span class="sourceLineNo">2900</span> public FileSystem getTestFileSystem() throws IOException {<a name="line.2900"></a> +<span class="sourceLineNo">2901</span> return HFileSystem.get(conf);<a name="line.2901"></a> +<span class="sourceLineNo">2902</span> }<a name="line.2902"></a> +<span class="sourceLineNo">2903</span><a name="line.2903"></a> +<span class="sourceLineNo">2904</span> /**<a name="line.2904"></a> +<span class="sourceLineNo">2905</span> * Wait until all regions in a table have been assigned. Waits default timeout before giving up<a name="line.2905"></a> +<span class="sourceLineNo">2906</span> * (30 seconds).<a name="line.2906"></a> +<span class="sourceLineNo">2907</span> * @param table Table to wait on.<a name="line.2907"></a> +<span class="sourceLineNo">2908</span> * @throws InterruptedException<a name="line.2908"></a> +<span class="sourceLineNo">2909</span> * @throws IOException<a name="line.2909"></a> +<span class="sourceLineNo">2910</span> */<a name="line.2910"></a> +<span class="sourceLineNo">2911</span> public void waitTableAvailable(TableName table)<a name="line.2911"></a> +<span class="sourceLineNo">2912</span> throws InterruptedException, IOException {<a name="line.2912"></a> +<span class="sourceLineNo">2913</span> waitTableAvailable(table.getName(), 30000);<a name="line.2913"></a> +<span class="sourceLineNo">2914</span> }<a name="line.2914"></a> +<span class="sourceLineNo">2915</span><a name="line.2915"></a> +<span class="sourceLineNo">2916</span> public void waitTableAvailable(TableName table, long timeoutMillis)<a name="line.2916"></a> +<span class="sourceLineNo">2917</span> throws InterruptedException, IOException {<a name="line.2917"></a> +<span class="sourceLineNo">2918</span> waitFor(timeoutMillis, predicateTableAvailable(table));<a name="line.2918"></a> +<span class="sourceLineNo">2919</span> }<a name="line.2919"></a> +<span class="sourceLineNo">2920</span><a name="line.2920"></a> +<span class="sourceLineNo">2921</span> /**<a name="line.2921"></a> +<span class="sourceLineNo">2922</span> * Wait until all regions in a table have been assigned<a name="line.2922"></a> +<span class="sourceLineNo">2923</span> * @param table Table to wait on.<a name="line.2923"></a> +<span class="sourceLineNo">2924</span> * @param timeoutMillis Timeout.<a name="line.2924"></a> +<span class="sourceLineNo">2925</span> * @throws InterruptedException<a name="line.2925"></a> +<span class="sourceLineNo">2926</span> * @throws IOException<a name="line.2926"></a> +<span class="sourceLineNo">2927</span> */<a name="line.2927"></a> +<span class="sourceLineNo">2928</span> public void waitTableAvailable(byte[] table, long timeoutMillis)<a name="line.2928"></a> +<span class="sourceLineNo">2929</span> throws InterruptedException, IOException {<a name="line.2929"></a> +<span class="sourceLineNo">2930</span> waitFor(timeoutMillis, predicateTableAvailable(TableName.valueOf(table)));<a name="line.2930"></a> +<span class="sourceLineNo">2931</span> }<a name="line.2931"></a> +<span class="sourceLineNo">2932</span><a name="line.2932"></a> +<span class="sourceLineNo">2933</span> public String explainTableAvailability(TableName tableName) throws IOException {<a name="line.2933"></a> +<span class="sourceLineNo">2934</span> String msg = explainTableState(tableName, TableState.State.ENABLED) + ", ";<a name="line.2934"></a> +<span class="sourceLineNo">2935</span> if (getHBaseCluster().getMaster().isAlive()) {<a name="line.2935"></a> +<span class="sourceLineNo">2936</span> Map<RegionInfo, ServerName> assignments =<a name="line.2936"></a> +<span class="sourceLineNo">2937</span> getHBaseCluster().getMaster().getAssignmentManager().getRegionStates()<a name="line.2937"></a> +<span class="sourceLineNo">2938</span> .getRegionAssignments();<a name="line.2938"></a> +<span class="sourceLineNo">2939</span> final List<Pair<RegionInfo, ServerName>> metaLocations =<a name="line.2939"></a> +<span class="sourceLineNo">2940</span> MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);<a name="line.2940"></a> +<span class="sourceLineNo">2941</span> for (Pair<RegionInfo, ServerName> metaLocation : metaLocations) {<a name="line.2941"></a> +<span class="sourceLineNo">2942</span> RegionInfo hri = metaLocation.getFirst();<a name="line.2942"></a> +<span class="sourceLineNo">2943</span> ServerName sn = metaLocation.getSecond();<a name="line.2943"></a> +<span class="sourceLineNo">2944</span> if (!assignments.containsKey(hri)) {<a name="line.2944"></a> +<span class="sourceLineNo">2945</span> msg += ", region " + hri<a name="line.2945"></a> +<span class="sourceLineNo">2946</span> + " not assigned, but found in meta, it expected to be on " + sn;<a name="line.2946"></a> +<span class="sourceLineNo">2947</span><a name="line.2947"></a> +<span class="sourceLineNo">2948</span> } else if (sn == null) {<a name="line.2948"></a> +<span class="sourceLineNo">2949</span> msg += ", region " + hri<a name="line.2949"></a> +<span class="sourceLineNo">2950</span> + " assigned, but has no server in meta";<a name="line.2950"></a> +<span class="sourceLineNo">2951</span> } else if (!sn.equals(assignments.get(hri))) {<a name="line.2951"></a> +<span class="sourceLineNo">2952</span> msg += ", region " + hri<a name="line.2952"></a> +<span class="sourceLineNo">2953</span> + " assigned, but has different servers in meta and AM ( " +<a name="line.2953"></a> +<span class="sourceLineNo">2954</span> sn + " <> " + assignments.get(hri);<a name="line.2954"></a> +<span class="sourceLineNo">2955</span> }<a name="line.2955"></a> +<span class="sourceLineNo">2956</span> }<a name="line.2956"></a> +<span class="sourceLineNo">2957</span> }<a name="line.2957"></a> +<span class="sourceLineNo">2958</span> return msg;<a name="line.2958"></a> +<span class="sourceLineNo">2959</span> }<a name="line.2959"></a> +<span class="sourceLineNo">2960</span><a name="line.2960"></a> +<span class="sourceLineNo">2961</span> public String explainTableState(final TableName table, TableState.State state)<a name="line.2961"></a> +<span class="sourceLineNo">2962</span> throws IOException {<a name="line.2962"></a> +<span class="sourceLineNo">2963</span> TableState tableState = MetaTableAccessor.getTableState(connection, table);<a name="line.2963"></a> +<span class="sourceLineNo">2964</span> if (tableState == null) {<a name="line.2964"></a> +<span class="sourceLineNo">2965</span> return "TableState in META: No table state in META for table " + table<a name="line.2965"></a> +<span class="sourceLineNo">2966</span> + " last state in meta (including deleted is " + findLastTableState(table) + ")";<a name="line.2966"></a> +<span class="sourceLineNo">2967</span> } else if (!tableState.inStates(state)) {<a name="line.2967"></a> +<span class="sourceLineNo">2968</span> return "TableState in META: Not " + state + " state, but " + tableState;<a name="line.2968"></a> +<span class="sourceLineNo">2969</span> } else {<a name="line.2969"></a> +<span class="sourceLineNo">2970</span> return "TableState in META: OK";<a name="line.2970"></a> +<span class="sourceLineNo">2971</span> }<a name="line.2971"></a> +<span class="sourceLineNo">2972</span> }<a name="line.2972"></a> +<span class="sourceLineNo">2973</span><a name="line.2973"></a> +<span class="sourceLineNo">2974</span> @Nullable<a name="line.2974"></a> +<span class="sourceLineNo">2975</span> public TableState findLastTableState(final TableName table) throws IOException {<a name="line.2975"></a> +<span class="sourceLineNo">2976</span> final AtomicReference<TableState> lastTableState = new AtomicReference<>(null);<a name="line.2976"></a> +<span class="sourceLineNo">2977</span> MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {<a name="line.2977"></a> +<span class="sourceLineNo">2978</span> @Override<a name="line.2978"></a> +<span class="sourceLineNo">2979</span> public boolean visit(Result r) throws IOException {<a name="line.2979"></a> +<span class="sourceLineNo">2980</span> if (!Arrays.equals(r.getRow(), table.getName()))<a name="line.2980"></a> +<span class="sourceLineNo">2981</span> return false;<a name="line.2981"></a> +<span class="sourceLineNo">2982</span> TableState state = MetaTableAccessor.getTableState(r);<a name="line.2982"></a> +<span class="sourceLineNo">2983</span> if (state != null)<a name="line.2983"></a> +<span class="sourceLineNo">2984</span> lastTableState.set(state);<a name="line.2984"></a> +<span class="sourceLineNo">2985</span> return true;<a name="line.2985"></a> +<span class="sourceLineNo">2986</span> }<a name="line.2986"></a> +<span class="sourceLineNo">2987</span> };<a name="line.2987"></a> +<span class="sourceLineNo">2988</span> MetaTableAccessor<a name="line.2988"></a> +<span class="sourceLineNo">2989</span> .scanMeta(connection, null, null,<a name="line.2989"></a> +<span class="sourceLineNo">2990</span> MetaTableAccessor.QueryType.TABLE,<a name="line.2990"></a> +<span class="sourceLineNo">2991</span> Integer.MAX_VALUE, visitor);<a name="line.2991"></a> +<span class="sourceLineNo">2992</span> return lastTableState.get();<a name="line.2992"></a> +<span class="sourceLineNo">2993</span> }<a name="line.2993"></a> +<span class="sourceLineNo">2994</span><a name="line.2994"></a> +<span class="sourceLineNo">2995</span> /**<a name="line.2995"></a> +<span class="sourceLineNo">2996</span> * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the<a name="line.2996"></a> +<span class="sourceLineNo">2997</span> * regions have been all assigned. Will timeout after default period (30 seconds)<a name="line.2997"></a> +<span class="sourceLineNo">2998</span> * Tolerates nonexistent table.<a name="line.2998"></a> +<span class="sourceLineNo">2999</span> * @param table Table to wait on.<a name="line.2999"></a> +<span class="sourceLineNo">3000</span> * @param table<a name="line.3000"></a> +<span class="sourceLineNo">3001</span> * @throws InterruptedException<a name="line.3001"></a> +<span class="sourceLineNo">3002</span> * @throws IOException<a name="line.3002"></a> +<span class="sourceLineNo">3003</span> */<a name="line.3003"></a> +<span class="sourceLineNo">3004</span> public void waitTableEnabled(TableName table)<a name="line.3004"></a> +<span class="sourceLineNo">3005</span> throws InterruptedException, IOException {<a name="line.3005"></a> +<span class="sourceLineNo">3006</span> waitTableEnabled(table, 30000);<a name="line.3006"></a> +<span class="sourceLineNo">3007</span> }<a name="line.3007"></a> +<span class="sourceLineNo">3008</span><a name="line.3008"></a> +<span class="sourceLineNo">3009</span> /**<a name="line.3009"></a> +<span class="sourceLineNo">3010</span> * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the<a name="line.3010"></a> +<span class="sourceLineNo">3011</span> * regions have been all assigned.<a name="line.3011"></a> +<span class="sourceLineNo">3012</span> * @see #waitTableEnabled(TableName, long)<a name="line.3012"></a> +<span class="sourceLineNo">3013</span> * @param table Table to wait on.<a name="line.3013"></a> +<span class="sourceLineNo">3014</span> * @param timeoutMillis Time to wait on it being marked enabled.<a name="line.3014"></a> +<span class="sourceLineNo">3015</span> * @throws InterruptedException<a name="line.3015"></a> +<span class="sourceLineNo">3016</span> * @throws IOException<a name="line.3016"></a> +<span class="sourceLineNo">3017</span> */<a name="line.3017"></a> +<span class="sourceLineNo">3018</span> public void waitTableEnabled(byte[] table, long timeoutMillis)<a name="line.3018"></a> +<span class="sourceLineNo">3019</span> throws InterruptedException, IOException {<a name="line.3019"></a> +<span class="sourceLineNo">3020</span> waitTableEnabled(TableName.valueOf(table), timeoutMillis);<a name="line.3020"></a> +<span class="sourceLineNo">3021</span> }<a name="line.3021"></a> +<span class="sourceLineNo">3022</span><a name="line.3022"></a> +<span class="sourceLineNo">3023</span> public void waitTableEnabled(TableName table, long timeoutMillis)<a name="line.3023"></a> +<span class="sourceLineNo">3024</span> throws IOException {<a name="line.3024"></a> +<span class="sourceLineNo">3025</span> waitFor(timeoutMillis, predicateTableEnabled(table));<a name="line.3025"></a> +<span class="sourceLineNo">3026</span> }<a name="line.3026"></a> +<span class="sourceLineNo">3027</span><a name="line.3027"></a> +<span class="sourceLineNo">3028</span> /**<a name="line.3028"></a> +<span class="sourceLineNo">3029</span> * Waits for a table to be 'disabled'. Disabled means that table is set as 'disabled'<a name="line.3029"></a> +<span class="sourceLineNo">3030</span> * Will timeout after default period (30 seconds)<a name="line.3030"></a> +<span class="sourceLineNo">3031</span> * @param table Table to wait on.<a name="line.3031"></a> +<span class="sourceLineNo">3032</span> * @throws InterruptedException<a name="line.3032"></a> +<span class="sourceLineNo">3033</span> * @throws IOException<a name="line.3033"></a> +<span class="sourceLineNo">3034</span> */<a name="line.3034"></a> +<span class="sourceLineNo">3035</span> public void waitTableDisabled(byte[] table)<a name="line.3035"></a> +<span class="sourceLineNo">3036</span> throws InterruptedException, IOException {<a name="line.3036"></a> +<span class="sourceLineNo">3037</span> waitTableDisabled(table, 30000);<a name="line.3037"></a> +<span class="sourceLineNo">3038</span> }<a name="line.3038"></a> +<span class="sourceLineNo">3039</span><a name="line.3039"></a> +<span class="sourceLineNo">3040</span> public void waitTableDisabled(TableName table, long millisTimeout)<a name="line.3040"></a> +<span class="sourceLineNo">3041</span> throws InterruptedException, IOException {<a name="line.3041"></a> +<span class="sourceLineNo">3042</span> waitFor(millisTimeout, predicateTableDisabled(table));<a name="line.3042"></a> +<span class="sourceLineNo">3043</span> }<a name="line.3043"></a> +<span class="sourceLineNo">3044</span><a name="line.3044"></a> +<span class="sourceLineNo">3045</span> /**<a name="line.3045"></a> +<span class="sourceLineNo">3046</span> * Waits for a table to be 'disabled'. Disabled means that table is set as 'disabled'<a name="line.3046"></a> +<span class="sourceLineNo">3047</span> * @param table Table to wait on.<a name="line.3047"></a> +<span class="sourceLineNo">3048</span> * @param timeoutMillis Time to wait on it being marked disabled.<a name="line.3048"></a> +<span class="sourceLineNo">3049</span> * @throws InterruptedException<a name="line.3049"></a> +<span class="sourceLineNo">3050</span> * @throws IOException<a name="line.3050"></a> +<span class="sourceLineNo">3051</span> */<a name="line.3051"></a> +<span class="sourceLineNo">3052</span> public void waitTableDisabled(byte[] table, long timeoutMillis)<a name="line.3052"></a> +<span class="sourceLineNo">3053</span> throws InterruptedException, IOException {<a name="line.3053"></a> +<span class="sourceLineNo">3054</span> waitTableDisabled(TableName.valueOf(table), timeoutMillis);<a name="line.3054"></a> +<span class="sourceLineNo">3055</span> }<a name="line.3055"></a> +<span class="sourceLineNo">3056</span><a name="line.3056"></a> +<span class="sourceLineNo">3057</span> /**<a name="line.3057"></a> +<span class="sourceLineNo">3058</span> * Make sure that at least the specified number of region servers<a name="line.3058"></a> +<span class="sourceLineNo">3059</span> * are running<a name="line.3059"></a> +<span class="sourceLineNo">3060</span> * @param num minimum number of region servers that should be running<a name="line.3060"></a> +<span class="sourceLineNo">3061</span> * @return true if we started some servers<a name="line.3061"></a> +<span class="sourceLineNo">3062</span> * @throws IOException<a name="line.3062"></a> +<span class="sourceLineNo">3063</span> */<a name="line.3063"></a> +<span class="sourceLineNo">3064</span> public boolean ensureSomeRegionServersAvailable(final int num)<a name="line.3064"></a> +<span class="sourceLineNo">3065</span> throws IOException {<a name="line.3065"></a> +<span class="sourceLineNo">3066</span> boolean startedServer = false;<a name="line.3066"></a> +<span class="sourceLineNo">3067</span> MiniHBaseCluster hbaseCluster = getMiniHBaseCluster();<a name="line.3067"></a> +<span class="sourceLineNo">3068</span> for (int i=hbaseCluster.getLiveRegionServerThreads().size(); i<num; ++i) {<a name="line.3068"></a> +<span class="sourceLineNo">3069</span> LOG.info("Started new server=" + hbaseCluster.startRegionServer());<a name="line.3069"></a> +<span class="sourceLineNo">3070</span> startedServer = true;<a name="line.3070"></a> +<span class="sourceLineNo">3071</span> }<a name="line.3071"></a> +<span class="sourceLineNo">3072</span><a name="line.3072"></a> +<span class="sourceLineNo">3073</span> return startedServer;<a name="line.3073"></a> +<span class="sourceLineNo">3074</span> }<a name="line.3074"></a> +<span class="sourceLineNo">3075</span><a name="line.3075"></a> <span class="sourceLineNo">3076</span><a name="line.3076"></a> -<span class="sourceLineNo">3077</span><a name="line.3077"></a> -<span class="sourceLineNo">3078</span> /**<a name="line.3078"></a> -<span class="sourceLineNo">3079</span> * Make sure that at least the specified number of region servers<a name="line.3079"></a> -<span class="sourceLineNo">3080</span> * are running. We don't count the ones that are currently stopping or are<a name="line.3080"></a> -<span class="sourceLineNo">3081</span> * stopped.<a name="line.3081"></a> -<span class="sourceLineNo">3082</span> * @param num minimum number of region servers that should be running<a name="line.3082"></a> -<span class="sourceLineNo">3083</span> * @return true if we started some servers<a name="line.3083"></a> -<span class="sourceLineNo">3084</span> * @throws IOException<a name="line.3084"></a> -<span class="sourceLineNo">3085</span> */<a name="line.3085"></a> -<span class="sourceLineNo">3086</span> public boolean ensureSomeNonStoppedRegionServersAvailable(final int num)<a name="line.3086"></a> -<span class="sourceLineNo">3087</span> throws IOException {<a name="line.3087"></a> -<span class="sourceLineNo">3088</span> boolean startedServer = ensureSomeRegionServersAvailable(num);<a name="line.3088"></a> -<span class="sourceLineNo">3089</span><a name="line.3089"></a> -<span class="sourceLineNo">3090</span> int nonStoppedServers = 0;<a name="line.3090"></a> -<span class="sourceLineNo">3091</span> for (JVMClusterUtil.RegionServerThread rst :<a name="line.3091"></a> -<span class="sourceLineNo">3092</span> getMiniHBaseCluster().getRegionServerThreads()) {<a name="line.3092"></a> -<span class="sourceLineNo">3093</span><a name="line.3093"></a> -<span class="sourceLineNo">3094</span> HRegionServer hrs = rst.getRegionServer();<a name="line.3094"></a> -<span class="sourceLineNo">3095</span> if (hrs.isStopping() || hrs.isStopped()) {<a name="line.3095"></a> -<span class="sourceLineNo">3096</span> LOG.info("A region server is stopp
<TRUNCATED>