|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.jackrabbit.oak.plugins.document; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | +/** |
| 23 | + * This class is as a wrapper around DocumentStore that expose two methods used to clean garbage from NODES collection |
| 24 | + * public int remove(Map<String, Long> orphanOrDeletedRemovalMap) |
| 25 | + * public List<NodeDocument> findAndUpdate(List<UpdateOp> updateOpList) |
| 26 | + * When enabled |
| 27 | + * Each method saves the document ID or empty properties names (that will be deleted) to a separate _bin collection as a BinDocument then delegates deletion to DocumentStore |
| 28 | + * |
| 29 | + * When disabled (default) |
| 30 | + * Each method delegates directly to DocumentStore |
| 31 | + */ |
| 32 | +public interface FullGcNodeBin { |
| 33 | + |
| 34 | + static FullGcNodeBin noBin(DocumentStore store) { |
| 35 | + return new FullGcNodeBin() { |
| 36 | + @Override |
| 37 | + public int remove(Map<String, Long> orphanOrDeletedRemovalMap) { |
| 38 | + return store.remove(Collection.NODES, orphanOrDeletedRemovalMap); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public List<NodeDocument> findAndUpdate(List<UpdateOp> updateOpList) { |
| 43 | + return store.findAndUpdate(Collection.NODES, updateOpList); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void setEnabled(boolean value) { |
| 48 | + // no-op |
| 49 | + } |
| 50 | + }; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Remove orphaned or deleted documents from the NODES collection |
| 55 | + * If bin is enabled, the document IDs are saved to the SETTINGS collection with ID prefixed with '/bin/' |
| 56 | + * If document ID cannot be saved then the removal of the document fails |
| 57 | + * If the bin is disabled, the document IDs are directly removed from the NODES collection |
| 58 | + * |
| 59 | + * @param orphanOrDeletedRemovalMap the keys of the documents to remove with the corresponding timestamps |
| 60 | + * @return the number of documents removed |
| 61 | + * @see DocumentStore#remove(Collection, Map) |
| 62 | + */ |
| 63 | + int remove(Map<String, Long> orphanOrDeletedRemovalMap); |
| 64 | + |
| 65 | + /** |
| 66 | + * Performs a conditional update |
| 67 | + * If the bin is enabled, the removed properties are saved to the SETTINGS collection with ID prefixed with '/bin/' and empty value |
| 68 | + * If the document ID and properties cannot be saved then the removal of the property fails |
| 69 | + * If bin is disabled, the removed properties are directly removed from the NODES collection |
| 70 | + * |
| 71 | + * @param updateOpList the update operation List |
| 72 | + * @return the list containing old documents |
| 73 | + * @see DocumentStore#findAndUpdate(Collection, List) |
| 74 | + */ |
| 75 | + List<NodeDocument> findAndUpdate(List<UpdateOp> updateOpList); |
| 76 | + |
| 77 | + /** |
| 78 | + * Enable or disable the bin |
| 79 | + * @param value true to enable, false to disable |
| 80 | + */ |
| 81 | + void setEnabled(boolean value); |
| 82 | +} |
0 commit comments