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/eraser_context.h"
19 #include "collections/collections_dockey.h"
20 #include "collections/collections_types.h"
21 #include "item.h"
22 #include "systemevent.h"
23 #include "vbucket.h"
24 
25 #include <iostream>
26 
27 namespace Collections {
28 namespace VB {
29 
manageSeparator(const ::DocKey& key)30 bool EraserContext::manageSeparator(const ::DocKey& key) {
31     if (ScanContext::manageSeparator(key)) {
32         // If the last key is valid, save it in the list of keys which will
33         // be deleted at the end of erasing process.
34         if (!lastSeparatorChangeKey.empty()) {
35             staleSeparatorChangeKeys.push_back(lastSeparatorChangeKey);
36         }
37 
38         // Now save this new key
39         lastSeparatorChangeKey = key;
40         return true;
41     }
42     return false;
43 }
44 
processKeys(VBucket& vb)45 void EraserContext::processKeys(VBucket& vb) {
46     for (auto& key : staleSeparatorChangeKeys) {
47         auto item = SystemEventFactory::make(
48                 key, SystemEvent::CollectionsSeparatorChanged);
49         item->setDeleted();
50         vb.queueItem(item.release(), {});
51     }
52 }
53 
54 } // end VB
55 } // end Collections