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