/** @return the number of log files in use */ public int getNumLogFiles() { // +1 for current use log return getNumRolledLogFiles() + 1; }
/** * returns the number of rolled WAL files. */ @VisibleForTesting public static int getNumRolledLogFiles(WAL wal) { return ((AbstractFSWAL<?>) wal).getNumRolledLogFiles(); }
/** * If the number of un-archived WAL files is greater than maximum allowed, check the first * (oldest) WAL file, and returns those regions which should be flushed so that it can be * archived. * @return regions (encodedRegionNames) to flush in order to archive oldest WAL file. */ byte[][] findRegionsToForceFlush() throws IOException { byte[][] regions = null; int logCount = getNumRolledLogFiles(); if (logCount > this.maxLogs && logCount > 0) { Map.Entry<Path, WalProps> firstWALEntry = this.walFile2Props.firstEntry(); regions = this.sequenceIdAccounting.findLower(firstWALEntry.getValue().encodedName2HighestSequenceId); } if (regions != null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < regions.length; i++) { if (i > 0) { sb.append(", "); } sb.append(Bytes.toStringBinary(regions[i])); } LOG.info("Too many WALs; count=" + logCount + ", max=" + this.maxLogs + "; forcing flush of " + regions.length + " regions(s): " + sb.toString()); } return regions; }
if (getNumRolledLogFiles() > 0) { cleanOldLogs(); regionsToFlush = findRegionsToForceFlush();
wal.rollWriter(); assertTrue(wal.getNumRolledLogFiles() == 2); wal.rollWriter(); assertEquals(1, wal.getNumRolledLogFiles()); assertEquals(0, wal.getNumRolledLogFiles()); wal.rollWriter(); assertEquals(1, wal.getNumRolledLogFiles()); addEdits(wal, hri1, t1, 2, mvcc, scopes1); wal.rollWriter(); flushRegion(wal, hri2.getEncodedNameAsBytes(), t2.getColumnFamilyNames()); wal.rollWriter(true); assertEquals(0, wal.getNumRolledLogFiles()); wal.rollWriter(); wal.completeCacheFlush(hri1.getEncodedNameAsBytes()); assertEquals(1, wal.getNumRolledLogFiles()); } finally { if (wal != null) {
wal.rollWriter(); assertTrue(wal.getNumRolledLogFiles() == 2); wal.rollWriter(); assertEquals(1, wal.getNumRolledLogFiles()); assertEquals(0, wal.getNumRolledLogFiles()); wal.rollWriter(); assertEquals(1, wal.getNumRolledLogFiles()); addEdits(wal, hri1, t1, 2, mvcc, scopes1); wal.rollWriter(); flushRegion(wal, hri2.getEncodedNameAsBytes(), t2.getColumnFamilyNames()); wal.rollWriter(true); assertEquals(0, wal.getNumRolledLogFiles()); wal.rollWriter(); wal.completeCacheFlush(hri1.getEncodedNameAsBytes()); assertEquals(1, wal.getNumRolledLogFiles()); } finally { if (wal != null) {