fix RetryCacheCleaner throw OutOfMemoryError
@@ -912,6 +912,7 @@ void startActiveServices() throws IOException {
if(isRetryCacheEnabled) {
this.retryCacheCleanerThread = new Daemon(new RetryCacheCleaner());
+ this.retryCacheCleanerThread.setName("retry cache cleane");
retryCacheCleanerThread.start();
}
@@ -8486,6 +8487,7 @@ public void run() {
int numRun = 0;
while (fsRunning && shouldCacheCleanerRun) {
try {
+ long start = Time.monotonicNow();
final List<CacheEntry> toRemove = new ArrayList<>();
int num = retryCache.getToRemove().drainTo(toRemove);
if (num > 0) {
@@ -8499,17 +8501,24 @@ public void acquireLock(TransactionLocks locks) throws IOException {
@Override
public Object performTask() throws IOException {
- for (CacheEntry entry : toRemove) {
+ int i = 0;
+ Iterator<CacheEntry> it = toRemove.iterator();
+ while (it.hasNext() && i<100) {
+ CacheEntry entry = it.next();
if (EntityManager.find(RetryCacheEntry.Finder.ByClientIdAndCallId, entry.getClientId(), entry.
getCallId()) != null) {
EntityManager.remove(new RetryCacheEntry(entry.getClientId(), entry.getCallId()));
}
+ i++;
+ it.remove();
}
return null;
}
};
+ while(!toRemove.isEmpty()){
rh.handle();
}
+ }
if (isLeader() && numRun % 60 == 0) {
new LightWeightRequestHandler(
@@ -8525,9 +8534,12 @@ public Object performTask() throws IOException {
}.handle();
}
- Thread.sleep(1000);
+ long pause = 1000-(Time.monotonicNow()-start);
+ if(pause>0){
+ Thread.sleep(pause);
+ }
numRun++;
- } catch (Exception e) {
+ } catch (Throwable e) {
FSNamesystem.LOG.error("Exception in RetryCacheCleaner: ", e);
}
}
