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.io.hfile.bucket; 019 020import java.io.IOException; 021import java.nio.ByteBuffer; 022import org.apache.hadoop.hbase.io.hfile.Cacheable; 023import org.apache.hadoop.hbase.nio.ByteBuff; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * A class implementing IOEngine interface supports data services for {@link BucketCache}. 028 */ 029@InterfaceAudience.Private 030public interface IOEngine { 031 /** Returns true if persistent storage is supported for the cache when shutdown */ 032 boolean isPersistent(); 033 034 /** 035 * IOEngine uses shared memory means, when reading Cacheable from it, those refers to the same 036 * memory area as used by the Engine for caching it. 037 * @return true when IOEngine using shared memory. 038 */ 039 default boolean usesSharedMemory() { 040 return false; 041 } 042 043 /** 044 * Transfers data from IOEngine to a Cacheable object. 045 * @param be maintains an (offset,len,refCnt) inside. 046 * @return Cacheable which will wrap the NIO ByteBuffers from IOEngine. 047 * @throws IOException when any IO error happen 048 * @throws IllegalArgumentException when the length of the ByteBuff read is less than 'len' 049 */ 050 Cacheable read(BucketEntry be) throws IOException; 051 052 /** 053 * Transfers data from the given byte buffer to IOEngine 054 * @param srcBuffer the given byte buffer from which bytes are to be read 055 * @param offset The offset in the IO engine where the first byte to be written n 056 */ 057 void write(ByteBuffer srcBuffer, long offset) throws IOException; 058 059 /** 060 * Transfers the data from the given MultiByteBuffer to IOEngine 061 * @param srcBuffer the given MultiBytebufffers from which bytes are to be read 062 * @param offset the offset in the IO engine where the first byte to be written n 063 */ 064 void write(ByteBuff srcBuffer, long offset) throws IOException; 065 066 /** 067 * Sync the data to IOEngine after writing n 068 */ 069 void sync() throws IOException; 070 071 /** 072 * Shutdown the IOEngine 073 */ 074 void shutdown(); 075}