MCPcopy Create free account
hub / github.com/OpenAtomFoundation/pikiwidb / HandleFileRsyncRequest

Method HandleFileRsyncRequest

src/rsync_server.cc:159–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159void RsyncServerConn::HandleFileRsyncRequest(void* arg) {
160 std::unique_ptr<RsyncServerTaskArg> task_arg(static_cast<RsyncServerTaskArg*>(arg));
161 const std::shared_ptr<RsyncService::RsyncRequest> req = task_arg->req;
162 std::shared_ptr<RsyncServerConn> conn = task_arg->conn;
163
164 std::string db_name = req->db_name();
165 std::string filename = req->file_req().filename();
166 size_t offset = req->file_req().offset();
167 size_t count = req->file_req().count();
168
169 RsyncService::RsyncResponse response;
170 response.set_reader_index(req->reader_index());
171 response.set_code(RsyncService::kOk);
172 response.set_type(RsyncService::kRsyncFile);
173 response.set_db_name(db_name);
174 /*
175 * Since the slot field is written in protobuffer,
176 * slot_id is set to the default value 0 for compatibility
177 * with older versions, but slot_id is not used
178 */
179 response.set_slot_id(0);
180
181 std::string snapshot_uuid;
182 Status s = g_pika_server->GetDumpUUID(db_name, &snapshot_uuid);
183 response.set_snapshot_uuid(snapshot_uuid);
184 if (!s.ok()) {
185 LOG(WARNING) << "rsyncserver get snapshotUUID failed";
186 response.set_code(RsyncService::kErr);
187 RsyncWriteResp(response, conn);
188 return;
189 }
190
191 std::shared_ptr<DB> db = g_pika_server->GetDB(db_name);
192 if (!db) {
193 LOG(WARNING) << "cannot find db for db_name: " << db_name;
194 response.set_code(RsyncService::kErr);
195 RsyncWriteResp(response, conn);
196 }
197
198 const std::string filepath = db->bgsave_info().path + "/" + filename;
199 char* buffer = new char[req->file_req().count() + 1];
200 size_t bytes_read{0};
201 std::string checksum = "";
202 bool is_eof = false;
203 std::shared_ptr<RsyncReader> reader = conn->readers_[req->reader_index()];
204 s = reader->Read(filepath, offset, count, buffer,
205 &bytes_read, &checksum, &is_eof);
206 if (!s.ok()) {
207 response.set_code(RsyncService::kErr);
208 RsyncWriteResp(response, conn);
209 delete []buffer;
210 return;
211 }
212
213 RsyncService::FileResponse* file_resp = response.mutable_file_resp();
214 file_resp->set_data(buffer, bytes_read);
215 file_resp->set_eof(is_eof);
216 file_resp->set_checksum(checksum);

Callers

nothing calls this directly

Calls 12

RsyncWriteRespFunction · 0.70
ReadMethod · 0.65
db_nameMethod · 0.45
filenameMethod · 0.45
offsetMethod · 0.45
countMethod · 0.45
GetDumpUUIDMethod · 0.45
okMethod · 0.45
GetDBMethod · 0.45
bgsave_infoMethod · 0.45
set_countMethod · 0.45
set_offsetMethod · 0.45

Tested by

no test coverage detected