apurtell commented on a change in pull request #330: HBASE-22617 Recovered WAL 
directories not getting cleaned up
URL: https://github.com/apache/hbase/pull/330#discussion_r296928893
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
 ##########
 @@ -1015,16 +1014,27 @@ private long initializeRegionInternals(final 
CancelableProgressable reporter,
     // (particularly if no recovered edits, seqid will be -1).
     long nextSeqId = maxSeqId + 1;
     if (!isRestoredRegion) {
-      long maxSeqIdFromFile = 
WALSplitUtil.getMaxRegionSequenceId(getWalFileSystem(),
-        getWALRegionDirOfDefaultReplica());
+      // always get openSeqNum from the default replica, even if we are 
secondary replicas
+      long maxSeqIdFromFile = WALSplitUtil.getMaxRegionSequenceId(conf,
+        RegionReplicaUtil.getRegionInfoForDefaultReplica(getRegionInfo()), 
this::getFilesystem,
+        this::getWalFileSystem);
       nextSeqId = Math.max(maxSeqId, maxSeqIdFromFile) + 1;
       // The openSeqNum will always be increase even for read only region, as 
we rely on it to
-      // determine whether a region has been successfully reopend, so here we 
always need to update
+      // determine whether a region has been successfully reopened, so here we 
always need to update
       // the max sequence id file.
       if (RegionReplicaUtil.isDefaultReplica(getRegionInfo())) {
         LOG.debug("writing seq id for {}", 
this.getRegionInfo().getEncodedName());
         WALSplitUtil.writeRegionSequenceIdFile(getWalFileSystem(), 
getWALRegionDir(),
           nextSeqId - 1);
+        // This means we have replayed all the recovered edits and also 
written out the max sequence
+        // id file, let's delete the wrong directories introduced in 
HBASE-20734, see HBASE-22617
+        // for more details.
+        Path wrongRegionWALDir = FSUtils.getWrongWALRegionDir(conf, 
getRegionInfo().getTable(),
+          getRegionInfo().getEncodedName());
+        FileSystem walFs = getWalFileSystem();
+        if (walFs.exists(wrongRegionWALDir)) {
+          walFs.delete(wrongRegionWALDir, true);
 
 Review comment:
   Please log at DEBUG if delete fails

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to