Java 类org.apache.hadoop.hbase.zookeeper.RootRegionTracker 实例源码

项目:LCIndex-HBase-0.94.16    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:IRIndex    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:RStore    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:HBase-Research    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:hbase-0.94.8-qod    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:hbase-0.94.8-qod    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:DominoHBase    文件:TestCatalogTracker.java   
private void testVerifyMetaRegionLocationWithException(Exception ex)
throws IOException, InterruptedException, KeeperException, ServiceException {
  // Mock an ClientProtocol.
  final ClientProtocol implementation = Mockito.mock(ClientProtocol.class);
  HConnection connection = mockConnection(null, implementation);
  try {
    // If a 'get' is called on mocked interface, throw connection refused.
    Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).
      thenThrow(new ServiceException(ex));
    // Now start up the catalogtracker with our doctored Connection.
    final CatalogTracker ct = constructAndStartCatalogTracker(connection);
    try {
      RootRegionTracker.setRootLocation(this.watcher, SN);
      long timeout = UTIL.getConfiguration().
        getLong("hbase.catalog.verification.timeout", 1000);
      Assert.assertFalse(ct.verifyMetaRegionLocation(timeout));
    } finally {
      // Clean out root location or later tests will be confused... they
      // presume start fresh in zk.
      RootRegionTracker.deleteRootLocation(this.watcher);
    }
  } finally {
    // Clear out our doctored connection or could mess up subsequent tests.
    HConnectionManager.deleteConnection(UTIL.getConfiguration(), true);
  }
}
项目:DominoHBase    文件:TestCatalogTracker.java   
/**
 * Test get of root region fails properly if nothing to connect to.
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 * @throws ServiceException
 */
@Test
public void testVerifyRootRegionLocationFails()
throws IOException, InterruptedException, KeeperException, ServiceException {
  HConnection connection = Mockito.mock(HConnection.class);
  ServiceException connectException =
    new ServiceException(new ConnectException("Connection refused"));
  final AdminProtocol implementation =
    Mockito.mock(AdminProtocol.class);
  Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(),
    (GetRegionInfoRequest)Mockito.any())).thenThrow(connectException);
  Mockito.when(connection.getAdmin(Mockito.anyString(),
    Mockito.anyInt(), Mockito.anyBoolean())).
    thenReturn(implementation);
  final CatalogTracker ct = constructAndStartCatalogTracker(connection);
  try {
    RootRegionTracker.setRootLocation(this.watcher,
      new ServerName("example.com", 1234, System.currentTimeMillis()));
    Assert.assertFalse(ct.verifyRootRegionLocation(100));
  } finally {
    // Clean out root location or later tests will be confused... they presume
    // start fresh in zk.
    RootRegionTracker.deleteRootLocation(this.watcher);
  }
}
项目:hindex    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, InterruptedException {
  RootRegionTracker rootRegionTracker =
    new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error(why, e);
        System.exit(1);
      }
      @Override
      public boolean isAborted(){
        return false;
      }

    });
  rootRegionTracker.start();
  ServerName sn = null;
  try {
    sn = rootRegionTracker.getRootRegionLocation();
  } finally {
    rootRegionTracker.stop();
  }
  return sn;
}
项目:LCIndex-HBase-0.94.16    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
}
项目:IRIndex    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
}
项目:RStore    文件:HConnectionManager.java   
private synchronized void setupZookeeperTrackers()
    throws ZooKeeperConnectionException{
  // initialize zookeeper and master address manager
  this.zooKeeper = getZooKeeperWatcher();
  masterAddressTracker = new MasterAddressTracker(this.zooKeeper, this);
  masterAddressTracker.start();

  this.rootRegionTracker = new RootRegionTracker(this.zooKeeper, this);
  this.rootRegionTracker.start();

  this.clusterId = new ClusterId(this.zooKeeper, this);
}
项目:HBase-Research    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
}
项目:hbase-0.94.8-qod    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
}
项目:hbase-0.94.8-qod    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
}
项目:DominoHBase    文件:HConnectionManager.java   
private HRegionLocation locateRegion(final byte [] tableName,
  final byte [] row, boolean useCache, boolean retry)
throws IOException {
  if (this.closed) throw new IOException(toString() + " closed");
  if (tableName == null || tableName.length == 0) {
    throw new IllegalArgumentException(
        "table name cannot be null or zero length");
  }

  if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
    ZooKeeperKeepAliveConnection zkw = getKeepAliveZooKeeperWatcher();
    try {
      LOG.debug("Looking up root region location in ZK," +
        " connection=" + this);
      ServerName servername =
        RootRegionTracker.blockUntilAvailable(zkw, this.rpcTimeout);

      LOG.debug("Looked up root region location, connection=" + this +
        "; serverName=" + ((servername == null) ? "null" : servername));
      if (servername == null) return null;
      return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
        servername.getHostname(), servername.getPort());
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      return null;
    } finally {
      zkw.close();
    }
  } else if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) {
    return locateRegionInMeta(HConstants.ROOT_TABLE_NAME, tableName, row,
      useCache, metaRegionLock, retry);
  } else {
    // Region not in the cache - have to go to the meta RS
    return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row,
      useCache, userRegionLock, retry);
  }
}
项目:DominoHBase    文件:HBaseFsck.java   
private ServerName getRootRegionServerName()
throws IOException, KeeperException {
  ZooKeeperWatcher zkw = createZooKeeperWatcher();
  ServerName sn = null;
  try {
    sn = RootRegionTracker.getRootRegionLocation(zkw);
  } finally {
    zkw.close();
  }
  return sn;
}
项目:DominoHBase    文件:HRegionServer.java   
@Override
public void postOpenDeployTasks(final HRegion r, final CatalogTracker ct,
    final boolean daughter)
