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 
20 #include <string>
21 
22 #pragma once
23 
24 struct DocKey;
25 
26 namespace Collections {
27 namespace VB {
28 
29 /**
30  * The ScanContext holds important data required when visits all of the keys of
31  * a vbucket (as part of compaction or a DCP backfill).
32  *
33  * When scanning historical data, the separator may not be the same value as the
34  * current separator, the ScanContext provides methods so that collections can
35  * correctly look at a historical key and break it into collection & key using
36  * the separator in force for that historical key.
37  */
38 class ScanContext {
39 public:
ScanContext()40     ScanContext() : separator(DefaultSeparator) {
41     }
42 
43     /**
44      * Manage the context's separator. If the DocKey is a system event for a
45      * changed separator, then we will update the context and return true.
46      *
47      * @return true if the separator was updated
48      */
49     bool manageSeparator(const ::DocKey& key);
50 
getSeparator() const51     const std::string& getSeparator() const {
52         return separator;
53     }
54 
55 private:
56     std::string separator;
57 };
58 } // end VB
59 } // end Collections