public static boolean isSorted(Collection<byte[]> arrays) { if (!CollectionUtils.isEmpty(arrays)) { byte[] previous = new byte[0]; for (byte[] array : arrays) { if (Bytes.compareTo(previous, array) > 0) { return false; } previous = array; } } return true; }
public static int totalLengthWithMvccVersion(final Iterable<? extends KeyValue> kvs, final boolean includeMvccVersion) { int length = 0; for (KeyValue kv : IterableUtils.emptyIfNull(kvs)) { length += lengthWithMvccVersion(kv, includeMvccVersion); } return length; }
/** * @return null if failed to report progress * @throws IOException */ @Override public List<Path> finishWritingAndClose() throws IOException { boolean isSuccessful = false; List<Path> result = null; try { isSuccessful = finishWriting(false); } finally { result = close(); List<IOException> thrown = closeLogWriters(null); if (CollectionUtils.isNotEmpty(thrown)) { throw MultipleIOException.createIOException(thrown); } } if (isSuccessful) { splits = result; } return splits; }
void filterCellByStore(Entry logEntry) { Map<byte[], Long> maxSeqIdInStores = regionMaxSeqIdInStores.get(Bytes.toString(logEntry.getKey().getEncodedRegionName())); if (MapUtils.isEmpty(maxSeqIdInStores)) { return; } // Create the array list for the cells that aren't filtered. // We make the assumption that most cells will be kept. ArrayList<Cell> keptCells = new ArrayList<>(logEntry.getEdit().getCells().size()); for (Cell cell : logEntry.getEdit().getCells()) { if (CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) { keptCells.add(cell); } else { byte[] family = CellUtil.cloneFamily(cell); Long maxSeqId = maxSeqIdInStores.get(family); // Do not skip cell even if maxSeqId is null. Maybe we are in a rolling upgrade, // or the master was crashed before and we can not get the information. if (maxSeqId == null || maxSeqId.longValue() < logEntry.getKey().getSequenceId()) { keptCells.add(cell); } } } // Anything in the keptCells array list is still live. // So rather than removing the cells from the array list // which would be an O(n^2) operation, we just replace the list logEntry.getEdit().setCells(keptCells); }
if (MapUtils.isNotEmpty(colFamTimeRangeMap)) { for (Map.Entry<ByteBuffer, TTimeRange> entry : colFamTimeRangeMap.entrySet()) { out.setColumnFamilyTimeRange(Bytes.toBytes(entry.getKey()),
@Override public void init(Map<String, Object> params) { MasterServices master = (MasterServices) MapUtils.getObject(params, HMaster.MASTER); if (master != null) { conn = master.getConnection(); if (getConf() == null) { super.setConf(conn.getConfiguration()); } } if (conn == null) { try { conn = ConnectionFactory.createConnection(getConf()); } catch (IOException ioe) { throw new RuntimeException("Failed to create connection", ioe); } } }
public static List<byte[]> getUtf8ByteArrays(List<String> strings) { if (CollectionUtils.isEmpty(strings)) { return Collections.emptyList(); } List<byte[]> byteArrays = new ArrayList<>(strings.size()); strings.forEach(s -> byteArrays.add(Bytes.toBytes(s))); return byteArrays; }
public static ByteBuffer toByteBufferAndRewind(final Iterable<? extends KeyValue> kvs, boolean includeMemstoreTS) { int totalBytes = KeyValueUtil.totalLengthWithMvccVersion(kvs, includeMemstoreTS); ByteBuffer bb = ByteBuffer.allocate(totalBytes); for (KeyValue kv : IterableUtils.emptyIfNull(kvs)) { KeyValueUtil.appendToByteBuffer(bb, kv, includeMemstoreTS); } bb.rewind(); return bb; }
@VisibleForTesting public synchronized void closeAndArchiveCompactedFiles(boolean storeClosing) throws IOException { // ensure other threads do not attempt to archive the same files on close() archiveLock.lock(); try { lock.readLock().lock(); Collection<HStoreFile> copyCompactedfiles = null; try { Collection<HStoreFile> compactedfiles = this.getStoreEngine().getStoreFileManager().getCompactedfiles(); if (CollectionUtils.isNotEmpty(compactedfiles)) { // Do a copy under read lock copyCompactedfiles = new ArrayList<>(compactedfiles); } else { LOG.trace("No compacted files to archive"); } } finally { lock.readLock().unlock(); } if (CollectionUtils.isNotEmpty(copyCompactedfiles)) { removeCompactedfiles(copyCompactedfiles, storeClosing); } } finally { archiveLock.unlock(); } }
/** * Create a {@link RowMutations} with the specified mutations. * @param mutations the mutations to send * @return RowMutations * @throws IOException if any row in mutations is different to another */ public static RowMutations of(List<? extends Mutation> mutations) throws IOException { if (CollectionUtils.isEmpty(mutations)) { throw new IllegalArgumentException("Cannot instantiate a RowMutations by empty list"); } return new RowMutations(mutations.get(0).getRow(), mutations.size()) .add(mutations); }
for (HStoreFile file : IterableUtils.emptyIfNull(compactedFiles)) { name2File.put(file.getFileInfo().getActiveFileName(), file);
for (TResult result : results) { List<TColumnValue> columnValues = result.getColumnValues(); if (CollectionUtils.isNotEmpty(columnValues)) { if (Bytes.equals(familyAname, columnValues.get(0).getFamily())) { familyACount++;
/** Adds the files to compacting files. filesCompacting must be locked. */ private void addToCompactingFiles(Collection<HStoreFile> filesToAdd) { if (CollectionUtils.isEmpty(filesToAdd)) { return; } // Check that we do not try to compact the same StoreFile twice. if (!Collections.disjoint(filesCompacting, filesToAdd)) { Preconditions.checkArgument(false, "%s overlaps with %s", filesToAdd, filesCompacting); } filesCompacting.addAll(filesToAdd); Collections.sort(filesCompacting, storeEngine.getStoreFileManager().getStoreFileComparator()); }
@VisibleForTesting static Set<byte[]> collectFamilies(List<Cell> cells) { if (CollectionUtils.isEmpty(cells)) { return Collections.emptySet(); } else { return cells.stream() .filter(v -> !CellUtil.matchingFamily(v, WALEdit.METAFAMILY)) .collect(toCollection(() -> new TreeSet<>(CellComparator.getInstance()::compareFamilies))) .stream() .map(CellUtil::cloneFamily) .collect(toCollection(() -> new TreeSet<>(Bytes.BYTES_COMPARATOR))); } }
@Override public void updateReaders(List<HStoreFile> sfs, List<KeyValueScanner> memStoreScanners) throws IOException { if (CollectionUtils.isEmpty(sfs) && CollectionUtils.isEmpty(memStoreScanners)) { return; } flushLock.lock(); try { flushed = true; final boolean isCompaction = false; boolean usePread = get || scanUsePread; // SEE HBASE-19468 where the flushed files are getting compacted even before a scanner // calls next(). So its better we create scanners here rather than next() call. Ensure // these scanners are properly closed() whether or not the scan is completed successfully // Eagerly creating scanners so that we have the ref counting ticking on the newly created // store files. In case of stream scanners this eager creation does not induce performance // penalty because in scans (that uses stream scanners) the next() call is bound to happen. List<KeyValueScanner> scanners = store.getScanners(sfs, cacheBlocks, get, usePread, isCompaction, matcher, scan.getStartRow(), scan.getStopRow(), this.readPt, false); flushedstoreFileScanners.addAll(scanners); if (!CollectionUtils.isEmpty(memStoreScanners)) { clearAndClose(memStoreScannersAfterFlush); memStoreScannersAfterFlush.addAll(memStoreScanners); } } finally { flushLock.unlock(); } // Let the next() call handle re-creating and seeking }
if (CollectionUtils.isEmpty(levelOneDirs)) { return;
@Override public boolean commit(MonitoredTask status) throws IOException { if (CollectionUtils.isEmpty(this.tempFiles)) { return false;
if (CollectionUtils.isEmpty(delSfs)) { return;
String oldQueueNode = getQueueNode(sourceServerName, queueId); List<String> wals = ZKUtil.listChildrenNoWatch(zookeeper, oldQueueNode); if (CollectionUtils.isEmpty(wals)) { ZKUtil.deleteNodeFailSilent(zookeeper, oldQueueNode); LOG.info("Removed empty {}/{}", sourceServerName, queueId);
private static Cell reckonDelta(final Cell delta, final Cell currentCell, final byte[] columnFamily, final long now, Mutation mutation, Function<Cell, byte[]> supplier) throws IOException { // Forward any tags found on the delta. List<Tag> tags = TagUtil.carryForwardTags(delta); tags = TagUtil.carryForwardTTLTag(tags, mutation.getTTL()); if (currentCell != null) { tags = TagUtil.carryForwardTags(tags, currentCell); byte[] newValue = supplier.apply(currentCell); return ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(mutation.getRow(), 0, mutation.getRow().length) .setFamily(columnFamily, 0, columnFamily.length) // copy the qualifier if the cell is located in shared memory. .setQualifier(CellUtil.cloneQualifier(delta)) .setTimestamp(Math.max(currentCell.getTimestamp() + 1, now)) .setType(KeyValue.Type.Put.getCode()) .setValue(newValue, 0, newValue.length) .setTags(TagUtil.fromList(tags)) .build(); } else { PrivateCellUtil.updateLatestStamp(delta, now); return CollectionUtils.isEmpty(tags) ? delta : PrivateCellUtil.createCell(delta, tags); } }