Runs through the log removing segments older than a certain age

@throws IOException
173114
private void cleanupLogs() throws IOException {
        logger.trace("Beginning log cleanup...");
        int total = 0;
        Iterator<Log> iter = getLogIterator();
        long startMs = System.currentTimeMillis();
        while (iter.hasNext()) {
            Log log = iter.next();
            total += cleanupExpiredSegments(log) + cleanupSegmentsToMaintainSize(log);
        }
        if (total > 0) {
            logger.warn("Log cleanup completed. " + total + " files deleted in " + (System.currentTimeMillis() - startMs) / 1000 + " seconds");
        } else {
            logger.trace("Log cleanup completed. " + total + " files deleted in " + (System.currentTimeMillis() - startMs) / 1000 + " seconds");
        }
    }
1262823
@Override
    public void run() {
        try {
            int maxEvents = PropertyManager.getIntegerProperty(PropertyNames.UNSCHEDULED_EVENTS_BATCH_SIZE, 100);
            if (maxEvents == 0 && hasRun) // indicates only run at startup (old behavior)
                return;
            int minAge = PropertyManager.getIntegerProperty(PropertyNames.UNSCHEDULED_EVENTS_MIN_AGE, 3600);
            if (minAge < 300) {
                logger.severe(PropertyNames.UNSCHEDULED_EVENTS_MIN_AGE + " cannot be less than 300 (5 minutes)");
                minAge = 300;
            }

            long curTime = DatabaseAccess.getCurrentTime();
            Date olderThan = new Date(curTime - minAge*1000);
            Date now = new Date(curTime);
            logger.log(LogLevel.TRACE, "Processing unscheduled events older than " + olderThan + " at: " + now);
            int count = processUnscheduledEvents(olderThan, maxEvents);
            if (count > 0)
                logger.log(LogLevel.INFO, "Processing " + count + " unscheduled events at " + new Date(DatabaseAccess.getCurrentTime()));
        }
        catch (Throwable t) {
            logger.severeException(t.getMessage(), t);
        }
    }
297205
public void flush() throws IOException {
        if (unflushed.get() == 0) return;

        synchronized (lock) {
            if (logger.isTraceEnabled()) {
                logger.debug("Flushing log '" + name + "' last flushed: " + getLastFlushedTime() + " current time: " + System
                        .currentTimeMillis());
            }
            segments.getLastView().getMessageSet().flush();
            unflushed.set(0);
            lastflushedTime.set(System.currentTimeMillis());
        }
    }
975431
private void fixBacklog() throws IOException {
            try {
                writers.values().parallelStream()
                        .forEach(groupWriter -> {
                            try {
                                groupWriter.fixBacklog(timestamps.size());
                            } catch (IOException ex) {
                                throw new RuntimeIOException(ex);
                            }
                        });
            } catch (RuntimeIOException ex) {
                throw ex.getEx();
            }
        }
984160
private void moveFromTempToPerm() throws IOException {
    try {
      FileStatus[] fileStatus =
          localFs.listStatus(temp, LuceneIndexFileNameFilter.getFilter());
      Path segmentsPath = null;
      Path segmentsGenPath = null;

      // move the files created in temp dir except segments_N and segments.gen
      for (int i = 0; i < fileStatus.length; i++) {
        Path path = fileStatus[i].getPath();
        String name = path.getName();

        if (LuceneUtil.isSegmentsGenFile(name)) {
          assert (segmentsGenPath == null);
          segmentsGenPath = path;
        } else if (LuceneUtil.isSegmentsFile(name)) {
          assert (segmentsPath == null);
          segmentsPath = path;
        } else {
          fs.completeLocalOutput(new Path(perm, name), path);
        }
      }

      // move the segments_N file
      if (segmentsPath != null) {
        fs.completeLocalOutput(new Path(perm, segmentsPath.getName()),
            segmentsPath);
      }

      // move the segments.gen file
      if (segmentsGenPath != null) {
        fs.completeLocalOutput(new Path(perm, segmentsGenPath.getName()),
            segmentsGenPath);
      }
    } finally {
      // finally delete the temp dir (files should have been deleted)
      localFs.delete(temp);
    }
  }
1315937
public void purgeLogsOlderThan(final long minTxIdToKeep) {
    synchronized (this) {
      // synchronized to prevent findbugs warning about inconsistent
      // synchronization. This will be JIT-ed out if asserts are
      // off.
      assert curSegmentTxId == HdfsConstants.INVALID_TXID || // on format this
                                                             // is no-op
          minTxIdToKeep <= curSegmentTxId : "cannot purge logs older than txid "
          + minTxIdToKeep + " when current segment starts at " + curSegmentTxId;
      try {
        journalSet.purgeLogsOlderThan(minTxIdToKeep);
      } catch (IOException ex) {
        // All journals have failed, it will be handled in logSync.
      }

    }
  }
