示例#1
0
 private void verifyWALCount(WALFactory wals, WAL log, int expected) throws Exception {
   Path walPath = DefaultWALProvider.getCurrentFileName(log);
   WAL.Reader reader = wals.createReader(FS, walPath);
   int count = 0;
   WAL.Entry entry = new WAL.Entry();
   while (reader.next(entry) != null) count++;
   reader.close();
   assertEquals(expected, count);
 }
 /**
  * Verify the content of the WAL file. Verify that the file has expected number of edits.
  *
  * @param wals may not be null
  * @param wal
  * @return Count of edits.
  * @throws IOException
  */
 private long verify(final WALFactory wals, final Path wal, final boolean verbose)
     throws IOException {
   WAL.Reader reader = wals.createReader(wal.getFileSystem(getConf()), wal);
   long count = 0;
   Map<String, Long> sequenceIds = new HashMap<String, Long>();
   try {
     while (true) {
       WAL.Entry e = reader.next();
       if (e == null) {
         LOG.debug("Read count=" + count + " from " + wal);
         break;
       }
       count++;
       long seqid = e.getKey().getLogSeqNum();
       if (sequenceIds.containsKey(Bytes.toString(e.getKey().getEncodedRegionName()))) {
         // sequenceIds should be increasing for every regions
         if (sequenceIds.get(Bytes.toString(e.getKey().getEncodedRegionName())) >= seqid) {
           throw new IllegalStateException(
               "wal = "
                   + wal.getName()
                   + ", "
                   + "previous seqid = "
                   + sequenceIds.get(Bytes.toString(e.getKey().getEncodedRegionName()))
                   + ", current seqid = "
                   + seqid);
         }
       }
       // update the sequence Id.
       sequenceIds.put(Bytes.toString(e.getKey().getEncodedRegionName()), seqid);
       if (verbose) LOG.info("seqid=" + seqid);
     }
   } finally {
     reader.close();
   }
   return count;
 }