/** * @param when When to expire, when to come up out of the queue. * Specify in milliseconds. This method adds EnvironmentEdgeManager.currentTime() * to whatever you pass. * @return This. */ public FlushRegionEntry requeue(final long when) { this.whenToExpire = EnvironmentEdgeManager.currentTime() + when; this.requeueCount++; return this; }
/** * Resets the managed instance to the default instance: {@link * DefaultEnvironmentEdge}. */ public static void reset() { injectEdge(new DefaultEnvironmentEdge()); }
/** * Injects the given edge such that it becomes the managed entity. If null is * passed to this method, the default type is assigned to the delegate. * * @param edge the new edge. */ public static void injectEdge(EnvironmentEdge edge) { if (edge == null) { reset(); } else { delegate = edge; } }
@Test public void testCurrentTimeInMillis() { EnvironmentEdge mock = mock(EnvironmentEdge.class); EnvironmentEdgeManager.injectEdge(mock); long expectation = 3456; when(mock.currentTime()).thenReturn(expectation); long result = EnvironmentEdgeManager.currentTime(); verify(mock).currentTime(); assertEquals(expectation, result); } }
@Test public void testManageSingleton() { EnvironmentEdgeManager.reset(); EnvironmentEdge edge = EnvironmentEdgeManager.getDelegate(); assertNotNull(edge); assertTrue(edge instanceof DefaultEnvironmentEdge); EnvironmentEdgeManager.reset(); EnvironmentEdge edge2 = EnvironmentEdgeManager.getDelegate(); assertFalse(edge == edge2); IncrementingEnvironmentEdge newEdge = new IncrementingEnvironmentEdge(); EnvironmentEdgeManager.injectEdge(newEdge); assertEquals(newEdge, EnvironmentEdgeManager.getDelegate()); //injecting null will result in default being assigned. EnvironmentEdgeManager.injectEdge(null); EnvironmentEdge nullResult = EnvironmentEdgeManager.getDelegate(); assertTrue(nullResult instanceof DefaultEnvironmentEdge); }
protected void checkShouldFlush(Configuration conf, boolean expected) throws Exception { try { EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest(); EnvironmentEdgeManager.injectEdge(edge); HBaseTestingUtility hbaseUtility = HBaseTestingUtility.createLocalHTU(conf); String cf = "foo"; HRegion region = hbaseUtility.createTestRegion("foobar", ColumnFamilyDescriptorBuilder.of(cf)); edge.setCurrentTimeMillis(1234); Put p = new Put(Bytes.toBytes("r")); p.add(KeyValueTestUtil.create("r", cf, "q", 100, "v")); region.put(p); edge.setCurrentTimeMillis(1234 + 100); StringBuilder sb = new StringBuilder(); assertTrue(!region.shouldFlush(sb)); edge.setCurrentTimeMillis(1234 + 10000); assertTrue(region.shouldFlush(sb) == expected); } finally { EnvironmentEdgeManager.reset(); } }
/** * Defers to the delegate and calls the * {@link EnvironmentEdge#currentTime()} method. * * @return current time in millis according to the delegate. */ public static long currentTime() { return getDelegate().currentTime(); } }
@Test public void testSortExtract(){ ManualEnvironmentEdge mee = new ManualEnvironmentEdge(); EnvironmentEdgeManager.injectEdge(mee); mee.setValue(1); DeadServer d = new DeadServer(); d.add(hostname123); mee.incValue(1); d.add(hostname1234); mee.incValue(1); d.add(hostname12345); List<Pair<ServerName, Long>> copy = d.copyDeadServersSince(2L); Assert.assertEquals(2, copy.size()); Assert.assertEquals(hostname1234, copy.get(0).getFirst()); Assert.assertEquals(new Long(2L), copy.get(0).getSecond()); Assert.assertEquals(hostname12345, copy.get(1).getFirst()); Assert.assertEquals(new Long(3L), copy.get(1).getSecond()); EnvironmentEdgeManager.reset(); }
private void waitForRegion() throws InterruptedIOException { if (busyRegions.isEmpty()) { return; } EnvironmentEdge ee = EnvironmentEdgeManager.getDelegate(); final long start = ee.currentTime(); while ((ee.currentTime() - start) <= MAX_WAITING_TIME) { for (byte[] region : busyRegions) { AtomicInteger count = taskCounterPerRegion.get(region); if (count == null || count.get() < maxConcurrentTasksPerRegion) { return; } } try { synchronized (tasksInProgress) { tasksInProgress.wait(10); } } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted." + " tasksInProgress=" + tasksInProgress); } } }
public PartitionedMobCompactionRequest(Collection<CompactionPartition> compactionPartitions, List<CompactionDelPartition> delPartitions) { this.selectionTime = EnvironmentEdgeManager.currentTime(); this.compactionPartitions = compactionPartitions; this.delPartitions = delPartitions; }
public static void injectEdge(EnvironmentEdge edge) { EnvironmentEdgeManager.injectEdge(edge); } }
public static void reset() { EnvironmentEdgeManager.reset(); }
private HStore prepareData() throws IOException { Admin admin = TEST_UTIL.getAdmin(); TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName) .setValue(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY, FIFOCompactionPolicy.class.getName()) .setValue(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, DisabledRegionSplitPolicy.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).setTimeToLive(1).build()) .build(); admin.createTable(desc); Table table = TEST_UTIL.getConnection().getTable(tableName); TimeOffsetEnvironmentEdge edge = (TimeOffsetEnvironmentEdge) EnvironmentEdgeManager.getDelegate(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { byte[] value = new byte[128 * 1024]; ThreadLocalRandom.current().nextBytes(value); table.put(new Put(Bytes.toBytes(i * 10 + j)).addColumn(family, qualifier, value)); } admin.flush(tableName); edge.increment(1001); } return getStoreWithName(tableName); }
ConnectionInfo(Connection conn, String user) { lastAccessTime = EnvironmentEdgeManager.currentTime(); connection = conn; closed = false; userName = user; }
protected static final void initialize(Class<?>... cps) throws Exception { // Uncomment the following lines if more verbosity is needed for // debugging (see HBASE-12285 for details). // ((Log4JLogger)RpcServer.LOG).getLogger().setLevel(Level.ALL); // ((Log4JLogger)RpcClient.LOG).getLogger().setLevel(Level.ALL); // ((Log4JLogger)ScannerCallable.LOG).getLogger().setLevel(Level.ALL); // make sure that we do not get the same ts twice, see HBASE-19731 for more details. EnvironmentEdgeManager.injectEdge(new NonRepeatedEnvironmentEdge()); Configuration conf = TEST_UTIL.getConfiguration(); conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, Arrays.stream(cps).map(Class::getName).toArray(String[]::new)); conf.setBoolean("hbase.table.sanity.checks", true); // enable for below tests // We need more than one region server in this test TEST_UTIL.startMiniCluster(SLAVES); }
@Before public void setUp() { EnvironmentEdgeManager.reset(); }
/** * We stop to retry when we have exhausted BOTH the number of tries and the time allocated. * @param numAttempt how many times we have tried by now */ boolean canTryMore(int numAttempt) { // If there is a single try we must not take into account the time. return numAttempt < maxTries || (maxTries > 1 && EnvironmentEdgeManager.currentTime() < this.canRetryUntil); }
@Before public void before() { mee.setValue(0); EnvironmentEdgeManager.injectEdge(mee); }
@AfterClass public static void teardown() { EnvironmentEdgeManager.reset(); }
/** * Return the limiter associated with this quota. * @return the quota limiter */ public synchronized QuotaLimiter getGlobalLimiter() { lastQuery = EnvironmentEdgeManager.currentTime(); return globalLimiter; }