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