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 java.util.List;
import java.util.Set;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType;
public class VersionGCSupport {
private final DocumentStore store;
public VersionGCSupport(DocumentStore store) {
this.store = store;
}
public Iterable getPossiblyDeletedDocs(final long lastModifiedTime) {
return Iterables.filter(getAllDocuments(), new Predicate() {
@Override
public boolean apply(NodeDocument input) {
return input.wasDeletedOnce() && !input.hasBeenModifiedSince(lastModifiedTime);
}
});
}
public int deleteSplitDocuments(Set gcTypes, long oldestRevTimeStamp) {
List docsToDelete = Lists.newArrayList();
for(NodeDocument doc : getAllDocuments()){
SplitDocType splitType = doc.getSplitDocType();
if(gcTypes.contains(splitType) && doc.hasAllRevisionLessThan(oldestRevTimeStamp)){
docsToDelete.add(doc.getId());
}
}
store.remove(Collection.NODES, docsToDelete);
return docsToDelete.size();
}
private List getAllDocuments() {
//Fetch all documents.
return store.query(Collection.NODES,NodeDocument.MIN_ID_VALUE,
NodeDocument.MAX_ID_VALUE, Integer.MAX_VALUE);
}
}