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 guonix
17 * \date Oct 2020
18 * \brief
19 */
20
21#pragma once
22
23#include <vector>
24#include <ailego/encoding/uri.h>
25#include "meta_types.h"
26
27namespace proxima {
28namespace be {
29namespace meta {
30
31//! Predefine class
32class MetaStore;
33//! Alias for MetaStore
34using MetaStorePtr = std::shared_ptr<MetaStore>;
35
36
37//! Alias for object allocator
38using CollectionAllocator = std::function<CollectionObject *()>;
39using ColumnAllocator = std::function<ColumnObject *()>;
40using DatabaseRepositoryAllocator = std::function<DatabaseRepositoryObject *()>;
41
42/*!
43 * Meta store
44 */
45class MetaStore {
46 public:
47 //! Destructor
48 virtual ~MetaStore() = default;
49
50 public:
51 //! initialize metastore
52 virtual int initialize(const ailego::Uri *uri) = 0;
53
54 //! cleanup
55 virtual int cleanup() = 0;
56
57 /** CRUD of CollectionObject **/
58 //! Create the collection
59 virtual int create_collection(const CollectionObject &collection) = 0;
60
61 //! Update collection by id, all field should be updated except id(most of
62 // them was identical)
63 virtual int update_collection(const CollectionObject &collection) = 0;
64
65 //! Delete collection
66 virtual int delete_collection(const std::string &name) = 0;
67
68 //! Delete collection
69 virtual int delete_collection_by_uuid(const std::string &name) = 0;
70
71 //! Retrieve all collections
72 virtual int list_collections(CollectionAllocator allocator) const = 0;
73
74 /** CRUD of ColumnObject **/
75 //! Create column
76 virtual int create_column(const ColumnObject &column) = 0;
77
78 //! Delete columns
79 virtual int delete_columns_by_uid(const std::string &uid) = 0;
80
81 //! Delete columns
82 virtual int delete_columns_by_uuid(const std::string &uuid) = 0;
83
84 //! Retrieve all collections
85 virtual int list_columns(ColumnAllocator allocator) const = 0;
86
87 /** CRUD of RepositoryObject **/
88 //! Create repository
89 virtual int create_repository(const DatabaseRepositoryObject &repository) = 0;
90
91 //! Delete repositories
92 virtual int delete_repositories_by_uid(const std::string &uid) = 0;
93
94 //! Delete repositories
95 virtual int delete_repositories_by_uuid(const std::string &uuid) = 0;
96
97 //! Retrieve all repositories
98 virtual int list_repositories(
99 DatabaseRepositoryAllocator allocator) const = 0;
100
101 //! Flush all changes to storage
102 virtual int flush() const = 0;
103};
104
105
106} // namespace meta
107} // namespace be
108} // namespace proxima
109