Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8B692200C65 for ; Sat, 29 Apr 2017 16:58:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8A06E160BC7; Sat, 29 Apr 2017 14:58:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F0F2B160BA0 for ; Sat, 29 Apr 2017 16:58:40 +0200 (CEST) Received: (qmail 21615 invoked by uid 500); 29 Apr 2017 14:58:39 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 21244 invoked by uid 99); 29 Apr 2017 14:58:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Apr 2017 14:58:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C688FE9681; Sat, 29 Apr 2017 14:58:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Sat, 29 Apr 2017 14:58:48 -0000 Message-Id: <9f79280ec82148968f48d3ac83010e21@git.apache.org> In-Reply-To: <583f7baa0f14489b97b65a71735dedf3@git.apache.org> References: <583f7baa0f14489b97b65a71735dedf3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/41] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Sat, 29 Apr 2017 14:58:43 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6fbeb554/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 8bb0018..f19eb7e 100644 --- a/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html +++ b/testapidocs/src-html/org/apache/hadoop/hbase/HBaseTestingUtility.html @@ -99,11 +99,11 @@ 091import org.apache.hadoop.hbase.master.RegionStates; 092import org.apache.hadoop.hbase.master.ServerManager; 093import org.apache.hadoop.hbase.regionserver.BloomType; -094import org.apache.hadoop.hbase.regionserver.HRegion; -095import org.apache.hadoop.hbase.regionserver.HRegionServer; -096import org.apache.hadoop.hbase.regionserver.HStore; -097import org.apache.hadoop.hbase.regionserver.InternalScanner; -098import org.apache.hadoop.hbase.regionserver.ChunkCreator; +094import org.apache.hadoop.hbase.regionserver.ChunkCreator; +095import org.apache.hadoop.hbase.regionserver.HRegion; +096import org.apache.hadoop.hbase.regionserver.HRegionServer; +097import org.apache.hadoop.hbase.regionserver.HStore; +098import org.apache.hadoop.hbase.regionserver.InternalScanner; 099import org.apache.hadoop.hbase.regionserver.MemStoreLABImpl; 100import org.apache.hadoop.hbase.regionserver.Region; 101import org.apache.hadoop.hbase.regionserver.RegionScanner; @@ -731,3510 +731,3512 @@ 723 conf.set("mapreduce.jobtracker.staging.root.dir", 724 new Path(root, "mapreduce-jobtracker-staging-root-dir").toString()); 725 conf.set("mapreduce.job.working.dir", new Path(root, "mapred-working-dir").toString()); -726 } -727 -728 -729 /** -730 * Get the HBase setting for dfs.client.read.shortcircuit from the conf or a system property. -731 * This allows to specify this parameter on the command line. -732 * If not set, default is true. -733 */ -734 public boolean isReadShortCircuitOn(){ -735 final String propName = "hbase.tests.use.shortcircuit.reads"; -736 String readOnProp = System.getProperty(propName); -737 if (readOnProp != null){ -738 return Boolean.parseBoolean(readOnProp); -739 } else { -740 return conf.getBoolean(propName, false); -741 } -742 } -743 -744 /** Enable the short circuit read, unless configured differently. -745 * Set both HBase and HDFS settings, including skipping the hdfs checksum checks. -746 */ -747 private void enableShortCircuit() { -748 if (isReadShortCircuitOn()) { -749 String curUser = System.getProperty("user.name"); -750 LOG.info("read short circuit is ON for user " + curUser); -751 // read short circuit, for hdfs -752 conf.set("dfs.block.local-path-access.user", curUser); -753 // read short circuit, for hbase -754 conf.setBoolean("dfs.client.read.shortcircuit", true); -755 // Skip checking checksum, for the hdfs client and the datanode -756 conf.setBoolean("dfs.client.read.shortcircuit.skip.checksum", true); -757 } else { -758 LOG.info("read short circuit is OFF"); -759 } -760 } -761 -762 private String createDirAndSetProperty(final String relPath, String property) { -763 String path = getDataTestDir(relPath).toString(); -764 System.setProperty(property, path); -765 conf.set(property, path); -766 new File(path).mkdirs(); -767 LOG.info("Setting " + property + " to " + path + " in system properties and HBase conf"); -768 return path; -769 } -770 -771 /** -772 * Shuts down instance created by call to {@link #startMiniDFSCluster(int)} -773 * or does nothing. -774 * @throws IOException -775 */ -776 public void shutdownMiniDFSCluster() throws IOException { -777 if (this.dfsCluster != null) { -778 // The below throws an exception per dn, AsynchronousCloseException. -779 this.dfsCluster.shutdown(); -780 dfsCluster = null; -781 dataTestDirOnTestFS = null; -782 FSUtils.setFsDefault(this.conf, new Path("file:///")); -783 } -784 } -785 -786 /** -787 * Call this if you only want a zk cluster. -788 * @see #startMiniZKCluster() if you want zk + dfs + hbase mini cluster. -789 * @throws Exception -790 * @see #shutdownMiniZKCluster() -791 * @return zk cluster started. -792 */ -793 public MiniZooKeeperCluster startMiniZKCluster() throws Exception { -794 return startMiniZKCluster(1); -795 } -796 -797 /** -798 * Call this if you only want a zk cluster. -799 * @param zooKeeperServerNum -800 * @see #startMiniZKCluster() if you want zk + dfs + hbase mini cluster. -801 * @throws Exception -802 * @see #shutdownMiniZKCluster() -803 * @return zk cluster started. -804 */ -805 public MiniZooKeeperCluster startMiniZKCluster( -806 final int zooKeeperServerNum, -807 final int ... clientPortList) -808 throws Exception { -809 setupClusterTestDir(); -810 return startMiniZKCluster(clusterTestDir, zooKeeperServerNum, clientPortList); -811 } -812 -813 private MiniZooKeeperCluster startMiniZKCluster(final File dir) -814 throws Exception { -815 return startMiniZKCluster(dir, 1, null); -816 } -817 -818 /** -819 * Start a mini ZK cluster. If the property "test.hbase.zookeeper.property.clientPort" is set -820 * the port mentionned is used as the default port for ZooKeeper. -821 */ -822 private MiniZooKeeperCluster startMiniZKCluster(final File dir, -823 final int zooKeeperServerNum, -824 final int [] clientPortList) -825 throws Exception { -826 if (this.zkCluster != null) { -827 throw new IOException("Cluster already running at " + dir); -828 } -829 this.passedZkCluster = false; -830 this.zkCluster = new MiniZooKeeperCluster(this.getConfiguration()); -831 final int defPort = this.conf.getInt("test.hbase.zookeeper.property.clientPort", 0); -832 if (defPort > 0){ -833 // If there is a port in the config file, we use it. -834 this.zkCluster.setDefaultClientPort(defPort); -835 } -836 -837 if (clientPortList != null) { -838 // Ignore extra client ports -839 int clientPortListSize = (clientPortList.length <= zooKeeperServerNum) ? -840 clientPortList.length : zooKeeperServerNum; -841 for (int i=0; i < clientPortListSize; i++) { -842 this.zkCluster.addClientPort(clientPortList[i]); -843 } -844 } -845 int clientPort = this.zkCluster.startup(dir,zooKeeperServerNum); -846 this.conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, -847 Integer.toString(clientPort)); -848 return this.zkCluster; -849 } -850 -851 /** -852 * Shuts down zk cluster created by call to {@link #startMiniZKCluster(File)} -853 * or does nothing. -854 * @throws IOException -855 * @see #startMiniZKCluster() -856 */ -857 public void shutdownMiniZKCluster() throws IOException { -858 if (this.zkCluster != null) { -859 this.zkCluster.shutdown(); -860 this.zkCluster = null; -861 } -862 } -863 -864 /** -865 * Start up a minicluster of hbase, dfs, and zookeeper. -866 * @throws Exception -867 * @return Mini hbase cluster instance created. -868 * @see {@link #shutdownMiniDFSCluster()} -869 */ -870 public MiniHBaseCluster startMiniCluster() throws Exception { -871 return startMiniCluster(1, 1); -872 } -873 -874 /** -875 * Start up a minicluster of hbase, dfs, and zookeeper where WAL's walDir is created separately. -876 * @throws Exception -877 * @return Mini hbase cluster instance created. -878 * @see {@link #shutdownMiniDFSCluster()} -879 */ -880 public MiniHBaseCluster startMiniCluster(boolean withWALDir) throws Exception { -881 return startMiniCluster(1, 1, 1, null, null, null, false, withWALDir); -882 } -883 -884 /** -885 * Start up a minicluster of hbase, dfs, and zookeeper. -886 * Set the <code>create</code> flag to create root or data directory path or not -887 * (will overwrite if dir already exists) -888 * @throws Exception -889 * @return Mini hbase cluster instance created. -890 * @see {@link #shutdownMiniDFSCluster()} -891 */ -892 public MiniHBaseCluster startMiniCluster(final int numSlaves, boolean create) -893 throws Exception { -894 return startMiniCluster(1, numSlaves, create); -895 } -896 -897 /** -898 * Start up a minicluster of hbase, optionally dfs, and zookeeper. -899 * Modifies Configuration. Homes the cluster data directory under a random -900 * subdirectory in a directory under System property test.build.data. -901 * Directory is cleaned up on exit. -902 * @param numSlaves Number of slaves to start up. We'll start this many -903 * datanodes and regionservers. If numSlaves is > 1, then make sure -904 * hbase.regionserver.info.port is -1 (i.e. no ui per regionserver) otherwise -905 * bind errors. -906 * @throws Exception -907 * @see {@link #shutdownMiniCluster()} -908 * @return Mini hbase cluster instance created. -909 */ -910 public MiniHBaseCluster startMiniCluster(final int numSlaves) -911 throws Exception { -912 return startMiniCluster(1, numSlaves, false); -913 } -914 -915 public MiniHBaseCluster startMiniCluster(final int numSlaves, boolean create, boolean withWALDir) -916 throws Exception { -917 return startMiniCluster(1, numSlaves, numSlaves, null, null, null, create, withWALDir); -918 } -919 -920 /** -921 * Start minicluster. Whether to create a new root or data dir path even if such a path -922 * has been created earlier is decided based on flag <code>create</code> -923 * @throws Exception -924 * @see {@link #shutdownMiniCluster()} -925 * @return Mini hbase cluster instance created. -926 */ -927 public MiniHBaseCluster startMiniCluster(final int numMasters, -928 final int numSlaves, boolean create) -929 throws Exception { -930 return startMiniCluster(numMasters, numSlaves, null, create); -931 } -932 -933 /** -934 * start minicluster -935 * @throws Exception -936 * @see {@link #shutdownMiniCluster()} -937 * @return Mini hbase cluster instance created. -938 */ -939 public MiniHBaseCluster startMiniCluster(final int numMasters, -940 final int numSlaves) -941 throws Exception { -942 return startMiniCluster(numMasters, numSlaves, null, false); -943 } -944 -945 public MiniHBaseCluster startMiniCluster(final int numMasters, -946 final int numSlaves, final String[] dataNodeHosts, boolean create) -947 throws Exception { -948 return startMiniCluster(numMasters, numSlaves, numSlaves, dataNodeHosts, -949 null, null, create, false); -950 } -951 -952 /** -953 * Start up a minicluster of hbase, optionally dfs, and zookeeper. -954 * Modifies Configuration. Homes the cluster data directory under a random -955 * subdirectory in a directory under System property test.build.data. -956 * Directory is cleaned up on exit. -957 * @param numMasters Number of masters to start up. We'll start this many -958 * hbase masters. If numMasters > 1, you can find the active/primary master -959 * with {@link MiniHBaseCluster#getMaster()}. -960 * @param numSlaves Number of slaves to start up. We'll start this many -961 * regionservers. If dataNodeHosts == null, this also indicates the number of -962 * datanodes to start. If dataNodeHosts != null, the number of datanodes is -963 * based on dataNodeHosts.length. -964 * If numSlaves is > 1, then make sure -965 * hbase.regionserver.info.port is -1 (i.e. no ui per regionserver) otherwise -966 * bind errors. -967 * @param dataNodeHosts hostnames DNs to run on. -968 * This is useful if you want to run datanode on distinct hosts for things -969 * like HDFS block location verification. -970 * If you start MiniDFSCluster without host names, -971 * all instances of the datanodes will have the same host name. -972 * @throws Exception -973 * @see {@link #shutdownMiniCluster()} -974 * @return Mini hbase cluster instance created. -975 */ -976 public MiniHBaseCluster startMiniCluster(final int numMasters, -977 final int numSlaves, final String[] dataNodeHosts) throws Exception { -978 return startMiniCluster(numMasters, numSlaves, numSlaves, dataNodeHosts, -979 null, null); -980 } -981 -982 /** -983 * Same as {@link #startMiniCluster(int, int)}, but with custom number of datanodes. -984 * @param numDataNodes Number of data nodes. -985 */ -986 public MiniHBaseCluster startMiniCluster(final int numMasters, -987 final int numSlaves, final int numDataNodes) throws Exception { -988 return startMiniCluster(numMasters, numSlaves, numDataNodes, null, null, null); -989 } -990 -991 /** -992 * Start up a minicluster of hbase, optionally dfs, and zookeeper. -993 * Modifies Configuration. Homes the cluster data directory under a random -994 * subdirectory in a directory under System property test.build.data. -995 * Directory is cleaned up on exit. -996 * @param numMasters Number of masters to start up. We'll start this many -997 * hbase masters. If numMasters > 1, you can find the active/primary master -998 * with {@link MiniHBaseCluster#getMaster()}. -999 * @param numSlaves Number of slaves to start up. We'll start this many -1000 * regionservers. If dataNodeHosts == null, this also indicates the number of -1001 * datanodes to start. If dataNodeHosts != null, the number of datanodes is -1002 * based on dataNodeHosts.length. -1003 * If numSlaves is > 1, then make sure -1004 * hbase.regionserver.info.port is -1 (i.e. no ui per regionserver) otherwise -1005 * bind errors. -1006 * @param dataNodeHosts hostnames DNs to run on. -1007 * This is useful if you want to run datanode on distinct hosts for things -1008 * like HDFS block location verification. -1009 * If you start MiniDFSCluster without host names, -1010 * all instances of the datanodes will have the same host name. -1011 * @param masterClass The class to use as HMaster, or null for default -1012 * @param regionserverClass The class to use as HRegionServer, or null for -1013 * default -1014 * @throws Exception -1015 * @see {@link #shutdownMiniCluster()} -1016 * @return Mini hbase cluster instance created. -1017 */ -1018 public MiniHBaseCluster startMiniCluster(final int numMasters, -1019 final int numSlaves, final String[] dataNodeHosts, Class<? extends HMaster> masterClass, -1020 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) -1021 throws Exception { -1022 return startMiniCluster( -1023 numMasters, numSlaves, numSlaves, dataNodeHosts, masterClass, regionserverClass); -1024 } -1025 -1026 public MiniHBaseCluster startMiniCluster(final int numMasters, -1027 final int numSlaves, int numDataNodes, final String[] dataNodeHosts, -1028 Class<? extends HMaster> masterClass, -1029 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) -1030 throws Exception { -1031 return startMiniCluster(numMasters, numSlaves, numDataNodes, dataNodeHosts, -1032 masterClass, regionserverClass, false, false); -1033 } -1034 -1035 /** -1036 * Same as {@link #startMiniCluster(int, int, String[], Class, Class)}, but with custom -1037 * number of datanodes. -1038 * @param numDataNodes Number of data nodes. -1039 * @param create Set this flag to create a new -1040 * root or data directory path or not (will overwrite if exists already). -1041 */ -1042 public MiniHBaseCluster startMiniCluster(final int numMasters, -1043 final int numSlaves, int numDataNodes, final String[] dataNodeHosts, -1044 Class<? extends HMaster> masterClass, -1045 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass, -1046 boolean create, boolean withWALDir) -1047 throws Exception { -1048 if (dataNodeHosts != null && dataNodeHosts.length != 0) { -1049 numDataNodes = dataNodeHosts.length; -1050 } -1051 -1052 LOG.info("Starting up minicluster with " + numMasters + " master(s) and " + -1053 numSlaves + " regionserver(s) and " + numDataNodes + " datanode(s)"); -1054 -1055 // If we already put up a cluster, fail. -1056 if (miniClusterRunning) { -1057 throw new IllegalStateException("A mini-cluster is already running"); -1058 } -1059 miniClusterRunning = true; -1060 -1061 setupClusterTestDir(); -1062 System.setProperty(TEST_DIRECTORY_KEY, this.clusterTestDir.getPath()); -1063 -1064 // Bring up mini dfs cluster. This spews a bunch of warnings about missing -1065 // scheme. Complaints are 'Scheme is undefined for build/test/data/dfs/name1'. -1066 if(this.dfsCluster == null && !localMode) { -1067 LOG.info("STARTING DFS"); -1068 dfsCluster = startMiniDFSCluster(numDataNodes, dataNodeHosts); -1069 } else LOG.info("NOT STARTING DFS"); -1070 -1071 // Start up a zk cluster. -1072 if (this.zkCluster == null) { -1073 startMiniZKCluster(clusterTestDir); -1074 } -1075 -1076 // Start the MiniHBaseCluster -1077 return startMiniHBaseCluster(numMasters, numSlaves, masterClass, -1078 regionserverClass, create, withWALDir); -1079 } -1080 -1081 public MiniHBaseCluster startMiniHBaseCluster(final int numMasters, final int numSlaves) -1082 throws IOException, InterruptedException{ -1083 return startMiniHBaseCluster(numMasters, numSlaves, null, null, false, false); -1084 } -1085 -1086 /** -1087 * Starts up mini hbase cluster. Usually used after call to -1088 * {@link #startMiniCluster(int, int)} when doing stepped startup of clusters. -1089 * Usually you won't want this. You'll usually want {@link #startMiniCluster()}. -1090 * @param numMasters -1091 * @param numSlaves -1092 * @param create Whether to create a -1093 * root or data directory path or not; will overwrite if exists already. -1094 * @return Reference to the hbase mini hbase cluster. -1095 * @throws IOException -1096 * @throws InterruptedException -1097 * @see {@link #startMiniCluster()} -1098 */ -1099 public MiniHBaseCluster startMiniHBaseCluster(final int numMasters, -1100 final int numSlaves, Class<? extends HMaster> masterClass, -1101 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass, -1102 boolean create, boolean withWALDir) -1103 throws IOException, InterruptedException { -1104 // Now do the mini hbase cluster. Set the hbase.rootdir in config. -1105 createRootDir(create); -1106 if (withWALDir) { -1107 createWALRootDir(); -1108 } -1109 // Set the hbase.fs.tmp.dir config to make sure that we have some default value. This is -1110 // for tests that do not read hbase-defaults.xml -1111 setHBaseFsTmpDir(); -1112 -1113 // These settings will make the server waits until this exact number of -1114 // regions servers are connected. -1115 if (conf.getInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1) == -1) { -1116 conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, numSlaves); -1117 } -1118 if (conf.getInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -1) == -1) { -1119 conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, numSlaves); -1120 } -1121 -1122 Configuration c = new Configuration(this.conf); -1123 this.hbaseCluster = -1124 new MiniHBaseCluster(c, numMasters, numSlaves, masterClass, regionserverClass); -1125 // Don't leave here till we've done a successful scan of the hbase:meta -1126 Table t = getConnection().getTable(TableName.META_TABLE_NAME); -1127 ResultScanner s = t.getScanner(new Scan()); -1128 while (s.next() != null) { -1129 continue; -1130 } -1131 s.close(); -1132 t.close(); -1133 -1134 getAdmin(); // create immediately the hbaseAdmin -1135 LOG.info("Minicluster is up"); -1136 -1137 return (MiniHBaseCluster)this.hbaseCluster; -1138 } -1139 -1140 /** -1141 * Starts the hbase cluster up again after shutting it down previously in a -1142 * test. Use this if you want to keep dfs/zk up and just stop/start hbase. -1143 * @param servers number of region servers -1144 * @throws IOException -1145 */ -1146 public void restartHBaseCluster(int servers) throws IOException, InterruptedException { -1147 if(connection != null){ -1148 connection.close(); -1149 connection = null; -1150 } -1151 this.hbaseCluster = new MiniHBaseCluster(this.conf, servers); -1152 // Don't leave here till we've done a successful scan of the hbase:meta -1153 Connection conn = ConnectionFactory.createConnection(this.conf); -1154 Table t = conn.getTable(TableName.META_TABLE_NAME); -1155 ResultScanner s = t.getScanner(new Scan()); -1156 while (s.next() != null) { -1157 // do nothing -1158 } -1159 LOG.info("HBase has been restarted"); -1160 s.close(); -1161 t.close(); -1162 conn.close(); -1163 } -1164 -1165 /** -1166 * @return Current mini hbase cluster. Only has something in it after a call -1167 * to {@link #startMiniCluster()}. -1168 * @see #startMiniCluster() -1169 */ -1170 public MiniHBaseCluster getMiniHBaseCluster() { -1171 if (this.hbaseCluster == null || this.hbaseCluster instanceof MiniHBaseCluster) { -1172 return (MiniHBaseCluster)this.hbaseCluster; -1173 } -1174 throw new RuntimeException(hbaseCluster + " not an instance of " + -1175 MiniHBaseCluster.class.getName()); -1176 } -1177 -1178 /** -1179 * Stops mini hbase, zk, and hdfs clusters. -1180 * @throws IOException -1181 * @see {@link #startMiniCluster(int)} -1182 */ -1183 public void shutdownMiniCluster() throws Exception { -1184 LOG.info("Shutting down minicluster"); -1185 if (this.connection != null && !this.connection.isClosed()) { -1186 this.connection.close(); -1187 this.connection = null; -1188 } -1189 shutdownMiniHBaseCluster(); -1190 if (!this.passedZkCluster){ -1191 shutdownMiniZKCluster(); -1192 } -1193 shutdownMiniDFSCluster(); -1194 -1195 cleanupTestDir(); -1196 miniClusterRunning = false; -1197 LOG.info("Minicluster is down"); -1198 } -1199 -1200 /** -1201 * @return True if we removed the test dirs -1202 * @throws IOException -1203 */ -1204 @Override -1205 public boolean cleanupTestDir() throws IOException { -1206 boolean ret = super.cleanupTestDir(); -1207 if (deleteDir(this.clusterTestDir)) { -1208 this.clusterTestDir = null; -1209 return ret & true; -1210 } -1211 return false; -1212 } -1213 -1214 /** -1215 * Shutdown HBase mini cluster. Does not shutdown zk or dfs if running. -1216 * @throws IOException -1217 */ -1218 public void shutdownMiniHBaseCluster() throws IOException { -1219 if (hbaseAdmin != null) { -1220 hbaseAdmin.close(); -1221 hbaseAdmin = null; -1222 } -1223 -1224 // unset the configuration for MIN and MAX RS to start -1225 conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1); -1226 conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -1); -1227 if (this.hbaseCluster != null) { -1228 this.hbaseCluster.shutdown(); -1229 // Wait till hbase is down before going on to shutdown zk. -1230 this.hbaseCluster.waitUntilShutDown(); -1231 this.hbaseCluster = null; -1232 } -1233 -1234 if (zooKeeperWatcher != null) { -1235 zooKeeperWatcher.close(); -1236 zooKeeperWatcher = null; -1237 } -1238 } -1239 -1240 /** -1241 * Returns the path to the default root dir the minicluster uses. If <code>create</code> -1242 * is true, a new root directory path is fetched irrespective of whether it has been fetched -1243 * before or not. If false, previous path is used. -1244 * Note: this does not cause the root dir to be created. -1245 * @return Fully qualified path for the default hbase root dir -1246 * @throws IOException -1247 */ -1248 public Path getDefaultRootDirPath(boolean create) throws IOException { -1249 if (!create) { -1250 return getDataTestDirOnTestFS(); -1251 } else { -1252 return getNewDataTestDirOnTestFS(); -1253 } -1254 } -1255 -1256 /** -1257 * Same as {{@link HBaseTestingUtility#getDefaultRootDirPath(boolean create)} -1258 * except that <code>create</code> flag is false. -1259 * Note: this does not cause the root dir to be created. -1260 * @return Fully qualified path for the default hbase root dir -1261 * @throws IOException -1262 */ -1263 public Path getDefaultRootDirPath() throws IOException { -1264 return getDefaultRootDirPath(false); -1265 } -1266 -1267 /** -1268 * Creates an hbase rootdir in user home directory. Also creates hbase -1269 * version file. Normally you won't make use of this method. Root hbasedir -1270 * is created for you as part of mini cluster startup. You'd only use this -1271 * method if you were doing manual operation. -1272 * @param create This flag decides whether to get a new -1273 * root or data directory path or not, if it has been fetched already. -1274 * Note : Directory will be made irrespective of whether path has been fetched or not. -1275 * If directory already exists, it will be overwritten -1276 * @return Fully qualified path to hbase root dir -1277 * @throws IOException -1278 */ -1279 public Path createRootDir(boolean create) throws IOException { -1280 FileSystem fs = FileSystem.get(this.conf); -1281 Path hbaseRootdir = getDefaultRootDirPath(create); -1282 FSUtils.setRootDir(this.conf, hbaseRootdir); -1283 fs.mkdirs(hbaseRootdir); -1284 FSUtils.setVersion(fs, hbaseRootdir); -1285 return hbaseRootdir; -1286 } -1287 -1288 /** -1289 * Same as {@link HBaseTestingUtility#createRootDir(boolean create)} -1290 * except that <code>create</code> flag is false. -1291 * @return Fully qualified path to hbase root dir -1292 * @throws IOException -1293 */ -1294 public Path createRootDir() throws IOException { -1295 return createRootDir(false); -1296 } -1297 -1298 /** -1299 * Creates a hbase walDir in the user's home directory. -1300 * Normally you won't make use of this method. Root hbaseWALDir -1301 * is created for you as part of mini cluster startup. You'd only use this -1302 * method if you were doing manual operation. -1303 * -1304 * @return Fully qualified path to hbase root dir -1305 * @throws IOException -1306 */ -1307 public Path createWALRootDir() throws IOException { -1308 FileSystem fs = FileSystem.get(this.conf); -1309 Path walDir = getNewDataTestDirOnTestFS(); -1310 FSUtils.setWALRootDir(this.conf, walDir); -1311 fs.mkdirs(walDir); -1312 return walDir; -1313 } -1314 -1315 private void setHBaseFsTmpDir() throws IOException { -1316 String hbaseFsTmpDirInString = this.conf.get("hbase.fs.tmp.dir"); -1317 if (hbaseFsTmpDirInString == null) { -1318 this.conf.set("hbase.fs.tmp.dir", getDataTestDirOnTestFS("hbase-staging").toString()); -1319 LOG.info("Setting hbase.fs.tmp.dir to " + this.conf.get("hbase.fs.tmp.dir")); -1320 } else { -1321 LOG.info("The hbase.fs.tmp.dir is set to " + hbaseFsTmpDirInString); -1322 } -1323 } -1324 -1325 /** -1326 * Flushes all caches in the mini hbase cluster -1327 * @throws IOException -1328 */ -1329 public void flush() throws IOException { -1330 getMiniHBaseCluster().flushcache(); -1331 } -1332 -1333 /** -1334 * Flushes all caches in the mini hbase cluster -1335 * @throws IOException -1336 */ -1337 public void flush(TableName tableName) throws IOException { -1338 getMiniHBaseCluster().flushcache(tableName); -1339 } -1340 -1341 /** -1342 * Compact all regions in the mini hbase cluster -1343 * @throws IOException -1344 */ -1345 public void compact(boolean major) throws IOException { -1346 getMiniHBaseCluster().compact(major); -1347 } -1348 -1349 /** -1350 * Compact all of a table's reagion in the mini hbase cluster -1351 * @throws IOException -1352 */ -1353 public void compact(TableName tableName, boolean major) throws IOException { -1354 getMiniHBaseCluster().compact(tableName, major); -1355 } -1356 -1357 /** -1358 * Create a table. -1359 * @param tableName -1360 * @param family -1361 * @return An HTable instance for the created table. -1362 * @throws IOException -1363 */ -1364 public Table createTable(TableName tableName, String family) -1365 throws IOException{ -1366 return createTable(tableName, new String[]{family}); -1367 } -1368 -1369 /** -1370 * Create a table. -1371 * @param tableName -1372 * @param families -1373 * @return An HTable instance for the created table. -1374 * @throws IOException -1375 */ -1376 public Table createTable(TableName tableName, String[] families) -1377 throws IOException { -1378 List<byte[]> fams = new ArrayList<>(families.length); -1379 for (String family : families) { -1380 fams.add(Bytes.toBytes(family)); -1381 } -1382 return createTable(tableName, fams.toArray(new byte[0][])); -1383 } -1384 -1385 /** -1386 * Create a table. -1387 * @param tableName -1388 * @param family -1389 * @return An HTable instance for the created table. -1390 * @throws IOException -1391 */ -1392 public Table createTable(TableName tableName, byte[] family) -1393 throws IOException{ -1394 return createTable(tableName, new byte[][]{family}); -1395 } -1396 -1397 /** -1398 * Create a table with multiple regions. -1399 * @param tableName -1400 * @param family -1401 * @param numRegions -1402 * @return An HTable instance for the created table. -1403 * @throws IOException -1404 */ -1405 public Table createMultiRegionTable(TableName tableName, byte[] family, int numRegions) -1406 throws IOException { -1407 if (numRegions < 3) throw new IOException("Must create at least 3 regions"); -1408 byte[] startKey = Bytes.toBytes("aaaaa"); -1409 byte[] endKey = Bytes.toBytes("zzzzz"); -1410 byte[][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); -1411 -1412 return createTable(tableName, new byte[][] { family }, splitKeys); -1413 } -1414 -1415 /** -1416 * Create a table. -1417 * @param tableName -1418 * @param families -1419 * @return An HTable instance for the created table. -1420 * @throws IOException -1421 */ -1422 public Table createTable(TableName tableName, byte[][] families) -1423 throws IOException { -1424 return createTable(tableName, families, (byte[][]) null); -1425 } -1426 -1427 /** -1428 * Create a table with multiple regions. -1429 * @param tableName -1430 * @param families -1431 * @return An HTable instance for the created table. -1432 * @throws IOException -1433 */ -1434 public Table createMultiRegionTable(TableName tableName, byte[][] families) throws IOException { -1435 return createTable(tableName, families, KEYS_FOR_HBA_CREATE_TABLE); -1436 } -1437 -1438 /** -1439 * Create a table. -1440 * @param tableName -1441 * @param families -1442 * @param splitKeys -1443 * @return An HTable instance for the created table. -1444 * @throws IOException -1445 */ -1446 public Table createTable(TableName tableName, byte[][] families, byte[][] splitKeys) -1447 throws IOException { -1448 return createTable(tableName, families, splitKeys, new Configuration(getConfiguration())); -1449 } -1450 -1451 public Table createTable(TableName tableName, byte[][] families, -1452 int numVersions, byte[] startKey, byte[] endKey, int numRegions) -1453 throws IOException{ -1454 HTableDescriptor desc = createTableDescriptor(tableName, families, numVersions); -1455 -1456 getAdmin().createTable(desc, startKey, endKey, numRegions); -1457 // HBaseAdmin only waits for regions to appear in hbase:meta we -1458 // should wait until they are assigned -1459 waitUntilAllRegionsAssigned(tableName); -1460 return getConnection().getTable(tableName); -1461 } -1462 -1463 /** -1464 * Create a table. -1465 * @param htd -1466 * @param families -1467 * @param c Configuration to use -1468 * @return An HTable instance for the created table. -1469 * @throws IOException -1470 */ -1471 public Table createTable(HTableDescriptor htd, byte[][] families, Configuration c) -1472 throws IOException { -1473 return createTable(htd, families, null, c); -1474 } -1475 -1476 /** -1477 * Create a table. -1478 * @param htd -1479 * @param families -1480 * @param splitKeys -1481 * @param c Configuration to use -1482 * @return An HTable instance for the created table. -1483 * @throws IOException -1484 */ -1485 public Table createTable(HTableDescriptor htd, byte[][] families, byte[][] splitKeys, -1486 Configuration c) throws IOException { -1487 for (byte[] family : families) { -1488 HColumnDescriptor hcd = new HColumnDescriptor(family); -1489 // Disable blooms (they are on by default as of 0.95) but we disable them here because -1490 // tests have hard coded counts of what to expect in block cache, etc., and blooms being -1491 // on is interfering. -1492 hcd.setBloomFilterType(BloomType.NONE); -1493 htd.addFamily(hcd); -1494 } -1495 getAdmin().createTable(htd, splitKeys); -1496 // HBaseAdmin only waits for regions to appear in hbase:meta -1497 // we should wait until they are assigned -1498 waitUntilAllRegionsAssigned(htd.getTableName()); -1499 return getConnection().getTable(htd.getTableName()); -1500 } -1501 -1502 /** -1503 * Create a table. -1504 * @param htd -1505 * @param splitRows -1506 * @return An HTable instance for the created table. -1507 * @throws IOException -1508 */ -1509 public Table createTable(HTableDescriptor htd, byte[][] splitRows) -1510 throws IOException { -1511 getAdmin().createTable(htd, splitRows); -1512 // HBaseAdmin only waits for regions to appear in hbase:meta -1513 // we should wait until they are assigned -1514 waitUntilAllRegionsAssigned(htd.getTableName()); -1515 return getConnection().getTable(htd.getTableName()); -1516 } -1517 -1518 /** -1519 * Create a table. -1520 * @param tableName -1521 * @param families -1522 * @param splitKeys -1523 * @param c Configuration to use -1524 * @return An HTable instance for the created table. -1525 * @throws IOException -1526 */ -1527 public Table createTable(TableName tableName, byte[][] families, byte[][] splitKeys, -1528 final Configuration c) throws IOException { -1529 return createTable(new HTableDescriptor(tableName), families, splitKeys, c); -1530 } -1531 -1532 /** -1533 * Create a table. -1534 * @param tableName -1535 * @param family -1536 * @param numVersions -1537 * @return An HTable instance for the created table. -1538 * @throws IOException -1539 */ -1540 public Table createTable(TableName tableName, byte[] family, int numVersions) -1541 throws IOException { -1542 return createTable(tableName, new byte[][]{family}, numVersions); -1543 } -1544 -1545 /** -1546 * Create a table. -1547 * @param tableName -1548 * @param families -1549 * @param numVersions -1550 * @return An HTable instance for the created table. -1551 * @throws IOException -1552 */ -1553 public Table createTable(TableName tableName, byte[][] families, int numVersions) -1554 throws IOException { -1555 return createTable(tableName, families, numVersions, (byte[][]) null); -1556 } -1557 -1558 /** -1559 * Create a table. -1560 * @param tableName -1561 * @param families -1562 * @param numVersions -1563 * @param splitKeys -1564 * @return An HTable instance for the created table. -1565 * @throws IOException -1566 */ -1567 public Table createTable(TableName tableName, byte[][] families, int numVersions, -1568 byte[][] splitKeys) throws IOException { -1569 HTableDescriptor desc = new HTableDescriptor(tableName); -1570 for (byte[] family : families) { -1571 HColumnDescriptor hcd = new HColumnDescriptor(family).setMaxVersions(numVersions); -1572 desc.addFamily(hcd); -1573 } -1574 getAdmin().createTable(desc, splitKeys); -1575 // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are -1576 // assigned -1577 waitUntilAllRegionsAssigned(tableName); -1578 return getConnection().getTable(tableName); -1579 } -1580 -1581 /** -1582 * Create a table with multiple regions. -1583 * @param tableName -1584 * @param families -1585 * @param numVersions -1586 * @return An HTable instance for the created table. -1587 * @throws IOException -1588 */ -1589 public Table createMultiRegionTable(TableName tableName, byte[][] families, int numVersions) -1590 throws IOException { -1591 return createTable(tableName, families, numVersions, KEYS_FOR_HBA_CREATE_TABLE); -1592 } -1593 -1594 /** -1595 * Create a table. -1596 * @param tableName -1597 * @param families -1598 * @param numVersions -1599 * @param blockSize -1600 * @return An HTable instance for the created table. -1601 * @throws IOException -1602 */ -1603 public Table createTable(TableName tableName, byte[][] families, -1604 int numVersions, int blockSize) throws IOException { -1605 HTableDescriptor desc = new HTableDescriptor(tableName); -1606 for (byte[] family : families) {