|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.master.region; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertThrows; |
| 21 | + |
| 22 | +import java.io.IOException; |
| 23 | +import java.time.Duration; |
| 24 | +import java.util.List; |
| 25 | +import org.apache.hadoop.conf.Configuration; |
| 26 | +import org.apache.hadoop.fs.FileSystem; |
| 27 | +import org.apache.hadoop.fs.Path; |
| 28 | +import org.apache.hadoop.hbase.Abortable; |
| 29 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 30 | +import org.apache.hadoop.hbase.client.Put; |
| 31 | +import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor; |
| 32 | +import org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL; |
| 33 | +import org.apache.hadoop.hbase.regionserver.wal.AsyncFSWAL; |
| 34 | +import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException; |
| 35 | +import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener; |
| 36 | +import org.apache.hadoop.hbase.regionserver.wal.WALSyncTimeoutIOException; |
| 37 | +import org.apache.hadoop.hbase.testclassification.MasterTests; |
| 38 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 39 | +import org.apache.hadoop.hbase.util.Bytes; |
| 40 | +import org.apache.hadoop.hbase.util.CommonFSUtils; |
| 41 | +import org.apache.hadoop.hbase.wal.AsyncFSWALProvider; |
| 42 | +import org.apache.hadoop.hbase.wal.WALFactory; |
| 43 | +import org.apache.hadoop.hbase.wal.WALProvider; |
| 44 | +import org.junit.ClassRule; |
| 45 | +import org.junit.Test; |
| 46 | +import org.junit.experimental.categories.Category; |
| 47 | + |
| 48 | +import org.apache.hbase.thirdparty.io.netty.channel.Channel; |
| 49 | +import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup; |
| 50 | + |
| 51 | +@Category({ MasterTests.class, MediumTests.class }) |
| 52 | +public class TestMasterRegionWALSyncTimeoutIOException extends MasterRegionTestBase { |
| 53 | + |
| 54 | + @ClassRule |
| 55 | + public static final HBaseClassTestRule CLASS_RULE = |
| 56 | + HBaseClassTestRule.forClass(TestMasterRegionWALSyncTimeoutIOException.class); |
| 57 | + |
| 58 | + private static final Duration WAL_SYNC_TIMEOUT = Duration.ofSeconds(3); |
| 59 | + |
| 60 | + private static volatile boolean testWalTimeout = false; |
| 61 | + |
| 62 | + @Override |
| 63 | + protected void configure(Configuration conf) throws IOException { |
| 64 | + conf.setClass(WALFactory.WAL_PROVIDER, SlowAsyncFSWALProvider.class, WALProvider.class); |
| 65 | + conf.setLong(AbstractFSWAL.WAL_SYNC_TIMEOUT_MS, WAL_SYNC_TIMEOUT.toMillis()); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + protected void configure(MasterRegionParams params) { |
| 70 | + params.flushIntervalMs(Duration.ofSeconds(1).toMillis()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testUpdateWalSyncWriteException() { |
| 75 | + testWalTimeout = true; |
| 76 | + assertThrows(WALSyncTimeoutIOException.class, () -> { |
| 77 | + for (int i = 0; i < 10; i++) { |
| 78 | + region.update( |
| 79 | + r -> r.put(new Put(Bytes.toBytes("0")).addColumn(CF1, QUALIFIER, Bytes.toBytes("0")))); |
| 80 | + Thread.sleep(Duration.ofSeconds(1).toMillis()); |
| 81 | + } |
| 82 | + }); |
| 83 | + } |
| 84 | + |
| 85 | + public static class SlowAsyncFSWAL extends AsyncFSWAL { |
| 86 | + |
| 87 | + public SlowAsyncFSWAL(FileSystem fs, Abortable abortable, Path rootDir, String logDir, |
| 88 | + String archiveDir, Configuration conf, List<WALActionsListener> listeners, |
| 89 | + boolean failIfWALExists, String prefix, String suffix, EventLoopGroup eventLoopGroup, |
| 90 | + Class<? extends Channel> channelClass, StreamSlowMonitor monitor) |
| 91 | + throws FailedLogCloseException, IOException { |
| 92 | + super(fs, abortable, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, |
| 93 | + suffix, eventLoopGroup, channelClass, monitor); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + protected void atHeadOfRingBufferEventHandlerAppend() { |
| 98 | + if (testWalTimeout) { |
| 99 | + try { |
| 100 | + Thread.sleep(WAL_SYNC_TIMEOUT.plusSeconds(1).toMillis()); |
| 101 | + } catch (InterruptedException e) { |
| 102 | + throw new RuntimeException(e); |
| 103 | + } |
| 104 | + } |
| 105 | + super.atHeadOfRingBufferEventHandlerAppend(); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + public static class SlowAsyncFSWALProvider extends AsyncFSWALProvider { |
| 110 | + |
| 111 | + @Override |
| 112 | + protected AsyncFSWAL createWAL() throws IOException { |
| 113 | + return new SlowAsyncFSWAL(CommonFSUtils.getWALFileSystem(conf), this.abortable, |
| 114 | + CommonFSUtils.getWALRootDir(conf), getWALDirectoryName(factory.getFactoryId()), |
| 115 | + getWALArchiveDirectoryName(conf, factory.getFactoryId()), conf, listeners, true, logPrefix, |
| 116 | + META_WAL_PROVIDER_ID.equals(providerId) ? META_WAL_PROVIDER_ID : null, eventLoopGroup, |
| 117 | + channelClass, factory.getExcludeDatanodeManager().getStreamSlowMonitor(providerId)); |
| 118 | + } |
| 119 | + } |
| 120 | +} |
0 commit comments