Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.Connection


   * The passed in list gets changed in this method
   */
  @Override
  protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
    MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
    Connection conn = masterServices.getShortCircuitConnection();
    FileSystem fs = fileSystemManager.getFileSystem();
    Path rootDir = fileSystemManager.getRootDir();
    TableName tableName = hTableDescriptor.getTableName();

    try {
View Full Code Here


      LOG.info("Starting mini zk cluster");
      UTIL.startMiniZKCluster();
      LOG.info("Starting mini hbase cluster");
      UTIL.startMiniHBaseCluster(1, 1);
      Configuration c = new Configuration(UTIL.getConfiguration());
      Connection connection = HConnectionManager.getConnection(c);

      List<HRegionInfo> originalTableRegions =
        MetaTableAccessor.getTableRegions(connection, desc.getTableName());
      LOG.info("originalTableRegions size=" + originalTableRegions.size() +
        "; " + originalTableRegions);
View Full Code Here

    if (tSplit.getTable() == null) {
      throw new IOException("Cannot create a record reader because of a"
          + " previous error. Please look at the previous logs lines from"
          + " the task's full log for more details.");
    }
    Connection connection = ConnectionFactory.createConnection(context.getConfiguration());
    Table table = connection.getTable(tSplit.getTable());

    TableRecordReader trr = this.tableRecordReader;

    try {
      // if no table record reader was provided use default
      if (trr == null) {
        trr = new TableRecordReader();
      }
      Scan sc = tSplit.getScan();
      sc.setStartRow(tSplit.getStartRow());
      sc.setStopRow(tSplit.getEndRow());
      trr.setScan(sc);
      trr.setTable(table);
    } catch (IOException ioe) {
      // If there is an exception make sure that all
      // resources are closed and released.
      connection.close();
      table.close();
      trr.close();
      throw ioe;
    }
    return trr;
View Full Code Here

        throw new IOException("A scan object did not have a table name");

      TableName tableName = TableName.valueOf(tableNameBytes);
      Table table = null;
      RegionLocator regionLocator = null;
      Connection conn = null;
      try {
        conn = ConnectionFactory.createConnection(context.getConfiguration());
        table = conn.getTable(tableName);
        regionLocator = conn.getRegionLocator(tableName);
        regionLocator = (RegionLocator) table;
        Pair<byte[][], byte[][]> keys = regionLocator.getStartEndKeys();
        if (keys == null || keys.getFirst() == null ||
            keys.getFirst().length == 0) {
          throw new IOException("Expecting at least one region for table : "
              + tableName.getNameAsString());
        }
        int count = 0;

        byte[] startRow = scan.getStartRow();
        byte[] stopRow = scan.getStopRow();

        RegionSizeCalculator sizeCalculator = new RegionSizeCalculator(
            regionLocator, conn.getAdmin());

        for (int i = 0; i < keys.getFirst().length; i++) {
          if (!includeRegionInSplit(keys.getFirst()[i], keys.getSecond()[i])) {
            continue;
          }
          HRegionLocation hregionLocation = regionLocator.getRegionLocation(
              keys.getFirst()[i], false);
          String regionHostname = hregionLocation.getHostname();
          HRegionInfo regionInfo = hregionLocation.getRegionInfo();

          // determine if the given start and stop keys fall into the range
          if ((startRow.length == 0 || keys.getSecond()[i].length == 0 ||
              Bytes.compareTo(startRow, keys.getSecond()[i]) < 0) &&
              (stopRow.length == 0 ||
                  Bytes.compareTo(stopRow, keys.getFirst()[i]) > 0)) {
            byte[] splitStart =
                startRow.length == 0 ||
                    Bytes.compareTo(keys.getFirst()[i], startRow) >= 0 ? keys
                    .getFirst()[i] : startRow;
            byte[] splitStop =
                (stopRow.length == 0 || Bytes.compareTo(keys.getSecond()[i],
                    stopRow) <= 0) && keys.getSecond()[i].length > 0 ? keys
                    .getSecond()[i] : stopRow;

            long regionSize = sizeCalculator.getRegionSize(regionInfo.getRegionName());
            TableSplit split =
                new TableSplit(regionLocator.getName(),
                    scan, splitStart, splitStop, regionHostname, regionSize);

            splits.add(split);
            if (LOG.isDebugEnabled())
              LOG.debug("getSplits: split -> " + (count++) + " -> " + split);
          }
        }
      } finally {
        if (null != table) table.close();
        if (null != regionLocator) regionLocator.close();
        if (null != conn) conn.close();
      }
    }
    return splits;
  }
View Full Code Here

      Permission.Action.ADMIN);

    AccessTestAction deleteTableAction = new AccessTestAction() {
      @Override
      public Object run() throws Exception {
        Connection unmanagedConnection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
        Admin admin = unmanagedConnection.getAdmin();
        try {
          admin.disableTable(TEST_TABLE.getTableName());
          admin.deleteTable(TEST_TABLE.getTableName());
        } finally {
          admin.close();
          unmanagedConnection.close();
        }
        return null;
      }
    };
