1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright 2017 Couchbase, Inc 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * 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 #include "collections/collections_types.h" 19 #include "collections/scan_context.h" 20 #include "storeddockey.h" 21 22 #include <vector> 23 24 class VBucket; 25 26 #pragma once 27 28 namespace Collections { 29 namespace VB { 30 31 /** 32 * The EraserContext holds important data that the erasing process requires 33 * as it visits all of the keys of a vbucket (as part of compaction). 34 * For example it tracks defunct collection separator keys (so the can be 35 * purged). 36 */ 37 class EraserContext : public ScanContext { 38 public: EraserContext()39 EraserContext() : staleSeparatorChangeKeys(0), lastSeparatorChangeKey() { 40 } 41 42 /** 43 * Manage the context's separator. If the DocKey is a system event for a 44 * changed separator, then we will update the context and return true. 45 * 46 * @return true if the separator was updated 47 */ 48 bool manageSeparator(const ::DocKey& key); 49 50 /** 51 * Function used to delete the staleSeparatorKeys. 52 * @param vb The vbucket to issue deletes against for each key in 53 * staleSeparatorKeys 54 */ 55 void processKeys(VBucket& vb); 56 57 private: 58 /// A list of separator change keys which can be deleted 59 std::vector<StoredDocKey> staleSeparatorChangeKeys; 60 StoredDocKey lastSeparatorChangeKey; 61 }; 62 } // end VB 63 } // end Collections