MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / seek

Method seek

core/cube/cube-api/src/cube_api.cpp:124–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124int CubeAPI::seek(const std::string& dict_name,
125 const uint64_t& key,
126 CubeValue* val) {
127 if (_meta == NULL) {
128 LOG(ERROR) << "seek, meta is null";
129 return -1;
130 }
131
132 MetaInfo* info = _meta->get_meta(dict_name);
133
134 if (info == NULL) {
135 LOG(ERROR) << "get meta [" << dict_name << "] failed";
136 return -1;
137 }
138
139 int shard_id = key % info->shard_num;
140 DictRequest req;
141 DictResponse res;
142
143 req.add_keys(key);
144
145 ::brpc::Channel* chan = info->cube_conn[shard_id];
146
147 DictService_Stub* stub = new DictService_Stub(chan);
148 brpc::Controller* cntl = new ::brpc::Controller();
149
150 stub->seek(cntl, &req, &res, NULL);
151
152 int ret = CubeError::E_OK;
153 if (cntl->Failed()) {
154 info->cube_rpcfail_num << 1;
155
156 val->error = CubeError::E_SEEK_FAILED;
157 val->buff.assign("");
158
159 ret = CubeError::E_ALL_SEEK_FAILED;
160 LOG(WARNING) << "cube seek from shard [" << shard_id << "] failed ["
161 << cntl->ErrorText() << "]";
162 } else if (res.values().size() > 0) {
163 DictValue* res_val = res.mutable_values(0);
164 if (static_cast<int>(res_val->status()) == CubeError::E_NO_SUCH_KEY) {
165 g_cube_keys_miss_num << 1;
166 }
167 val->error = res_val->status();
168 val->buff.swap(*res_val->mutable_value());
169 } else {
170 val->error = CubeError::E_SEEK_FAILED;
171 val->buff.assign("");
172 ret = CubeError::E_ALL_SEEK_FAILED;
173 }
174 info->cube_request_num << 1;
175 g_cube_keys_num << 1;
176
177 // cleanup
178 delete stub;
179 stub = NULL;
180 delete cntl;
181 cntl = NULL;

Callers 2

runFunction · 0.45
opt_seekMethod · 0.45

Calls 8

get_metaMethod · 0.80
statusMethod · 0.80
push_backMethod · 0.80
JoinClass · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
ClearMethod · 0.45
versionMethod · 0.45

Tested by

no test coverage detected