From abea347cb292babe1b70b6be9da425f9203da1cf Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Mon, 23 Apr 2018 16:31:54 +0800 Subject: [PATCH] HBASE-20458 Support removing a WAL from LogRoller --- .../hadoop/hbase/regionserver/LogRoller.java | 18 ++++++--- .../hbase/regionserver/wal/DualAsyncFSWAL.java | 9 +++++ .../wal/DualAsyncFSWALClosedException.java | 45 ++++++++++++++++++++++ 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWALClosedException.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 55c5219..1e5f2b6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -28,6 +28,7 @@ import java.util.concurrent.locks.ReentrantLock; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL; +import org.apache.hadoop.hbase.regionserver.wal.DualAsyncFSWALClosedException; import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException; import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener; import org.apache.hadoop.hbase.util.Bytes; @@ -181,13 +182,18 @@ public class LogRoller extends HasThread implements Closeable { final WAL wal = entry.getKey(); // Force the roll if the logroll.period is elapsed or if a roll was requested. // The returned value is an array of actual region names. - final byte [][] regionsToFlush = wal.rollWriter(periodic || - entry.getValue().booleanValue()); - walNeedsRoll.put(wal, Boolean.FALSE); - if (regionsToFlush != null) { - for (byte[] r : regionsToFlush) { - scheduleFlush(r); + try { + final byte[][] regionsToFlush = + wal.rollWriter(periodic || entry.getValue().booleanValue()); + walNeedsRoll.put(wal, Boolean.FALSE); + if (regionsToFlush != null) { + for (byte[] r : regionsToFlush) { + scheduleFlush(r); + } } + } catch (DualAsyncFSWALClosedException e) { + LOG.warn("The DualAsyncFSWAL has been closed, just remove it directly", e); + walNeedsRoll.remove(wal); } } } catch (FailedLogCloseException e) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWAL.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWAL.java index a98567a..500fc40 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWAL.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWAL.java @@ -78,4 +78,13 @@ public class DualAsyncFSWAL extends AsyncFSWAL { public void skipRemoteWal() { this.skipRemoteWal = true; } + + @Override + public byte[][] rollWriter(boolean force) throws FailedLogCloseException, IOException { + if (closed) { + throw new DualAsyncFSWALClosedException("WAL has been closed"); + } else { + return super.rollWriter(force); + } + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWALClosedException.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWALClosedException.java new file mode 100644 index 0000000..321ff63 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/DualAsyncFSWALClosedException.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver.wal; + +import java.io.IOException; + +import org.apache.hadoop.hbase.regionserver.LogRoller; +import org.apache.hadoop.hbase.replication.SyncReplicationState; + +/** + * Thrown when {@link LogRoller} try to roll writer but the {@link DualAsyncFSWAL} already was + * closed. This happened when peer's sync replication state was transited from + * {@link SyncReplicationState#ACTIVE} to {@link SyncReplicationState#DOWNGRADE_ACTIVE} and the + * region's WAL will be changed to a new one. But the old WAL was still left in {@link LogRoller}. + */ +public class DualAsyncFSWALClosedException extends IOException { + + private static final long serialVersionUID = 1L; + + public DualAsyncFSWALClosedException() { + super(); + } + + /** + * @param msg exception message + */ + public DualAsyncFSWALClosedException(String msg) { + super(msg); + } +} -- 1.9.1