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/collections_types.h"
19dea18910SJim Walker#include "collections/scan_context.h"
20dea18910SJim Walker#include "storeddockey.h"
21dea18910SJim Walker
22dea18910SJim Walker#include <vector>
23dea18910SJim Walker
24dea18910SJim Walkerclass VBucket;
25dea18910SJim Walker
26dea18910SJim Walker#pragma once
27dea18910SJim Walker
28dea18910SJim Walkernamespace Collections {
29dea18910SJim Walkernamespace VB {
30dea18910SJim Walker
31dea18910SJim Walker/**
32dea18910SJim Walker * The EraserContext holds important data that the erasing process requires
33dea18910SJim Walker * as it visits all of the keys of a vbucket (as part of compaction).
34dea18910SJim Walker * For example it tracks defunct collection separator keys (so the can be
35dea18910SJim Walker * purged).
36dea18910SJim Walker */
37dea18910SJim Walkerclass EraserContext : public ScanContext {
38dea18910SJim Walkerpublic:
39dea18910SJim Walker    EraserContext() : staleSeparatorChangeKeys(0), lastSeparatorChangeKey() {
40dea18910SJim Walker    }
41dea18910SJim Walker
42dea18910SJim Walker    /**
43dea18910SJim Walker     * Manage the context's separator. If the DocKey is a system event for a
44dea18910SJim Walker     * changed separator, then we will update the context and return true.
45dea18910SJim Walker     *
46dea18910SJim Walker     * @return true if the separator was updated
47dea18910SJim Walker     */
48dea18910SJim Walker    bool manageSeparator(const ::DocKey& key);
49dea18910SJim Walker
50dea18910SJim Walker    /**
51dea18910SJim Walker     * Function used to delete the staleSeparatorKeys.
52dea18910SJim Walker     * @param vb The vbucket to issue deletes against for each key in
53dea18910SJim Walker     *        staleSeparatorKeys
54dea18910SJim Walker     */
55dea18910SJim Walker    void processKeys(VBucket& vb);
56dea18910SJim Walker
57dea18910SJim Walkerprivate:
58dea18910SJim Walker    /// A list of separator change keys which can be deleted
59dea18910SJim Walker    std::vector<StoredDocKey> staleSeparatorChangeKeys;
60dea18910SJim Walker    StoredDocKey lastSeparatorChangeKey;
61dea18910SJim Walker};
62dea18910SJim Walker} // end VB
63dea18910SJim Walker} // end Collections