private static CompactionRequest createDummyRequest() throws Exception { // "Files" are totally unused, it's Scanner class below that gives compactor fake KVs. // But compaction depends on everything under the sun, so stub everything with dummies. StoreFile sf = mock(StoreFile.class); StoreFile.Reader r = mock(StoreFile.Reader.class); when(r.length()).thenReturn(1L); when(r.getBloomFilterType()).thenReturn(BloomType.NONE); when(r.getHFileReader()).thenReturn(mock(HFile.Reader.class)); when(r.getStoreFileScanner(anyBoolean(), anyBoolean(), anyBoolean(), anyLong())) .thenReturn(mock(StoreFileScanner.class)); when(sf.getReader()).thenReturn(r); when(sf.createReader()).thenReturn(r); return new CompactionRequest(Arrays.asList(sf)); }
/** * Return an array of scanners corresponding to the given set of store files, And set the * ScanQueryMatcher for each store file scanner for further optimization */ public static List<StoreFileScanner> getScannersForStoreFiles( Collection<StoreFile> files, boolean cacheBlocks, boolean isCompaction, ScanQueryMatcher matcher) throws IOException { List<StoreFileScanner> scanners = new ArrayList<StoreFileScanner>(files.size()); for (StoreFile file : files) { StoreFile.Reader r = file.createReader(); StoreFileScanner scanner = r.getStoreFileScanner(cacheBlocks, isCompaction); scanner.setScanQueryMatcher(matcher); scanners.add(scanner); } return scanners; }
@Override public Boolean call() throws Exception { Thread.currentThread().setName("reader " + readerId); Random rand = new Random(); StoreFileScanner scanner = reader.getStoreFileScanner(true, pread); while (System.currentTimeMillis() < endTime) { byte[] row = createRandomRow(rand, firstRow, lastRow); KeyValue kvToSeek = new KeyValue(row, family, createRandomQualifier(rand)); if (rand.nextDouble() < 0.0001) { LOG.info("kvToSeek=" + kvToSeek); } boolean seekResult; try { seekResult = scanner.seek(kvToSeek); } catch (IOException ex) { throw new IOException("Seek failed for key " + kvToSeek + ", pread=" + pread, ex); } numSeeks.incrementAndGet(); if (!seekResult) { error("Seek returned false for row " + Bytes.toStringBinary(row)); return false; } for (int i = 0; i < rand.nextInt(10) + 1; ++i) { KeyValue kv = scanner.next(); numKV.incrementAndGet(); if (i == 0 && kv == null) { error( "scanner.next() returned null at the first iteration for " + "row " + Bytes.toStringBinary(row)); return false; } if (kv == null) break; String keyHashStr = MD5Hash.getMD5AsHex(kv.getKey()); keysRead.add(keyHashStr); totalBytes.addAndGet(kv.getLength()); } } return true; }