001/*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.regionserver;
020
021import java.util.List;
022import java.util.Map;
023
024import org.apache.hadoop.hbase.wal.AbstractWALRoller;
025import org.apache.hadoop.hbase.wal.WAL;
026import org.apache.yetus.audience.InterfaceAudience;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
031
032/**
033 * Runs periodically to determine if the WAL should be rolled.
034 *
035 * NOTE: This class extends Thread rather than Chore because the sleep time
036 * can be interrupted when there is something to do, rather than the Chore
037 * sleep time which is invariant.
038 *
039 * TODO: change to a pool of threads
040 */
041@InterfaceAudience.Private
042@VisibleForTesting
043public class LogRoller extends AbstractWALRoller<RegionServerServices> {
044  private static final Logger LOG = LoggerFactory.getLogger(LogRoller.class);
045
046  public LogRoller(RegionServerServices services) {
047    super("LogRoller", services.getConfiguration(), services);
048  }
049
050  protected void scheduleFlush(String encodedRegionName, List<byte[]> families) {
051    RegionServerServices services = this.abortable;
052    HRegion r = (HRegion) services.getRegion(encodedRegionName);
053    if (r == null) {
054      LOG.warn("Failed to schedule flush of {}, because it is not online on us", encodedRegionName);
055      return;
056    }
057    FlushRequester requester = services.getFlushRequester();
058    if (requester == null) {
059      LOG.warn("Failed to schedule flush of {}, region={}, because FlushRequester is null",
060        encodedRegionName, r);
061      return;
062    }
063    // flush specified stores to clean old logs
064    requester.requestFlush(r, families, FlushLifeCycleTracker.DUMMY);
065  }
066
067  @VisibleForTesting
068  Map<WAL, Boolean> getWalNeedsRoll() {
069    return this.walNeedsRoll;
070  }
071}