@Override public Iterable<FileStatus> getDeletableFiles(Iterable<FileStatus> files) { return Iterables.filter(files, this::isFileDeletable); }
/** * Computes the number of regions reported for a table. */ int getNumReportedRegions(TableName table, QuotaSnapshotStore<TableName> tableStore) throws IOException { return Iterables.size(tableStore.filterBySubject(table)); }
@Override public void addCompactionResults(Collection<HStoreFile> newCompactedfiles, Collection<HStoreFile> results) { this.storefiles = ImmutableList.sortedCopyOf(storeFileComparator, Iterables .concat(Iterables.filter(storefiles, sf -> !newCompactedfiles.contains(sf)), results)); // Mark the files as compactedAway once the storefiles and compactedfiles list is finalized // Let a background thread close the actual reader on these compacted files and also // ensure to evict the blocks from block cache so that they are no longer in // cache newCompactedfiles.forEach(HStoreFile::markCompactedAway); this.compactedfiles = ImmutableList.sortedCopyOf(storeFileComparator, Iterables.concat(this.compactedfiles, newCompactedfiles)); }
/** * Sends a {@link Mutation} to the table. The mutations will be buffered and sent over the wire as * part of a batch. Currently only supports {@link Put} and {@link Delete} mutations. * @param mutation The data to send. */ default CompletableFuture<Void> mutate(Mutation mutation) { return Iterables.getOnlyElement(mutate(Collections.singletonList(mutation))); }
Set<String> families = Sets.newHashSet(); if (cf != null) { Iterables.addAll(families, Splitter.on(",").split(cf));
@Override public void insertNewFiles(Collection<HStoreFile> sfs) throws IOException { this.storefiles = ImmutableList.sortedCopyOf(storeFileComparator, Iterables.concat(this.storefiles, sfs)); }
/** * Assert that the given comparator orders the given storefiles in the * same way that they're passed. */ private void assertOrdering(Comparator<? super HStoreFile> comparator, HStoreFile ... sfs) { ArrayList<HStoreFile> sorted = Lists.newArrayList(sfs); Collections.shuffle(sorted); Collections.sort(sorted, comparator); LOG.debug("sfs: " + Joiner.on(",").join(sfs)); LOG.debug("sorted: " + Joiner.on(",").join(sorted)); assertTrue(Iterables.elementsEqual(Arrays.asList(sfs), sorted)); }
String referencedFile = Iterables.getFirst(referencedFiles, null); assertNotNull(referencedFile);
/** * Read all blocks from {@code path} to populate {@code blockCache}. */ private static void cacheBlocks(Configuration conf, CacheConfig cacheConfig, FileSystem fs, Path path, HFileContext cxt) throws IOException { FSDataInputStreamWrapper fsdis = new FSDataInputStreamWrapper(fs, path); long fileSize = fs.getFileStatus(path).getLen(); FixedFileTrailer trailer = FixedFileTrailer.readFromStream(fsdis.getStream(false), fileSize); HFile.Reader reader = new HFileReaderImpl(path, trailer, fsdis, fileSize, cacheConfig, fsdis.getHfs(), conf); reader.loadFileInfo(); long offset = trailer.getFirstDataBlockOffset(), max = trailer.getLastDataBlockOffset(); List<HFileBlock> blocks = new ArrayList<>(4); HFileBlock block; while (offset <= max) { block = reader.readBlock(offset, -1, /* cacheBlock */ true, /* pread */ false, /* isCompaction */ false, /* updateCacheMetrics */ true, null, null); offset += block.getOnDiskSizeWithHeader(); blocks.add(block); } LOG.info("read " + Iterables.toString(blocks)); }
private void verifyFetchableViaAPI(Admin admin, ThrottleType type, long limit, TimeUnit tu) throws Exception { // Verify we can retrieve the new quota via the QuotaRetriever API try (QuotaRetriever quotaScanner = QuotaRetriever.open(admin.getConfiguration())) { assertRPCQuota(type, limit, tu, Iterables.getOnlyElement(quotaScanner)); } }
/** * Returns a new, <i>mutable</i> {@code EnumSet} instance containing the given elements in their * natural order. This method behaves identically to {@link EnumSet#copyOf(Collection)}, but also * accepts non-{@code Collection} iterables and empty iterables. */ public static <E extends Enum<E>> EnumSet<E> newEnumSet( Iterable<E> iterable, Class<E> elementType) { EnumSet<E> set = EnumSet.noneOf(elementType); Iterables.addAll(set, iterable); return set; }
final double percentRegionsReportedThreshold = getRegionReportPercent(getConfiguration()); Set<TableName> tablesToRemove = new HashSet<>(); for (TableName table : Iterables.concat(tablesWithTableQuotas, tablesWithNamespaceQuotas)) {
private void checkParsing(ParsedLine parsed, Iterable<String> expected) { ArrayList<String> parsedCols = new ArrayList<>(); for (int i = 0; i < parsed.getColumnCount(); i++) { parsedCols.add(Bytes.toString(parsed.getLineBytes(), parsed.getColumnOffset(i), parsed.getColumnLength(i))); } if (!Iterables.elementsEqual(parsedCols, expected)) { fail("Expected: " + Joiner.on(",").join(expected) + "\n" + "Got:" + Joiner.on(",").join(parsedCols)); } }
/** * A sensible definition of {@link #firstEntry} in terms of the {@code iterator()} of * {@link #entrySet}. If you override {@code entrySet}, you may wish to override * {@code firstEntry} to forward to this implementation. */ protected Entry<K, V> standardFirstEntry() { return Iterables.getFirst(entrySet(), null); }
/** * Returns a string representation of this fluent iterable, with the format {@code [e1, e2, ..., * en]}. * * <p><b>{@code Stream} equivalent:</b> {@code stream.collect(Collectors.joining(", ", "[", "]"))} * or (less efficiently) {@code stream.collect(Collectors.toList()).toString()}. */ @Override public String toString() { return Iterables.toString(getDelegate()); }
/** * Returns the number of quotas defined in the HBase quota table. */ long listNumDefinedQuotas(Connection conn) throws IOException { QuotaRetriever scanner = QuotaRetriever.open(conn.getConfiguration()); try { return Iterables.size(scanner); } finally { if (scanner != null) { scanner.close(); } } }
private void testZookeeperCanaryWithArgs(String[] args) throws Exception { Integer port = Iterables.getOnlyElement(testingUtility.getZkCluster().getClientPortList(), null); testingUtility.getConfiguration().set(HConstants.ZOOKEEPER_QUORUM, "localhost:" + port + "/hbase"); ExecutorService executor = new ScheduledThreadPoolExecutor(2); Canary.ZookeeperStdOutSink sink = spy(new Canary.ZookeeperStdOutSink()); Canary canary = new Canary(executor, sink); assertEquals(0, ToolRunner.run(testingUtility.getConfiguration(), canary, args)); String baseZnode = testingUtility.getConfiguration() .get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); verify(sink, atLeastOnce()) .publishReadTiming(eq(baseZnode), eq("localhost:" + port), anyLong()); } }
@Override public Iterable<Entry<RegionInfo,Long>> filterBySubject(TableName table) { rlock.lock(); try { return Iterables.filter(regionUsage.entrySet(), new Predicate<Entry<RegionInfo,Long>>() { @Override public boolean apply(Entry<RegionInfo,Long> input) { return table.equals(input.getKey().getTable()); } }); } finally { rlock.unlock(); } }
/** * Returns a new {@code EnumMultiset} instance containing the given elements. Unlike * {@link EnumMultiset#create(Iterable)}, this method does not produce an exception on an empty * iterable. * * @since 14.0 */ public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements, Class<E> type) { EnumMultiset<E> result = create(type); Iterables.addAll(result, elements); return result; }