if (this.sequenceIdAccounting.areAllLower(sequenceNums, regionsBlockingThisWal)) { if (logsToArchive == null) { logsToArchive = new ArrayList<>();
Map<byte[], Long> m = new HashMap<>(); m.put(ENCODED_REGION_NAME, HConstants.NO_SEQNUM); assertTrue(sida.areAllLower(m, null)); long sequenceid = 1; sida.update(ENCODED_REGION_NAME, FAMILIES, sequenceid, true); sida.update(ENCODED_REGION_NAME, FAMILIES, sequenceid++, true); sida.update(ENCODED_REGION_NAME, FAMILIES, sequenceid++, true); assertTrue(sida.areAllLower(m, null)); m.put(ENCODED_REGION_NAME, sequenceid); assertFalse(sida.areAllLower(m, null)); ArrayList<byte[]> regions = new ArrayList<>(); assertFalse(sida.areAllLower(m, regions)); assertEquals(1, regions.size()); assertArrayEquals(ENCODED_REGION_NAME, regions.get(0)); assertEquals("Lowest should be first sequence id inserted", 1, lowest); m.put(ENCODED_REGION_NAME, lowest); assertFalse(sida.areAllLower(m, null)); assertFalse(sida.areAllLower(m, null)); m.put(ENCODED_REGION_NAME, HConstants.NO_SEQNUM); assertTrue(sida.areAllLower(m, null)); assertTrue(sida.areAllLower(m, null)); lowest = sida.getLowestSequenceId(ENCODED_REGION_NAME); m.put(ENCODED_REGION_NAME, lowest); assertFalse(sida.areAllLower(m, null)); sida.startCacheFlush(ENCODED_REGION_NAME, FAMILIES);
/** * Archive old logs. A WAL is eligible for archiving if all its WALEdits have been flushed. * @throws IOException */ private void cleanOldLogs() throws IOException { List<Path> logsToArchive = null; // For each log file, look at its Map of regions to highest sequence id; if all sequence ids // are older than what is currently in memory, the WAL can be GC'd. for (Map.Entry<Path, Map<byte[], Long>> e : this.byWalRegionSequenceIds.entrySet()) { Path log = e.getKey(); Map<byte[], Long> sequenceNums = e.getValue(); if (this.sequenceIdAccounting.areAllLower(sequenceNums)) { if (logsToArchive == null) logsToArchive = new ArrayList<Path>(); logsToArchive.add(log); if (LOG.isTraceEnabled()) LOG.trace("WAL file ready for archiving " + log); } } if (logsToArchive != null) { for (Path p : logsToArchive) { this.totalLogSize.addAndGet(-this.fs.getFileStatus(p).getLen()); archiveLogFile(p); this.byWalRegionSequenceIds.remove(p); } } }
Map<byte[], Long> m = new HashMap<>(); m.put(ENCODED_REGION_NAME, HConstants.NO_SEQNUM); assertTrue(sida.areAllLower(m)); long sequenceid = 1; sida.update(ENCODED_REGION_NAME, FAMILIES, sequenceid, true); sida.update(ENCODED_REGION_NAME, FAMILIES, sequenceid++, true); sida.update(ENCODED_REGION_NAME, FAMILIES, sequenceid++, true); assertTrue(sida.areAllLower(m)); m.put(ENCODED_REGION_NAME, sequenceid); assertFalse(sida.areAllLower(m)); long lowest = sida.getLowestSequenceId(ENCODED_REGION_NAME); assertEquals("Lowest should be first sequence id inserted", 1, lowest); m.put(ENCODED_REGION_NAME, lowest); assertFalse(sida.areAllLower(m)); assertFalse(sida.areAllLower(m)); m.put(ENCODED_REGION_NAME, HConstants.NO_SEQNUM); assertTrue(sida.areAllLower(m)); assertTrue(sida.areAllLower(m)); lowest = sida.getLowestSequenceId(ENCODED_REGION_NAME); m.put(ENCODED_REGION_NAME, lowest); assertFalse(sida.areAllLower(m)); sida.startCacheFlush(ENCODED_REGION_NAME, FAMILIES); sida.update(ENCODED_REGION_NAME, FAMILIES, ++sequenceid, true); sida.update(ENCODED_REGION_NAME, FAMILIES, ++sequenceid, true); assertTrue(sida.areAllLower(m));