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 Oct 2020
18 * \brief Includes some micro definitions and alias using names
19 */
20
21#pragma once
22
23#include <memory>
24#include <string>
25#include <aitheta2/index_framework.h>
26#include "common/error_code.h"
27#include "common/logger.h"
28#include "common/types.h"
29
30namespace proxima {
31namespace be {
32namespace index {
33
34using idx_t = uint64_t;
35using SegmentID = uint32_t;
36
37using IndexStoragePtr = aitheta2::IndexStorage::Pointer;
38using IndexBlockPtr = aitheta2::IndexStorage::Segment::Pointer;
39using IndexDumperPtr = aitheta2::IndexDumper::Pointer;
40using IndexContainerPtr = aitheta2::IndexContainer::Pointer;
41using IndexContextPtr = aitheta2::IndexContext::Pointer;
42using IndexSearcherPtr = aitheta2::IndexSearcher::Pointer;
43using IndexContainerBlockPtr = aitheta2::IndexContainer::Segment::Pointer;
44using IndexStreamerPtr = aitheta2::IndexStreamer::Pointer;
45using ThreadPoolPtr = std::shared_ptr<aitheta2::SingleQueueIndexThreads>;
46using IndexReformerPtr = std::shared_ptr<aitheta2::IndexReformer>;
47using IndexMeasurePtr = std::shared_ptr<aitheta2::IndexMeasure>;
48using IndexConverterPtr = std::shared_ptr<aitheta2::IndexConverter>;
49using IndexClosetPtr = std::shared_ptr<aitheta2::IndexCloset>;
50using IndexImmutableClosetPtr = std::shared_ptr<aitheta2::IndexImmutableCloset>;
51
52using FeatureTypes = aitheta2::IndexMeta::FeatureTypes;
53using IndexBlock = aitheta2::IndexStorage::Segment;
54using IndexMeta = aitheta2::IndexMeta;
55using IndexQueryMeta = aitheta2::IndexQueryMeta;
56using IndexParams = aitheta2::IndexParams;
57using IndexDocumentList = aitheta2::IndexDocumentList;
58using IndexSegmentDumper = aitheta2::IndexSegmentDumper;
59using IndexFactory = aitheta2::IndexFactory;
60using ThreadPool = aitheta2::SingleQueueIndexThreads;
61using IndexStorage = aitheta2::IndexStorage;
62
63} // end namespace index
64} // namespace be
65} // end namespace proxima
66
67#define COLLECTION_FORMAT " collection[%s] "
68
69#define CLOG_DEBUG(format, ...) \
70 LOG_DEBUG(format COLLECTION_FORMAT, ##__VA_ARGS__, collection_name().c_str())
71
72#define CLOG_INFO(format, ...) \
73 LOG_INFO(format COLLECTION_FORMAT, ##__VA_ARGS__, collection_name().c_str())
74
75#define CLOG_WARN(format, ...) \
76 LOG_WARN(format COLLECTION_FORMAT, ##__VA_ARGS__, collection_name().c_str())
77
78#define CLOG_ERROR(format, ...) \
79 LOG_ERROR(format COLLECTION_FORMAT, ##__VA_ARGS__, collection_name().c_str())
80
81#define CLOG_FATAL(format, ...) \
82 LOG_FATAL(format COLLECTION_FORMAT, ##__VA_ARGS__, collection_name().c_str())
83
84
85#define SEGMENT_FORMAT " segment[%zu] collection[%s] "
86
87#define SLOG_DEBUG(format, ...) \
88 LOG_DEBUG(format SEGMENT_FORMAT, ##__VA_ARGS__, (size_t)segment_id(), \
89 collection_name().c_str())
90
91#define SLOG_INFO(format, ...) \
92 LOG_INFO(format SEGMENT_FORMAT, ##__VA_ARGS__, (size_t)segment_id(), \
93 collection_name().c_str())
94
95#define SLOG_WARN(format, ...) \
96 LOG_WARN(format SEGMENT_FORMAT, ##__VA_ARGS__, (size_t)segment_id(), \
97 collection_name().c_str())
98
99#define SLOG_ERROR(format, ...) \
100 LOG_ERROR(format SEGMENT_FORMAT, ##__VA_ARGS__, (size_t)segment_id(), \
101 collection_name().c_str())
102
103#define SLOG_FATAL(format, ...) \
104 LOG_FATAL(format SEGMENT_FORMAT, ##__VA_ARGS__, (size_t)segment_id(), \
105 collection_name().c_str())
106
107#define COLUMN_FORMAT " column[%s] segment[%zu] collection[%s] "
108
109#define LLOG_DEBUG(format, ...) \
110 LOG_DEBUG(format COLUMN_FORMAT, ##__VA_ARGS__, column_name().c_str(), \
111 (size_t)segment_id(), collection_name().c_str())
112
113#define LLOG_INFO(format, ...) \
114 LOG_INFO(format COLUMN_FORMAT, ##__VA_ARGS__, column_name().c_str(), \
115 (size_t)segment_id(), collection_name().c_str())
116
117#define LLOG_WARN(format, ...) \
118 LOG_WARN(format COLUMN_FORMAT, ##__VA_ARGS__, column_name().c_str(), \
119 (size_t)segment_id(), collection_name().c_str())
120
121#define LLOG_ERROR(format, ...) \
122 LOG_ERROR(format COLUMN_FORMAT, ##__VA_ARGS__, column_name().c_str(), \
123 (size_t)segment_id(), collection_name().c_str())
124
125#define LLOG_FATAL(format, ...) \
126 LOG_FATAL(format COLUMN_FORMAT, ##__VA_ARGS__, column_name().c_str(), \
127 (size_t)segment_id(), collection_name().c_str())
128
129#define CHECK_STATUS(status, expect) \
130 if (status != expect) { \
131 LOG_ERROR("Check status failed. status[%d] expect[%d]", status, expect); \
132 return ErrorCode_StatusError; \
133 }
134
135#define CHECK_RETURN(ret, expect_ret) \
136 if (ret != expect_ret) { \
137 return ret; \
138 }
139
140#define CHECK_RETURN_WITH_LOG(ret, expect_ret, format, ...) \
141 if (ret != expect_ret) { \
142 LOG_ERROR(format, ##__VA_ARGS__); \
143 return ret; \
144 }
145
146#define CHECK_RETURN_WITH_CLOG(ret, expect_ret, format, ...) \
147 if (ret != expect_ret) { \
148 CLOG_ERROR(format, ##__VA_ARGS__); \
149 return ret; \
150 }
151
152#define CHECK_RETURN_WITH_SLOG(ret, expect_ret, format, ...) \
153 if (ret != expect_ret) { \
154 SLOG_ERROR(format, ##__VA_ARGS__); \
155 return ret; \
156 }
157
158#define CHECK_RETURN_WITH_LLOG(ret, expect_ret, format, ...) \
159 if (ret != expect_ret) { \
160 LLOG_ERROR(format, ##__VA_ARGS__); \
161 return ret; \
162 }
163