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.regionserver;
019
020import java.util.List;
021import java.util.Map;
022import org.apache.hadoop.hbase.wal.AbstractWALRoller;
023import org.apache.hadoop.hbase.wal.WAL;
024import org.apache.yetus.audience.InterfaceAudience;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027
028/**
029 * Runs periodically to determine if the WAL should be rolled. NOTE: This class extends Thread
030 * rather than Chore because the sleep time can be interrupted when there is something to do, rather
031 * than the Chore sleep time which is invariant. TODO: change to a pool of threads
032 */
033@InterfaceAudience.Private
034public class LogRoller extends AbstractWALRoller<RegionServerServices> {
035  private static final Logger LOG = LoggerFactory.getLogger(LogRoller.class);
036
037  public LogRoller(RegionServerServices services) {
038    super("LogRoller", services.getConfiguration(), services);
039  }
040
041  protected void scheduleFlush(String encodedRegionName, List<byte[]> families) {
042    RegionServerServices services = this.abortable;
043    HRegion r = (HRegion) services.getRegion(encodedRegionName);
044    if (r == null) {
045      LOG.warn("Failed to schedule flush of {}, because it is not online on us", encodedRegionName);
046      return;
047    }
048    FlushRequester requester = services.getFlushRequester();
049    if (requester == null) {
050      LOG.warn("Failed to schedule flush of {}, region={}, because FlushRequester is null",
051        encodedRegionName, r);
052      return;
053    }
054    // flush specified stores to clean old logs
055    requester.requestFlush(r, families, FlushLifeCycleTracker.DUMMY);
056  }
057
058  Map<WAL, RollController> getWalNeedsRoll() {
059    return this.wals;
060  }
061}