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#include "meta_store_factory.h"
22#include "common/logger.h"
23
24namespace proxima {
25namespace be {
26namespace meta {
27
28MetaStorePtr MetaStoreFactory::create(const char *name,
29 const ailego::Uri *uri) {
30 auto iter = store_cache_.find(name);
31 if (iter != store_cache_.end()) {
32 return iter->second;
33 }
34
35 if (ailego::Factory<MetaStore>::Has(name)) {
36 auto meta = ailego::Factory<MetaStore>::MakeShared(name);
37 if (meta->initialize(uri) == 0) {
38 store_cache_[name] = meta;
39 return meta;
40 } else {
41 LOG_ERROR("Failed to init meta store");
42 }
43 }
44 return nullptr;
45}
46
47} // namespace meta
48} // namespace be
49} // namespace proxima
50