Search in sources :

Example 6 with AbstractFSWAL

use of org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL in project hbase by apache.

the class TestSequenceIdMonotonicallyIncreasing method getMaxSeqId.

private long getMaxSeqId(HRegionServer rs, RegionInfo region) throws IOException {
    Path walFile = ((AbstractFSWAL<?>) rs.getWAL(null)).getCurrentFileName();
    long maxSeqId = -1L;
    try (WAL.Reader reader = WALFactory.createReader(UTIL.getTestFileSystem(), walFile, UTIL.getConfiguration())) {
        for (; ; ) {
            WAL.Entry entry = reader.next();
            if (entry == null) {
                break;
            }
            if (Bytes.equals(region.getEncodedNameAsBytes(), entry.getKey().getEncodedRegionName())) {
                maxSeqId = Math.max(maxSeqId, entry.getKey().getSequenceId());
            }
        }
    }
    return maxSeqId;
}
Also used : Path(org.apache.hadoop.fs.Path) AbstractFSWAL(org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL) WAL(org.apache.hadoop.hbase.wal.WAL) AbstractFSWAL(org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL)

Example 7 with AbstractFSWAL

use of org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL in project hbase by apache.

the class TestMasterRegionOnTwoFileSystems method testFlushAndCompact.

@Test
public void testFlushAndCompact() throws Exception {
    int compactMinMinusOne = COMPACT_MIN - 1;
    for (int i = 0; i < compactMinMinusOne; i++) {
        final int index = i;
        region.update(r -> r.put(new Put(Bytes.toBytes(index)).addColumn(CF, CQ, Bytes.toBytes(index))));
        region.flush(true);
    }
    byte[] bytes = Bytes.toBytes(compactMinMinusOne);
    region.update(r -> r.put(new Put(bytes).addColumn(CF, CQ, bytes)));
    region.flusherAndCompactor.requestFlush();
    HFILE_UTIL.waitFor(15000, () -> getStorefilesCount() == 1);
    // make sure the archived hfiles are on the root fs
    Path storeArchiveDir = HFileArchiveUtil.getStoreArchivePathForRootDir(HFILE_UTIL.getDataTestDir(), region.region.getRegionInfo(), CF);
    FileSystem rootFs = storeArchiveDir.getFileSystem(HFILE_UTIL.getConfiguration());
    HFILE_UTIL.waitFor(15000, () -> {
        try {
            FileStatus[] fses = rootFs.listStatus(storeArchiveDir);
            return fses != null && fses.length == COMPACT_MIN;
        } catch (FileNotFoundException e) {
            return false;
        }
    });
    LOG.info("hfile archive content {}", Arrays.stream(rootFs.listStatus(storeArchiveDir)).map(f -> f.getPath().toString()).collect(Collectors.joining(",")));
    // make sure the archived wal files are on the wal fs
    Path walArchiveDir = new Path(CommonFSUtils.getWALRootDir(HFILE_UTIL.getConfiguration()), HConstants.HREGION_OLDLOGDIR_NAME);
    LOG.info("wal archive dir {}", walArchiveDir);
    AbstractFSWAL<?> wal = (AbstractFSWAL<?>) region.region.getWAL();
    Path currentWALFile = wal.getCurrentFileName();
    for (; ; ) {
        region.requestRollAll();
        region.waitUntilWalRollFinished();
        Path newWALFile = wal.getCurrentFileName();
        // make sure we actually rolled the wal
        if (!newWALFile.equals(currentWALFile)) {
            break;
        }
    }
    HFILE_UTIL.waitFor(15000, () -> {
        try {
            FileStatus[] fses = WAL_UTIL.getTestFileSystem().listStatus(walArchiveDir);
            if (fses != null && fses.length > 0) {
                LOG.info("wal archive dir content {}", Arrays.stream(fses).map(f -> f.getPath().toString()).collect(Collectors.joining(",")));
            } else {
                LOG.info("none found");
            }
            return fses != null && fses.length >= 1;
        } catch (FileNotFoundException e) {
            return false;
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) AbstractFSWAL(org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 8 with AbstractFSWAL

use of org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL in project hbase by apache.

the class TestAddToSerialReplicationPeer method waitUntilReplicatedToTheCurrentWALFile.

private void waitUntilReplicatedToTheCurrentWALFile(HRegionServer rs, final String oldWalName) throws Exception {
    Path path = ((AbstractFSWAL<?>) rs.getWAL(null)).getCurrentFileName();
    String logPrefix = AbstractFSWALProvider.getWALPrefixFromWALName(path.getName());
    UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            ReplicationSourceManager manager = ((Replication) rs.getReplicationSourceService()).getReplicationManager();
            // Make sure replication moves to the new file.
            return (manager.getWALs().get(PEER_ID).get(logPrefix).size() == 1) && !oldWalName.equals(manager.getWALs().get(PEER_ID).get(logPrefix).first());
        }

        @Override
        public String explainFailure() throws Exception {
            return "Still not replicated to the current WAL file yet";
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) AbstractFSWAL(org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL) ReplicationSourceManager(org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager) IOException(java.io.IOException) StreamLacksCapabilityException(org.apache.hadoop.hbase.util.CommonFSUtils.StreamLacksCapabilityException)

Example 9 with AbstractFSWAL

use of org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL in project hbase by apache.

the class TestWALMonotonicallyIncreasingSeqId method testWALMonotonicallyIncreasingSeqId.

@Test
public void testWALMonotonicallyIncreasingSeqId() throws Exception {
    List<Thread> putThreads = new ArrayList<>();
    for (int i = 0; i < 1; i++) {
        putThreads.add(new PutThread(region));
    }
    IncThread incThread = new IncThread(region);
    for (int i = 0; i < 1; i++) {
        putThreads.get(i).start();
    }
    incThread.start();
    incThread.join();
    Path logPath = ((AbstractFSWAL<?>) region.getWAL()).getCurrentFileName();
    region.getWAL().rollWriter();
    Thread.sleep(10);
    Path hbaseDir = new Path(walConf.get(HConstants.HBASE_DIR));
    Path oldWalsDir = new Path(hbaseDir, HConstants.HREGION_OLDLOGDIR_NAME);
    try (WAL.Reader reader = createReader(logPath, oldWalsDir)) {
        long currentMaxSeqid = 0;
        for (WAL.Entry e; (e = reader.next()) != null; ) {
            if (!WALEdit.isMetaEditFamily(e.getEdit().getCells().get(0))) {
                long currentSeqid = e.getKey().getSequenceId();
                if (currentSeqid > currentMaxSeqid) {
                    currentMaxSeqid = currentSeqid;
                } else {
                    fail("Current max Seqid is " + currentMaxSeqid + ", but the next seqid in wal is smaller:" + currentSeqid);
                }
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AbstractFSWAL(org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL) WAL(org.apache.hadoop.hbase.wal.WAL) AbstractFSWAL(org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

AbstractFSWAL (org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL)9 Path (org.apache.hadoop.fs.Path)7 Test (org.junit.Test)5 IOException (java.io.IOException)2 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)2 WAL (org.apache.hadoop.hbase.wal.WAL)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Waiter (org.apache.hadoop.hbase.Waiter)1 Delete (org.apache.hadoop.hbase.client.Delete)1 Get (org.apache.hadoop.hbase.client.Get)1 Put (org.apache.hadoop.hbase.client.Put)1 Table (org.apache.hadoop.hbase.client.Table)1 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)1 ReplicationSourceManager (org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager)1