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 */
018
019package org.apache.hadoop.hbase.regionserver;
020
021import java.io.IOException;
022import java.util.List;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.monitoring.MonitoredTask;
025import org.apache.yetus.audience.InterfaceAudience;
026
027/**
028 * A package protected interface for a store flushing.
029 * A store flush context carries the state required to prepare/flush/commit the store's cache.
030 */
031@InterfaceAudience.Private
032interface StoreFlushContext {
033
034  /**
035   * Prepare for a store flush (create snapshot)
036   * Requires pausing writes.
037   * A very short operation.
038   * @return The size of snapshot to flush
039   */
040  MemStoreSize prepare();
041
042  /**
043   * Flush the cache (create the new store file)
044   *
045   * A length operation which doesn't require locking out any function
046   * of the store.
047   *
048   * @throws IOException in case the flush fails
049   */
050  void flushCache(MonitoredTask status) throws IOException;
051
052  /**
053   * Commit the flush - add the store file to the store and clear the
054   * memstore snapshot.
055   *
056   * Requires pausing scans.
057   *
058   * A very short operation
059   *
060   * @return
061   * @throws IOException
062   */
063  boolean commit(MonitoredTask status) throws IOException;
064
065  /**
066   * Similar to commit, but called in secondary region replicas for replaying the
067   * flush cache from primary region. Adds the new files to the store, and drops the
068   * snapshot depending on dropMemstoreSnapshot argument.
069   * @param fileNames names of the flushed files
070   * @param dropMemstoreSnapshot whether to drop the prepared memstore snapshot
071   * @throws IOException
072   */
073  void replayFlush(List<String> fileNames, boolean dropMemstoreSnapshot) throws IOException;
074
075  /**
076   * Abort the snapshot preparation. Drops the snapshot if any.
077   * @throws IOException
078   */
079  void abort() throws IOException;
080
081  /**
082   * Returns the newly committed files from the flush. Called only if commit returns true
083   * @return a list of Paths for new files
084   */
085  List<Path> getCommittedFiles();
086
087  /**
088   * @return the total file size for flush output files, in bytes
089   */
090  long getOutputFileSize();
091}