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 */ 019 020package org.apache.hadoop.hbase.mob; 021 022import java.io.Closeable; 023import java.io.IOException; 024 025import org.apache.hadoop.hbase.Cell; 026import org.apache.hadoop.hbase.regionserver.StoreFileScanner; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * The MobCell will maintain a {@link Cell} and a {@link StoreFileScanner} inside. Now, the mob cell 031 * is backend by NIO ByteBuffers which are allocated from ByteBuffAllocator, so we cannot just read 032 * the cell and close the MOB file scanner because the MOB file scanner closing will deallocate the 033 * NIO ByteBuffers, which resulting memory leak. 034 * <p> 035 * Actually, the right solution is: <br> 036 * 1. Read the normal cell; <br> 037 * 2. Parse the value of normal cell and get MOB fileName,offset,length; <br> 038 * 3. Open scanner to read the mob value; <br> 039 * 4. Construct the response cell whose key is from the normal cell and value is from the mob cell. 040 * <br> 041 * 5. Ship the response cell to HBase client. <br> 042 * 6. Release both normal cell's block and mob cell's block. <br> 043 * <p> 044 * For mob cell, the block releasing just means closing the the mob scanner, so here we need to keep 045 * the {@link StoreFileScanner} inside and close only when we're ensure that the MobCell has been 046 * shipped to RPC client. 047 */ 048@InterfaceAudience.Private 049public class MobCell implements Closeable { 050 051 private final Cell cell; 052 private final StoreFileScanner sfScanner; 053 054 public MobCell(Cell cell) { 055 this.cell = cell; 056 this.sfScanner = null; 057 } 058 059 public MobCell(Cell cell, StoreFileScanner sfScanner) { 060 this.cell = cell; 061 this.sfScanner = sfScanner; 062 } 063 064 public Cell getCell() { 065 return cell; 066 } 067 068 @Override 069 public void close() throws IOException { 070 if (this.sfScanner != null) { 071 this.sfScanner.close(); 072 } 073 } 074}