1dea18910SJim Walker/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2dea18910SJim Walker/*
3dea18910SJim Walker *     Copyright 2017 Couchbase, Inc
4dea18910SJim Walker *
5dea18910SJim Walker *   Licensed under the Apache License, Version 2.0 (the "License");
6dea18910SJim Walker *   you may not use this file except in compliance with the License.
7dea18910SJim Walker *   You may obtain a copy of the License at
8dea18910SJim Walker *
9dea18910SJim Walker *       http://www.apache.org/licenses/LICENSE-2.0
10dea18910SJim Walker *
11dea18910SJim Walker *   Unless required by applicable law or agreed to in writing, software
12dea18910SJim Walker *   distributed under the License is distributed on an "AS IS" BASIS,
13dea18910SJim Walker *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dea18910SJim Walker *   See the License for the specific language governing permissions and
15dea18910SJim Walker *   limitations under the License.
16dea18910SJim Walker */
17dea18910SJim Walker
18dea18910SJim Walker#include "collections/eraser_context.h"
19dea18910SJim Walker#include "collections/collections_dockey.h"
20dea18910SJim Walker#include "collections/collections_types.h"
21dea18910SJim Walker#include "item.h"
22dea18910SJim Walker#include "systemevent.h"
23dea18910SJim Walker#include "vbucket.h"
24dea18910SJim Walker
25dea18910SJim Walker#include <iostream>
26dea18910SJim Walker
27dea18910SJim Walkernamespace Collections {
28dea18910SJim Walkernamespace VB {
29dea18910SJim Walker
30dea18910SJim Walkerbool EraserContext::manageSeparator(const ::DocKey& key) {
31dea18910SJim Walker    if (ScanContext::manageSeparator(key)) {
32dea18910SJim Walker        // If the last key is valid, save it in the list of keys which will
33dea18910SJim Walker        // be deleted at the end of erasing process.
34dea18910SJim Walker        if (!lastSeparatorChangeKey.empty()) {
35dea18910SJim Walker            staleSeparatorChangeKeys.push_back(lastSeparatorChangeKey);
36dea18910SJim Walker        }
37dea18910SJim Walker
38dea18910SJim Walker        // Now save this new key
39dea18910SJim Walker        lastSeparatorChangeKey = key;
40dea18910SJim Walker        return true;
41dea18910SJim Walker    }
42dea18910SJim Walker    return false;
43dea18910SJim Walker}
44dea18910SJim Walker
45dea18910SJim Walkervoid EraserContext::processKeys(VBucket& vb) {
46dea18910SJim Walker    for (auto& key : staleSeparatorChangeKeys) {
47dea18910SJim Walker        auto item = SystemEventFactory::make(
48dea18910SJim Walker                key, SystemEvent::CollectionsSeparatorChanged);
49dea18910SJim Walker        item->setDeleted();
50dea18910SJim Walker        vb.queueItem(item.release(), {});
51dea18910SJim Walker    }
52dea18910SJim Walker}
53dea18910SJim Walker
54dea18910SJim Walker} // end VB
55dea18910SJim Walker} // end Collections