taklwu commented on a change in pull request #2931: URL: https://github.com/apache/hbase/pull/2931#discussion_r585250257
########## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/PersistedStoreFileManager.java ########## @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.CellComparator; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration; +import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; +import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; +import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSortedSet; +import org.apache.hbase.thirdparty.com.google.common.collect.Iterables; +import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils; + +/** + * A Storefile manager that is used by {@link PersistedStoreEngine} that persists the in-memory + * storefile tracking to a persistent table hbase:storefile. + * + * We don't override the {@link #clearFiles()} from {@link DefaultStoreFileManager} and persist + * in-memory storefiles tracking, it will be reused when region reassigns on a different + * region server. + */ [email protected] +public class PersistedStoreFileManager extends DefaultStoreFileManager { + private static final Logger LOG = LoggerFactory.getLogger(PersistedStoreFileManager.class); + private final RegionInfo regionInfo; + private final String tableName; + private final String regionName; + private final String storeName; + private StoreFilePathAccessor accessor; + private Configuration conf; + // only uses for warmupHRegion + private boolean readOnly; + + public PersistedStoreFileManager(CellComparator cellComparator, + Comparator<HStoreFile> storeFileComparator, Configuration conf, + CompactionConfiguration compactionConfiguration, HRegionFileSystem regionFs, + RegionInfo regionInfo, String familyName, StoreFilePathAccessor accessor, boolean readOnly) { + super(cellComparator, storeFileComparator, conf, compactionConfiguration, regionFs, familyName); + this.conf = conf; + this.regionInfo = regionInfo; + this.tableName = regionInfo.getTable().getNameAsString(); + this.regionName = regionInfo.getEncodedName(); + this.storeName = familyName; + this.accessor = accessor; + this.readOnly = readOnly; + } + + public PersistedStoreFileManager(CellComparator cellComparator, + Comparator<HStoreFile> storeFileComparator, Configuration conf, + CompactionConfiguration compactionConfiguration, HRegionFileSystem regionFs, + RegionInfo regionInfo, String familyName, StoreFilePathAccessor accessor) { + this(cellComparator, storeFileComparator, conf, compactionConfiguration, regionFs, regionInfo, + familyName, accessor, false); + } + + /** + * Loads the specified storeFiles to the StoreFileManager to be included in reads. + * + * @param storeFiles list of storefiles to be loaded, could be an empty list. throws exception + * if it's null. + */ + @Override + public void loadFiles(List<HStoreFile> storeFiles) throws IOException { + Preconditions.checkArgument(storeFiles != null, "store files cannot be " + + "null when loading"); + if (storeFiles.isEmpty()) { + LOG.warn("Other than fresh region with no store files, store files should not be empty"); + return; + } + ImmutableList<HStoreFile> sortedStorefiles = + ImmutableList.sortedCopyOf(getStoreFileComparator(), storeFiles); + setStorefiles(sortedStorefiles); + updatePathListToTracker(StoreFilePathUpdate.builder().withStoreFiles(sortedStorefiles).build()); + } + + @Override + public Collection<StoreFileInfo> loadInitialFiles() throws IOException { + List<Path> pathList = accessor.getIncludedStoreFilePaths(tableName, regionName, storeName); + boolean isEmptyInPersistedFilePaths = CollectionUtils.isEmpty(pathList); Review comment: IMO this is the cleanest by looking up the table for this store, and if the result is empty, it's definitely uninitialized because we don't allow writing empty list for a given store. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
