Package org.apache.hadoop.hbase.ipc

Examples of org.apache.hadoop.hbase.ipc.HRegionInterface


    Mockito.when(c.getRegionLocation((byte[]) Mockito.any(),
        (byte[]) Mockito.any(), Mockito.anyBoolean())).
      thenReturn(loc);
    Mockito.when(c.locateRegion((byte[]) Mockito.any(), (byte[]) Mockito.any())).
      thenReturn(loc);
    HRegionInterface hri = Mockito.mock(HRegionInterface.class);
    Mockito.when(hri.bulkLoadHFiles(Mockito.anyList(), (byte [])Mockito.any(),
      Mockito.anyBoolean())).thenThrow(new IOException("injecting bulk load error"));
    Mockito.when(c.getHRegionConnection(Mockito.anyString(), Mockito.anyInt())).
      thenReturn(hri);
    return c;
  }
View Full Code Here


    @Override
    public synchronized Void call() throws IOException {
      errors.progress();
      try {
        HRegionInterface server =
            connection.getHRegionConnection(rsinfo.getHostname(), rsinfo.getPort());

        // list all online regions from this region server
        List<HRegionInfo> regions = server.getOnlineRegions();
        regions = filterRegions(regions);
        if (details) {
          errors.detail("RegionServer: " + rsinfo.getServerName() +
                           " number of regions: " + regions.size());
          for (HRegionInfo rinfo: regions) {
View Full Code Here

    // connection needed for poll-wait
    HConnection conn = HConnectionManager.getConnection(TEST_UTIL
        .getConfiguration());
    HRegionLocation loc = table.getRegionLocation(row, true);
    HRegionInterface server = conn.getHRegionConnection(loc.getHostname(), loc
        .getPort());
    byte[] regName = loc.getRegionInfo().getRegionName();

    for (int i = 0; i < nFlushes; i++) {
      randomCFPuts(table, row, family, nPuts);
      int sfCount = server.getStoreFileList(regName, FAMILY).size();

      // TODO: replace this api with a synchronous flush after HBASE-2949
      admin.flush(table.getTableName());

      // synchronously poll wait for a new storefile to appear (flush happened)
      while (server.getStoreFileList(regName, FAMILY).size() == sfCount) {
        Thread.sleep(40);
      }
    }
  }
View Full Code Here

    performMultiplePutAndFlush(admin, hTable, row, FAMILY, 3, 100);

    // Verify we have multiple store files.
    HRegionLocation loc = hTable.getRegionLocation(row, true);
    byte[] regionName = loc.getRegionInfo().getRegionName();
    HRegionInterface server = connection.getHRegionConnection(
        loc.getHostname(), loc.getPort());
    assertTrue(server.getStoreFileList(regionName, FAMILY).size() > 1);

    // Issue a compaction request
    admin.compact(TABLE);

    // poll wait for the compactions to happen
    for (int i = 0; i < 10 * 1000 / 40; ++i) {
      // The number of store files after compaction should be lesser.
      loc = hTable.getRegionLocation(row, true);
      if (!loc.getRegionInfo().isOffline()) {
        regionName = loc.getRegionInfo().getRegionName();
        server = connection.getHRegionConnection(loc.getHostname(), loc
            .getPort());
        if (server.getStoreFileList(regionName, FAMILY).size() <= 1) {
          break;
        }
      }
      Thread.sleep(40);
    }
    // verify the compactions took place and that we didn't just time out
    assertTrue(server.getStoreFileList(regionName, FAMILY).size() <= 1);

    // change the compaction.min config option for this table to 5
    LOG.info("hbase.hstore.compaction.min should now be 5");
    HTableDescriptor htd = new HTableDescriptor(hTable.getTableDescriptor());
    htd.setValue("hbase.hstore.compaction.min", String.valueOf(5));
    admin.modifyTable(TABLE, htd);
    Pair<Integer, Integer> st;
    while (null != (st = admin.getAlterStatus(TABLE)) && st.getFirst() > 0) {
      LOG.debug(st.getFirst() + " regions left to update");
      Thread.sleep(40);
    }
    LOG.info("alter status finished");

    // Create 3 more store files.
    performMultiplePutAndFlush(admin, hTable, row, FAMILY, 3, 10);

    // Issue a compaction request
    admin.compact(TABLE);

    // This time, the compaction request should not happen
    Thread.sleep(10 * 1000);
    int sfCount = 0;
    loc = hTable.getRegionLocation(row, true);
    regionName = loc.getRegionInfo().getRegionName();
    server = connection.getHRegionConnection(loc.getHostname(), loc.getPort());
    sfCount = server.getStoreFileList(regionName, FAMILY).size();
    assertTrue(sfCount > 1);

    // change an individual CF's config option to 2 & online schema update
    LOG.info("hbase.hstore.compaction.min should now be 2");
    HColumnDescriptor hcd = new HColumnDescriptor(htd.getFamily(FAMILY));
    hcd.setValue("hbase.hstore.compaction.min", String.valueOf(2));
    htd.addFamily(hcd);
    admin.modifyTable(TABLE, htd);
    while (null != (st = admin.getAlterStatus(TABLE)) && st.getFirst() > 0) {
      LOG.debug(st.getFirst() + " regions left to update");
      Thread.sleep(40);
    }
    LOG.info("alter status finished");

    // Issue a compaction request
    admin.compact(TABLE);

    // poll wait for the compactions to happen
    for (int i = 0; i < 10 * 1000 / 40; ++i) {
      loc = hTable.getRegionLocation(row, true);
      regionName = loc.getRegionInfo().getRegionName();
      try {
        server = connection.getHRegionConnection(loc.getHostname(), loc
            .getPort());
        if (server.getStoreFileList(regionName, FAMILY).size() < sfCount) {
          break;
        }
      } catch (Exception e) {
        LOG.debug("Waiting for region to come online: " + regionName);
      }
      Thread.sleep(40);
    }
    // verify the compaction took place and that we didn't just time out
    assertTrue(server.getStoreFileList(regionName, FAMILY).size() < sfCount);

    // Finally, ensure that we can remove a custom config value after we made it
    LOG.info("Removing CF config value");
    LOG.info("hbase.hstore.compaction.min should now be 5");
    hcd = new HColumnDescriptor(htd.getFamily(FAMILY));
View Full Code Here

    // Make sure our new AM gets callbacks; once registered, can't unregister.
    // Thats ok because we make a new zk watcher for each test.
    this.watcher.registerListenerFirst(am);
    // Need to set up a fake scan of meta for the servershutdown handler
    // Make an RS Interface implementation.  Make it so a scanner can go against it.
    HRegionInterface implementation = Mockito.mock(HRegionInterface.class);
    // Get a meta row result that has region up on SERVERNAME_A

    Result r = null;
    if (sn == null) {
      if (splitRegion) {
        r = getMetaTableRowResultAsSplitRegion(REGIONINFO, SERVERNAME_A);
      } else {
        r = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
      }
    } else {
      if (sn.equals(SERVERNAME_A)) {
        r = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
      } else if (sn.equals(SERVERNAME_B)) {
        r = new Result(new KeyValue[0]);
      }
    }

    Mockito.when(implementation.openScanner((byte [])Mockito.any(), (Scan)Mockito.any())).
      thenReturn(System.currentTimeMillis());
    // Return a good result first and then return null to indicate end of scan
    Mockito.when(implementation.next(Mockito.anyLong(), Mockito.anyInt())).
      thenReturn(new Result [] {r}, (Result [])null);

    // Get a connection w/ mocked up common methods.
    HConnection connection =
      HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
View Full Code Here

    // Make an RS Interface implementation. Make it so a scanner can go against
    // it and a get to return the single region, REGIONINFO, this test is
    // messing with. Needed when "new master" joins cluster. AM will try and
    // rebuild its list of user regions and it will also get the HRI that goes
    // with an encoded name by doing a Get on .META.
    HRegionInterface ri = Mockito.mock(HRegionInterface.class);
    // Get a meta row result that has region up on SERVERNAME_A for REGIONINFO
    Result[] result = null;
    if (enabling) {
      result = new Result[2];
      result[0] = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
      result[1] = getMetaTableRowResult(REGIONINFO_2, SERVERNAME_A);
    }
    Result r = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
    Mockito.when(ri .openScanner((byte[]) Mockito.any(), (Scan) Mockito.any())).
      thenReturn(System.currentTimeMillis());
   if (enabling) {
      Mockito.when(ri.next(Mockito.anyLong(), Mockito.anyInt())).thenReturn(result, result, result,
          (Result[]) null);
      // If a get, return the above result too for REGIONINFO_2
      Mockito.when(ri.get((byte[]) Mockito.any(), (Get) Mockito.any())).thenReturn(
          getMetaTableRowResult(REGIONINFO_2, SERVERNAME_A));
    } else {
      // Return good result 'r' first and then return null to indicate end of scan
      Mockito.when(ri.next(Mockito.anyLong(), Mockito.anyInt())).thenReturn(new Result[] { r });
      // If a get, return the above result too for REGIONINFO
      Mockito.when(ri.get((byte[]) Mockito.any(), (Get) Mockito.any())).thenReturn(r);
    }
    // Get a connection w/ mocked up common methods.
    HConnection connection = HConnectionTestingUtility.
      getMockedConnectionAndDecorate(HTU.getConfiguration(), ri, SERVERNAME_B,
        REGIONINFO);
View Full Code Here

          sleepMultiplier++;
        }
        continue;
      }
      try {
        HRegionInterface rrs = getRS();
        LOG.debug("Replicating " + entries.size() + ", " + this.currentSize + " bytes");
        // can't avoid the copy here, the replicateLogEntries RPC require an HLog.Entry[]
        rrs.replicateLogEntries(entries.toArray(new HLog.Entry[entries.size()]));
        if (this.lastLoggedPosition != this.repLogReader.getPosition()) {
          this.manager.logPositionAndCleanOldLogs(this.currentPath,
              this.peerClusterZnode, this.repLogReader.getPosition(), queueRecovered, currentWALisBeingWrittenTo);
          this.lastLoggedPosition = this.repLogReader.getPosition();
        }
View Full Code Here

  public boolean isSlaveDown() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    Thread pingThread = new Thread() {
      public void run() {
        try {
          HRegionInterface rrs = getRS();
          // Dummy call which should fail
          rrs.getHServerInfo();
          latch.countDown();
        } catch (IOException ex) {
          if (ex instanceof RemoteException) {
            ex = ((RemoteException) ex).unwrapRemoteException();
          }
View Full Code Here

      getMaster().deleteTable(tableName);
    } catch (RemoteException e) {
      throw RemoteExceptionHandler.decodeRemoteException(e);
    }
    // Wait until all regions deleted
    HRegionInterface server =
      connection.getHRegionConnection(firstMetaServer.getHostname(), firstMetaServer.getPort());
    List<String> tableNameAsList = new ArrayList<String>(1);
    tableNameAsList.add(Bytes.toString(tableName));
    for (int tries = 0; tries < (this.numRetries * this.retryLongerMultiplier); tries++) {
      long scannerId = -1L;
      try {

        Scan scan = MetaReader.getScanForTableName(tableName);
        scan.addColumn(HConstants.CATALOG_FAMILY,
            HConstants.REGIONINFO_QUALIFIER);
        scannerId = server.openScanner(
          firstMetaServer.getRegionInfo().getRegionName(), scan);
        // Get a batch at a time.
        Result values = server.next(scannerId);

        // let us wait until .META. table is updated and
        // HMaster removes the table from its HTableDescriptors
        if (values == null) {
          tableExists = false;
          HTableDescriptor[] htds = getMaster().getHTableDescriptors(tableNameAsList);
          tableExists = (htds != null && htds.length > 0);
          if (!tableExists) {
            break;
          }
        }
      } catch (IOException ex) {
        if(tries == numRetries - 1) {           // no more tries left
          if (ex instanceof RemoteException) {
            ex = RemoteExceptionHandler.decodeRemoteException((RemoteException) ex);
          }
          throw ex;
        }
      } finally {
        if (scannerId != -1L) {
          try {
            server.close(scannerId);
          } catch (Exception ex) {
            LOG.warn(ex);
          }
        }
      }
View Full Code Here

    if (null == serverName || ("").equals(serverName.trim())) {
      throw new IllegalArgumentException(
          "The servername cannot be null or empty.");
    }
    ServerName sn = new ServerName(serverName);
    HRegionInterface rs = this.connection.getHRegionConnection(
        sn.getHostname(), sn.getPort());
    // Close the region without updating zk state.
    boolean isRegionClosed = rs.closeRegion(encodedRegionNameInBytes, false);
    if (false == isRegionClosed) {
      LOG.error("Not able to close the region " + encodedRegionName + ".");
    }
    return isRegionClosed;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.ipc.HRegionInterface

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.