1/**
2 * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15
16 * \author Haichao.chc
17 * \date Jun 2021
18 * \brief ForwardReader load forward index and provides read ability.
19 */
20
21#pragma once
22
23#include <memory>
24#include "forward_data.h"
25#include "index_provider.h"
26#include "../snapshot.h"
27#include "../typedef.h"
28
29namespace proxima {
30namespace be {
31namespace index {
32
33class ForwardReader;
34using ForwardReaderPtr = std::shared_ptr<ForwardReader>;
35
36/*
37 * ForwardReader load persist forward index, and provides
38 * seek ability.
39 */
40class ForwardReader : public IndexProvider {
41 public:
42 //! Destructor
43 virtual ~ForwardReader() = default;
44
45 public:
46 //! Create an instance and return a shared ptr
47 static ForwardReaderPtr Create(const std::string &collection_name,
48 const std::string &collection_path,
49 SegmentID segment_id);
50
51 public:
52 //! Open and load forward index file
53 virtual int open(const ReadOptions &read_options) = 0;
54
55 //! Close and release forward index file
56 virtual int close() = 0;
57
58 //! Seek a specific doc id
59 virtual int seek(idx_t doc_id, ForwardData *forward_data) = 0;
60
61 public:
62 //! Set min doc id
63 void set_start_doc_id(uint32_t val) {
64 start_doc_id_ = val;
65 }
66
67 //! Get min doc id
68 uint32_t start_doc_id() {
69 return start_doc_id_;
70 }
71
72 private:
73 uint32_t start_doc_id_{0U};
74};
75
76} // end namespace index
77} // namespace be
78} // end namespace proxima
79