1173073
public void clearExpired() {
		Iterator keys = cacheLineTable.keySet().iterator();

		while (keys.hasNext()) {
			Object key = keys.next();

			if (hasExpired(key)) {
				removeObject(key);
			}
		}
	}
949564
private void cleanup() {
		CacheEntry oldest = null;
		_count = 0;

		// Cleanup obsolete entries and find the oldest
		for (Map.Entry<String, CacheEntry> e : _cache.entrySet()) {
			String key = e.getKey();
			CacheEntry entry = e.getValue();
			// Remove obsolete entry
			if (entry.isExpired()) {
				_cache.remove(key);
			}
			// Count the remaining entry
			else {
				_count++;
				if (oldest == null || oldest.getExpiration() > entry.getExpiration())
					oldest = entry;
			}
		}

		// Remove the oldest if cache size exceeded maximum
		if (_count > _maxSize && oldest != null) {
			_cache.remove(oldest.getKey());
			_count--;
		}
	}
630251
@Override
	public void run()
	{

		try {
			ArchiveManager archives = new ArchiveManager();
			ArticleReaderInterface articleReader = null;
			ArchiveDescription description = null;
			Task<Revision> task = null;
			DiffCalculatorInterface diffCalc;

			if (MODE_STATISTICAL_OUTPUT) {
				diffCalc = new TimedDiffCalculator(new TaskTransmitter());
			}
			else {
				diffCalc = new DiffCalculator(new TaskTransmitter());
			}

			long start, time;

			while (archives.hasArchive()) {


				// Retrieve Archive
				try {
					description = archives.getArchive();

					// initialize filter
					ArticleFilter nameFilter = new ArticleFilter();

					articleReader = InputFactory.getTaskReader(description,
							nameFilter);
					ArticleConsumerLogMessages.logArchiveRetrieved(logger,
							description);

					// Exception while accessing the archive
				}
				catch (ArticleReaderException e) {

					articleReader = null;
					ArticleConsumerLogMessages.logExceptionRetrieveArchive(
							logger, description, e);
				}

				// Process Archive
				while (articleReader != null) {
					try {
						if (articleReader.hasNext()) {

							start = System.currentTimeMillis();
							//read the next article (may be null if filtered)
							task = articleReader.next();
							time = System.currentTimeMillis() - start;

							// task will be null if the name filter removed that
							// article
							if (task == null) {
								continue;
							}

							ArticleConsumerLogMessages
									.logArticleRead(logger, task, time,
											articleReader.getBytePosition());

							start = System.currentTimeMillis();
							//calculate the diff for this article version
							diffCalc.process(task);
							time = System.currentTimeMillis() - start;

							DiffConsumerLogMessages.logArticleProcessed(logger,
									task, time);

						}
						else {
							ArticleConsumerLogMessages.logNoMoreArticles(
									logger, description);
							articleReader = null;
						}

						// Reset current article
					}
					catch (ArticleReaderException e) {

						ArticleConsumerLogMessages.logTaskReaderException(
								logger, e);
						articleReader.resetTaskCompleted();

					}
					catch (DiffException e) {

						DiffConsumerLogMessages.logDiffException(logger, e);
						articleReader.resetTaskCompleted();
						diffCalc.reset();
					}
				}
			}
			diffCalc.closeTransmitter();

			ArticleConsumerLogMessages.logNoMoreArchives(logger);

			// Critical Exceptions
		}
		catch (ConfigurationException e) {
			DiffToolLogMessages.logException(logger, e);
			throw new RuntimeException(e);
		}
		catch (UnsupportedEncodingException e) {
			DiffToolLogMessages.logException(logger, e);
			throw new RuntimeException(e);
		}
		catch (IOException e) {
			DiffToolLogMessages.logException(logger, e);
			throw new RuntimeException(e);
		}
		catch (TimeoutException e) {
			DiffToolLogMessages.logException(logger, e);
			throw new RuntimeException(e);
		}
		catch (Exception e) {
			DiffToolLogMessages.logException(logger, e);
			throw new RuntimeException(e);
		}
	}
601737
protected void prune (long now, List<Entry> history)
    {
        int prunepos = 0;
        for (int ll = history.size(); prunepos < ll; prunepos++) {
            Entry entry = history.get(prunepos);
            if (now - entry.message.timestamp < HISTORY_EXPIRATION) {
                break; // stop when we get to the first valid message
            }
        }
        history.subList(0, prunepos).clear();
    }
