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 daibing.db
17 * \date Jun 2021
18 * \brief Interface of AiTheta Index Closet
19 */
20
21#ifndef __AITHETA2_INDEX_SUMMARY_H__
22#define __AITHETA2_INDEX_SUMMARY_H__
23
24#include "index_context.h"
25#include "index_helper.h"
26#include "index_provider.h"
27#include "index_stats.h"
28
29namespace aitheta2 {
30
31/*! Index Closet
32 */
33class IndexCloset : public IndexModule {
34 public:
35 //! Index Closet Pointer
36 typedef std::shared_ptr<IndexCloset> Pointer;
37
38 //! Destructor
39 virtual ~IndexCloset(void) {}
40
41 //! Initialize the closet
42 virtual int init(const IndexParams &params) = 0;
43
44 //! Cleanup the closet
45 virtual int cleanup(void) = 0;
46
47 //! Open a closet index from storage
48 virtual int open(IndexStorage::Pointer stg) = 0;
49
50 //! Close closet index
51 virtual int close(void) = 0;
52
53 //! Flush closet index
54 virtual int flush(uint64_t check_point) = 0;
55
56 //! Put a document and retrieve the local index
57 virtual int append(const void *data, size_t len, uint64_t *index) = 0;
58
59 //! Delete the document by local index
60 virtual int erase(uint64_t index) = 0;
61
62 //! Fetch a document via a local index
63 virtual int fetch(uint64_t index, std::string *out) const = 0;
64
65 //! Update the document via a local index
66 virtual int update(uint64_t index, const void *data, size_t len) = 0;
67
68 //! Retrieve the count of index
69 virtual uint64_t count(void) const = 0;
70
71 //! Dump closet index into storage
72 virtual int dump(const IndexDumper::Pointer &dumper) = 0;
73};
74
75/*! Index Immutable Closet
76 */
77class IndexImmutableCloset : public IndexModule {
78 public:
79 //! Index Closet Searcher Pointer
80 typedef std::shared_ptr<IndexImmutableCloset> Pointer;
81
82 //! Destructor
83 virtual ~IndexImmutableCloset(void) {}
84
85 //! Initialize the closet
86 virtual int init(const IndexParams &params) = 0;
87
88 //! Cleanup the closet
89 virtual int cleanup(void) = 0;
90
91 //! Open a closet index from storage
92 virtual int load(IndexContainer::Pointer cntr) = 0;
93
94 //! Close closet index
95 virtual int unload(void) = 0;
96
97 //! Fetch a document via a local index
98 virtual int fetch(uint64_t index, std::string *out) const = 0;
99
100 //! Retrieve the count of index
101 virtual uint64_t count(void) const = 0;
102};
103
104
105} // namespace aitheta2
106
107#endif // __AITHETA2_INDEX_CLOSET_H__
108