@Test
  public void testIsStale() throws IOException {
    int period = 0;
    byte[][] families = new byte[][] {Bytes.toBytes("cf")};
    byte[] qf = Bytes.toBytes("cq");

    HRegionServer regionServer = mock(HRegionServer.class);
    List<Region> regions = new ArrayList<Region>();
    when(regionServer.getOnlineRegionsLocalContext()).thenReturn(regions);
    when(regionServer.getConfiguration()).thenReturn(TEST_UTIL.getConfiguration());

    HTableDescriptor htd = getTableDesc(TableName.valueOf("testIsStale"), families);
    Region primary = initHRegion(htd, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, 0);
    Region replica1 = initHRegion(htd, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, 1);
    regions.add(primary);
    regions.add(replica1);

    StaleStorefileRefresherChore chore =
        new StaleStorefileRefresherChore(period, regionServer, new StoppableImplementation());

    // write some data to primary and flush
    putData(primary, 0, 100, qf, families);
    primary.flush(true);
    verifyData(primary, 0, 100, qf, families);

    try {
      verifyData(replica1, 0, 100, qf, families);
      Assert.fail("should have failed");
    } catch (AssertionError ex) {
      // expected
    }
    chore.chore();
    verifyData(replica1, 0, 100, qf, families);

    // simulate an fs failure where we cannot refresh the store files for the replica
    ((FailingHRegionFileSystem) ((HRegion) replica1).getRegionFileSystem()).fail = true;

    // write some more data to primary and flush
    putData(primary, 100, 100, qf, families);
    primary.flush(true);
    verifyData(primary, 0, 200, qf, families);

    chore.chore(); // should not throw ex, but we cannot refresh the store files

    verifyData(replica1, 0, 100, qf, families);
    try {
      verifyData(replica1, 100, 100, qf, families);
      Assert.fail("should have failed");
    } catch (AssertionError ex) {
      // expected
    }

    chore.isStale = true;
    chore.chore(); // now after this, we cannot read back any value
    try {
      verifyData(replica1, 0, 100, qf, families);
      Assert.fail("should have failed with IOException");
    } catch (IOException ex) {
      // expected
    }
  }
Example #2
0
  /** @param server */
  CompactSplitThread(HRegionServer server) {
    super();
    this.server = server;
    this.conf = server.getConfiguration();
    this.regionSplitLimit = conf.getInt("hbase.regionserver.regionSplitLimit", Integer.MAX_VALUE);

    int largeThreads =
        Math.max(1, conf.getInt(LARGE_COMPACTION_THREADS, LARGE_COMPACTION_THREADS_DEFAULT));
    int smallThreads = conf.getInt(SMALL_COMPACTION_THREADS, SMALL_COMPACTION_THREADS_DEFAULT);

    int splitThreads = conf.getInt(SPLIT_THREADS, SPLIT_THREADS_DEFAULT);

    // if we have throttle threads, make sure the user also specified size
    Preconditions.checkArgument(largeThreads > 0 && smallThreads > 0);

    final String n = Thread.currentThread().getName();

    this.longCompactions =
        new ThreadPoolExecutor(
            largeThreads,
            largeThreads,
            60,
            TimeUnit.SECONDS,
            new PriorityBlockingQueue<Runnable>(),
            new ThreadFactory() {
              @Override
              public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setName(n + "-longCompactions-" + System.currentTimeMillis());
                return t;
              }
            });
    this.longCompactions.setRejectedExecutionHandler(new Rejection());
    this.shortCompactions =
        new ThreadPoolExecutor(
            smallThreads,
            smallThreads,
            60,
            TimeUnit.SECONDS,
            new PriorityBlockingQueue<Runnable>(),
            new ThreadFactory() {
              @Override
              public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setName(n + "-shortCompactions-" + System.currentTimeMillis());
                return t;
              }
            });
    this.shortCompactions.setRejectedExecutionHandler(new Rejection());
    this.splits =
        (ThreadPoolExecutor)
            Executors.newFixedThreadPool(
                splitThreads,
                new ThreadFactory() {
                  @Override
                  public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-splits-" + System.currentTimeMillis());
                    return t;
                  }
                });
    int mergeThreads = conf.getInt(MERGE_THREADS, MERGE_THREADS_DEFAULT);
    this.mergePool =
        (ThreadPoolExecutor)
            Executors.newFixedThreadPool(
                mergeThreads,
                new ThreadFactory() {
                  @Override
                  public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-merges-" + System.currentTimeMillis());
                    return t;
                  }
                });
  }