321667
private static void deleteOldAndEmptyFiles() {
            File dir = LOG_FILE_DIR;
            if (dir.exists()) {
                File[] files = dir.listFiles();

                for (File f : files) {
                    if (f.length() == 0 ||
                            f.lastModified() + MAXFILEAGE < System.currentTimeMillis()) {
                        f.delete();
                    }
                }
            }
        }
638209
public void cleanup() {
		long currentTime = System.currentTimeMillis();

		// remove entries which have exceeded their time to live
		cachedExecutionGraphs.values().removeIf(
			(ExecutionGraphEntry entry) -> currentTime >= entry.getTTL());
	}
1229686
public synchronized boolean freeSegment(Segment seg) throws IOException {
        if (seg == null)
            return false;

        int segId = seg.getSegmentId();
        if (segId < _segList.size() && _segList.get(segId) == seg) {
            _segList.set(segId, null);
            seg.close(false);
            
            if(segId == (_segList.size() - 1)) {
                try {
                    // Delete last segment.
                    _segList.remove(segId);
                    
                    File segFile = seg.getSegmentFile();
                    if(segFile.exists()) segFile.delete();
                    
                    File sibFile = getSegmentIndexBufferFile(segId);
                    if(sibFile.exists()) sibFile.delete();
                    
                    _log.info("Segment " + seg.getSegmentId() + " deleted");
                } catch(Exception e) {
                    _log.warn("Segment " + seg.getSegmentId() + " not deleted", e);
                }
            } else {
                if (seg.isRecyclable() && recycle(seg)) {
                    _log.info("Segment " + seg.getSegmentId() + " recycled");
                } else {
                    _log.info("Segment " + seg.getSegmentId() + " freed");
                }
            }
            
            return true;
        }
        
        return false;
    }
808420
public void finish() throws IOException 
    {
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"finish", "finish");
        } 
        // PM18453 start
        WebContainerRequestState requestState = WebContainerRequestState.getInstance(false);
        if (requestState != null && (Boolean.valueOf((String)requestState.getAttribute("InputStreamEarlyReadCompleted"))).booleanValue()) {
            if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
                logger.logp(Level.FINE, CLASS_NAME,"finish", "Skip read because data has already been read and destroyed.");
            } 
            total=limit;
        }
        // PM18453 End
        else if (!SRTServletResponse.isSkipInputStreamRead() &&  length != -1 )        {
            // if content length set then skip remaining bytes in message body
            long remaining = limit - total;   // PK79219
            while ( remaining > 0 )
            {
                long n = skip(remaining);   // PM03146
                if ( n == 0 )
                {
                    // begin 280584.3    6021: Cleanup of  defect 280584.2    WAS.webcontainer
                    //logger.logp(Level.SEVERE, CLASS_NAME,"finish", nls.getString("Invalid.Content.Length"));
                    // end 280584.3    6021: Cleanup of  defect 280584.2    WAS.webcontainer
                    throw new IOException(nls.getString("Invalid.Content.Length","Invalid content length"));
                }
                remaining -= n;
            }
        }
    }
737194
public function deleteOldLogs(int $max_age_in_seconds): void
    {
        $timestamp = Carbon::now()->subSeconds($max_age_in_seconds);

        DB::table('log')
            ->whereIn('log_type', ['error', 'media'])
            ->where('log_time', '<', $timestamp)
            ->delete();
    }
499082
public static void cleanObsolete() {
        HandlerThreadFactory.getWriteLogThreadHandler().post(new Runnable() {
            @Override
            public void run() {
                long now = System.currentTimeMillis();
                File[] f = BlockCanaryInternals.getLogFiles();
                if (f != null && f.length > 0) {
                    synchronized (SAVE_DELETE_LOCK) {
                        for (File aF : f) {
                            if (now - aF.lastModified() > OBSOLETE_DURATION) {
                                aF.delete();
                            }
                        }
                    }
                }
            }
        });
    }
584560
public final void clear() throws IOException {
        if ((bufferSize == 0) && (out != null))
            // clear() is illegal after any unbuffered output (JSP.5.5)
             throw new IllegalStateException("jsp.error.ise_on_clear");
        if (flushed)
            throw new IOException("jsp.error.attempt_to_clear_flushed_buffer");
        // defect 312981 begin
        //ensureOpen();
    	if (closed) {
    	    throw new IOException("Stream closed");
        }
        // defect 312981 end
        nextChar = 0;
    }