[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-28 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r738496846



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
##
@@ -1895,6 +1900,22 @@ private void initializeThreads() {
   this.storefileRefresher = new 
StorefileRefresherChore(storefileRefreshPeriod,
   onlyMetaRefresh, this, this);
 }
+
+int fileBasedStoreFileCleanerPeriod  = conf.getInt(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_PERIOD,
+  FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_PERIOD);
+int fileBasedStoreFileCleanerDelay  = conf.getInt(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_DELAY,
+  FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY);
+double fileBasedStoreFileCleanerDelayJitter = conf.getDouble(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_DELAY_JITTER,
+  
FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY_JITTER);
+double jitterRate = (RandomUtils.nextDouble() - 0.5D) * 
fileBasedStoreFileCleanerDelayJitter;
+long jitterValue = Math.round(fileBasedStoreFileCleanerDelay * jitterRate);

Review comment:
   If you feel it's cleaner this way, I'm ok with that.




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

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-28 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r738440217



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/Compactor.java
##
@@ -537,4 +547,17 @@ protected InternalScanner createScanner(HStore store, 
ScanInfo scanInfo,
 return new StoreScanner(store, scanInfo, scanners, smallestReadPoint, 
earliestPutTs,
 dropDeletesFromRow, dropDeletesToRow);
   }
+
+  public List getCompactionTargets(){
+if (writer == null){

Review comment:
   I'm ok with that.




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

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-28 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r738419886



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/FileBasedStoreFileCleaner.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 org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.io.HFileLink;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.ipc.RemoteException;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This Chore, every time it runs, will clear the unsused HFiles in the data
+ * folder.
+ */
+@InterfaceAudience.Private public class FileBasedStoreFileCleaner extends 
ScheduledChore {
+  private static final Logger LOG = 
LoggerFactory.getLogger(FileBasedStoreFileCleaner.class);
+  public static final String FILEBASED_STOREFILE_CLEANER_ENABLED =
+  "hbase.region.filebased.storefilecleaner.enabled";
+  public static final boolean DEFAULT_FILEBASED_STOREFILE_CLEANER_ENABLED = 
false;
+  public static final String FILEBASED_STOREFILE_CLEANER_TTL =
+  "hbase.region.filebased.storefilecleaner.ttl";
+  public static final long DEFAULT_FILEBASED_STOREFILE_CLEANER_TTL = 1000 * 60 
* 60 * 12; //12h
+  public static final String FILEBASED_STOREFILE_CLEANER_DELAY =
+  "hbase.region.filebased.storefilecleaner.delay";
+  public static final int DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY = 1000 * 
60 * 60 * 2; //2h
+  public static final String FILEBASED_STOREFILE_CLEANER_DELAY_JITTER =
+  "hbase.region.filebased.storefilecleaner.delay.jitter";
+  public static final double DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY_JITTER 
= 0.25D;
+  public static final String FILEBASED_STOREFILE_CLEANER_PERIOD =
+  "hbase.region.filebased.storefilecleaner.period";
+  public static final int DEFAULT_FILEBASED_STOREFILE_CLEANER_PERIOD = 1000 * 
60 * 60 * 6; //6h
+
+  private HRegionServer regionServer;
+  private final AtomicBoolean enabled = new AtomicBoolean(true);
+  private long ttl;
+
+  public FileBasedStoreFileCleaner(final int delay, final int period, final 
Stoppable stopper, Configuration conf,
+  HRegionServer regionServer) {
+super("FileBasedStoreFileCleaner", stopper, period, delay);
+this.regionServer = regionServer;
+setEnabled(conf.getBoolean(FILEBASED_STOREFILE_CLEANER_ENABLED, 
DEFAULT_FILEBASED_STOREFILE_CLEANER_ENABLED));
+ttl = conf.getLong(FILEBASED_STOREFILE_CLEANER_TTL, 
DEFAULT_FILEBASED_STOREFILE_CLEANER_TTL);
+  }
+
+  public boolean setEnabled(final boolean enabled) {
+return this.enabled.getAndSet(enabled);
+  }
+
+  public boolean getEnabled() {
+return this.enabled.get();
+  }
+
+  @InterfaceAudience.Private
+  @Override public void chore() {
+if (getEnabled()) {
+  long start = EnvironmentEdgeManager.currentTime();
+  AtomicLong deletedFiles = new AtomicLong(0);
+  AtomicLong failedDeletes = new AtomicLong(0);
+  for (HRegion region : regionServer.getRegions()) {
+for (HStore store : region.getStores()) {
+  //only clean do cleanup in store using file based storefile tracking
+  if (store.getStoreEngine().requireWritingToTmpDirFirst()) {
+continue;
+  }
+  Path storePath =
+  new Path(region.getRegionFileSystem().getRegionDir(), 
store.getColumnFamilyName());
+
+  try {
+List fsStoreFiles = 
Arrays.asList(region.getRegionFileSystem().fs.listStatus(storePath));
+fsStoreFiles.forEach(file -> cleanFileIfNeeded(file, store, 
deletedFiles, failedDeletes));
+  } catch (IOException e) {
+LOG.warn("Failed to list files in 

[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-26 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r736329025



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/Compactor.java
##
@@ -537,4 +547,17 @@ protected InternalScanner createScanner(HStore store, 
ScanInfo scanInfo,
 return new StoreScanner(store, scanInfo, scanners, smallestReadPoint, 
earliestPutTs,
 dropDeletesFromRow, dropDeletesToRow);
   }
+
+  public List getCompactionTargets(){
+if (writer == null){

Review comment:
   > I would prefer to put the writer reset call to HStore in doCompaction, 
just after the replaceStoreFiles call.
   
   So move `commitWriter` call out of `Compactor.compact`? Or do you plan to 
move the nulling of write to a `resetWriter` method?
   
   >  It would have the downside that StoreEngine has to expose the reset 
method, but I would argue moving it any lower on the call chain would just 
involve additional complications ( being called during replayCompactionMarker, 
handling different StoreEngine implementations )
   
   Yeah, looks like your suggestion is less complex, and you have an idea of 
the impacts, so I  just trust your judgement.




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

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-26 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r736316274



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
##
@@ -1895,6 +1900,22 @@ private void initializeThreads() {
   this.storefileRefresher = new 
StorefileRefresherChore(storefileRefreshPeriod,
   onlyMetaRefresh, this, this);
 }
+
+int fileBasedStoreFileCleanerPeriod  = conf.getInt(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_PERIOD,
+  FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_PERIOD);
+int fileBasedStoreFileCleanerDelay  = conf.getInt(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_DELAY,
+  FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY);
+double fileBasedStoreFileCleanerDelayJitter = conf.getDouble(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_DELAY_JITTER,
+  
FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY_JITTER);
+double jitterRate = (RandomUtils.nextDouble() - 0.5D) * 
fileBasedStoreFileCleanerDelayJitter;
+long jitterValue = Math.round(fileBasedStoreFileCleanerDelay * jitterRate);

Review comment:
   Yeah, since we already pass the Configuration and these are all specific 
for this Cleaner itself, I think it's better to move it out of HRegionServer 
scope.




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

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-26 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r736315277



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/FileBasedStoreFileCleaner.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 org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.io.HFileLink;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.ipc.RemoteException;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This Chore, every time it runs, will clear the unsused HFiles in the data
+ * folder.
+ */
+@InterfaceAudience.Private public class FileBasedStoreFileCleaner extends 
ScheduledChore {

Review comment:
   Just another name suggestion: "LeftoversStoreFileCleaner"... Up to you, 
@BukrosSzabolcs !




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

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-26 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r736312453



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/Compactor.java
##
@@ -348,8 +353,14 @@ private InternalScanner 
postCompactScannerOpen(CompactionRequestImpl request, Sc
 smallestReadPoint = Math.min(fd.minSeqIdToKeep, smallestReadPoint);
 cleanSeqId = true;
   }
+  if (writer != null){
+LOG.warn("Writer exists when it should not: " + 
getCompactionTargets().stream()
+  .map(n -> n.toString())
+  .collect(Collectors.joining(", ", "{ ", " }")));
+writer = null;

Review comment:
   I agree with the WARN, what I meant is that we don't need to explicitly 
set it to null in line #360, when we just go and set it again on line #362.




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

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] wchevreuil commented on a change in pull request #3786: HBASE-26271: Cleanup the broken store files under data directory

2021-10-25 Thread GitBox


wchevreuil commented on a change in pull request #3786:
URL: https://github.com/apache/hbase/pull/3786#discussion_r735493337



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
##
@@ -1895,6 +1900,22 @@ private void initializeThreads() {
   this.storefileRefresher = new 
StorefileRefresherChore(storefileRefreshPeriod,
   onlyMetaRefresh, this, this);
 }
+
+int fileBasedStoreFileCleanerPeriod  = conf.getInt(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_PERIOD,
+  FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_PERIOD);
+int fileBasedStoreFileCleanerDelay  = conf.getInt(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_DELAY,
+  FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY);
+double fileBasedStoreFileCleanerDelayJitter = conf.getDouble(
+  FileBasedStoreFileCleaner.FILEBASED_STOREFILE_CLEANER_DELAY_JITTER,
+  
FileBasedStoreFileCleaner.DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY_JITTER);
+double jitterRate = (RandomUtils.nextDouble() - 0.5D) * 
fileBasedStoreFileCleanerDelayJitter;
+long jitterValue = Math.round(fileBasedStoreFileCleanerDelay * jitterRate);

Review comment:
   Can we move all these properties initialisation to the Cleaner 
constructor itself?

##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/Compactor.java
##
@@ -348,8 +353,14 @@ private InternalScanner 
postCompactScannerOpen(CompactionRequestImpl request, Sc
 smallestReadPoint = Math.min(fd.minSeqIdToKeep, smallestReadPoint);
 cleanSeqId = true;
   }
+  if (writer != null){
+LOG.warn("Writer exists when it should not: " + 
getCompactionTargets().stream()
+  .map(n -> n.toString())
+  .collect(Collectors.joining(", ", "{ ", " }")));
+writer = null;

Review comment:
   Do we need this? We are setting the writer in the next line...

##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/FileBasedStoreFileCleaner.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 org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.io.HFileLink;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.ipc.RemoteException;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This Chore, every time it runs, will clear the unsused HFiles in the data
+ * folder.
+ */
+@InterfaceAudience.Private public class FileBasedStoreFileCleaner extends 
ScheduledChore {
+  private static final Logger LOG = 
LoggerFactory.getLogger(FileBasedStoreFileCleaner.class);
+  public static final String FILEBASED_STOREFILE_CLEANER_ENABLED =
+  "hbase.region.filebased.storefilecleaner.enabled";
+  public static final boolean DEFAULT_FILEBASED_STOREFILE_CLEANER_ENABLED = 
false;
+  public static final String FILEBASED_STOREFILE_CLEANER_TTL =
+  "hbase.region.filebased.storefilecleaner.ttl";
+  public static final long DEFAULT_FILEBASED_STOREFILE_CLEANER_TTL = 1000 * 60 
* 60 * 12; //12h
+  public static final String FILEBASED_STOREFILE_CLEANER_DELAY =
+  "hbase.region.filebased.storefilecleaner.delay";
+  public static final int DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY = 1000 * 
60 * 60 * 2; //2h
+  public static final String FILEBASED_STOREFILE_CLEANER_DELAY_JITTER =
+  "hbase.region.filebased.storefilecleaner.delay.jitter";
+  public static final double DEFAULT_FILEBASED_STOREFILE_CLEANER_DELAY_JITTER 
= 0.25D;
+  public static final String FILEBASED_STOREFILE_CLEANER_PERIOD =
+