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 Nov 2020
18 * \brief
19 */
20
21#include "equal_task.h"
22#include "common/error_code.h"
23
24namespace proxima {
25namespace be {
26namespace query {
27
28EqualTask::EqualTask(index::SegmentPtr segment, QueryKeyContext *context)
29 : BthreadTask("EqualTask"),
30 hit_count_(0),
31 segment_(std::move(segment)),
32 context_(context) {}
33
34EqualTask::~EqualTask() = default;
35
36uint32_t EqualTask::hit() const {
37 return hit_count_;
38}
39
40const index::QueryResult &EqualTask::forward() const {
41 return forward_;
42}
43
44int EqualTask::do_run() {
45 if (!segment_ || !context_) {
46 return PROXIMA_BE_ERROR_CODE(InvalidSegment);
47 }
48 // Invoke kv_search with segment
49 int code = segment_->kv_search(context_->primary_key(), &forward_);
50 if (code == 0 && forward_.primary_key != index::INVALID_KEY) {
51 hit_count_ = 1;
52 }
53
54 return code;
55}
56
57} // namespace query
58} // namespace be
59} // namespace proxima
60