Repository: hbase-site Updated Branches: refs/heads/asf-site ba00a2513 -> 5299e6673
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/5299e667/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html index 1c0118e..63362ed 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html @@ -1120,2858 +1120,2862 @@ <span class="sourceLineNo">1112</span> getChoreService().scheduleChore(catalogJanitorChore);<a name="line.1112"></a> <span class="sourceLineNo">1113</span> this.serverManager.startChore();<a name="line.1113"></a> <span class="sourceLineNo">1114</span><a name="line.1114"></a> -<span class="sourceLineNo">1115</span> // NAMESPACE READ!!!!<a name="line.1115"></a> -<span class="sourceLineNo">1116</span> // Here we expect hbase:namespace to be online. See inside initClusterSchemaService.<a name="line.1116"></a> -<span class="sourceLineNo">1117</span> // TODO: Fix this. Namespace is a pain being a sort-of system table. Fold it in to hbase:meta.<a name="line.1117"></a> -<span class="sourceLineNo">1118</span> // isNamespace does like isMeta and waits until namespace is onlined before allowing progress.<a name="line.1118"></a> -<span class="sourceLineNo">1119</span> if (!waitForNamespaceOnline()) {<a name="line.1119"></a> -<span class="sourceLineNo">1120</span> return;<a name="line.1120"></a> -<span class="sourceLineNo">1121</span> }<a name="line.1121"></a> -<span class="sourceLineNo">1122</span> status.setStatus("Starting cluster schema service");<a name="line.1122"></a> -<span class="sourceLineNo">1123</span> initClusterSchemaService();<a name="line.1123"></a> -<span class="sourceLineNo">1124</span><a name="line.1124"></a> -<span class="sourceLineNo">1125</span> if (this.cpHost != null) {<a name="line.1125"></a> -<span class="sourceLineNo">1126</span> try {<a name="line.1126"></a> -<span class="sourceLineNo">1127</span> this.cpHost.preMasterInitialization();<a name="line.1127"></a> -<span class="sourceLineNo">1128</span> } catch (IOException e) {<a name="line.1128"></a> -<span class="sourceLineNo">1129</span> LOG.error("Coprocessor preMasterInitialization() hook failed", e);<a name="line.1129"></a> -<span class="sourceLineNo">1130</span> }<a name="line.1130"></a> -<span class="sourceLineNo">1131</span> }<a name="line.1131"></a> -<span class="sourceLineNo">1132</span><a name="line.1132"></a> -<span class="sourceLineNo">1133</span> status.markComplete("Initialization successful");<a name="line.1133"></a> -<span class="sourceLineNo">1134</span> LOG.info(String.format("Master has completed initialization %.3fsec",<a name="line.1134"></a> -<span class="sourceLineNo">1135</span> (System.currentTimeMillis() - masterActiveTime) / 1000.0f));<a name="line.1135"></a> -<span class="sourceLineNo">1136</span> this.masterFinishedInitializationTime = System.currentTimeMillis();<a name="line.1136"></a> -<span class="sourceLineNo">1137</span> configurationManager.registerObserver(this.balancer);<a name="line.1137"></a> -<span class="sourceLineNo">1138</span> configurationManager.registerObserver(this.hfileCleaner);<a name="line.1138"></a> -<span class="sourceLineNo">1139</span> configurationManager.registerObserver(this.logCleaner);<a name="line.1139"></a> -<span class="sourceLineNo">1140</span> // Set master as 'initialized'.<a name="line.1140"></a> -<span class="sourceLineNo">1141</span> setInitialized(true);<a name="line.1141"></a> -<span class="sourceLineNo">1142</span><a name="line.1142"></a> -<span class="sourceLineNo">1143</span> if (maintenanceMode) {<a name="line.1143"></a> -<span class="sourceLineNo">1144</span> LOG.info("Detected repair mode, skipping final initialization steps.");<a name="line.1144"></a> -<span class="sourceLineNo">1145</span> return;<a name="line.1145"></a> -<span class="sourceLineNo">1146</span> }<a name="line.1146"></a> -<span class="sourceLineNo">1147</span><a name="line.1147"></a> -<span class="sourceLineNo">1148</span> assignmentManager.checkIfShouldMoveSystemRegionAsync();<a name="line.1148"></a> -<span class="sourceLineNo">1149</span> status.setStatus("Assign meta replicas");<a name="line.1149"></a> -<span class="sourceLineNo">1150</span> MasterMetaBootstrap metaBootstrap = createMetaBootstrap();<a name="line.1150"></a> -<span class="sourceLineNo">1151</span> metaBootstrap.assignMetaReplicas();<a name="line.1151"></a> -<span class="sourceLineNo">1152</span> status.setStatus("Starting quota manager");<a name="line.1152"></a> -<span class="sourceLineNo">1153</span> initQuotaManager();<a name="line.1153"></a> -<span class="sourceLineNo">1154</span> if (QuotaUtil.isQuotaEnabled(conf)) {<a name="line.1154"></a> -<span class="sourceLineNo">1155</span> // Create the quota snapshot notifier<a name="line.1155"></a> -<span class="sourceLineNo">1156</span> spaceQuotaSnapshotNotifier = createQuotaSnapshotNotifier();<a name="line.1156"></a> -<span class="sourceLineNo">1157</span> spaceQuotaSnapshotNotifier.initialize(getClusterConnection());<a name="line.1157"></a> -<span class="sourceLineNo">1158</span> this.quotaObserverChore = new QuotaObserverChore(this, getMasterMetrics());<a name="line.1158"></a> -<span class="sourceLineNo">1159</span> // Start the chore to read the region FS space reports and act on them<a name="line.1159"></a> -<span class="sourceLineNo">1160</span> getChoreService().scheduleChore(quotaObserverChore);<a name="line.1160"></a> -<span class="sourceLineNo">1161</span><a name="line.1161"></a> -<span class="sourceLineNo">1162</span> this.snapshotQuotaChore = new SnapshotQuotaObserverChore(this, getMasterMetrics());<a name="line.1162"></a> -<span class="sourceLineNo">1163</span> // Start the chore to read snapshots and add their usage to table/NS quotas<a name="line.1163"></a> -<span class="sourceLineNo">1164</span> getChoreService().scheduleChore(snapshotQuotaChore);<a name="line.1164"></a> -<span class="sourceLineNo">1165</span> }<a name="line.1165"></a> -<span class="sourceLineNo">1166</span><a name="line.1166"></a> -<span class="sourceLineNo">1167</span> // clear the dead servers with same host name and port of online server because we are not<a name="line.1167"></a> -<span class="sourceLineNo">1168</span> // removing dead server with same hostname and port of rs which is trying to check in before<a name="line.1168"></a> -<span class="sourceLineNo">1169</span> // master initialization. See HBASE-5916.<a name="line.1169"></a> -<span class="sourceLineNo">1170</span> this.serverManager.clearDeadServersWithSameHostNameAndPortOfOnlineServer();<a name="line.1170"></a> -<span class="sourceLineNo">1171</span><a name="line.1171"></a> -<span class="sourceLineNo">1172</span> // Check and set the znode ACLs if needed in case we are overtaking a non-secure configuration<a name="line.1172"></a> -<span class="sourceLineNo">1173</span> status.setStatus("Checking ZNode ACLs");<a name="line.1173"></a> -<span class="sourceLineNo">1174</span> zooKeeper.checkAndSetZNodeAcls();<a name="line.1174"></a> +<span class="sourceLineNo">1115</span> // Only for rolling upgrade, where we need to migrate the data in namespace table to meta table.<a name="line.1115"></a> +<span class="sourceLineNo">1116</span> if (!waitForNamespaceOnline()) {<a name="line.1116"></a> +<span class="sourceLineNo">1117</span> return;<a name="line.1117"></a> +<span class="sourceLineNo">1118</span> }<a name="line.1118"></a> +<span class="sourceLineNo">1119</span> status.setStatus("Starting cluster schema service");<a name="line.1119"></a> +<span class="sourceLineNo">1120</span> initClusterSchemaService();<a name="line.1120"></a> +<span class="sourceLineNo">1121</span><a name="line.1121"></a> +<span class="sourceLineNo">1122</span> if (this.cpHost != null) {<a name="line.1122"></a> +<span class="sourceLineNo">1123</span> try {<a name="line.1123"></a> +<span class="sourceLineNo">1124</span> this.cpHost.preMasterInitialization();<a name="line.1124"></a> +<span class="sourceLineNo">1125</span> } catch (IOException e) {<a name="line.1125"></a> +<span class="sourceLineNo">1126</span> LOG.error("Coprocessor preMasterInitialization() hook failed", e);<a name="line.1126"></a> +<span class="sourceLineNo">1127</span> }<a name="line.1127"></a> +<span class="sourceLineNo">1128</span> }<a name="line.1128"></a> +<span class="sourceLineNo">1129</span><a name="line.1129"></a> +<span class="sourceLineNo">1130</span> status.markComplete("Initialization successful");<a name="line.1130"></a> +<span class="sourceLineNo">1131</span> LOG.info(String.format("Master has completed initialization %.3fsec",<a name="line.1131"></a> +<span class="sourceLineNo">1132</span> (System.currentTimeMillis() - masterActiveTime) / 1000.0f));<a name="line.1132"></a> +<span class="sourceLineNo">1133</span> this.masterFinishedInitializationTime = System.currentTimeMillis();<a name="line.1133"></a> +<span class="sourceLineNo">1134</span> configurationManager.registerObserver(this.balancer);<a name="line.1134"></a> +<span class="sourceLineNo">1135</span> configurationManager.registerObserver(this.hfileCleaner);<a name="line.1135"></a> +<span class="sourceLineNo">1136</span> configurationManager.registerObserver(this.logCleaner);<a name="line.1136"></a> +<span class="sourceLineNo">1137</span> // Set master as 'initialized'.<a name="line.1137"></a> +<span class="sourceLineNo">1138</span> setInitialized(true);<a name="line.1138"></a> +<span class="sourceLineNo">1139</span><a name="line.1139"></a> +<span class="sourceLineNo">1140</span> if (maintenanceMode) {<a name="line.1140"></a> +<span class="sourceLineNo">1141</span> LOG.info("Detected repair mode, skipping final initialization steps.");<a name="line.1141"></a> +<span class="sourceLineNo">1142</span> return;<a name="line.1142"></a> +<span class="sourceLineNo">1143</span> }<a name="line.1143"></a> +<span class="sourceLineNo">1144</span><a name="line.1144"></a> +<span class="sourceLineNo">1145</span> assignmentManager.checkIfShouldMoveSystemRegionAsync();<a name="line.1145"></a> +<span class="sourceLineNo">1146</span> status.setStatus("Assign meta replicas");<a name="line.1146"></a> +<span class="sourceLineNo">1147</span> MasterMetaBootstrap metaBootstrap = createMetaBootstrap();<a name="line.1147"></a> +<span class="sourceLineNo">1148</span> metaBootstrap.assignMetaReplicas();<a name="line.1148"></a> +<span class="sourceLineNo">1149</span> status.setStatus("Starting quota manager");<a name="line.1149"></a> +<span class="sourceLineNo">1150</span> initQuotaManager();<a name="line.1150"></a> +<span class="sourceLineNo">1151</span> if (QuotaUtil.isQuotaEnabled(conf)) {<a name="line.1151"></a> +<span class="sourceLineNo">1152</span> // Create the quota snapshot notifier<a name="line.1152"></a> +<span class="sourceLineNo">1153</span> spaceQuotaSnapshotNotifier = createQuotaSnapshotNotifier();<a name="line.1153"></a> +<span class="sourceLineNo">1154</span> spaceQuotaSnapshotNotifier.initialize(getClusterConnection());<a name="line.1154"></a> +<span class="sourceLineNo">1155</span> this.quotaObserverChore = new QuotaObserverChore(this, getMasterMetrics());<a name="line.1155"></a> +<span class="sourceLineNo">1156</span> // Start the chore to read the region FS space reports and act on them<a name="line.1156"></a> +<span class="sourceLineNo">1157</span> getChoreService().scheduleChore(quotaObserverChore);<a name="line.1157"></a> +<span class="sourceLineNo">1158</span><a name="line.1158"></a> +<span class="sourceLineNo">1159</span> this.snapshotQuotaChore = new SnapshotQuotaObserverChore(this, getMasterMetrics());<a name="line.1159"></a> +<span class="sourceLineNo">1160</span> // Start the chore to read snapshots and add their usage to table/NS quotas<a name="line.1160"></a> +<span class="sourceLineNo">1161</span> getChoreService().scheduleChore(snapshotQuotaChore);<a name="line.1161"></a> +<span class="sourceLineNo">1162</span> }<a name="line.1162"></a> +<span class="sourceLineNo">1163</span><a name="line.1163"></a> +<span class="sourceLineNo">1164</span> // clear the dead servers with same host name and port of online server because we are not<a name="line.1164"></a> +<span class="sourceLineNo">1165</span> // removing dead server with same hostname and port of rs which is trying to check in before<a name="line.1165"></a> +<span class="sourceLineNo">1166</span> // master initialization. See HBASE-5916.<a name="line.1166"></a> +<span class="sourceLineNo">1167</span> this.serverManager.clearDeadServersWithSameHostNameAndPortOfOnlineServer();<a name="line.1167"></a> +<span class="sourceLineNo">1168</span><a name="line.1168"></a> +<span class="sourceLineNo">1169</span> // Check and set the znode ACLs if needed in case we are overtaking a non-secure configuration<a name="line.1169"></a> +<span class="sourceLineNo">1170</span> status.setStatus("Checking ZNode ACLs");<a name="line.1170"></a> +<span class="sourceLineNo">1171</span> zooKeeper.checkAndSetZNodeAcls();<a name="line.1171"></a> +<span class="sourceLineNo">1172</span><a name="line.1172"></a> +<span class="sourceLineNo">1173</span> status.setStatus("Initializing MOB Cleaner");<a name="line.1173"></a> +<span class="sourceLineNo">1174</span> initMobCleaner();<a name="line.1174"></a> <span class="sourceLineNo">1175</span><a name="line.1175"></a> -<span class="sourceLineNo">1176</span> status.setStatus("Initializing MOB Cleaner");<a name="line.1176"></a> -<span class="sourceLineNo">1177</span> initMobCleaner();<a name="line.1177"></a> -<span class="sourceLineNo">1178</span><a name="line.1178"></a> -<span class="sourceLineNo">1179</span> status.setStatus("Calling postStartMaster coprocessors");<a name="line.1179"></a> -<span class="sourceLineNo">1180</span> if (this.cpHost != null) {<a name="line.1180"></a> -<span class="sourceLineNo">1181</span> // don't let cp initialization errors kill the master<a name="line.1181"></a> -<span class="sourceLineNo">1182</span> try {<a name="line.1182"></a> -<span class="sourceLineNo">1183</span> this.cpHost.postStartMaster();<a name="line.1183"></a> -<span class="sourceLineNo">1184</span> } catch (IOException ioe) {<a name="line.1184"></a> -<span class="sourceLineNo">1185</span> LOG.error("Coprocessor postStartMaster() hook failed", ioe);<a name="line.1185"></a> -<span class="sourceLineNo">1186</span> }<a name="line.1186"></a> -<span class="sourceLineNo">1187</span> }<a name="line.1187"></a> -<span class="sourceLineNo">1188</span><a name="line.1188"></a> -<span class="sourceLineNo">1189</span> zombieDetector.interrupt();<a name="line.1189"></a> -<span class="sourceLineNo">1190</span><a name="line.1190"></a> -<span class="sourceLineNo">1191</span> /*<a name="line.1191"></a> -<span class="sourceLineNo">1192</span> * After master has started up, lets do balancer post startup initialization. Since this runs<a name="line.1192"></a> -<span class="sourceLineNo">1193</span> * in activeMasterManager thread, it should be fine.<a name="line.1193"></a> -<span class="sourceLineNo">1194</span> */<a name="line.1194"></a> -<span class="sourceLineNo">1195</span> long start = System.currentTimeMillis();<a name="line.1195"></a> -<span class="sourceLineNo">1196</span> this.balancer.postMasterStartupInitialize();<a name="line.1196"></a> -<span class="sourceLineNo">1197</span> if (LOG.isDebugEnabled()) {<a name="line.1197"></a> -<span class="sourceLineNo">1198</span> LOG.debug("Balancer post startup initialization complete, took " + (<a name="line.1198"></a> -<span class="sourceLineNo">1199</span> (System.currentTimeMillis() - start) / 1000) + " seconds");<a name="line.1199"></a> -<span class="sourceLineNo">1200</span> }<a name="line.1200"></a> -<span class="sourceLineNo">1201</span> }<a name="line.1201"></a> -<span class="sourceLineNo">1202</span><a name="line.1202"></a> -<span class="sourceLineNo">1203</span> /**<a name="line.1203"></a> -<span class="sourceLineNo">1204</span> * Check hbase:meta is up and ready for reading. For use during Master startup only.<a name="line.1204"></a> -<span class="sourceLineNo">1205</span> * @return True if meta is UP and online and startup can progress. Otherwise, meta is not online<a name="line.1205"></a> -<span class="sourceLineNo">1206</span> * and we will hold here until operator intervention.<a name="line.1206"></a> -<span class="sourceLineNo">1207</span> */<a name="line.1207"></a> -<span class="sourceLineNo">1208</span> @VisibleForTesting<a name="line.1208"></a> -<span class="sourceLineNo">1209</span> public boolean waitForMetaOnline() throws InterruptedException {<a name="line.1209"></a> -<span class="sourceLineNo">1210</span> return isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO);<a name="line.1210"></a> -<span class="sourceLineNo">1211</span> }<a name="line.1211"></a> -<span class="sourceLineNo">1212</span><a name="line.1212"></a> -<span class="sourceLineNo">1213</span> /**<a name="line.1213"></a> -<span class="sourceLineNo">1214</span> * @return True if region is online and scannable else false if an error or shutdown (Otherwise<a name="line.1214"></a> -<span class="sourceLineNo">1215</span> * we just block in here holding up all forward-progess).<a name="line.1215"></a> -<span class="sourceLineNo">1216</span> */<a name="line.1216"></a> -<span class="sourceLineNo">1217</span> private boolean isRegionOnline(RegionInfo ri) throws InterruptedException {<a name="line.1217"></a> -<span class="sourceLineNo">1218</span> RetryCounter rc = null;<a name="line.1218"></a> -<span class="sourceLineNo">1219</span> while (!isStopped()) {<a name="line.1219"></a> -<span class="sourceLineNo">1220</span> RegionState rs = this.assignmentManager.getRegionStates().getRegionState(ri);<a name="line.1220"></a> -<span class="sourceLineNo">1221</span> if (rs.isOpened()) {<a name="line.1221"></a> -<span class="sourceLineNo">1222</span> if (this.getServerManager().isServerOnline(rs.getServerName())) {<a name="line.1222"></a> -<span class="sourceLineNo">1223</span> return true;<a name="line.1223"></a> -<span class="sourceLineNo">1224</span> }<a name="line.1224"></a> -<span class="sourceLineNo">1225</span> }<a name="line.1225"></a> -<span class="sourceLineNo">1226</span> // Region is not OPEN.<a name="line.1226"></a> -<span class="sourceLineNo">1227</span> Optional<Procedure<MasterProcedureEnv>> optProc = this.procedureExecutor.getProcedures().<a name="line.1227"></a> -<span class="sourceLineNo">1228</span> stream().filter(p -> p instanceof ServerCrashProcedure).findAny();<a name="line.1228"></a> -<span class="sourceLineNo">1229</span> // TODO: Add a page to refguide on how to do repair. Have this log message point to it.<a name="line.1229"></a> -<span class="sourceLineNo">1230</span> // Page will talk about loss of edits, how to schedule at least the meta WAL recovery, and<a name="line.1230"></a> -<span class="sourceLineNo">1231</span> // then how to assign including how to break region lock if one held.<a name="line.1231"></a> -<span class="sourceLineNo">1232</span> LOG.warn("{} is NOT online; state={}; ServerCrashProcedures={}. Master startup cannot " +<a name="line.1232"></a> -<span class="sourceLineNo">1233</span> "progress, in holding-pattern until region onlined.",<a name="line.1233"></a> -<span class="sourceLineNo">1234</span> ri.getRegionNameAsString(), rs, optProc.isPresent());<a name="line.1234"></a> -<span class="sourceLineNo">1235</span> // Check once-a-minute.<a name="line.1235"></a> -<span class="sourceLineNo">1236</span> if (rc == null) {<a name="line.1236"></a> -<span class="sourceLineNo">1237</span> rc = new RetryCounterFactory(1000).create();<a name="line.1237"></a> -<span class="sourceLineNo">1238</span> }<a name="line.1238"></a> -<span class="sourceLineNo">1239</span> Threads.sleep(rc.getBackoffTimeAndIncrementAttempts());<a name="line.1239"></a> -<span class="sourceLineNo">1240</span> }<a name="line.1240"></a> -<span class="sourceLineNo">1241</span> return false;<a name="line.1241"></a> -<span class="sourceLineNo">1242</span> }<a name="line.1242"></a> -<span class="sourceLineNo">1243</span><a name="line.1243"></a> -<span class="sourceLineNo">1244</span> /**<a name="line.1244"></a> -<span class="sourceLineNo">1245</span> * Check hbase:namespace table is assigned. If not, startup will hang looking for the ns table<a name="line.1245"></a> -<span class="sourceLineNo">1246</span> * (TODO: Fix this! NS should not hold-up startup).<a name="line.1246"></a> +<span class="sourceLineNo">1176</span> status.setStatus("Calling postStartMaster coprocessors");<a name="line.1176"></a> +<span class="sourceLineNo">1177</span> if (this.cpHost != null) {<a name="line.1177"></a> +<span class="sourceLineNo">1178</span> // don't let cp initialization errors kill the master<a name="line.1178"></a> +<span class="sourceLineNo">1179</span> try {<a name="line.1179"></a> +<span class="sourceLineNo">1180</span> this.cpHost.postStartMaster();<a name="line.1180"></a> +<span class="sourceLineNo">1181</span> } catch (IOException ioe) {<a name="line.1181"></a> +<span class="sourceLineNo">1182</span> LOG.error("Coprocessor postStartMaster() hook failed", ioe);<a name="line.1182"></a> +<span class="sourceLineNo">1183</span> }<a name="line.1183"></a> +<span class="sourceLineNo">1184</span> }<a name="line.1184"></a> +<span class="sourceLineNo">1185</span><a name="line.1185"></a> +<span class="sourceLineNo">1186</span> zombieDetector.interrupt();<a name="line.1186"></a> +<span class="sourceLineNo">1187</span><a name="line.1187"></a> +<span class="sourceLineNo">1188</span> /*<a name="line.1188"></a> +<span class="sourceLineNo">1189</span> * After master has started up, lets do balancer post startup initialization. Since this runs<a name="line.1189"></a> +<span class="sourceLineNo">1190</span> * in activeMasterManager thread, it should be fine.<a name="line.1190"></a> +<span class="sourceLineNo">1191</span> */<a name="line.1191"></a> +<span class="sourceLineNo">1192</span> long start = System.currentTimeMillis();<a name="line.1192"></a> +<span class="sourceLineNo">1193</span> this.balancer.postMasterStartupInitialize();<a name="line.1193"></a> +<span class="sourceLineNo">1194</span> if (LOG.isDebugEnabled()) {<a name="line.1194"></a> +<span class="sourceLineNo">1195</span> LOG.debug("Balancer post startup initialization complete, took " + (<a name="line.1195"></a> +<span class="sourceLineNo">1196</span> (System.currentTimeMillis() - start) / 1000) + " seconds");<a name="line.1196"></a> +<span class="sourceLineNo">1197</span> }<a name="line.1197"></a> +<span class="sourceLineNo">1198</span> }<a name="line.1198"></a> +<span class="sourceLineNo">1199</span><a name="line.1199"></a> +<span class="sourceLineNo">1200</span> /**<a name="line.1200"></a> +<span class="sourceLineNo">1201</span> * Check hbase:meta is up and ready for reading. For use during Master startup only.<a name="line.1201"></a> +<span class="sourceLineNo">1202</span> * @return True if meta is UP and online and startup can progress. Otherwise, meta is not online<a name="line.1202"></a> +<span class="sourceLineNo">1203</span> * and we will hold here until operator intervention.<a name="line.1203"></a> +<span class="sourceLineNo">1204</span> */<a name="line.1204"></a> +<span class="sourceLineNo">1205</span> @VisibleForTesting<a name="line.1205"></a> +<span class="sourceLineNo">1206</span> public boolean waitForMetaOnline() throws InterruptedException {<a name="line.1206"></a> +<span class="sourceLineNo">1207</span> return isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO);<a name="line.1207"></a> +<span class="sourceLineNo">1208</span> }<a name="line.1208"></a> +<span class="sourceLineNo">1209</span><a name="line.1209"></a> +<span class="sourceLineNo">1210</span> /**<a name="line.1210"></a> +<span class="sourceLineNo">1211</span> * @return True if region is online and scannable else false if an error or shutdown (Otherwise<a name="line.1211"></a> +<span class="sourceLineNo">1212</span> * we just block in here holding up all forward-progess).<a name="line.1212"></a> +<span class="sourceLineNo">1213</span> */<a name="line.1213"></a> +<span class="sourceLineNo">1214</span> private boolean isRegionOnline(RegionInfo ri) throws InterruptedException {<a name="line.1214"></a> +<span class="sourceLineNo">1215</span> RetryCounter rc = null;<a name="line.1215"></a> +<span class="sourceLineNo">1216</span> while (!isStopped()) {<a name="line.1216"></a> +<span class="sourceLineNo">1217</span> RegionState rs = this.assignmentManager.getRegionStates().getRegionState(ri);<a name="line.1217"></a> +<span class="sourceLineNo">1218</span> if (rs.isOpened()) {<a name="line.1218"></a> +<span class="sourceLineNo">1219</span> if (this.getServerManager().isServerOnline(rs.getServerName())) {<a name="line.1219"></a> +<span class="sourceLineNo">1220</span> return true;<a name="line.1220"></a> +<span class="sourceLineNo">1221</span> }<a name="line.1221"></a> +<span class="sourceLineNo">1222</span> }<a name="line.1222"></a> +<span class="sourceLineNo">1223</span> // Region is not OPEN.<a name="line.1223"></a> +<span class="sourceLineNo">1224</span> Optional<Procedure<MasterProcedureEnv>> optProc = this.procedureExecutor.getProcedures().<a name="line.1224"></a> +<span class="sourceLineNo">1225</span> stream().filter(p -> p instanceof ServerCrashProcedure).findAny();<a name="line.1225"></a> +<span class="sourceLineNo">1226</span> // TODO: Add a page to refguide on how to do repair. Have this log message point to it.<a name="line.1226"></a> +<span class="sourceLineNo">1227</span> // Page will talk about loss of edits, how to schedule at least the meta WAL recovery, and<a name="line.1227"></a> +<span class="sourceLineNo">1228</span> // then how to assign including how to break region lock if one held.<a name="line.1228"></a> +<span class="sourceLineNo">1229</span> LOG.warn("{} is NOT online; state={}; ServerCrashProcedures={}. Master startup cannot " +<a name="line.1229"></a> +<span class="sourceLineNo">1230</span> "progress, in holding-pattern until region onlined.",<a name="line.1230"></a> +<span class="sourceLineNo">1231</span> ri.getRegionNameAsString(), rs, optProc.isPresent());<a name="line.1231"></a> +<span class="sourceLineNo">1232</span> // Check once-a-minute.<a name="line.1232"></a> +<span class="sourceLineNo">1233</span> if (rc == null) {<a name="line.1233"></a> +<span class="sourceLineNo">1234</span> rc = new RetryCounterFactory(1000).create();<a name="line.1234"></a> +<span class="sourceLineNo">1235</span> }<a name="line.1235"></a> +<span class="sourceLineNo">1236</span> Threads.sleep(rc.getBackoffTimeAndIncrementAttempts());<a name="line.1236"></a> +<span class="sourceLineNo">1237</span> }<a name="line.1237"></a> +<span class="sourceLineNo">1238</span> return false;<a name="line.1238"></a> +<span class="sourceLineNo">1239</span> }<a name="line.1239"></a> +<span class="sourceLineNo">1240</span><a name="line.1240"></a> +<span class="sourceLineNo">1241</span> /**<a name="line.1241"></a> +<span class="sourceLineNo">1242</span> * Check hbase:namespace table is assigned. If not, startup will hang looking for the ns table<a name="line.1242"></a> +<span class="sourceLineNo">1243</span> * <p/><a name="line.1243"></a> +<span class="sourceLineNo">1244</span> * This is for rolling upgrading, later we will migrate the data in ns table to the ns family of<a name="line.1244"></a> +<span class="sourceLineNo">1245</span> * meta table. And if this is a new clsuter, this method will return immediately as there will be<a name="line.1245"></a> +<span class="sourceLineNo">1246</span> * no namespace table/region.<a name="line.1246"></a> <span class="sourceLineNo">1247</span> * @return True if namespace table is up/online.<a name="line.1247"></a> <span class="sourceLineNo">1248</span> */<a name="line.1248"></a> -<span class="sourceLineNo">1249</span> @VisibleForTesting<a name="line.1249"></a> -<span class="sourceLineNo">1250</span> public boolean waitForNamespaceOnline() throws InterruptedException {<a name="line.1250"></a> -<span class="sourceLineNo">1251</span> List<RegionInfo> ris = this.assignmentManager.getRegionStates().<a name="line.1251"></a> -<span class="sourceLineNo">1252</span> getRegionsOfTable(TableName.NAMESPACE_TABLE_NAME);<a name="line.1252"></a> -<span class="sourceLineNo">1253</span> if (ris.isEmpty()) {<a name="line.1253"></a> -<span class="sourceLineNo">1254</span> // If empty, means we've not assigned the namespace table yet... Just return true so startup<a name="line.1254"></a> -<span class="sourceLineNo">1255</span> // continues and the namespace table gets created.<a name="line.1255"></a> -<span class="sourceLineNo">1256</span> return true;<a name="line.1256"></a> -<span class="sourceLineNo">1257</span> }<a name="line.1257"></a> -<span class="sourceLineNo">1258</span> // Else there are namespace regions up in meta. Ensure they are assigned before we go on.<a name="line.1258"></a> -<span class="sourceLineNo">1259</span> for (RegionInfo ri: ris) {<a name="line.1259"></a> -<span class="sourceLineNo">1260</span> isRegionOnline(ri);<a name="line.1260"></a> -<span class="sourceLineNo">1261</span> }<a name="line.1261"></a> -<span class="sourceLineNo">1262</span> return true;<a name="line.1262"></a> -<span class="sourceLineNo">1263</span> }<a name="line.1263"></a> -<span class="sourceLineNo">1264</span><a name="line.1264"></a> -<span class="sourceLineNo">1265</span> /**<a name="line.1265"></a> -<span class="sourceLineNo">1266</span> * Adds the {@code MasterQuotasObserver} to the list of configured Master observers to<a name="line.1266"></a> -<span class="sourceLineNo">1267</span> * automatically remove quotas for a table when that table is deleted.<a name="line.1267"></a> -<span class="sourceLineNo">1268</span> */<a name="line.1268"></a> -<span class="sourceLineNo">1269</span> @VisibleForTesting<a name="line.1269"></a> -<span class="sourceLineNo">1270</span> public void updateConfigurationForQuotasObserver(Configuration conf) {<a name="line.1270"></a> -<span class="sourceLineNo">1271</span> // We're configured to not delete quotas on table deletion, so we don't need to add the obs.<a name="line.1271"></a> -<span class="sourceLineNo">1272</span> if (!conf.getBoolean(<a name="line.1272"></a> -<span class="sourceLineNo">1273</span> MasterQuotasObserver.REMOVE_QUOTA_ON_TABLE_DELETE,<a name="line.1273"></a> -<span class="sourceLineNo">1274</span> MasterQuotasObserver.REMOVE_QUOTA_ON_TABLE_DELETE_DEFAULT)) {<a name="line.1274"></a> -<span class="sourceLineNo">1275</span> return;<a name="line.1275"></a> -<span class="sourceLineNo">1276</span> }<a name="line.1276"></a> -<span class="sourceLineNo">1277</span> String[] masterCoprocs = conf.getStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);<a name="line.1277"></a> -<span class="sourceLineNo">1278</span> final int length = null == masterCoprocs ? 0 : masterCoprocs.length;<a name="line.1278"></a> -<span class="sourceLineNo">1279</span> String[] updatedCoprocs = new String[length + 1];<a name="line.1279"></a> -<span class="sourceLineNo">1280</span> if (length > 0) {<a name="line.1280"></a> -<span class="sourceLineNo">1281</span> System.arraycopy(masterCoprocs, 0, updatedCoprocs, 0, masterCoprocs.length);<a name="line.1281"></a> -<span class="sourceLineNo">1282</span> }<a name="line.1282"></a> -<span class="sourceLineNo">1283</span> updatedCoprocs[length] = MasterQuotasObserver.class.getName();<a name="line.1283"></a> -<span class="sourceLineNo">1284</span> conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, updatedCoprocs);<a name="line.1284"></a> -<span class="sourceLineNo">1285</span> }<a name="line.1285"></a> -<span class="sourceLineNo">1286</span><a name="line.1286"></a> -<span class="sourceLineNo">1287</span> private void initMobCleaner() {<a name="line.1287"></a> -<span class="sourceLineNo">1288</span> this.expiredMobFileCleanerChore = new ExpiredMobFileCleanerChore(this);<a name="line.1288"></a> -<span class="sourceLineNo">1289</span> getChoreService().scheduleChore(expiredMobFileCleanerChore);<a name="line.1289"></a> -<span class="sourceLineNo">1290</span><a name="line.1290"></a> -<span class="sourceLineNo">1291</span> int mobCompactionPeriod = conf.getInt(MobConstants.MOB_COMPACTION_CHORE_PERIOD,<a name="line.1291"></a> -<span class="sourceLineNo">1292</span> MobConstants.DEFAULT_MOB_COMPACTION_CHORE_PERIOD);<a name="line.1292"></a> -<span class="sourceLineNo">1293</span> if (mobCompactionPeriod > 0) {<a name="line.1293"></a> -<span class="sourceLineNo">1294</span> this.mobCompactChore = new MobCompactionChore(this, mobCompactionPeriod);<a name="line.1294"></a> -<span class="sourceLineNo">1295</span> getChoreService().scheduleChore(mobCompactChore);<a name="line.1295"></a> -<span class="sourceLineNo">1296</span> } else {<a name="line.1296"></a> -<span class="sourceLineNo">1297</span> LOG<a name="line.1297"></a> -<span class="sourceLineNo">1298</span> .info("The period is " + mobCompactionPeriod + " seconds, MobCompactionChore is disabled");<a name="line.1298"></a> -<span class="sourceLineNo">1299</span> }<a name="line.1299"></a> -<span class="sourceLineNo">1300</span> this.mobCompactThread = new MasterMobCompactionThread(this);<a name="line.1300"></a> -<span class="sourceLineNo">1301</span> }<a name="line.1301"></a> -<span class="sourceLineNo">1302</span><a name="line.1302"></a> -<span class="sourceLineNo">1303</span> /**<a name="line.1303"></a> -<span class="sourceLineNo">1304</span> * <p><a name="line.1304"></a> -<span class="sourceLineNo">1305</span> * Create a {@link MasterMetaBootstrap} instance.<a name="line.1305"></a> -<span class="sourceLineNo">1306</span> * </p><a name="line.1306"></a> -<span class="sourceLineNo">1307</span> * <p><a name="line.1307"></a> -<span class="sourceLineNo">1308</span> * Will be overridden in tests.<a name="line.1308"></a> -<span class="sourceLineNo">1309</span> * </p><a name="line.1309"></a> -<span class="sourceLineNo">1310</span> */<a name="line.1310"></a> -<span class="sourceLineNo">1311</span> @VisibleForTesting<a name="line.1311"></a> -<span class="sourceLineNo">1312</span> protected MasterMetaBootstrap createMetaBootstrap() {<a name="line.1312"></a> -<span class="sourceLineNo">1313</span> // We put this out here in a method so can do a Mockito.spy and stub it out<a name="line.1313"></a> -<span class="sourceLineNo">1314</span> // w/ a mocked up MasterMetaBootstrap.<a name="line.1314"></a> -<span class="sourceLineNo">1315</span> return new MasterMetaBootstrap(this);<a name="line.1315"></a> -<span class="sourceLineNo">1316</span> }<a name="line.1316"></a> -<span class="sourceLineNo">1317</span><a name="line.1317"></a> -<span class="sourceLineNo">1318</span> /**<a name="line.1318"></a> -<span class="sourceLineNo">1319</span> * <p><a name="line.1319"></a> -<span class="sourceLineNo">1320</span> * Create a {@link ServerManager} instance.<a name="line.1320"></a> -<span class="sourceLineNo">1321</span> * </p><a name="line.1321"></a> -<span class="sourceLineNo">1322</span> * <p><a name="line.1322"></a> -<span class="sourceLineNo">1323</span> * Will be overridden in tests.<a name="line.1323"></a> -<span class="sourceLineNo">1324</span> * </p><a name="line.1324"></a> -<span class="sourceLineNo">1325</span> */<a name="line.1325"></a> -<span class="sourceLineNo">1326</span> @VisibleForTesting<a name="line.1326"></a> -<span class="sourceLineNo">1327</span> protected ServerManager createServerManager(final MasterServices master) throws IOException {<a name="line.1327"></a> -<span class="sourceLineNo">1328</span> // We put this out here in a method so can do a Mockito.spy and stub it out<a name="line.1328"></a> -<span class="sourceLineNo">1329</span> // w/ a mocked up ServerManager.<a name="line.1329"></a> -<span class="sourceLineNo">1330</span> setupClusterConnection();<a name="line.1330"></a> -<span class="sourceLineNo">1331</span> return new ServerManager(master);<a name="line.1331"></a> -<span class="sourceLineNo">1332</span> }<a name="line.1332"></a> -<span class="sourceLineNo">1333</span><a name="line.1333"></a> -<span class="sourceLineNo">1334</span> private void waitForRegionServers(final MonitoredTask status)<a name="line.1334"></a> -<span class="sourceLineNo">1335</span> throws IOException, InterruptedException {<a name="line.1335"></a> -<span class="sourceLineNo">1336</span> this.serverManager.waitForRegionServers(status);<a name="line.1336"></a> +<span class="sourceLineNo">1249</span> private boolean waitForNamespaceOnline() throws InterruptedException, IOException {<a name="line.1249"></a> +<span class="sourceLineNo">1250</span> TableState nsTableState =<a name="line.1250"></a> +<span class="sourceLineNo">1251</span> MetaTableAccessor.getTableState(getClusterConnection(), TableName.NAMESPACE_TABLE_NAME);<a name="line.1251"></a> +<span class="sourceLineNo">1252</span> if (nsTableState == null || nsTableState.isDisabled()) {<a name="line.1252"></a> +<span class="sourceLineNo">1253</span> // this means we have already migrated the data and disabled or deleted the namespace table,<a name="line.1253"></a> +<span class="sourceLineNo">1254</span> // or this is a new depliy which does not have a namespace table from the beginning.<a name="line.1254"></a> +<span class="sourceLineNo">1255</span> return true;<a name="line.1255"></a> +<span class="sourceLineNo">1256</span> }<a name="line.1256"></a> +<span class="sourceLineNo">1257</span> List<RegionInfo> ris =<a name="line.1257"></a> +<span class="sourceLineNo">1258</span> this.assignmentManager.getRegionStates().getRegionsOfTable(TableName.NAMESPACE_TABLE_NAME);<a name="line.1258"></a> +<span class="sourceLineNo">1259</span> if (ris.isEmpty()) {<a name="line.1259"></a> +<span class="sourceLineNo">1260</span> // maybe this will not happen any more, but anyway, no harm to add a check here...<a name="line.1260"></a> +<span class="sourceLineNo">1261</span> return true;<a name="line.1261"></a> +<span class="sourceLineNo">1262</span> }<a name="line.1262"></a> +<span class="sourceLineNo">1263</span> // Else there are namespace regions up in meta. Ensure they are assigned before we go on.<a name="line.1263"></a> +<span class="sourceLineNo">1264</span> for (RegionInfo ri : ris) {<a name="line.1264"></a> +<span class="sourceLineNo">1265</span> isRegionOnline(ri);<a name="line.1265"></a> +<span class="sourceLineNo">1266</span> }<a name="line.1266"></a> +<span class="sourceLineNo">1267</span> return true;<a name="line.1267"></a> +<span class="sourceLineNo">1268</span> }<a name="line.1268"></a> +<span class="sourceLineNo">1269</span><a name="line.1269"></a> +<span class="sourceLineNo">1270</span> /**<a name="line.1270"></a> +<span class="sourceLineNo">1271</span> * Adds the {@code MasterQuotasObserver} to the list of configured Master observers to<a name="line.1271"></a> +<span class="sourceLineNo">1272</span> * automatically remove quotas for a table when that table is deleted.<a name="line.1272"></a> +<span class="sourceLineNo">1273</span> */<a name="line.1273"></a> +<span class="sourceLineNo">1274</span> @VisibleForTesting<a name="line.1274"></a> +<span class="sourceLineNo">1275</span> public void updateConfigurationForQuotasObserver(Configuration conf) {<a name="line.1275"></a> +<span class="sourceLineNo">1276</span> // We're configured to not delete quotas on table deletion, so we don't need to add the obs.<a name="line.1276"></a> +<span class="sourceLineNo">1277</span> if (!conf.getBoolean(<a name="line.1277"></a> +<span class="sourceLineNo">1278</span> MasterQuotasObserver.REMOVE_QUOTA_ON_TABLE_DELETE,<a name="line.1278"></a> +<span class="sourceLineNo">1279</span> MasterQuotasObserver.REMOVE_QUOTA_ON_TABLE_DELETE_DEFAULT)) {<a name="line.1279"></a> +<span class="sourceLineNo">1280</span> return;<a name="line.1280"></a> +<span class="sourceLineNo">1281</span> }<a name="line.1281"></a> +<span class="sourceLineNo">1282</span> String[] masterCoprocs = conf.getStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);<a name="line.1282"></a> +<span class="sourceLineNo">1283</span> final int length = null == masterCoprocs ? 0 : masterCoprocs.length;<a name="line.1283"></a> +<span class="sourceLineNo">1284</span> String[] updatedCoprocs = new String[length + 1];<a name="line.1284"></a> +<span class="sourceLineNo">1285</span> if (length > 0) {<a name="line.1285"></a> +<span class="sourceLineNo">1286</span> System.arraycopy(masterCoprocs, 0, updatedCoprocs, 0, masterCoprocs.length);<a name="line.1286"></a> +<span class="sourceLineNo">1287</span> }<a name="line.1287"></a> +<span class="sourceLineNo">1288</span> updatedCoprocs[length] = MasterQuotasObserver.class.getName();<a name="line.1288"></a> +<span class="sourceLineNo">1289</span> conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, updatedCoprocs);<a name="line.1289"></a> +<span class="sourceLineNo">1290</span> }<a name="line.1290"></a> +<span class="sourceLineNo">1291</span><a name="line.1291"></a> +<span class="sourceLineNo">1292</span> private void initMobCleaner() {<a name="line.1292"></a> +<span class="sourceLineNo">1293</span> this.expiredMobFileCleanerChore = new ExpiredMobFileCleanerChore(this);<a name="line.1293"></a> +<span class="sourceLineNo">1294</span> getChoreService().scheduleChore(expiredMobFileCleanerChore);<a name="line.1294"></a> +<span class="sourceLineNo">1295</span><a name="line.1295"></a> +<span class="sourceLineNo">1296</span> int mobCompactionPeriod = conf.getInt(MobConstants.MOB_COMPACTION_CHORE_PERIOD,<a name="line.1296"></a> +<span class="sourceLineNo">1297</span> MobConstants.DEFAULT_MOB_COMPACTION_CHORE_PERIOD);<a name="line.1297"></a> +<span class="sourceLineNo">1298</span> if (mobCompactionPeriod > 0) {<a name="line.1298"></a> +<span class="sourceLineNo">1299</span> this.mobCompactChore = new MobCompactionChore(this, mobCompactionPeriod);<a name="line.1299"></a> +<span class="sourceLineNo">1300</span> getChoreService().scheduleChore(mobCompactChore);<a name="line.1300"></a> +<span class="sourceLineNo">1301</span> } else {<a name="line.1301"></a> +<span class="sourceLineNo">1302</span> LOG<a name="line.1302"></a> +<span class="sourceLineNo">1303</span> .info("The period is " + mobCompactionPeriod + " seconds, MobCompactionChore is disabled");<a name="line.1303"></a> +<span class="sourceLineNo">1304</span> }<a name="line.1304"></a> +<span class="sourceLineNo">1305</span> this.mobCompactThread = new MasterMobCompactionThread(this);<a name="line.1305"></a> +<span class="sourceLineNo">1306</span> }<a name="line.1306"></a> +<span class="sourceLineNo">1307</span><a name="line.1307"></a> +<span class="sourceLineNo">1308</span> /**<a name="line.1308"></a> +<span class="sourceLineNo">1309</span> * <p><a name="line.1309"></a> +<span class="sourceLineNo">1310</span> * Create a {@link MasterMetaBootstrap} instance.<a name="line.1310"></a> +<span class="sourceLineNo">1311</span> * </p><a name="line.1311"></a> +<span class="sourceLineNo">1312</span> * <p><a name="line.1312"></a> +<span class="sourceLineNo">1313</span> * Will be overridden in tests.<a name="line.1313"></a> +<span class="sourceLineNo">1314</span> * </p><a name="line.1314"></a> +<span class="sourceLineNo">1315</span> */<a name="line.1315"></a> +<span class="sourceLineNo">1316</span> @VisibleForTesting<a name="line.1316"></a> +<span class="sourceLineNo">1317</span> protected MasterMetaBootstrap createMetaBootstrap() {<a name="line.1317"></a> +<span class="sourceLineNo">1318</span> // We put this out here in a method so can do a Mockito.spy and stub it out<a name="line.1318"></a> +<span class="sourceLineNo">1319</span> // w/ a mocked up MasterMetaBootstrap.<a name="line.1319"></a> +<span class="sourceLineNo">1320</span> return new MasterMetaBootstrap(this);<a name="line.1320"></a> +<span class="sourceLineNo">1321</span> }<a name="line.1321"></a> +<span class="sourceLineNo">1322</span><a name="line.1322"></a> +<span class="sourceLineNo">1323</span> /**<a name="line.1323"></a> +<span class="sourceLineNo">1324</span> * <p><a name="line.1324"></a> +<span class="sourceLineNo">1325</span> * Create a {@link ServerManager} instance.<a name="line.1325"></a> +<span class="sourceLineNo">1326</span> * </p><a name="line.1326"></a> +<span class="sourceLineNo">1327</span> * <p><a name="line.1327"></a> +<span class="sourceLineNo">1328</span> * Will be overridden in tests.<a name="line.1328"></a> +<span class="sourceLineNo">1329</span> * </p><a name="line.1329"></a> +<span class="sourceLineNo">1330</span> */<a name="line.1330"></a> +<span class="sourceLineNo">1331</span> @VisibleForTesting<a name="line.1331"></a> +<span class="sourceLineNo">1332</span> protected ServerManager createServerManager(final MasterServices master) throws IOException {<a name="line.1332"></a> +<span class="sourceLineNo">1333</span> // We put this out here in a method so can do a Mockito.spy and stub it out<a name="line.1333"></a> +<span class="sourceLineNo">1334</span> // w/ a mocked up ServerManager.<a name="line.1334"></a> +<span class="sourceLineNo">1335</span> setupClusterConnection();<a name="line.1335"></a> +<span class="sourceLineNo">1336</span> return new ServerManager(master);<a name="line.1336"></a> <span class="sourceLineNo">1337</span> }<a name="line.1337"></a> <span class="sourceLineNo">1338</span><a name="line.1338"></a> -<span class="sourceLineNo">1339</span> // Will be overridden in tests<a name="line.1339"></a> -<span class="sourceLineNo">1340</span> @VisibleForTesting<a name="line.1340"></a> -<span class="sourceLineNo">1341</span> protected void initClusterSchemaService() throws IOException, InterruptedException {<a name="line.1341"></a> -<span class="sourceLineNo">1342</span> this.clusterSchemaService = new ClusterSchemaServiceImpl(this);<a name="line.1342"></a> -<span class="sourceLineNo">1343</span> this.clusterSchemaService.startAsync();<a name="line.1343"></a> -<span class="sourceLineNo">1344</span> try {<a name="line.1344"></a> -<span class="sourceLineNo">1345</span> this.clusterSchemaService.awaitRunning(getConfiguration().getInt(<a name="line.1345"></a> -<span class="sourceLineNo">1346</span> HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS,<a name="line.1346"></a> -<span class="sourceLineNo">1347</span> DEFAULT_HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS), TimeUnit.SECONDS);<a name="line.1347"></a> -<span class="sourceLineNo">1348</span> } catch (TimeoutException toe) {<a name="line.1348"></a> -<span class="sourceLineNo">1349</span> throw new IOException("Timedout starting ClusterSchemaService", toe);<a name="line.1349"></a> -<span class="sourceLineNo">1350</span> }<a name="line.1350"></a> -<span class="sourceLineNo">1351</span> }<a name="line.1351"></a> -<span class="sourceLineNo">1352</span><a name="line.1352"></a> -<span class="sourceLineNo">1353</span> private void initQuotaManager() throws IOException {<a name="line.1353"></a> -<span class="sourceLineNo">1354</span> MasterQuotaManager quotaManager = new MasterQuotaManager(this);<a name="line.1354"></a> -<span class="sourceLineNo">1355</span> quotaManager.start();<a name="line.1355"></a> -<span class="sourceLineNo">1356</span> this.quotaManager = quotaManager;<a name="line.1356"></a> -<span class="sourceLineNo">1357</span> }<a name="line.1357"></a> -<span class="sourceLineNo">1358</span><a name="line.1358"></a> -<span class="sourceLineNo">1359</span> private SpaceQuotaSnapshotNotifier createQuotaSnapshotNotifier() {<a name="line.1359"></a> -<span class="sourceLineNo">1360</span> SpaceQuotaSnapshotNotifier notifier =<a name="line.1360"></a> -<span class="sourceLineNo">1361</span> SpaceQuotaSnapshotNotifierFactory.getInstance().create(getConfiguration());<a name="line.1361"></a> -<span class="sourceLineNo">1362</span> return notifier;<a name="line.1362"></a> -<span class="sourceLineNo">1363</span> }<a name="line.1363"></a> -<span class="sourceLineNo">1364</span><a name="line.1364"></a> -<span class="sourceLineNo">1365</span> boolean isCatalogJanitorEnabled() {<a name="line.1365"></a> -<span class="sourceLineNo">1366</span> return catalogJanitorChore != null ?<a name="line.1366"></a> -<span class="sourceLineNo">1367</span> catalogJanitorChore.getEnabled() : false;<a name="line.1367"></a> +<span class="sourceLineNo">1339</span> private void waitForRegionServers(final MonitoredTask status)<a name="line.1339"></a> +<span class="sourceLineNo">1340</span> throws IOException, InterruptedException {<a name="line.1340"></a> +<span class="sourceLineNo">1341</span> this.serverManager.waitForRegionServers(status);<a name="line.1341"></a> +<span class="sourceLineNo">1342</span> }<a name="line.1342"></a> +<span class="sourceLineNo">1343</span><a name="line.1343"></a> +<span class="sourceLineNo">1344</span> // Will be overridden in tests<a name="line.1344"></a> +<span class="sourceLineNo">1345</span> @VisibleForTesting<a name="line.1345"></a> +<span class="sourceLineNo">1346</span> protected void initClusterSchemaService() throws IOException, InterruptedException {<a name="line.1346"></a> +<span class="sourceLineNo">1347</span> this.clusterSchemaService = new ClusterSchemaServiceImpl(this);<a name="line.1347"></a> +<span class="sourceLineNo">1348</span> this.clusterSchemaService.startAsync();<a name="line.1348"></a> +<span class="sourceLineNo">1349</span> try {<a name="line.1349"></a> +<span class="sourceLineNo">1350</span> this.clusterSchemaService.awaitRunning(getConfiguration().getInt(<a name="line.1350"></a> +<span class="sourceLineNo">1351</span> HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS,<a name="line.1351"></a> +<span class="sourceLineNo">1352</span> DEFAULT_HBASE_MASTER_WAIT_ON_SERVICE_IN_SECONDS), TimeUnit.SECONDS);<a name="line.1352"></a> +<span class="sourceLineNo">1353</span> } catch (TimeoutException toe) {<a name="line.1353"></a> +<span class="sourceLineNo">1354</span> throw new IOException("Timedout starting ClusterSchemaService", toe);<a name="line.1354"></a> +<span class="sourceLineNo">1355</span> }<a name="line.1355"></a> +<span class="sourceLineNo">1356</span> }<a name="line.1356"></a> +<span class="sourceLineNo">1357</span><a name="line.1357"></a> +<span class="sourceLineNo">1358</span> private void initQuotaManager() throws IOException {<a name="line.1358"></a> +<span class="sourceLineNo">1359</span> MasterQuotaManager quotaManager = new MasterQuotaManager(this);<a name="line.1359"></a> +<span class="sourceLineNo">1360</span> quotaManager.start();<a name="line.1360"></a> +<span class="sourceLineNo">1361</span> this.quotaManager = quotaManager;<a name="line.1361"></a> +<span class="sourceLineNo">1362</span> }<a name="line.1362"></a> +<span class="sourceLineNo">1363</span><a name="line.1363"></a> +<span class="sourceLineNo">1364</span> private SpaceQuotaSnapshotNotifier createQuotaSnapshotNotifier() {<a name="line.1364"></a> +<span class="sourceLineNo">1365</span> SpaceQuotaSnapshotNotifier notifier =<a name="line.1365"></a> +<span class="sourceLineNo">1366</span> SpaceQuotaSnapshotNotifierFactory.getInstance().create(getConfiguration());<a name="line.1366"></a> +<span class="sourceLineNo">1367</span> return notifier;<a name="line.1367"></a> <span class="sourceLineNo">1368</span> }<a name="line.1368"></a> <span class="sourceLineNo">1369</span><a name="line.1369"></a> -<span class="sourceLineNo">1370</span> boolean isCleanerChoreEnabled() {<a name="line.1370"></a> -<span class="sourceLineNo">1371</span> boolean hfileCleanerFlag = true, logCleanerFlag = true;<a name="line.1371"></a> -<span class="sourceLineNo">1372</span><a name="line.1372"></a> -<span class="sourceLineNo">1373</span> if (hfileCleaner != null) {<a name="line.1373"></a> -<span class="sourceLineNo">1374</span> hfileCleanerFlag = hfileCleaner.getEnabled();<a name="line.1374"></a> -<span class="sourceLineNo">1375</span> }<a name="line.1375"></a> -<span class="sourceLineNo">1376</span><a name="line.1376"></a> -<span class="sourceLineNo">1377</span> if (logCleaner != null) {<a name="line.1377"></a> -<span class="sourceLineNo">1378</span> logCleanerFlag = logCleaner.getEnabled();<a name="line.1378"></a> -<span class="sourceLineNo">1379</span> }<a name="line.1379"></a> -<span class="sourceLineNo">1380</span><a name="line.1380"></a> -<span class="sourceLineNo">1381</span> return (hfileCleanerFlag && logCleanerFlag);<a name="line.1381"></a> -<span class="sourceLineNo">1382</span> }<a name="line.1382"></a> -<span class="sourceLineNo">1383</span><a name="line.1383"></a> -<span class="sourceLineNo">1384</span> @Override<a name="line.1384"></a> -<span class="sourceLineNo">1385</span> public ServerManager getServerManager() {<a name="line.1385"></a> -<span class="sourceLineNo">1386</span> return this.serverManager;<a name="line.1386"></a> +<span class="sourceLineNo">1370</span> boolean isCatalogJanitorEnabled() {<a name="line.1370"></a> +<span class="sourceLineNo">1371</span> return catalogJanitorChore != null ?<a name="line.1371"></a> +<span class="sourceLineNo">1372</span> catalogJanitorChore.getEnabled() : false;<a name="line.1372"></a> +<span class="sourceLineNo">1373</span> }<a name="line.1373"></a> +<span class="sourceLineNo">1374</span><a name="line.1374"></a> +<span class="sourceLineNo">1375</span> boolean isCleanerChoreEnabled() {<a name="line.1375"></a> +<span class="sourceLineNo">1376</span> boolean hfileCleanerFlag = true, logCleanerFlag = true;<a name="line.1376"></a> +<span class="sourceLineNo">1377</span><a name="line.1377"></a> +<span class="sourceLineNo">1378</span> if (hfileCleaner != null) {<a name="line.1378"></a> +<span class="sourceLineNo">1379</span> hfileCleanerFlag = hfileCleaner.getEnabled();<a name="line.1379"></a> +<span class="sourceLineNo">1380</span> }<a name="line.1380"></a> +<span class="sourceLineNo">1381</span><a name="line.1381"></a> +<span class="sourceLineNo">1382</span> if (logCleaner != null) {<a name="line.1382"></a> +<span class="sourceLineNo">1383</span> logCleanerFlag = logCleaner.getEnabled();<a name="line.1383"></a> +<span class="sourceLineNo">1384</span> }<a name="line.1384"></a> +<span class="sourceLineNo">1385</span><a name="line.1385"></a> +<span class="sourceLineNo">1386</span> return (hfileCleanerFlag && logCleanerFlag);<a name="line.1386"></a> <span class="sourceLineNo">1387</span> }<a name="line.1387"></a> <span class="sourceLineNo">1388</span><a name="line.1388"></a> <span class="sourceLineNo">1389</span> @Override<a name="line.1389"></a> -<span class="sourceLineNo">1390</span> public MasterFileSystem getMasterFileSystem() {<a name="line.1390"></a> -<span class="sourceLineNo">1391</span> return this.fileSystemManager;<a name="line.1391"></a> +<span class="sourceLineNo">1390</span> public ServerManager getServerManager() {<a name="line.1390"></a> +<span class="sourceLineNo">1391</span> return this.serverManager;<a name="line.1391"></a> <span class="sourceLineNo">1392</span> }<a name="line.1392"></a> <span class="sourceLineNo">1393</span><a name="line.1393"></a> <span class="sourceLineNo">1394</span> @Override<a name="line.1394"></a> -<span class="sourceLineNo">1395</span> public MasterWalManager getMasterWalManager() {<a name="line.1395"></a> -<span class="sourceLineNo">1396</span> return this.walManager;<a name="line.1396"></a> +<span class="sourceLineNo">1395</span> public MasterFileSystem getMasterFileSystem() {<a name="line.1395"></a> +<span class="sourceLineNo">1396</span> return this.fileSystemManager;<a name="line.1396"></a> <span class="sourceLineNo">1397</span> }<a name="line.1397"></a> <span class="sourceLineNo">1398</span><a name="line.1398"></a> <span class="sourceLineNo">1399</span> @Override<a name="line.1399"></a> -<span class="sourceLineNo">1400</span> public TableStateManager getTableStateManager() {<a name="line.1400"></a> -<span class="sourceLineNo">1401</span> return tableStateManager;<a name="line.1401"></a> +<span class="sourceLineNo">1400</span> public MasterWalManager getMasterWalManager() {<a name="line.1400"></a> +<span class="sourceLineNo">1401</span> return this.walManager;<a name="line.1401"></a> <span class="sourceLineNo">1402</span> }<a name="line.1402"></a> <span class="sourceLineNo">1403</span><a name="line.1403"></a> -<span class="sourceLineNo">1404</span> /*<a name="line.1404"></a> -<span class="sourceLineNo">1405</span> * Start up all services. If any of these threads gets an unhandled exception<a name="line.1405"></a> -<span class="sourceLineNo">1406</span> * then they just die with a logged message. This should be fine because<a name="line.1406"></a> -<span class="sourceLineNo">1407</span> * in general, we do not expect the master to get such unhandled exceptions<a name="line.1407"></a> -<span class="sourceLineNo">1408</span> * as OOMEs; it should be lightly loaded. See what HRegionServer does if<a name="line.1408"></a> -<span class="sourceLineNo">1409</span> * need to install an unexpected exception handler.<a name="line.1409"></a> -<span class="sourceLineNo">1410</span> */<a name="line.1410"></a> -<span class="sourceLineNo">1411</span> private void startServiceThreads() throws IOException{<a name="line.1411"></a> -<span class="sourceLineNo">1412</span> // Start the executor service pools<a name="line.1412"></a> -<span class="sourceLineNo">1413</span> this.executorService.startExecutorService(ExecutorType.MASTER_OPEN_REGION,<a name="line.1413"></a> -<span class="sourceLineNo">1414</span> conf.getInt("hbase.master.executor.openregion.threads", 5));<a name="line.1414"></a> -<span class="sourceLineNo">1415</span> this.executorService.startExecutorService(ExecutorType.MASTER_CLOSE_REGION,<a name="line.1415"></a> -<span class="sourceLineNo">1416</span> conf.getInt("hbase.master.executor.closeregion.threads", 5));<a name="line.1416"></a> -<span class="sourceLineNo">1417</span> this.executorService.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS,<a name="line.1417"></a> -<span class="sourceLineNo">1418</span> conf.getInt("hbase.master.executor.serverops.threads", 5));<a name="line.1418"></a> -<span class="sourceLineNo">1419</span> this.executorService.startExecutorService(ExecutorType.MASTER_META_SERVER_OPERATIONS,<a name="line.1419"></a> -<span class="sourceLineNo">1420</span> conf.getInt("hbase.master.executor.meta.serverops.threads", 5));<a name="line.1420"></a> -<span class="sourceLineNo">1421</span> this.executorService.startExecutorService(ExecutorType.M_LOG_REPLAY_OPS,<a name="line.1421"></a> -<span class="sourceLineNo">1422</span> conf.getInt("hbase.master.executor.logreplayops.threads", 10));<a name="line.1422"></a> -<span class="sourceLineNo">1423</span><a name="line.1423"></a> -<span class="sourceLineNo">1424</span> // We depend on there being only one instance of this executor running<a name="line.1424"></a> -<span class="sourceLineNo">1425</span> // at a time. To do concurrency, would need fencing of enable/disable of<a name="line.1425"></a> -<span class="sourceLineNo">1426</span> // tables.<a name="line.1426"></a> -<span class="sourceLineNo">1427</span> // Any time changing this maxThreads to > 1, pls see the comment at<a name="line.1427"></a> -<span class="sourceLineNo">1428</span> // AccessController#postCompletedCreateTableAction<a name="line.1428"></a> -<span class="sourceLineNo">1429</span> this.executorService.startExecutorService(ExecutorType.MASTER_TABLE_OPERATIONS, 1);<a name="line.1429"></a> -<span class="sourceLineNo">1430</span> startProcedureExecutor();<a name="line.1430"></a> -<span class="sourceLineNo">1431</span><a name="line.1431"></a> -<span class="sourceLineNo">1432</span> // Initial cleaner chore<a name="line.1432"></a> -<span class="sourceLineNo">1433</span> CleanerChore.initChorePool(conf);<a name="line.1433"></a> -<span class="sourceLineNo">1434</span> // Start log cleaner thread<a name="line.1434"></a> -<span class="sourceLineNo">1435</span> int cleanerInterval = conf.getInt("hbase.master.cleaner.interval", 600 * 1000);<a name="line.1435"></a> -<span class="sourceLineNo">1436</span> this.logCleaner =<a name="line.1436"></a> -<span class="sourceLineNo">1437</span> new LogCleaner(cleanerInterval,<a name="line.1437"></a> -<span class="sourceLineNo">1438</span> this, conf, getMasterWalManager().getFileSystem(),<a name="line.1438"></a> -<span class="sourceLineNo">1439</span> getMasterWalManager().getOldLogDir());<a name="line.1439"></a> -<span class="sourceLineNo">1440</span> getChoreService().scheduleChore(logCleaner);<a name="line.1440"></a> -<span class="sourceLineNo">1441</span><a name="line.1441"></a> -<span class="sourceLineNo">1442</span> // start the hfile archive cleaner thread<a name="line.1442"></a> -<span class="sourceLineNo">1443</span> Path archiveDir = HFileArchiveUtil.getArchivePath(conf);<a name="line.1443"></a> -<span class="sourceLineNo">1444</span> Map<String, Object> params = new HashMap<>();<a name="line.1444"></a> -<span class="sourceLineNo">1445</span> params.put(MASTER, this);<a name="line.1445"></a> -<span class="sourceLineNo">1446</span> this.hfileCleaner = new HFileCleaner(cleanerInterval, this, conf, getMasterFileSystem()<a name="line.1446"></a> -<span class="sourceLineNo">1447</span> .getFileSystem(), archiveDir, params);<a name="line.1447"></a> -<span class="sourceLineNo">1448</span> getChoreService().scheduleChore(hfileCleaner);<a name="line.1448"></a> -<span class="sourceLineNo">1449</span><a name="line.1449"></a> -<span class="sourceLineNo">1450</span> replicationBarrierCleaner = new ReplicationBarrierCleaner(conf, this, getConnection(),<a name="line.1450"></a> -<span class="sourceLineNo">1451</span> replicationPeerManager);<a name="line.1451"></a> -<span class="sourceLineNo">1452</span> getChoreService().scheduleChore(replicationBarrierCleaner);<a name="line.1452"></a> -<span class="sourceLineNo">1453</span><a name="line.1453"></a> -<span class="sourceLineNo">1454</span> serviceStarted = true;<a name="line.1454"></a> -<span class="sourceLineNo">1455</span> if (LOG.isTraceEnabled()) {<a name="line.1455"></a> -<span class="sourceLineNo">1456</span> LOG.trace("Started service threads");<a name="line.1456"></a> -<span class="sourceLineNo">1457</span> }<a name="line.1457"></a> -<span class="sourceLineNo">1458</span> }<a name="line.1458"></a> -<span class="sourceLineNo">1459</span><a name="line.1459"></a> -<span class="sourceLineNo">1460</span> @Override<a name="line.1460"></a> -<span class="sourceLineNo">1461</span> protected void stopServiceThreads() {<a name="line.1461"></a> -<span class="sourceLineNo">1462</span> if (masterJettyServer != null) {<a name="line.1462"></a> -<span class="sourceLineNo">1463</span> LOG.info("Stopping master jetty server");<a name="line.1463"></a> -<span class="sourceLineNo">1464</span> try {<a name="line.1464"></a> -<span class="sourceLineNo">1465</span> masterJettyServer.stop();<a name="line.1465"></a> -<span class="sourceLineNo">1466</span> } catch (Exception e) {<a name="line.1466"></a> -<span class="sourceLineNo">1467</span> LOG.error("Failed to stop master jetty server", e);<a name="line.1467"></a> -<span class="sourceLineNo">1468</span> }<a name="line.1468"></a> -<span class="sourceLineNo">1469</span> }<a name="line.1469"></a> -<span class="sourceLineNo">1470</span> stopChores();<a name="line.1470"></a> -<span class="sourceLineNo">1471</span> if (this.mobCompactThread != null) {<a name="line.1471"></a> -<span class="sourceLineNo">1472</span> this.mobCompactThread.close();<a name="line.1472"></a> -<span class="sourceLineNo">1473</span> }<a name="line.1473"></a> -<span class="sourceLineNo">1474</span> super.stopServiceThreads();<a name="line.1474"></a> -<span class="sourceLineNo">1475</span> CleanerChore.shutDownChorePool();<a name="line.1475"></a> -<span class="sourceLineNo">1476</span><a name="line.1476"></a> -<span class="sourceLineNo">1477</span> LOG.debug("Stopping service threads");<a name="line.1477"></a> -<span class="sourceLineNo">1478</span><a name="line.1478"></a> -<span class="sourceLineNo">1479</span> if (this.quotaManager != null) {<a name="line.1479"></a> -<span class="sourceLineNo">1480</span> this.quotaManager.stop();<a name="line.1480"></a> -<span class="sourceLineNo">1481</span> }<a name="line.1481"></a> -<span class="sourceLineNo">1482</span><a name="line.1482"></a> -<span class="sourceLineNo">1483</span> if (this.activeMasterManager != null) {<a name="line.1483"></a> -<span class="sourceLineNo">1484</span> this.activeMasterManager.stop();<a name="line.1484"></a> -<span class="sourceLineNo">1485</span> }<a name="line.1485"></a> -<span class="sourceLineNo">1486</span> if (this.serverManager != null) {<a name="line.1486"></a> -<span class="sourceLineNo">1487</span> this.serverManager.stop();<a name="line.1487"></a> -<span class="sourceLineNo">1488</span> }<a name="line.1488"></a> -<span class="sourceLineNo">1489</span> if (this.assignmentManager != null) {<a name="line.1489"></a> -<span class="sourceLineNo">1490</span> this.assignmentManager.stop();<a name="line.1490"></a> -<span class="sourceLineNo">1491</span> }<a name="line.1491"></a> -<span class="sourceLineNo">1492</span><a name="line.1492"></a> -<span class="sourceLineNo">1493</span> stopProcedureExecutor();<a name="line.1493"></a> -<span class="sourceLineNo">1494</span><a name="line.1494"></a> -<span class="sourceLineNo">1495</span> if (this.walManager != null) {<a name="line.1495"></a> -<span class="sourceLineNo">1496</span> this.walManager.stop();<a name="line.1496"></a> -<span class="sourceLineNo">1497</span> }<a name="line.1497"></a> -<span class="sourceLineNo">1498</span> if (this.fileSystemManager != null) {<a name="line.1498"></a> -<span class="sourceLineNo">1499</span> this.fileSystemManager.stop();<a name="line.1499"></a> -<span class="sourceLineNo">1500</span> }<a name="line.1500"></a> -<span class="sourceLineNo">1501</span> if (this.mpmHost != null) {<a name="line.1501"></a> -<span class="sourceLineNo">1502</span> this.mpmHost.stop("server shutting down.");<a name="line.1502"></a> -<span class="sourceLineNo">1503</span> }<a name="line.1503"></a> -<span class="sourceLineNo">1504</span> if (this.regionServerTracker != null) {<a name="line.1504"></a> -<span class="sourceLineNo">1505</span> this.regionServerTracker.stop();<a name="line.1505"></a> -<span class="sourceLineNo">1506</span> }<a name="line.1506"></a> -<span class="sourceLineNo">1507</span> }<a name="line.1507"></a> -<span class="sourceLineNo">1508</span><a name="line.1508"></a> -<span class="sourceLineNo">1509</span> private void createProcedureExecutor() throws IOException {<a name="line.1509"></a> -<span class="sourceLineNo">1510</span> MasterProcedureEnv procEnv = new MasterProcedureEnv(this);<a name="line.1510"></a> -<span class="sourceLineNo">1511</span> procedureStore =<a name="line.1511"></a> -<span class="sourceLineNo">1512</span> new WALProcedureStore(conf, new MasterProcedureEnv.WALStoreLeaseRecovery(this));<a name="line.1512"></a> -<span class="sourceLineNo">1513</span> procedureStore.registerListener(new ProcedureStoreListener() {<a name="line.1513"></a> -<span class="sourceLineNo">1514</span><a name="line.1514"></a> -<span class="sourceLineNo">1515</span> @Override<a name="line.1515"></a> -<span class="sourceLineNo">1516</span> public void abortProcess() {<a name="line.1516"></a> -<span class="sourceLineNo">1517</span> abort("The Procedure Store lost the lease", null);<a name="line.1517"></a> -<span class="sourceLineNo">1518</span> }<a name="line.1518"></a> -<span class="sourceLineNo">1519</span> });<a name="line.1519"></a> -<span class="sourceLineNo">1520</span> MasterProcedureScheduler procedureScheduler = procEnv.getProcedureScheduler();<a name="line.1520"></a> -<span class="sourceLineNo">1521</span> procedureExecutor = new ProcedureExecutor<>(conf, procEnv, procedureStore, procedureScheduler);<a name="line.1521"></a> -<span class="sourceLineNo">1522</span> configurationManager.registerObserver(procEnv);<a name="line.1522"></a> -<span class="sourceLineNo">1523</span><a name="line.1523"></a> -<span class="sourceLineNo">1524</span> int cpus = Runtime.getRuntime().availableProcessors();<a name="line.1524"></a> -<span class="sourceLineNo">1525</span> final int numThreads = conf.getInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, Math.max(<a name="line.1525"></a> -<span class="sourceLineNo">1526</span> (cpus > 0 ? cpus / 4 : 0), MasterProcedureConstants.DEFAULT_MIN_MASTER_PROCEDURE_THREADS));<a name="line.1526"></a> -<span class="sourceLineNo">1527</span> final boolean abortOnCorruption =<a name="line.1527"></a> -<span class="sourceLineNo">1528</span> conf.getBoolean(MasterProcedureConstants.EXECUTOR_ABORT_ON_CORRUPTION,<a name="line.1528"></a> -<span class="sourceLineNo">1529</span> MasterProcedureConstants.DEFAULT_EXECUTOR_ABORT_ON_CORRUPTION);<a name="line.1529"></a> -<span class="sourceLineNo">1530</span> procedureStore.start(numThreads);<a name="line.1530"></a> -<span class="sourceLineNo">1531</span> // Just initialize it but do not start the workers, we will start the workers later by calling<a name="line.1531"></a> -<span class="sourceLineNo">1532</span> // startProcedureExecutor. See the javadoc for finishActiveMasterInitialization for more<a name="line.1532"></a> -<span class="sourceLineNo">1533</span> // details.<a name="line.1533"></a> -<span class="sourceLineNo">1534</span> procedureExecutor.init(numThreads, abortOnCorruption);<a name="line.1534"></a> -<span class="sourceLineNo">1535</span> procEnv.getRemoteDispatcher().start();<a name="line.1535"></a> -<span class="sourceLineNo">1536</span> }<a name="line.1536"></a> -<span class="sourceLineNo">1537</span><a name="line.1537"></a> -<span class="sourceLineNo">1538</span> private void startProcedureExecutor() throws IOException {<a name="line.1538"></a> -<span class="sourceLineNo">1539</span> procedureExecutor.startWorkers();<a name="line.1539"></a> -<span class="sourceLineNo">1540</span> }<a name="line.1540"></a> -<span class="sourceLineNo">1541</span><a name="line.1541"></a> -<span class="sourceLineNo">1542</span> private void stopProcedureExecutor() {<a name="line.1542"></a> -<span class="sourceLineNo">1543</span> if (procedureExecutor != null) {<a name="line.1543"></a> -<span class="sourceLineNo">1544</span> configurationManager.deregisterObserver(procedureExecutor.getEnvironment());<a name="line.1544"></a> -<span class="sourceLineNo">1545</span> procedureExecutor.getEnvironment().getRemoteDispatcher().stop();<a name="line.1545"></a> -<span class="sourceLineNo">1546</span> procedureExecutor.stop();<a name="line.1546"></a> -<span class="sourceLineNo">1547</span> procedureExecutor.join();<a name="line.1547"></a> -<span class="sourceLineNo">1548</span> procedureExecutor = null;<a name="line.1548"></a> -<span class="sourceLineNo">1549</span> }<a name="line.1549"></a> -<span class="sourceLineNo">1550</span><a name="line.1550"></a> -<span class="sourceLineNo">1551</span> if (procedureStore != null) {<a name="line.1551"></a> -<span class="sourceLineNo">1552</span> procedureStore.stop(isAborted());<a name="line.1552"></a> -<span class="sourceLineNo">1553</span> procedureStore = null;<a name="line.1553"></a> +<span class="sourceLineNo">1404</span> @Override<a name="line.1404"></a> +<span class="sourceLineNo">1405</span> public TableStateManager getTableStateManager() {<a name="line.1405"></a> +<span class="sourceLineNo">1406</span> return tableStateManager;<a name="line.1406"></a> +<span class="sourceLineNo">1407</span> }<a name="line.1407"></a> +<span class="sourceLineNo">1408</span><a name="line.1408"></a> +<span class="sourceLineNo">1409</span> /*<a name="line.1409"></a> +<span class="sourceLineNo">1410</span> * Start up all services. If any of these threads gets an unhandled exception<a name="line.1410"></a> +<span class="sourceLineNo">1411</span> * then they just die with a logged message. This should be fine because<a name="line.1411"></a> +<span class="sourceLineNo">1412</span> * in general, we do not expect the master to get such unhandled exceptions<a name="line.1412"></a> +<span class="sourceLineNo">1413</span> * as OOMEs; it should be lightly loaded. See what HRegionServer does if<a name="line.1413"></a> +<span class="sourceLineNo">1414</span> * need to install an unexpected exception handler.<a name="line.1414"></a> +<span class="sourceLineNo">1415</span> */<a name="line.1415"></a> +<span class="sourceLineNo">1416</span> private void startServiceThreads() throws IOException{<a name="line.1416"></a> +<span class="sourceLineNo">1417</span> // Start the executor service pools<a name="line.1417"></a> +<span class="sourceLineNo">1418</span> this.executorService.startExecutorService(ExecutorType.MASTER_OPEN_REGION,<a name="line.1418"></a> +<span class="sourceLineNo">1419</span> conf.getInt("hbase.master.executor.openregion.threads", 5));<a name="line.1419"></a> +<span class="sourceLineNo">1420</span> this.executorService.startExecutorService(ExecutorType.MASTER_CLOSE_REGION,<a name="line.1420"></a> +<span class="sourceLineNo">1421</span> conf.getInt("hbase.master.executor.closeregion.threads", 5));<a name="line.1421"></a> +<span class="sourceLineNo">1422</span> this.executorService.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS,<a name="line.1422"></a> +<span class="sourceLineNo">1423</span> conf.getInt("hbase.master.executor.serverops.threads", 5));<a name="line.1423"></a> +<span class="sourceLineNo">1424</span> this.executorService.startExecutorService(ExecutorType.MASTER_META_SERVER_OPERATIONS,<a name="line.1424"></a> +<span class="sourceLineNo">1425</span> conf.getInt("hbase.master.executor.meta.serverops.threads", 5));<a name="line.1425"></a> +<span class="sourceLineNo">1426</span> this.executorService.startExecutorService(ExecutorType.M_LOG_REPLAY_OPS,<a name="line.1426"></a> +<span class="sourceLineNo">1427</span> conf.getInt("hbase.master.executor.logreplayops.threads", 10));<a name="line.1427"></a> +<span class="sourceLineNo">1428</span><a name="line.1428"></a> +<span class="sourceLineNo">1429</span> // We depend on there being only one instance of this executor running<a name="line.1429"></a> +<span class="sourceLineNo">1430</span> // at a time. To do concurrency, would need fencing of enable/disable of<a name="line.1430"></a> +<span class="sourceLineNo">1431</span> // tables.<a name="line.1431"></a> +<span class="sourceLineNo">1432</span> // Any time changing this maxThreads to > 1, pls see the comment at<a name="line.1432"></a> +<span class="sourceLineNo">1433</span> // AccessController#postCompletedCreateTableAction<a name="line.1433"></a> +<span class="sourceLineNo">1434</span> this.executorService.startExecutorService(ExecutorType.MASTER_TABLE_OPERATIONS, 1);<a name="line.1434"></a> +<span class="sourceLineNo">1435</span> startProcedureExecutor();<a name="line.1435"></a> +<span class="sourceLineNo">1436</span><a name="line.1436"></a> +<span class="sourceLineNo">1437</span> // Initial cleaner chore<a name="line.1437"></a> +<span class="sourceLineNo">1438</span> CleanerChore.initChorePool(conf);<a name="line.1438"></a> +<span class="sourceLineNo">1439</span> // Start log cleaner thread<a name="line.1439"></a> +<span class="sourceLineNo">1440</span> int cleanerInterval = conf.getInt("hbase.master.cleaner.interval", 600 * 1000);<a name="line.1440"></a> +<span class="sourceLineNo">1441</span> this.logCleaner =<a name="line.1441"></a> +<span class="sourceLineNo">1442</span> new LogCleaner(cleanerInterval,<a name="line.1442"></a> +<span class="sourceLineNo">1443</span> this, conf, getMasterWalManager().getFileSystem(),<a name="line.1443"></a> +<span class="sourceLineNo">1444</span> getMasterWalManager().getOldLogDir());<a name="line.1444"></a> +<span class="sourceLineNo">1445</span> getChoreService().scheduleChore(logCleaner);<a name="line.1445"></a> +<span class="sourceLineNo">1446</span><a name="line.1446"></a> +<span class="sourceLineNo">1447</span> // start the hfile archive cleaner thread<a name="line.1447"></a> +<span class="sourceLineNo">1448</span> Path archiveDir = HFileArchiveUtil.getArchivePath(conf);<a name="line.1448"></a> +<span class="sourceLineNo">1449</span> Map<String, Object> params = new HashMap<>();<a name="line.1449"></a> +<span class="sourceLineNo">1450</span> params.put(MASTER, this);<a name="line.1450"></a> +<span class="sourceLineNo">1451</span> this.hfileCleaner = new HFileCleaner(cleanerInterval, this, conf, getMasterFileSystem()<a name="line.1451"></a> +<span class="sourceLineNo">1452</span> .getFileSystem(), archiveDir, params);<a name="line.1452"></a> +<span class="sourceLineNo">1453</span> getChoreService().scheduleChore(hfileCleaner);<a name="line.1453"></a> +<span class="sourceLineNo">1454</span><a name="line.1454"></a> +<span class="sourceLineNo">1455</span> replicationBarrierCleaner = new ReplicationBarrierCleaner(conf, this, getConnection(),<a name="line.1455"></a> +<span class="sourceLineNo">1456</span> replicationPeerManager);<a name="line.1456"></a> +<span class="sourceLineNo">1457</span> getChoreService().scheduleChore(replicationBarrierCleaner);<a name="line.1457"></a> +<span class="sourceLineNo">1458</span><a name="line.1458"></a> +<span class="sourceLineNo">1459</span> serviceStarted = true;<a name="line.1459"></a> +<span class="sourceLineNo">1460</span> if (LOG.isTraceEnabled()) {<a name="line.1460"></a> +<span class="sourceLineNo">1461</span> LOG.trace("Started service threads");<a name="line.1461"></a> +<span class="sourceLineNo">1462</span> }<a name="line.1462"></a> +<span class="sourceLineNo">1463</span> }<a name="line.1463"></a> +<span class="sourceLineNo">1464</span><a name="line.1464"></a> +<span class="sourceLineNo">1465</span> @Override<a name="line.1465"></a> +<span class="sourceLineNo">1466</span> protected void stopServiceThreads() {<a name="line.1466"></a> +<span class="sourceLineNo">1467</span> if (masterJettyServer != null) {<a name="line.1467"></a> +<span class="sourceLineNo">1468</span> LOG.info("Stopping master jetty server");<a name="line.1468"></a> +<span class="sourceLineNo">1469</span> try {<a name="line.1469"></a> +<span class="sourceLineNo">1470</span> masterJettyServer.stop();<a name="line.1470"></a> +<span class="sourceLineNo">1471</span> } catch (Exception e) {<a name="line.1471"></a> +<span class="sourceLineNo">1472</span> LOG.error("Failed to stop master jetty server", e);<a name="line.1472"></a> +<span class="sourceLineNo">1473</span> }<a name="line.1473"></a> +<span class="sourceLineNo">1474</span> }<a name="line.1474"></a> +<span class="sourceLineNo">1475</span> stopChores();<a name="line.1475"></a> +<span class="sourceLineNo">1476</span> if (this.mobCompactThread != null) {<a name="line.1476"></a> +<span class="sourceLineNo">1477</span> this.mobCompactThread.close();<a name="line.1477"></a> +<span class="sourceLineNo">1478</span> }<a name="line.1478"></a> +<span class="sourceLineNo">1479</span> super.stopServiceThreads();<a name="line.1479"></a> +<span class="sourceLineNo">1480</span> CleanerChore.shutDownChorePool();<a name="line.1480"></a> +<span class="sourceLineNo">1481</span><a name="line.1481"></a> +<span class="sourceLineNo">1482</span> LOG.debug("Stopping service threads");<a name="line.1482"></a> +<span class="sourceLineNo">1483</span><a name="line.1483"></a> +<span class="sourceLineNo">1484</span> if (this.quotaManager != null) {<a name="line.1484"></a> +<span class="sourceLineNo">1485</span> this.quotaManager.stop();<a name="line.1485"></a> +<span class="sourceLineNo">1486</span> }<a name="line.1486"></a> +<span class="sourceLineNo">1487</span><a name="line.1487"></a> +<span class="sourceLineNo">1488</span> if (this.activeMasterManager != null) {<a name="line.1488"></a> +<span class="sourceLineNo">1489</span> this.activeMasterManager.stop();<a name="line.1489"></a> +<span class="sourceLineNo">1490</span> }<a name="line.1490"></a> +<span class="sourceLineNo">1491</span> if (this.serverManager != null) {<a name="line.1491"></a> +<span class="sourceLineNo">1492</span> this.serverManager.stop();<a name="line.1492"></a> +<span class="sourceLineNo">1493</span> }<a name="line.1493"></a> +<span class="sourceLineNo">1494</span> if (this.assignmentManager != null) {<a name="line.1494"></a> +<span class="sourceLineNo">1495</span> this.assignmentManager.stop();<a name="line.1495"></a> +<span class="sourceLineNo">1496</span> }<a name="line.1496"></a> +<span class="sourceLineNo">1497</span><a name="line.1497"></a> +<span class="sourceLineNo">1498</span> stopProcedureExecutor();<a name="line.1498"></a> +<span class="sourceLineNo">1499</span><a name="line.1499"></a> +<span class="sourceLineNo">1500</span> if (this.walManager != null) {<a name="line.1500"></a> +<span class="sourceLineNo">1501</span> this.walManager.stop();<a name="line.1501"></a> +<span class="sourceLineNo">1502</span> }<a name="line.1502"></a> +<span class="sourceLineNo">1503</span> if (this.fileSystemManager != null) {<a name="line.1503"></a> +<span class="sourceLineNo">1504</span> this.fileSystemManager.stop();<a name="line.1504"></a> +<span class="sourceLineNo">1505</span> }<a name="line.1505"></a> +<span class="sourceLineNo">1506</span> if (this.mpmHost != null) {<a name="line.1506"></a> +<span class="sourceLineNo">1507</span> this.mpmHost.stop("server shutting down.");<a name="line.1507"></a> +<span class="sourceLineNo">1508</span> }<a name="line.1508"></a> +<span class="sourceLineNo">1509</span> if (this.regionServerTracker != null) {<a name="line.1509"></a> +<span class="sourceLineNo">1510</span> this.regionServerTracker.stop();<a name="line.1510"></a> +<span class="sourceLineNo">1511</span> }<a name="line.1511"></a> +<span class="sourceLineNo">1512</span> }<a name="line.1512"></a> +<span class="sourceLineNo">1513</span><a name="line.1513"></a> +<span class="sourceLineNo">1514</span> private void createProcedureExecutor() throws IOException {<a name="line.1514"></a> +<span class="sourceLineNo">1515</span> MasterProcedureEnv procEnv = new MasterProcedureEnv(this);<a name="line.1515"></a> +<span class="sourceLineNo">1516</span> procedureStore =<a name="line.1516"></a> +<span class="sourceLineNo">1517</span> new WALProcedureStore(conf, new MasterProcedureEnv.WALStoreLeaseRecovery(this));<a name="line.1517"></a> +<span class="sourceLineNo">1518</span> procedureStore.registerListener(new ProcedureStoreListener() {<a name="line.1518"></a> +<span class="sourceLineNo">1519</span><a name="line.1519"></a> +<span class="sourceLineNo">1520</span> @Override<a name="line.1520"></a> +<span class="sourceLineNo">1521</span> public void abortProcess() {<a name="line.1521"></a> +<span class="sourceLineNo">1522</span> abort("The Procedure Store lost the lease", null);<a name="line.1522"></a> +<span class="sourceLineNo">1523</span> }<a name="line.1523"></a> +<span class="sourceLineNo">1524</span> });<a name="line.1524"></a> +<span class="sourceLineNo">1525</span> MasterProcedureScheduler procedureScheduler = procEnv.getProcedureScheduler();<a name="line.1525"></a> +<span class="sourceLineNo">1526</span> procedureExecutor = new ProcedureExecutor<>(conf, procEnv, procedureStore, procedureScheduler);<a name="line.1526"></a> +<span class="sourceLineNo">1527</span> configurationManager.registerObserver(procEnv);<a name="line.1527"></a> +<span class="sourceLineNo">1528</span><a name="line.1528"></a> +<span class="sourceLineNo">1529</span> int cpus = Runtime.getRuntime().availableProcessors();<a name="line.1529"></a> +<span class="sourceLineNo">1530</span> final int numThreads = conf.getInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, Math.max(<a name="line.1530"></a> +<span class="sourceLineNo">1531</span> (cpus > 0 ? cpus / 4 : 0), MasterProcedureConstants.DEFAULT_MIN_MASTER_PROCEDURE_THREADS));<a name="line.1531"></a> +<span class="sourceLineNo">1532</span> final boolean abortOnCorruption =<a name="line.1532"></a> +<span class="sourceLineNo">1533</span> conf.getBoolean(MasterProcedureConstants.EXECUTOR_ABORT_ON_CORRUPTION,<a name="line.1533"></a> +<span class="sourceLineNo">1534</span> MasterProcedureConstants.DEFAULT_EXECUTOR_ABORT_ON_CORRUPTION);<a name="line.1534"></a> +<span class="sourceLineNo">1535</span> procedureStore.start(numThreads);<a name="line.1535"></a> +<span class="sourceLineNo">1536</span> // Just initialize it but do not start the workers, we will start the workers later by calling<a name="line.1536"></a> +<span class="sourceLineNo">1537</span> // startProcedureExecutor. See the javadoc for finishActiveMasterInitialization for more<a name="line.1537"></a> +<span class="sourceLineNo">1538</span> // details.<a name="line.1538"></a> +<span class="sourceLineNo">1539</span> procedureExecutor.init(numThreads, abortOnCorruption);<a name="line.1539"></a> +<span class="sourceLineNo">1540</span> procEnv.getRemoteDispatcher().start();<a name="line.1540"></a> +<span class="sourceLineNo">1541</span> }<a name="line.1541"></a> +<span class="sourceLineNo">1542</span><a name="line.1542"></a> +<span class="sourceLineNo">1543</span> private void startProcedureExecutor() throws IOException {<a name="line.1543"></a> +<span class="sourceLineNo">1544</span> procedureExecutor.startWorkers();<a name="line.1544"></a> +<span class="sourceLineNo">1545</span> }<a name="line.1545"></a> +<span class="sourceLineNo">1546</span><a name="line.1546"></a> +<span class="sourceLineNo">1547</span> private void stopProcedureExecutor() {<a name="line.1547"></a> +<span class="sourceLineNo">1548</span> if (procedureExecutor != null) {<a name="line.1548"></a> +<span class="sourceLineNo">1549</span> configurationManager.deregisterObserver(procedureExecutor.getEnvironment());<a name="line.1549"></a> +<span class="sourceLineNo">1550</span> procedureExecutor.getEnvironment().getRemoteDispatcher().stop();<a name="line.1550"></a> +<span class="sourceLineNo">1551</span> procedureExecutor.stop();<a name="line.1551"></a> +<span class="sourceLineNo">1552</span> procedureExecutor.join();<a name="line.1552"></a> +<span class="sourceLineNo">1553</span> procedureExecutor = null;<a name="line.1553"></a> <span class="sourceLineNo">1554</span> }<a name="line.1554"></a> -<span class="sourceLineNo">1555</span> }<a name="line.1555"></a> -<span class="sourceLineNo">1556</span><a name="line.1556"></a> -<span class="sourceLineNo">1557</span> private void stopChores() {<a name="line.1557"></a> -<span class="sourceLineNo">1558</span> ChoreService choreService = getChoreService();<a name="line.1558"></a> -<span class="sourceLineNo">1559</span> if (choreService != null) {<a name="line.1559"></a> -<span class="sourceLineNo">1560< <TRUNCATED>