Search in sources :

Example 1 with FlushAction

use of org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.FlushAction in project hbase by apache.

the class HRegion method replayWALFlushMarker.

void replayWALFlushMarker(FlushDescriptor flush, long replaySeqId) throws IOException {
    checkTargetRegion(flush.getEncodedRegionName().toByteArray(), "Flush marker from WAL ", flush);
    if (ServerRegionReplicaUtil.isDefaultReplica(this.getRegionInfo())) {
        // if primary nothing to do
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(getRegionInfo().getEncodedName() + " : " + "Replaying flush marker " + TextFormat.shortDebugString(flush));
    }
    // use region close lock to guard against close
    startRegionOperation(Operation.REPLAY_EVENT);
    try {
        FlushAction action = flush.getAction();
        switch(action) {
            case START_FLUSH:
                replayWALFlushStartMarker(flush);
                break;
            case COMMIT_FLUSH:
                replayWALFlushCommitMarker(flush);
                break;
            case ABORT_FLUSH:
                replayWALFlushAbortMarker(flush);
                break;
            case CANNOT_FLUSH:
                replayWALFlushCannotFlushMarker(flush, replaySeqId);
                break;
            default:
                LOG.warn(getRegionInfo().getEncodedName() + " : " + "Received a flush event with unknown action, ignoring. " + TextFormat.shortDebugString(flush));
                break;
        }
        logRegionFiles();
    } finally {
        closeRegionOperation(Operation.REPLAY_EVENT);
    }
}
Also used : FlushAction(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.FlushAction)

Example 2 with FlushAction

use of org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.FlushAction in project hbase by apache.

the class TestHRegion method testFlushMarkersWALFail.

@Test
public void testFlushMarkersWALFail() throws Exception {
    // test the cases where the WAL append for flush markers fail.
    byte[] family = Bytes.toBytes("family");
    // spy an actual WAL implementation to throw exception (was not able to mock)
    Path logDir = TEST_UTIL.getDataTestDirOnTestFS(method + "log");
    final Configuration walConf = new Configuration(TEST_UTIL.getConfiguration());
    FSUtils.setRootDir(walConf, logDir);
    // Make up a WAL that we can manipulate at append time.
    class FailAppendFlushMarkerWAL extends FSHLog {

        volatile FlushAction[] flushActions = null;

        public FailAppendFlushMarkerWAL(FileSystem fs, Path root, String logDir, Configuration conf) throws IOException {
            super(fs, root, logDir, conf);
        }

        @Override
        protected Writer createWriterInstance(Path path) throws IOException {
            final Writer w = super.createWriterInstance(path);
            return new Writer() {

                @Override
                public void close() throws IOException {
                    w.close();
                }

                @Override
                public void sync() throws IOException {
                    w.sync();
                }

                @Override
                public void append(Entry entry) throws IOException {
                    List<Cell> cells = entry.getEdit().getCells();
                    if (WALEdit.isMetaEditFamily(cells.get(0))) {
                        FlushDescriptor desc = WALEdit.getFlushDescriptor(cells.get(0));
                        if (desc != null) {
                            for (FlushAction flushAction : flushActions) {
                                if (desc.getAction().equals(flushAction)) {
                                    throw new IOException("Failed to append flush marker! " + flushAction);
                                }
                            }
                        }
                    }
                    w.append(entry);
                }

                @Override
                public long getLength() {
                    return w.getLength();
                }
            };
        }
    }
    FailAppendFlushMarkerWAL wal = new FailAppendFlushMarkerWAL(FileSystem.get(walConf), FSUtils.getRootDir(walConf), method, walConf);
    this.region = initHRegion(tableName, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, Durability.USE_DEFAULT, wal, family);
    try {
        int i = 0;
        Put put = new Put(Bytes.toBytes(i));
        // have to skip mocked wal
        put.setDurability(Durability.SKIP_WAL);
        put.addColumn(family, Bytes.toBytes(i), Bytes.toBytes(i));
        region.put(put);
        // 1. Test case where START_FLUSH throws exception
        wal.flushActions = new FlushAction[] { FlushAction.START_FLUSH };
        // start cache flush will throw exception
        try {
            region.flush(true);
            fail("This should have thrown exception");
        } catch (DroppedSnapshotException unexpected) {
            // this should not be a dropped snapshot exception. Meaning that RS will not abort
            throw unexpected;
        } catch (IOException expected) {
        // expected
        }
        // The WAL is hosed now. It has two edits appended. We cannot roll the log without it
        // throwing a DroppedSnapshotException to force an abort. Just clean up the mess.
        region.close(true);
        wal.close();
        // 2. Test case where START_FLUSH succeeds but COMMIT_FLUSH will throw exception
        wal.flushActions = new FlushAction[] { FlushAction.COMMIT_FLUSH };
        wal = new FailAppendFlushMarkerWAL(FileSystem.get(walConf), FSUtils.getRootDir(walConf), method, walConf);
        this.region = initHRegion(tableName, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, Durability.USE_DEFAULT, wal, family);
        region.put(put);
        // 3. Test case where ABORT_FLUSH will throw exception.
        // Even if ABORT_FLUSH throws exception, we should not fail with IOE, but continue with
        // DroppedSnapshotException. Below COMMMIT_FLUSH will cause flush to abort
        wal.flushActions = new FlushAction[] { FlushAction.COMMIT_FLUSH, FlushAction.ABORT_FLUSH };
        try {
            region.flush(true);
            fail("This should have thrown exception");
        } catch (DroppedSnapshotException expected) {
        // we expect this exception, since we were able to write the snapshot, but failed to
        // write the flush marker to WAL
        } catch (IOException unexpected) {
            throw unexpected;
        }
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(this.region);
        this.region = null;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) DroppedSnapshotException(org.apache.hadoop.hbase.DroppedSnapshotException) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) FlushDescriptor(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor) StoreFlushDescriptor(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.StoreFlushDescriptor) Put(org.apache.hadoop.hbase.client.Put) FSHLog(org.apache.hadoop.hbase.regionserver.wal.FSHLog) FlushAction(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.FlushAction) FileSystem(org.apache.hadoop.fs.FileSystem) FaultyFileSystem(org.apache.hadoop.hbase.regionserver.TestStore.FaultyFileSystem) Cell(org.apache.hadoop.hbase.Cell) Writer(org.apache.hadoop.hbase.wal.WALProvider.Writer) Test(org.junit.Test)

Aggregations

FlushAction (org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.FlushAction)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Cell (org.apache.hadoop.hbase.Cell)1 DroppedSnapshotException (org.apache.hadoop.hbase.DroppedSnapshotException)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 Put (org.apache.hadoop.hbase.client.Put)1 FaultyFileSystem (org.apache.hadoop.hbase.regionserver.TestStore.FaultyFileSystem)1 FSHLog (org.apache.hadoop.hbase.regionserver.wal.FSHLog)1 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)1 FlushDescriptor (org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor)1 StoreFlushDescriptor (org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor.StoreFlushDescriptor)1 Writer (org.apache.hadoop.hbase.wal.WALProvider.Writer)1 Test (org.junit.Test)1