001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.wal; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import java.io.IOException; 023import java.util.NavigableSet; 024import org.apache.hadoop.fs.FileStatus; 025import org.apache.hadoop.fs.FileSystem; 026import org.apache.hadoop.fs.Path; 027import org.apache.hadoop.fs.PathFilter; 028import org.apache.hadoop.hbase.HBaseCommonTestingUtil; 029import org.apache.hadoop.hbase.testclassification.RegionServerTests; 030import org.apache.hadoop.hbase.testclassification.SmallTests; 031import org.apache.hadoop.hbase.util.CommonFSUtils; 032import org.junit.jupiter.api.AfterAll; 033import org.junit.jupiter.api.BeforeAll; 034import org.junit.jupiter.api.Tag; 035import org.junit.jupiter.api.Test; 036import org.slf4j.Logger; 037import org.slf4j.LoggerFactory; 038 039@Tag(RegionServerTests.TAG) 040@Tag(SmallTests.TAG) 041public class TestReadWriteSeqIdFiles { 042 043 private static final Logger LOG = LoggerFactory.getLogger(TestReadWriteSeqIdFiles.class); 044 045 private static final HBaseCommonTestingUtil UTIL = new HBaseCommonTestingUtil(); 046 047 private static FileSystem walFS; 048 049 private static Path REGION_DIR; 050 051 @BeforeAll 052 public static void setUp() throws IOException { 053 walFS = FileSystem.getLocal(UTIL.getConfiguration()); 054 REGION_DIR = UTIL.getDataTestDir(); 055 } 056 057 @AfterAll 058 public static void tearDown() throws IOException { 059 UTIL.cleanupTestDir(); 060 } 061 062 @Test 063 public void test() throws IOException { 064 WALSplitUtil.writeRegionSequenceIdFile(walFS, REGION_DIR, 1000L); 065 assertEquals(1000L, WALSplitUtil.getMaxRegionSequenceId(walFS, REGION_DIR)); 066 WALSplitUtil.writeRegionSequenceIdFile(walFS, REGION_DIR, 2000L); 067 assertEquals(2000L, WALSplitUtil.getMaxRegionSequenceId(walFS, REGION_DIR)); 068 // can not write a sequence id which is smaller 069 try { 070 WALSplitUtil.writeRegionSequenceIdFile(walFS, REGION_DIR, 1500L); 071 } catch (IOException e) { 072 // expected 073 LOG.info("Expected error", e); 074 } 075 076 Path editsdir = WALSplitUtil.getRegionDirRecoveredEditsDir(REGION_DIR); 077 FileStatus[] files = CommonFSUtils.listStatus(walFS, editsdir, new PathFilter() { 078 @Override 079 public boolean accept(Path p) { 080 return WALSplitUtil.isSequenceIdFile(p); 081 } 082 }); 083 // only one seqid file should exist 084 assertEquals(1, files.length); 085 086 // verify all seqId files aren't treated as recovered.edits files 087 NavigableSet<Path> recoveredEdits = WALSplitUtil.getSplitEditFilesSorted(walFS, REGION_DIR); 088 assertEquals(0, recoveredEdits.size()); 089 } 090}