View Full Code Here

        HConstants.EMPTY_START_ROW);
    ServerName hsa = metaLocation.getServerName();
    HRegionInfo hri = metaLocation.getRegionInfo();
    if (unassign) {
      LOG.info("Undeploying meta region " + hri + " from server " + hsa);
      Connection unmanagedConnection = ConnectionFactory.createConnection(conf);
      HBaseAdmin admin = (HBaseAdmin) unmanagedConnection.getAdmin();
      try {
        undeployRegion(admin, hsa, hri);
      } finally {
        admin.close();
        unmanagedConnection.close();
      }
    }

    if (regionInfoOnly) {
      LOG.info("deleting hdfs .regioninfo data: " + hri.toString() + hsa.toString());
View Full Code Here

    if (!desc.hasFamily(hcd.getName())) {
      desc.addFamily(hcd);
    }

    int totalNumberOfRegions = 0;
    Connection unmanagedConnection = ConnectionFactory.createConnection(conf);
    Admin admin = unmanagedConnection.getAdmin();

    try {
      // create a table a pre-splits regions.
      // The number of splits is set as:
      //    region servers * regions per region server).
      int numberOfServers = admin.getClusterStatus().getServers().size();
      if (numberOfServers == 0) {
        throw new IllegalStateException("No live regionservers");
      }

      totalNumberOfRegions = numberOfServers * numRegionsPerServer;
      LOG.info("Number of live regionservers: " + numberOfServers + ", " +
          "pre-splitting table into " + totalNumberOfRegions + " regions " +
          "(regions per server: " + numRegionsPerServer + ")");

      byte[][] splits = new RegionSplitter.HexStringSplit().split(
          totalNumberOfRegions);

      admin.createTable(desc, splits);
    } catch (MasterNotRunningException e) {
      LOG.error("Master not running", e);
      throw new IOException(e);
    } catch (TableExistsException e) {
      LOG.warn("Table " + desc.getTableName() +
          " already exists, continuing");
    } finally {
      admin.close();
      unmanagedConnection.close();
    }
    return totalNumberOfRegions;
  }
View Full Code Here

    TableName tableNameNoReplicas =
        TableName.valueOf("testRegionReplicaReplicationWithReplicas_NO_REPLICAS");
    HTU.deleteTableIfAny(tableNameNoReplicas);
    HTU.createTable(tableNameNoReplicas, HBaseTestingUtility.fam1);

    Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
    Table table = connection.getTable(tableName);
    Table tableNoReplicas = connection.getTable(tableNameNoReplicas);

    try {
      // load some data to the non-replicated table
      HTU.loadNumericRows(tableNoReplicas, HBaseTestingUtility.fam1, 6000, 7000);

      // load the data to the table
      HTU.loadNumericRows(table, HBaseTestingUtility.fam1, 0, 1000);

      verifyReplication(tableName, regionReplication, 0, 6000);

    } finally {
      table.close();
      tableNoReplicas.close();
      HTU.deleteTableIfAny(tableNameNoReplicas);
      connection.close();
    }
  }
View Full Code Here

    HTableDescriptor htd = HTU.createTableDescriptor(tableName.toString());
    htd.setRegionReplication(regionReplication);
    HTU.getHBaseAdmin().createTable(htd);


    Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
    Table table = connection.getTable(tableName);

    try {
      // load the data to the table

      for (int i = 0; i < 6000; i += 1000) {
        LOG.info("Writing data from " + i + " to " + (i+1000));
        HTU.loadNumericRows(table, HBaseTestingUtility.fam1, i, i+1000);
        LOG.info("flushing table");
        HTU.flush(tableName);
        LOG.info("compacting table");
        HTU.compact(tableName, false);
      }

      verifyReplication(tableName, regionReplication, 0, 6000);
    } finally {
      table.close();
      connection.close();
    }
  }
View Full Code Here

    assert cmd != null;
    Future<RunResult>[] threads = new Future[opts.numClientThreads];
    RunResult[] results = new RunResult[opts.numClientThreads];
    ExecutorService pool = Executors.newFixedThreadPool(opts.numClientThreads,
      new ThreadFactoryBuilder().setNameFormat("TestClient-%s").build());
    final Connection con = ConnectionFactory.createConnection(conf);
    for (int i = 0; i < threads.length; i++) {
      final int index = i;
      threads[i] = pool.submit(new Callable<RunResult>() {
        @Override
        public RunResult call() throws Exception {
          TestOptions threadOpts = new TestOptions(opts);
          if (threadOpts.startRow == 0) threadOpts.startRow = index * threadOpts.perClientRunRows;
          RunResult run = runOneClient(cmd, conf, con, threadOpts, new Status() {
            @Override
            public void setStatus(final String msg) throws IOException {
              LOG.info(msg);
            }
          });
          LOG.info("Finished " + Thread.currentThread().getName() + " in " + run.duration +
            "ms over " + threadOpts.perClientRunRows + " rows");
          return run;
        }
      });
    }
    pool.shutdown();

    for (int i = 0; i < threads.length; i++) {
      try {
        results[i] = threads[i].get();
      } catch (ExecutionException e) {
        throw new IOException(e.getCause());
      }
    }
    final String test = cmd.getSimpleName();
    LOG.info("[" + test + "] Summary of timings (ms): "
             + Arrays.toString(results));
    Arrays.sort(results);
    long total = 0;
    for (RunResult result : results) {
      total += result.duration;
    }
    LOG.info("[" + test + "]"
      + "\tMin: " + results[0] + "ms"
      + "\tMax: " + results[results.length - 1] + "ms"
      + "\tAvg: " + (total / results.length) + "ms");

    con.close();

    return results;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.