| | |
| | |
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.FileUtils;
|
| | | import com.gitblit.utils.TimeUtils;
|
| | |
|
| | | /**
|
| | | * The GC executor handles periodic garbage collection in repositories.
|
| | |
| | |
|
| | | private final IStoredSettings settings;
|
| | |
|
| | | private AtomicBoolean running = new AtomicBoolean(false);
|
| | | |
| | | private AtomicBoolean forceClose = new AtomicBoolean(false);
|
| | |
|
| | | private final Map<String, GCStatus> gcCache = new ConcurrentHashMap<String, GCStatus>();
|
| | |
| | | */
|
| | | public boolean isReady() {
|
| | | return settings.getBoolean(Keys.git.enableGarbageCollection, false);
|
| | | }
|
| | | |
| | | public boolean isRunning() {
|
| | | return running.get();
|
| | | }
|
| | |
|
| | | public boolean lock(String repositoryName) {
|
| | |
| | | if (!isReady()) {
|
| | | return;
|
| | | }
|
| | | |
| | | running.set(true); |
| | | Date now = new Date();
|
| | |
|
| | | for (String repositoryName : GitBlit.self().getRepositoryList()) {
|
| | |
| | | RepoStatistics stats = gc.getStatistics();
|
| | |
|
| | | // determine if this is a scheduled GC
|
| | | int gcPeriodInDays = TimeUtils.convertFrequencyToMinutes(model.gcPeriod)/(60*24);
|
| | | Calendar cal = Calendar.getInstance();
|
| | | cal.setTime(model.lastGC);
|
| | | cal.set(Calendar.HOUR_OF_DAY, 0);
|
| | | cal.set(Calendar.MINUTE, 0);
|
| | | cal.set(Calendar.SECOND, 0);
|
| | | cal.set(Calendar.MILLISECOND, 0);
|
| | | cal.add(Calendar.DATE, gcPeriodInDays);
|
| | | cal.add(Calendar.DATE, model.gcPeriod);
|
| | | Date gcDate = cal.getTime();
|
| | | boolean shouldCollectGarbage = now.after(gcDate);
|
| | |
|
| | |
| | | logger.debug(MessageFormat.format("GCExecutor released GC lock for {0}", repositoryName));
|
| | | }
|
| | | }
|
| | | |
| | | running.set(false);
|
| | | }
|
| | |
|
| | | private boolean isRepositoryIdle(FileRepository repository) {
|