View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master;
20  
21  import java.io.IOException;
22  import java.io.InterruptedIOException;
23  import java.util.ArrayList;
24  import java.util.HashSet;
25  import java.util.List;
26  import java.util.Set;
27  import java.util.concurrent.locks.Lock;
28  import java.util.concurrent.locks.ReentrantLock;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.apache.hadoop.classification.InterfaceAudience;
33  import org.apache.hadoop.conf.Configuration;
34  import org.apache.hadoop.fs.FileStatus;
35  import org.apache.hadoop.fs.FileSystem;
36  import org.apache.hadoop.fs.Path;
37  import org.apache.hadoop.fs.PathFilter;
38  import org.apache.hadoop.hbase.ClusterId;
39  import org.apache.hadoop.hbase.HColumnDescriptor;
40  import org.apache.hadoop.hbase.HConstants;
41  import org.apache.hadoop.hbase.HRegionInfo;
42  import org.apache.hadoop.hbase.HTableDescriptor;
43  import org.apache.hadoop.hbase.InvalidFamilyOperationException;
44  import org.apache.hadoop.hbase.Server;
45  import org.apache.hadoop.hbase.ServerName;
46  import org.apache.hadoop.hbase.TableDescriptor;
47  import org.apache.hadoop.hbase.TableName;
48  import org.apache.hadoop.hbase.backup.HFileArchiver;
49  import org.apache.hadoop.hbase.client.TableState;
50  import org.apache.hadoop.hbase.exceptions.DeserializationException;
51  import org.apache.hadoop.hbase.fs.HFileSystem;
52  import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.SplitLogTask.RecoveryMode;
53  import org.apache.hadoop.hbase.regionserver.HRegion;
54  import org.apache.hadoop.hbase.regionserver.wal.HLog;
55  import org.apache.hadoop.hbase.regionserver.wal.HLogUtil;
56  import org.apache.hadoop.hbase.util.Bytes;
57  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
58  import org.apache.hadoop.hbase.util.FSTableDescriptors;
59  import org.apache.hadoop.hbase.util.FSUtils;
60  import org.apache.hadoop.ipc.RemoteException;
61  
62  /**
63   * This class abstracts a bunch of operations the HMaster needs to interact with
64   * the underlying file system, including splitting log files, checking file
65   * system status, etc.
66   */
67  @InterfaceAudience.Private
68  public class MasterFileSystem {
69    private static final Log LOG = LogFactory.getLog(MasterFileSystem.class.getName());
70    // HBase configuration
71    Configuration conf;
72    // master status
73    Server master;
74    // metrics for master
75    private final MetricsMasterFileSystem metricsMasterFilesystem = new MetricsMasterFileSystem();
76    // Persisted unique cluster ID
77    private ClusterId clusterId;
78    // Keep around for convenience.
79    private final FileSystem fs;
80    // Is the fileystem ok?
81    private volatile boolean fsOk = true;
82    // The Path to the old logs dir
83    private final Path oldLogDir;
84    // root hbase directory on the FS
85    private final Path rootdir;
86    // hbase temp directory used for table construction and deletion
87    private final Path tempdir;
88    // create the split log lock
89    final Lock splitLogLock = new ReentrantLock();
90    final boolean distributedLogReplay;
91    final SplitLogManager splitLogManager;
92    private final MasterServices services;
93  
94    final static PathFilter META_FILTER = new PathFilter() {
95      @Override
96      public boolean accept(Path p) {
97        return HLogUtil.isMetaFile(p);
98      }
99    };
100 
101   final static PathFilter NON_META_FILTER = new PathFilter() {
102     @Override
103     public boolean accept(Path p) {
104       return !HLogUtil.isMetaFile(p);
105     }
106   };
107 
108   public MasterFileSystem(Server master, MasterServices services)
109   throws IOException {
110     this.conf = master.getConfiguration();
111     this.master = master;
112     this.services = services;
113     // Set filesystem to be that of this.rootdir else we get complaints about
114     // mismatched filesystems if hbase.rootdir is hdfs and fs.defaultFS is
115     // default localfs.  Presumption is that rootdir is fully-qualified before
116     // we get to here with appropriate fs scheme.
117     this.rootdir = FSUtils.getRootDir(conf);
118     this.tempdir = new Path(this.rootdir, HConstants.HBASE_TEMP_DIRECTORY);
119     // Cover both bases, the old way of setting default fs and the new.
120     // We're supposed to run on 0.20 and 0.21 anyways.
121     this.fs = this.rootdir.getFileSystem(conf);
122     FSUtils.setFsDefault(conf, new Path(this.fs.getUri()));
123     // make sure the fs has the same conf
124     fs.setConf(conf);
125     // setup the filesystem variable
126     // set up the archived logs path
127     this.oldLogDir = createInitialFileSystemLayout();
128     HFileSystem.addLocationsOrderInterceptor(conf);
129     this.splitLogManager =
130         new SplitLogManager(master, master.getConfiguration(), master, services,
131             master.getServerName());
132     this.distributedLogReplay = this.splitLogManager.isLogReplaying();
133   }
134 
135   /**
136    * Create initial layout in filesystem.
137    * <ol>
138    * <li>Check if the meta region exists and is readable, if not create it.
139    * Create hbase.version and the hbase:meta directory if not one.
140    * </li>
141    * <li>Create a log archive directory for RS to put archived logs</li>
142    * </ol>
143    * Idempotent.
144    */
145   private Path createInitialFileSystemLayout() throws IOException {
146     // check if the root directory exists
147     checkRootDir(this.rootdir, conf, this.fs);
148 
149     // check if temp directory exists and clean it
150     checkTempDir(this.tempdir, conf, this.fs);
151 
152     Path oldLogDir = new Path(this.rootdir, HConstants.HREGION_OLDLOGDIR_NAME);
153 
154     // Make sure the region servers can archive their old logs
155     if(!this.fs.exists(oldLogDir)) {
156       this.fs.mkdirs(oldLogDir);
157     }
158 
159     return oldLogDir;
160   }
161 
162   public FileSystem getFileSystem() {
163     return this.fs;
164   }
165 
166   /**
167    * Get the directory where old logs go
168    * @return the dir
169    */
170   public Path getOldLogDir() {
171     return this.oldLogDir;
172   }
173 
174   /**
175    * Checks to see if the file system is still accessible.
176    * If not, sets closed
177    * @return false if file system is not available
178    */
179   public boolean checkFileSystem() {
180     if (this.fsOk) {
181       try {
182         FSUtils.checkFileSystemAvailable(this.fs);
183         FSUtils.checkDfsSafeMode(this.conf);
184       } catch (IOException e) {
185         master.abort("Shutting down HBase cluster: file system not available", e);
186         this.fsOk = false;
187       }
188     }
189     return this.fsOk;
190   }
191 
192   /**
193    * @return HBase root dir.
194    */
195   public Path getRootDir() {
196     return this.rootdir;
197   }
198 
199   /**
200    * @return HBase temp dir.
201    */
202   public Path getTempDir() {
203     return this.tempdir;
204   }
205 
206   /**
207    * @return The unique identifier generated for this cluster
208    */
209   public ClusterId getClusterId() {
210     return clusterId;
211   }
212 
213   /**
214    * Inspect the log directory to find dead servers which need recovery work
215    * @return A set of ServerNames which aren't running but still have WAL files left in file system
216    */
217   Set<ServerName> getFailedServersFromLogFolders() {
218     boolean retrySplitting = !conf.getBoolean("hbase.hlog.split.skip.errors",
219       HLog.SPLIT_SKIP_ERRORS_DEFAULT);
220 
221     Set<ServerName> serverNames = new HashSet<ServerName>();
222     Path logsDirPath = new Path(this.rootdir, HConstants.HREGION_LOGDIR_NAME);
223 
224     do {
225       if (master.isStopped()) {
226         LOG.warn("Master stopped while trying to get failed servers.");
227         break;
228       }
229       try {
230         if (!this.fs.exists(logsDirPath)) return serverNames;
231         FileStatus[] logFolders = FSUtils.listStatus(this.fs, logsDirPath, null);
232         // Get online servers after getting log folders to avoid log folder deletion of newly
233         // checked in region servers . see HBASE-5916
234         Set<ServerName> onlineServers = ((HMaster) master).getServerManager().getOnlineServers()
235             .keySet();
236 
237         if (logFolders == null || logFolders.length == 0) {
238           LOG.debug("No log files to split, proceeding...");
239           return serverNames;
240         }
241         for (FileStatus status : logFolders) {
242           String sn = status.getPath().getName();
243           // truncate splitting suffix if present (for ServerName parsing)
244           if (sn.endsWith(HLog.SPLITTING_EXT)) {
245             sn = sn.substring(0, sn.length() - HLog.SPLITTING_EXT.length());
246           }
247           ServerName serverName = ServerName.parseServerName(sn);
248           if (!onlineServers.contains(serverName)) {
249             LOG.info("Log folder " + status.getPath() + " doesn't belong "
250                 + "to a known region server, splitting");
251             serverNames.add(serverName);
252           } else {
253             LOG.info("Log folder " + status.getPath() + " belongs to an existing region server");
254           }
255         }
256         retrySplitting = false;
257       } catch (IOException ioe) {
258         LOG.warn("Failed getting failed servers to be recovered.", ioe);
259         if (!checkFileSystem()) {
260           LOG.warn("Bad Filesystem, exiting");
261           Runtime.getRuntime().halt(1);
262         }
263         try {
264           if (retrySplitting) {
265             Thread.sleep(conf.getInt("hbase.hlog.split.failure.retry.interval", 30 * 1000));
266           }
267         } catch (InterruptedException e) {
268           LOG.warn("Interrupted, aborting since cannot return w/o splitting");
269           Thread.currentThread().interrupt();
270           retrySplitting = false;
271           Runtime.getRuntime().halt(1);
272         }
273       }
274     } while (retrySplitting);
275 
276     return serverNames;
277   }
278 
279   public void splitLog(final ServerName serverName) throws IOException {
280     Set<ServerName> serverNames = new HashSet<ServerName>();
281     serverNames.add(serverName);
282     splitLog(serverNames);
283   }
284 
285   /**
286    * Specialized method to handle the splitting for meta HLog
287    * @param serverName
288    * @throws IOException
289    */
290   public void splitMetaLog(final ServerName serverName) throws IOException {
291     Set<ServerName> serverNames = new HashSet<ServerName>();
292     serverNames.add(serverName);
293     splitMetaLog(serverNames);
294   }
295 
296   /**
297    * Specialized method to handle the splitting for meta HLog
298    * @param serverNames
299    * @throws IOException
300    */
301   public void splitMetaLog(final Set<ServerName> serverNames) throws IOException {
302     splitLog(serverNames, META_FILTER);
303   }
304 
305   private List<Path> getLogDirs(final Set<ServerName> serverNames) throws IOException {
306     List<Path> logDirs = new ArrayList<Path>();
307     boolean needReleaseLock = false;
308     if (!this.services.isInitialized()) {
309       // during master initialization, we could have multiple places splitting a same wal
310       this.splitLogLock.lock();
311       needReleaseLock = true;
312     }
313     try {
314       for (ServerName serverName : serverNames) {
315         Path logDir = new Path(this.rootdir, HLogUtil.getHLogDirectoryName(serverName.toString()));
316         Path splitDir = logDir.suffix(HLog.SPLITTING_EXT);
317         // Rename the directory so a rogue RS doesn't create more HLogs
318         if (fs.exists(logDir)) {
319           if (!this.fs.rename(logDir, splitDir)) {
320             throw new IOException("Failed fs.rename for log split: " + logDir);
321           }
322           logDir = splitDir;
323           LOG.debug("Renamed region directory: " + splitDir);
324         } else if (!fs.exists(splitDir)) {
325           LOG.info("Log dir for server " + serverName + " does not exist");
326           continue;
327         }
328         logDirs.add(splitDir);
329       }
330     } finally {
331       if (needReleaseLock) {
332         this.splitLogLock.unlock();
333       }
334     }
335     return logDirs;
336   }
337 
338   /**
339    * Mark regions in recovering state when distributedLogReplay are set true
340    * @param serverName Failed region server whose wals to be replayed
341    * @param regions Set of regions to be recovered
342    * @throws IOException
343    */
344   public void prepareLogReplay(ServerName serverName, Set<HRegionInfo> regions) throws IOException {
345     if (!this.distributedLogReplay) {
346       return;
347     }
348     // mark regions in recovering state
349     if (regions == null || regions.isEmpty()) {
350       return;
351     }
352     this.splitLogManager.markRegionsRecovering(serverName, regions);
353   }
354 
355   public void splitLog(final Set<ServerName> serverNames) throws IOException {
356     splitLog(serverNames, NON_META_FILTER);
357   }
358 
359   /**
360    * Wrapper function on {@link SplitLogManager#removeStaleRecoveringRegions(Set)}
361    * @param failedServers
362    * @throws IOException
363    */
364   void removeStaleRecoveringRegionsFromZK(final Set<ServerName> failedServers)
365       throws IOException, InterruptedIOException {
366     this.splitLogManager.removeStaleRecoveringRegions(failedServers);
367   }
368 
369   /**
370    * This method is the base split method that splits HLog files matching a filter. Callers should
371    * pass the appropriate filter for meta and non-meta HLogs.
372    * @param serverNames
373    * @param filter
374    * @throws IOException
375    */
376   public void splitLog(final Set<ServerName> serverNames, PathFilter filter) throws IOException {
377     long splitTime = 0, splitLogSize = 0;
378     List<Path> logDirs = getLogDirs(serverNames);
379 
380     splitLogManager.handleDeadWorkers(serverNames);
381     splitTime = EnvironmentEdgeManager.currentTime();
382     splitLogSize = splitLogManager.splitLogDistributed(serverNames, logDirs, filter);
383     splitTime = EnvironmentEdgeManager.currentTime() - splitTime;
384 
385     if (this.metricsMasterFilesystem != null) {
386       if (filter == META_FILTER) {
387         this.metricsMasterFilesystem.addMetaWALSplit(splitTime, splitLogSize);
388       } else {
389         this.metricsMasterFilesystem.addSplit(splitTime, splitLogSize);
390       }
391     }
392   }
393 
394   /**
395    * Get the rootdir.  Make sure its wholesome and exists before returning.
396    * @param rd
397    * @param c
398    * @param fs
399    * @return hbase.rootdir (after checks for existence and bootstrapping if
400    * needed populating the directory with necessary bootup files).
401    * @throws IOException
402    */
403   @SuppressWarnings("deprecation")
404   private Path checkRootDir(final Path rd, final Configuration c,
405     final FileSystem fs)
406   throws IOException {
407     // If FS is in safe mode wait till out of it.
408     FSUtils.waitOnSafeMode(c, c.getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000));
409     // Filesystem is good. Go ahead and check for hbase.rootdir.
410     try {
411       if (!fs.exists(rd)) {
412         fs.mkdirs(rd);
413         // DFS leaves safe mode with 0 DNs when there are 0 blocks.
414         // We used to handle this by checking the current DN count and waiting until
415         // it is nonzero. With security, the check for datanode count doesn't work --
416         // it is a privileged op. So instead we adopt the strategy of the jobtracker
417         // and simply retry file creation during bootstrap indefinitely. As soon as
418         // there is one datanode it will succeed. Permission problems should have
419         // already been caught by mkdirs above.
420         FSUtils.setVersion(fs, rd, c.getInt(HConstants.THREAD_WAKE_FREQUENCY,
421           10 * 1000), c.getInt(HConstants.VERSION_FILE_WRITE_ATTEMPTS,
422             HConstants.DEFAULT_VERSION_FILE_WRITE_ATTEMPTS));
423       } else {
424         if (!fs.isDirectory(rd)) {
425           throw new IllegalArgumentException(rd.toString() + " is not a directory");
426         }
427         // as above
428         FSUtils.checkVersion(fs, rd, true, c.getInt(HConstants.THREAD_WAKE_FREQUENCY,
429           10 * 1000), c.getInt(HConstants.VERSION_FILE_WRITE_ATTEMPTS,
430             HConstants.DEFAULT_VERSION_FILE_WRITE_ATTEMPTS));
431       }
432     } catch (DeserializationException de) {
433       LOG.fatal("Please fix invalid configuration for " + HConstants.HBASE_DIR, de);
434       IOException ioe = new IOException();
435       ioe.initCause(de);
436       throw ioe;
437     } catch (IllegalArgumentException iae) {
438       LOG.fatal("Please fix invalid configuration for "
439         + HConstants.HBASE_DIR + " " + rd.toString(), iae);
440       throw iae;
441     }
442     // Make sure cluster ID exists
443     if (!FSUtils.checkClusterIdExists(fs, rd, c.getInt(
444         HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000))) {
445       FSUtils.setClusterId(fs, rd, new ClusterId(), c.getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000));
446     }
447     clusterId = FSUtils.getClusterId(fs, rd);
448 
449     // Make sure the meta region directory exists!
450     if (!FSUtils.metaRegionExists(fs, rd)) {
451       bootstrap(rd, c);
452     } else {
453       // Migrate table descriptor files if necessary
454       org.apache.hadoop.hbase.util.FSTableDescriptorMigrationToSubdir
455         .migrateFSTableDescriptorsIfNecessary(fs, rd);
456     }
457 
458     // Create tableinfo-s for hbase:meta if not already there.
459     // assume, created table descriptor is for enabling table
460     new FSTableDescriptors(fs, rd).createTableDescriptor(
461         new TableDescriptor(HTableDescriptor.META_TABLEDESC, TableState.State.ENABLING));
462 
463     return rd;
464   }
465 
466   /**
467    * Make sure the hbase temp directory exists and is empty.
468    * NOTE that this method is only executed once just after the master becomes the active one.
469    */
470   private void checkTempDir(final Path tmpdir, final Configuration c, final FileSystem fs)
471       throws IOException {
472     // If the temp directory exists, clear the content (left over, from the previous run)
473     if (fs.exists(tmpdir)) {
474       // Archive table in temp, maybe left over from failed deletion,
475       // if not the cleaner will take care of them.
476       for (Path tabledir: FSUtils.getTableDirs(fs, tmpdir)) {
477         for (Path regiondir: FSUtils.getRegionDirs(fs, tabledir)) {
478           HFileArchiver.archiveRegion(fs, this.rootdir, tabledir, regiondir);
479         }
480       }
481       if (!fs.delete(tmpdir, true)) {
482         throw new IOException("Unable to clean the temp directory: " + tmpdir);
483       }
484     }
485 
486     // Create the temp directory
487     if (!fs.mkdirs(tmpdir)) {
488       throw new IOException("HBase temp directory '" + tmpdir + "' creation failure.");
489     }
490   }
491 
492   private static void bootstrap(final Path rd, final Configuration c)
493   throws IOException {
494     LOG.info("BOOTSTRAP: creating hbase:meta region");
495     try {
496       // Bootstrapping, make sure blockcache is off.  Else, one will be
497       // created here in bootstrap and it'll need to be cleaned up.  Better to
498       // not make it in first place.  Turn off block caching for bootstrap.
499       // Enable after.
500       HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
501       setInfoFamilyCachingForMeta(false);
502       HRegion meta = HRegion.createHRegion(metaHRI, rd, c,
503           HTableDescriptor.META_TABLEDESC);
504       setInfoFamilyCachingForMeta(true);
505       HRegion.closeHRegion(meta);
506     } catch (IOException e) {
507         e = e instanceof RemoteException ?
508                 ((RemoteException)e).unwrapRemoteException() : e;
509       LOG.error("bootstrap", e);
510       throw e;
511     }
512   }
513 
514   /**
515    * Enable in memory caching for hbase:meta
516    */
517   public static void setInfoFamilyCachingForMeta(final boolean b) {
518     for (HColumnDescriptor hcd:
519         HTableDescriptor.META_TABLEDESC.getColumnFamilies()) {
520       if (Bytes.equals(hcd.getName(), HConstants.CATALOG_FAMILY)) {
521         hcd.setBlockCacheEnabled(b);
522         hcd.setInMemory(b);
523       }
524     }
525   }
526 
527 
528   public void deleteRegion(HRegionInfo region) throws IOException {
529     HFileArchiver.archiveRegion(conf, fs, region);
530   }
531 
532   public void deleteTable(TableName tableName) throws IOException {
533     fs.delete(FSUtils.getTableDir(rootdir, tableName), true);
534   }
535 
536   /**
537    * Move the specified table to the hbase temp directory
538    * @param tableName Table name to move
539    * @return The temp location of the table moved
540    * @throws IOException in case of file-system failure
541    */
542   public Path moveTableToTemp(TableName tableName) throws IOException {
543     Path srcPath = FSUtils.getTableDir(rootdir, tableName);
544     Path tempPath = FSUtils.getTableDir(this.tempdir, tableName);
545 
546     // Ensure temp exists
547     if (!fs.exists(tempPath.getParent()) && !fs.mkdirs(tempPath.getParent())) {
548       throw new IOException("HBase temp directory '" + tempPath.getParent() + "' creation failure.");
549     }
550 
551     if (!fs.rename(srcPath, tempPath)) {
552       throw new IOException("Unable to move '" + srcPath + "' to temp '" + tempPath + "'");
553     }
554 
555     return tempPath;
556   }
557 
558   public void updateRegionInfo(HRegionInfo region) {
559     // TODO implement this.  i think this is currently broken in trunk i don't
560     //      see this getting updated.
561     //      @see HRegion.checkRegioninfoOnFilesystem()
562   }
563 
564   public void deleteFamilyFromFS(HRegionInfo region, byte[] familyName)
565       throws IOException {
566     // archive family store files
567     Path tableDir = FSUtils.getTableDir(rootdir, region.getTable());
568     HFileArchiver.archiveFamily(fs, conf, region, tableDir, familyName);
569 
570     // delete the family folder
571     Path familyDir = new Path(tableDir,
572       new Path(region.getEncodedName(), Bytes.toString(familyName)));
573     if (fs.delete(familyDir, true) == false) {
574       throw new IOException("Could not delete family "
575           + Bytes.toString(familyName) + " from FileSystem for region "
576           + region.getRegionNameAsString() + "(" + region.getEncodedName()
577           + ")");
578     }
579   }
580 
581   public void stop() {
582     if (splitLogManager != null) {
583       this.splitLogManager.stop();
584     }
585   }
586 
587   /**
588    * Delete column of a table
589    * @param tableName
590    * @param familyName
591    * @return Modified HTableDescriptor with requested column deleted.
592    * @throws IOException
593    */
594   public HTableDescriptor deleteColumn(TableName tableName, byte[] familyName)
595       throws IOException {
596     LOG.info("DeleteColumn. Table = " + tableName
597         + " family = " + Bytes.toString(familyName));
598     HTableDescriptor htd = this.services.getTableDescriptors().get(tableName);
599     htd.removeFamily(familyName);
600     this.services.getTableDescriptors().add(htd);
601     return htd;
602   }
603 
604   /**
605    * Modify Column of a table
606    * @param tableName
607    * @param hcd HColumnDesciptor
608    * @return Modified HTableDescriptor with the column modified.
609    * @throws IOException
610    */
611   public HTableDescriptor modifyColumn(TableName tableName, HColumnDescriptor hcd)
612       throws IOException {
613     LOG.info("AddModifyColumn. Table = " + tableName
614         + " HCD = " + hcd.toString());
615 
616     HTableDescriptor htd = this.services.getTableDescriptors().get(tableName);
617     byte [] familyName = hcd.getName();
618     if(!htd.hasFamily(familyName)) {
619       throw new InvalidFamilyOperationException("Family '" +
620         Bytes.toString(familyName) + "' doesn't exists so cannot be modified");
621     }
622     htd.addFamily(hcd);
623     this.services.getTableDescriptors().add(htd);
624     return htd;
625   }
626 
627   /**
628    * Add column to a table
629    * @param tableName
630    * @param hcd
631    * @return Modified HTableDescriptor with new column added.
632    * @throws IOException
633    */
634   public HTableDescriptor addColumn(TableName tableName, HColumnDescriptor hcd)
635       throws IOException {
636     LOG.info("AddColumn. Table = " + tableName + " HCD = " +
637       hcd.toString());
638     HTableDescriptor htd = this.services.getTableDescriptors().get(tableName);
639     if (htd == null) {
640       throw new InvalidFamilyOperationException("Family '" +
641         hcd.getNameAsString() + "' cannot be modified as HTD is null");
642     }
643     htd.addFamily(hcd);
644     this.services.getTableDescriptors().add(htd);
645     return htd;
646   }
647 
648   /**
649    * The function is used in SSH to set recovery mode based on configuration after all outstanding
650    * log split tasks drained.
651    * @throws IOException
652    */
653   public void setLogRecoveryMode() throws IOException {
654       this.splitLogManager.setRecoveryMode(false);
655   }
656 
657   public RecoveryMode getLogRecoveryMode() {
658     return this.splitLogManager.getRecoveryMode();
659   }
660 }