org.apache.jackrabbit.oak.plugins.document.VersionGCSupport Maven / Gradle / Ivy
/*
* 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.jackrabbit.oak.plugins.document;
import static com.google.common.collect.Iterables.filter;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getAllDocuments;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getSelectedDocuments;
import java.util.Set;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType;
import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
import com.google.common.base.Predicate;
public class VersionGCSupport {
private final DocumentStore store;
public VersionGCSupport(DocumentStore store) {
this.store = store;
}
public Iterable getPossiblyDeletedDocs(final long lastModifiedTime) {
return filter(getSelectedDocuments(store, NodeDocument.DELETED_ONCE, 1), new Predicate() {
@Override
public boolean apply(NodeDocument input) {
return input.wasDeletedOnce() && !input.hasBeenModifiedSince(lastModifiedTime);
}
});
}
public void deleteSplitDocuments(Set gcTypes,
long oldestRevTimeStamp,
VersionGCStats stats) {
stats.splitDocGCCount += createCleanUp(gcTypes, oldestRevTimeStamp, stats)
.disconnect()
.deleteSplitDocuments();
}
protected SplitDocumentCleanUp createCleanUp(Set gcTypes,
long oldestRevTimeStamp,
VersionGCStats stats) {
return new SplitDocumentCleanUp(store, stats,
identifyGarbage(gcTypes, oldestRevTimeStamp));
}
protected Iterable identifyGarbage(final Set gcTypes,
final long oldestRevTimeStamp) {
return filter(getAllDocuments(store), new Predicate() {
@Override
public boolean apply(NodeDocument doc) {
return gcTypes.contains(doc.getSplitDocType())
&& doc.hasAllRevisionLessThan(oldestRevTimeStamp);
}
});
}
}