|
18 | 18 | */
|
19 | 19 | package org.apache.hadoop.hbase.regionserver;
|
20 | 20 |
|
| 21 | +import com.google.common.annotations.VisibleForTesting; |
| 22 | +import com.google.common.base.Optional; |
| 23 | +import com.google.common.base.Preconditions; |
| 24 | +import com.google.common.collect.Iterables; |
| 25 | +import com.google.common.collect.Lists; |
| 26 | +import com.google.common.collect.Maps; |
| 27 | +import com.google.common.collect.Sets; |
| 28 | +import com.google.common.io.Closeables; |
| 29 | +import com.google.protobuf.ByteString; |
| 30 | +import com.google.protobuf.Descriptors; |
| 31 | +import com.google.protobuf.Message; |
| 32 | +import com.google.protobuf.RpcCallback; |
| 33 | +import com.google.protobuf.RpcController; |
| 34 | +import com.google.protobuf.Service; |
| 35 | +import com.google.protobuf.TextFormat; |
| 36 | + |
21 | 37 | import java.io.EOFException;
|
22 | 38 | import java.io.FileNotFoundException;
|
23 | 39 | import java.io.IOException;
|
|
187 | 203 | import org.apache.htrace.Trace;
|
188 | 204 | import org.apache.htrace.TraceScope;
|
189 | 205 |
|
190 |
| -import com.google.common.annotations.VisibleForTesting; |
191 |
| -import com.google.common.base.Optional; |
192 |
| -import com.google.common.base.Preconditions; |
193 |
| -import com.google.common.collect.Lists; |
194 |
| -import com.google.common.collect.Maps; |
195 |
| -import com.google.common.io.Closeables; |
196 |
| -import com.google.protobuf.ByteString; |
197 |
| -import com.google.protobuf.Descriptors; |
198 |
| -import com.google.protobuf.Message; |
199 |
| -import com.google.protobuf.RpcCallback; |
200 |
| -import com.google.protobuf.RpcController; |
201 |
| -import com.google.protobuf.Service; |
202 |
| -import com.google.protobuf.TextFormat; |
203 |
| - |
204 | 206 | @InterfaceAudience.Private
|
205 | 207 | public class HRegion implements HeapSize, PropagatingConfigurationObserver, Region {
|
206 | 208 | private static final Log LOG = LogFactory.getLog(HRegion.class);
|
@@ -4033,7 +4035,7 @@ private void removeNonExistentColumnFamilyForReplay(
|
4033 | 4035 | if (nonExistentList != null) {
|
4034 | 4036 | for (byte[] family : nonExistentList) {
|
4035 | 4037 | // Perhaps schema was changed between crash and replay
|
4036 |
| - LOG.info("No family for " + Bytes.toString(family) + " omit from reply."); |
| 4038 | + LOG.info("No family for " + Bytes.toString(family) + " omit from replay."); |
4037 | 4039 | familyMap.remove(family);
|
4038 | 4040 | }
|
4039 | 4041 | }
|
@@ -4146,62 +4148,76 @@ protected long replayRecoveredEditsIfAny(Map<byte[], Long> maxSeqIdInStores,
|
4146 | 4148 | minSeqIdForTheRegion = maxSeqIdInStore;
|
4147 | 4149 | }
|
4148 | 4150 | }
|
4149 |
| - long seqid = minSeqIdForTheRegion; |
| 4151 | + long seqId = minSeqIdForTheRegion; |
4150 | 4152 |
|
4151 | 4153 | FileSystem walFS = getWalFileSystem();
|
4152 |
| - Path regionDir = getWALRegionDir(); |
4153 | 4154 | FileSystem rootFS = getFilesystem();
|
4154 |
| - Path defaultRegionDir = getRegionDir(FSUtils.getRootDir(conf), getRegionInfo()); |
| 4155 | + Path regionDir = FSUtils.getRegionDirFromRootDir(FSUtils.getRootDir(conf), getRegionInfo()); |
| 4156 | + Path regionWALDir = getWALRegionDir(); |
| 4157 | + Path wrongRegionWALDir = FSUtils.getWrongWALRegionDir(conf, getRegionInfo().getTable(), |
| 4158 | + getRegionInfo().getEncodedName()); |
4155 | 4159 |
|
| 4160 | + // We made a mistake in HBASE-20734 so we need to do this dirty hack... |
| 4161 | + NavigableSet<Path> filesUnderWrongRegionWALDir = |
| 4162 | + WALSplitter.getSplitEditFilesSorted(walFS, wrongRegionWALDir); |
| 4163 | + seqId = Math.max(seqId, replayRecoveredEditsForPaths(minSeqIdForTheRegion, walFS, |
| 4164 | + filesUnderWrongRegionWALDir, reporter, regionDir)); |
4156 | 4165 | // This is to ensure backwards compatability with HBASE-20723 where recovered edits can appear
|
4157 | 4166 | // under the root dir even if walDir is set.
|
4158 |
| - NavigableSet<Path> filesUnderRootDir = null; |
4159 |
| - if (!regionDir.equals(defaultRegionDir)) { |
4160 |
| - filesUnderRootDir = |
4161 |
| - WALSplitter.getSplitEditFilesSorted(rootFS, defaultRegionDir); |
4162 |
| - seqid = Math.max(seqid, |
4163 |
| - replayRecoveredEditsForPaths(minSeqIdForTheRegion, rootFS, filesUnderRootDir, reporter, |
4164 |
| - defaultRegionDir)); |
4165 |
| - } |
4166 |
| - NavigableSet<Path> files = WALSplitter.getSplitEditFilesSorted(walFS, regionDir); |
4167 |
| - seqid = Math.max(seqid, replayRecoveredEditsForPaths(minSeqIdForTheRegion, walFS, |
4168 |
| - files, reporter, regionDir)); |
4169 |
| - |
4170 |
| - if (seqid > minSeqIdForTheRegion) { |
| 4167 | + NavigableSet<Path> filesUnderRootDir = Sets.newTreeSet(); |
| 4168 | + if (!regionWALDir.equals(regionDir)) { |
| 4169 | + filesUnderRootDir = WALSplitter.getSplitEditFilesSorted(rootFS, regionDir); |
| 4170 | + seqId = Math.max(seqId, replayRecoveredEditsForPaths(minSeqIdForTheRegion, rootFS, |
| 4171 | + filesUnderRootDir, reporter, regionDir)); |
| 4172 | + } |
| 4173 | + NavigableSet<Path> files = WALSplitter.getSplitEditFilesSorted(walFS, regionWALDir); |
| 4174 | + seqId = Math.max(seqId, replayRecoveredEditsForPaths(minSeqIdForTheRegion, walFS, |
| 4175 | + files, reporter, regionWALDir)); |
| 4176 | + if (seqId > minSeqIdForTheRegion) { |
4171 | 4177 | // Then we added some edits to memory. Flush and cleanup split edit files.
|
4172 |
| - internalFlushcache(null, seqid, stores.values(), status, false); |
| 4178 | + internalFlushcache(null, seqId, stores.values(), status, false); |
4173 | 4179 | }
|
4174 |
| - // Now delete the content of recovered edits. We're done w/ them. |
4175 |
| - if (files.size() > 0 && this.conf.getBoolean("hbase.region.archive.recovered.edits", false)) { |
| 4180 | + // Now delete the content of recovered edits. We're done w/ them. |
| 4181 | + if (conf.getBoolean("hbase.region.archive.recovered.edits", false)) { |
4176 | 4182 | // For debugging data loss issues!
|
4177 | 4183 | // If this flag is set, make use of the hfile archiving by making recovered.edits a fake
|
4178 | 4184 | // column family. Have to fake out file type too by casting our recovered.edits as storefiles
|
4179 |
| - String fakeFamilyName = WALSplitter.getRegionDirRecoveredEditsDir(regionDir).getName(); |
4180 |
| - Set<StoreFile> fakeStoreFiles = new HashSet<>(files.size()); |
4181 |
| - for (Path file: files) { |
4182 |
| - fakeStoreFiles.add( |
4183 |
| - new StoreFile(walFS, file, this.conf, null, null)); |
| 4185 | + String fakeFamilyName = WALSplitter.getRegionDirRecoveredEditsDir(regionWALDir).getName(); |
| 4186 | + Set<StoreFile> fakeStoreFiles = new HashSet<>(); |
| 4187 | + for (Path file: Iterables.concat(files, filesUnderWrongRegionWALDir)) { |
| 4188 | + fakeStoreFiles.add(new StoreFile(walFS, file, conf, null, null)); |
| 4189 | + } |
| 4190 | + for (Path file: filesUnderRootDir) { |
| 4191 | + fakeStoreFiles.add(new StoreFile(rootFS, file, conf, null, null)); |
4184 | 4192 | }
|
4185 | 4193 | getRegionWALFileSystem().removeStoreFiles(fakeFamilyName, fakeStoreFiles);
|
4186 | 4194 | } else {
|
4187 |
| - if (filesUnderRootDir != null) { |
4188 |
| - for (Path file : filesUnderRootDir) { |
4189 |
| - if (!rootFS.delete(file, false)) { |
4190 |
| - LOG.error("Failed delete of {} under root directory." + file); |
4191 |
| - } else { |
4192 |
| - LOG.debug("Deleted recovered.edits root directory file=" + file); |
4193 |
| - } |
| 4195 | + for (Path file : filesUnderRootDir) { |
| 4196 | + if (!rootFS.delete(file, false)) { |
| 4197 | + LOG.error("Failed delete of " + file + " from under the root directory"); |
| 4198 | + } else { |
| 4199 | + LOG.debug("Deleted recovered.edits under root directory, file=" + file); |
4194 | 4200 | }
|
4195 | 4201 | }
|
4196 |
| - for (Path file: files) { |
| 4202 | + for (Path file : Iterables.concat(files, filesUnderWrongRegionWALDir)) { |
4197 | 4203 | if (!walFS.delete(file, false)) {
|
4198 | 4204 | LOG.error("Failed delete of " + file);
|
4199 | 4205 | } else {
|
4200 | 4206 | LOG.debug("Deleted recovered.edits file=" + file);
|
4201 | 4207 | }
|
4202 | 4208 | }
|
4203 | 4209 | }
|
4204 |
| - return seqid; |
| 4210 | + |
| 4211 | + // We have replayed all the recovered edits. Let's delete the wrong directories introduced |
| 4212 | + // in HBASE-20734, see HBASE-22617 for more details. |
| 4213 | + FileSystem walFs = getWalFileSystem(); |
| 4214 | + if (walFs.exists(wrongRegionWALDir)) { |
| 4215 | + if (!walFs.delete(wrongRegionWALDir, true)) { |
| 4216 | + LOG.warn("Unable to delete " + wrongRegionWALDir); |
| 4217 | + } |
| 4218 | + } |
| 4219 | + |
| 4220 | + return seqId; |
4205 | 4221 | }
|
4206 | 4222 |
|
4207 | 4223 | private long replayRecoveredEditsForPaths(long minSeqIdForTheRegion, FileSystem fs,
|
@@ -7023,34 +7039,6 @@ public static void addRegionToMETA(final HRegion meta, final HRegion r) throws I
|
7023 | 7039 | meta.put(row, HConstants.CATALOG_FAMILY, cells);
|
7024 | 7040 | }
|
7025 | 7041 |
|
7026 |
| - /** |
7027 |
| - * Computes the Path of the HRegion |
7028 |
| - * |
7029 |
| - * @param tabledir qualified path for table |
7030 |
| - * @param name ENCODED region name |
7031 |
| - * @return Path of HRegion directory |
7032 |
| - * @deprecated For tests only; to be removed. |
7033 |
| - */ |
7034 |
| - @Deprecated |
7035 |
| - public static Path getRegionDir(final Path tabledir, final String name) { |
7036 |
| - return new Path(tabledir, name); |
7037 |
| - } |
7038 |
| - |
7039 |
| - /** |
7040 |
| - * Computes the Path of the HRegion |
7041 |
| - * |
7042 |
| - * @param rootdir qualified path of HBase root directory |
7043 |
| - * @param info HRegionInfo for the region |
7044 |
| - * @return qualified path of region directory |
7045 |
| - * @deprecated For tests only; to be removed. |
7046 |
| - */ |
7047 |
| - @Deprecated |
7048 |
| - @VisibleForTesting |
7049 |
| - public static Path getRegionDir(final Path rootdir, final HRegionInfo info) { |
7050 |
| - return new Path( |
7051 |
| - FSUtils.getTableDir(rootdir, info.getTable()), info.getEncodedName()); |
7052 |
| - } |
7053 |
| - |
7054 | 7042 | /**
|
7055 | 7043 | * Determines if the specified row is within the row range specified by the
|
7056 | 7044 | * specified HRegionInfo
|
|
0 commit comments