throws KeeperException, IOException {
  checkOpen();
  LOG.info("Post open deploy tasks for region=" + r.getRegionNameAsString() +
    ", daughter=" + daughter);
  // Do checks to see if we need to compact (references or too many files)
  for (Store s : r.getStores().values()) {
    if (s.hasReferences() || s.needsCompaction()) {
      getCompactionRequester().requestCompaction(r, s, "Opening Region");
    }
  }
  // Update ZK, ROOT or META
  if (r.getRegionInfo().isRootRegion()) {
    RootRegionTracker.setRootLocation(getZooKeeper(),
     this.serverNameFromMasterPOV);
  } else if (r.getRegionInfo().isMetaRegion()) {
    MetaEditor.updateMetaLocation(ct, r.getRegionInfo(),
      this.serverNameFromMasterPOV);
  } else {
    if (daughter) {
      // If daughter of a split, update whole row, not just location.
      MetaEditor.addDaughter(ct, r.getRegionInfo(),
        this.serverNameFromMasterPOV);
    } else {
      MetaEditor.updateRegionLocation(ct, r.getRegionInfo(),
        this.serverNameFromMasterPOV);
    }
  }
  LOG.info("Done with post open deploy task for region=" +
    r.getRegionNameAsString() + ", daughter=" + daughter);

}
项目:DominoHBase    文件:TestCatalogTrackerOnCluster.java   
/**
 * @throws Exception 
 * @see {https://issues.apache.org/jira/browse/HBASE-3445}
 */
@Test public void testBadOriginalRootLocation() throws Exception {
  UTIL.getConfiguration().setInt("ipc.socket.timeout", 3000);
  // Launch cluster so it does bootstrapping.
  UTIL.startMiniCluster();
  // Shutdown hbase.
  UTIL.shutdownMiniHBaseCluster();
  // Mess with the root location in the running zk.  Set it to be nonsense.
  ZooKeeperWatcher zookeeper = new ZooKeeperWatcher(UTIL.getConfiguration(),
    "Bad Root Location Writer", new Abortable() {
      @Override
      public void abort(String why, Throwable e) {
        LOG.error("Abort was called on 'bad root location writer'", e);
      }

      @Override
      public boolean isAborted() {
        return false;
      }
  });
  ServerName nonsense =
    new ServerName("example.org", 1234, System.currentTimeMillis());
  RootRegionTracker.setRootLocation(zookeeper, nonsense);

  // Bring back up the hbase cluster.  See if it can deal with nonsense root
  // location. The cluster should start and be fully available.
  UTIL.startMiniHBaseCluster(1, 1);

  // if we can create a table, it's a good sign that it's working
  UTIL.createTable(
    getClass().getSimpleName().getBytes(), "family".getBytes());

  UTIL.shutdownMiniCluster();
}
项目:DominoHBase    文件:TestCatalogTracker.java   
/**
 * Test that we get notification if .META. moves.
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 */
@Test public void testThatIfMETAMovesWeAreNotified()
throws IOException, InterruptedException, KeeperException {
  HConnection connection = Mockito.mock(HConnection.class);
  constructAndStartCatalogTracker(connection);
  try {
    RootRegionTracker.setRootLocation(this.watcher,
      new ServerName("example.com", 1234, System.currentTimeMillis()));
  } finally {
    // Clean out root location or later tests will be confused... they presume
    // start fresh in zk.
    RootRegionTracker.deleteRootLocation(this.watcher);
  }
}
项目:hindex    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
}
项目:RStore    文件:CatalogTracker.java   
CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable, final int defaultTimeout)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
  this.defaultTimeout = defaultTimeout;
}
项目:DominoHBase    文件:CatalogTracker.java   
public CatalogTracker(final ZooKeeperWatcher zk, final Configuration conf,
    HConnection connection, Abortable abortable, final int defaultTimeout)
throws IOException {
  this.connection = connection;
  if (abortable == null) {
    // A connection is abortable.
    this.abortable = this.connection;
  }
  Abortable throwableAborter = new Abortable() {

    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return true;
    }

  };
  if (zk == null) {
    // Create our own.  Set flag so we tear it down on stop.
    this.zookeeper =
      new ZooKeeperWatcher(conf, "catalogtracker-on-" + connection.toString(),
        abortable);
    instantiatedzkw = true;
  } else {
    this.zookeeper = zk;
  }
  this.rootRegionTracker = new RootRegionTracker(zookeeper, throwableAborter);
  final CatalogTracker ct = this;
  // Override nodeDeleted so we get notified when meta node deleted
  this.metaNodeTracker = new MetaNodeTracker(zookeeper, throwableAborter) {
    public void nodeDeleted(String path) {
      if (!path.equals(node)) return;
      ct.resetMetaLocation();
    }
  };
  this.defaultTimeout = defaultTimeout;
}
项目:DominoHBase    文件:TestCatalogTracker.java   
private ServerName setRootLocation() throws KeeperException {
  RootRegionTracker.setRootLocation(this.watcher, SN);
  return SN;
}
项目:DominoHBase    文件:AssignmentManager.java   
/**
 * Assigns the ROOT region.
 * <p>
 * Assumes that ROOT is currently closed and is not being actively served by
 * any RegionServer.
 * <p>
 * Forcibly unsets the current root region location in ZooKeeper and assigns
 * ROOT to a random RegionServer.
 * @throws KeeperException
 */
public void assignRoot() throws KeeperException {
  RootRegionTracker.deleteRootLocation(this.watcher);
  assign(HRegionInfo.ROOT_REGIONINFO, true);
}