Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.hadoop.hbase.replication.regionserver;
 
In a scenario of Replication based Disaster/Recovery, when hbase Master-Cluster crashes, this tool is used to sync-up the delta from Master to Slave using the info from Zookeeper. The tool will run on Master-Cluser, and assume ZK, Filesystem and NetWork still available after hbase crashes hbase org.apache.hadoop.hbase.replication.regionserver.ReplicationSyncUp
 
 
 public class ReplicationSyncUp extends Configured implements Tool {
 
   static final Log LOG = LogFactory.getLog(ReplicationSyncUp.class.getName());
 
   private static Configuration conf;
 
   private static final long SLEEP_TIME = 10000;
 
   // although the tool is designed to be run on command line
   // this api is provided for executing the tool through another app
   public static void setConfigure(Configuration config) {
      = config;
   }

  
Main program

Parameters:
args
Throws:
java.lang.Exception
 
   public static void main(String[] argsthrows Exception {
     if ( == null = HBaseConfiguration.create();
     int ret = ToolRunner.run(new ReplicationSyncUp(), args);
     System.exit(ret);
   }
 
   @Override
   public int run(String[] argsthrows Exception {
     Replication replication;
     ReplicationSourceManager manager;
     FileSystem fs;
     Path oldLogDirlogDirrootDir;
     ZooKeeperWatcher zkw;
 
     Abortable abortable = new Abortable() {
       @Override
       public void abort(String whyThrowable e) {
       }
 
       @Override
       public boolean isAborted() {
         return false;
       }
     };
 
     zkw =
         new ZooKeeperWatcher("syncupReplication" + System.currentTimeMillis(), abortable,
             true);
 
     rootDir = FSUtils.getRootDir();
     fs = FileSystem.get();
     oldLogDir = new Path(rootDir.);
     logDir = new Path(rootDir.);
    ..println("Start Replication Server start");
    replication = new Replication(new DummyServer(zkw), fslogDiroldLogDir);
    manager = replication.getReplicationManager();
    manager.init();
    try {
      int numberOfOldSource = 1; // default wait once
      while (numberOfOldSource > 0) {
        Thread.sleep();
        numberOfOldSource = manager.getOldSources().size();
      }
    } catch (InterruptedException e) {
      ..println("didn't wait long enough:" + e);
      return (-1);
    }
    manager.join();
    zkw.close();
    return (0);
  }
  static class DummyServer implements Server {
      // an unique name in case the first run fails
       = System.currentTimeMillis() + ".SyncUpTool.replication.org";
      this. = zkw;
    }
    DummyServer(String hostname) {
      this. = hostname;
    }
    @Override
    public Configuration getConfiguration() {
      return ;
    }
    @Override
    public ZooKeeperWatcher getZooKeeper() {
      return ;
    }
    @Override
    public CatalogTracker getCatalogTracker() {
      return null;
    }
    @Override
    public ServerName getServerName() {
      return ServerName.valueOf(, 1234, 1L);
    }
    @Override
    public void abort(String whyThrowable e) {
    }
    @Override
    public boolean isAborted() {
      return false;
    }
    @Override
    public void stop(String why) {
    }
    @Override
    public boolean isStopped() {
      return false;
    }
  }
New to GrepCode? Check out our FAQ X