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.namequeues;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertTrue;
022
023import java.io.IOException;
024import java.util.Collections;
025import java.util.List;
026import java.util.Set;
027import org.apache.hadoop.hbase.HBaseTestingUtil;
028import org.apache.hadoop.hbase.HConstants;
029import org.apache.hadoop.hbase.ServerName;
030import org.apache.hadoop.hbase.TableName;
031import org.apache.hadoop.hbase.client.Admin;
032import org.apache.hadoop.hbase.client.LogEntry;
033import org.apache.hadoop.hbase.client.OnlineLogRecord;
034import org.apache.hadoop.hbase.client.ResultScanner;
035import org.apache.hadoop.hbase.client.Scan;
036import org.apache.hadoop.hbase.client.ServerType;
037import org.apache.hadoop.hbase.client.Table;
038import org.apache.hadoop.hbase.regionserver.HRegionServer;
039import org.apache.hadoop.hbase.testclassification.MediumTests;
040import org.apache.hadoop.hbase.testclassification.RegionServerTests;
041import org.apache.hadoop.hbase.util.Bytes;
042import org.junit.jupiter.api.AfterAll;
043import org.junit.jupiter.api.BeforeAll;
044import org.junit.jupiter.api.Tag;
045import org.junit.jupiter.api.Test;
046
047@Tag(MediumTests.TAG)
048@Tag(RegionServerTests.TAG)
049public class TestTooLargeLog {
050
051  protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
052  protected static Admin ADMIN;
053
054  @BeforeAll
055  public static void setUpBeforeClass() throws Exception {
056    // Slow log needs to be enabled initially to spin up the SlowLogQueueService
057    TEST_UTIL.getConfiguration().setBoolean(HConstants.SLOW_LOG_BUFFER_ENABLED_KEY, true);
058    TEST_UTIL.getConfiguration().setInt("hbase.ipc.warn.response.size",
059      HConstants.DEFAULT_BLOCKSIZE / 2);
060    TEST_UTIL.startMiniCluster(1);
061    ADMIN = TEST_UTIL.getAdmin();
062  }
063
064  @AfterAll
065  public static void afterClass() throws Exception {
066    TEST_UTIL.shutdownMiniCluster();
067  }
068
069  /**
070   * Tests that we can trigger based on blocks scanned, and also that we properly pass the block
071   * bytes scanned value through to the client.
072   */
073  @Test
074  public void testLogLargeBlockBytesScanned() throws IOException {
075    // Turn off slow log buffer for initial loadTable, because we were seeing core dump
076    // issues coming from that slow log entry. We will re-enable below.
077    HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(0);
078    regionServer.getConfiguration().setBoolean(HConstants.SLOW_LOG_BUFFER_ENABLED_KEY, false);
079    regionServer.updateConfiguration();
080
081    byte[] family = Bytes.toBytes("0");
082    Table table = TEST_UTIL.createTable(TableName.valueOf("testLogLargeBlockBytesScanned"), family);
083    TEST_UTIL.loadTable(table, family);
084    TEST_UTIL.flush(table.getName());
085
086    Set<ServerName> server = Collections.singleton(regionServer.getServerName());
087    Admin admin = TEST_UTIL.getAdmin();
088
089    // Turn on slow log so we capture large scan below
090    regionServer.getConfiguration().setBoolean(HConstants.SLOW_LOG_BUFFER_ENABLED_KEY, true);
091    regionServer.updateConfiguration();
092
093    Scan scan = new Scan();
094    scan.setCaching(1);
095
096    try (ResultScanner scanner = table.getScanner(scan)) {
097      scanner.next();
098    }
099
100    List<LogEntry> entries = admin.getLogEntries(server, "LARGE_LOG", ServerType.REGION_SERVER, 100,
101      Collections.emptyMap());
102
103    assertEquals(1, entries.size());
104
105    OnlineLogRecord record = (OnlineLogRecord) entries.get(0);
106
107    assertTrue(record.getBlockBytesScanned() >= 100,
108      "expected " + record.getBlockBytesScanned() + " to be >= 100");
109    assertTrue(record.getResponseSize() < 100,
110      "expected " + record.getResponseSize() + " to be < 100");
111    assertTrue(record.getFsReadTime() > 0, "expected " + record.getFsReadTime() + " to be > 0");
112  }
113}