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.storefiletracker; 019 020import java.io.IOException; 021import java.util.Collection; 022import java.util.List; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.regionserver.StoreContext; 025import org.apache.hadoop.hbase.regionserver.StoreFileInfo; 026import org.apache.yetus.audience.InterfaceAudience; 027 028import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; 029 030/** 031 * A store file tracker used for migrating between store file tracker implementations. 032 */ 033@InterfaceAudience.Private 034class MigrationStoreFileTracker extends StoreFileTrackerBase { 035 036 public static final String SRC_IMPL = "hbase.store.file-tracker.migration.src.impl"; 037 038 public static final String DST_IMPL = "hbase.store.file-tracker.migration.dst.impl"; 039 040 private final StoreFileTrackerBase src; 041 042 private final StoreFileTrackerBase dst; 043 044 public MigrationStoreFileTracker(Configuration conf, boolean isPrimaryReplica, StoreContext ctx) { 045 super(conf, isPrimaryReplica, ctx); 046 this.src = StoreFileTrackerFactory.createForMigration(conf, SRC_IMPL, isPrimaryReplica, ctx); 047 this.dst = StoreFileTrackerFactory.createForMigration(conf, DST_IMPL, isPrimaryReplica, ctx); 048 Preconditions.checkArgument(!src.getClass().equals(dst.getClass()), 049 "src and dst is the same: %s", src.getClass()); 050 } 051 052 @Override 053 public List<StoreFileInfo> load() throws IOException { 054 List<StoreFileInfo> files = src.load(); 055 dst.set(files); 056 return files; 057 } 058 059 @Override 060 public boolean requireWritingToTmpDirFirst() { 061 // Returns true if either of the two StoreFileTracker returns true. 062 // For example, if we want to migrate from a tracker implementation which can ignore the broken 063 // files under data directory to a tracker implementation which can not, if we still allow 064 // writing in tmp directory directly, we may have some broken files under the data directory and 065 // then after we finally change the implementation which can not ignore the broken files, we 066 // will be in trouble. 067 return src.requireWritingToTmpDirFirst() || dst.requireWritingToTmpDirFirst(); 068 } 069 070 @Override 071 protected void doAddNewStoreFiles(Collection<StoreFileInfo> newFiles) throws IOException { 072 src.doAddNewStoreFiles(newFiles); 073 dst.doAddNewStoreFiles(newFiles); 074 } 075 076 @Override 077 protected void doAddCompactionResults(Collection<StoreFileInfo> compactedFiles, 078 Collection<StoreFileInfo> newFiles) throws IOException { 079 src.doAddCompactionResults(compactedFiles, newFiles); 080 dst.doAddCompactionResults(compactedFiles, newFiles); 081 } 082 083 @Override 084 public void set(List<StoreFileInfo> files) { 085 throw new UnsupportedOperationException( 086 "Should not call this method on " + getClass().getSimpleName()); 087 } 088 089 static Class<? extends StoreFileTracker> getSrcTrackerClass(Configuration conf) { 090 return StoreFileTrackerFactory.getStoreFileTrackerClassForMigration(conf, SRC_IMPL); 091 } 092 093 static Class<? extends StoreFileTracker> getDstTrackerClass(Configuration conf) { 094 return StoreFileTrackerFactory.getStoreFileTrackerClassForMigration(conf, DST_IMPL); 095 } 096}