Files
scylladb/streaming/stream_transfer_task.cc
Asias He 14ae9e66ae streaming: Use shared_ptr to track back to stream_session
I tried our lw_shared_ptr, the compiler complained endless usage of
incomplete type stream_session. I can not include stream_session.hh
everywhere due to circular dependency.

For now, I'm using std::shared_ptr which works fine.
2015-07-14 20:41:14 +08:00

69 lines
2.5 KiB
C++

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Modified by Cloudius Systems.
* Copyright 2015 Cloudius Systems.
*/
#include "streaming/stream_detail.hh"
#include "streaming/stream_transfer_task.hh"
#include "streaming/stream_session.hh"
#include "streaming/messages/outgoing_file_message.hh"
#include "mutation_reader.hh"
#include "frozen_mutation.hh"
#include "mutation.hh"
#include "message/messaging_service.hh"
namespace streaming {
stream_transfer_task::stream_transfer_task(std::shared_ptr<stream_session> session, UUID cf_id)
: stream_task(session, cf_id) {
}
stream_transfer_task::~stream_transfer_task() = default;
void stream_transfer_task::add_transfer_file(stream_detail detail) {
assert(cf_id == detail.cf_id);
auto message = messages::outgoing_file_message(sequence_number++, std::move(detail), session->keep_ss_table_level());
auto size = message.header.size();
auto seq = message.header.sequence_number;
files.emplace(seq, std::move(message));
total_size += size;
}
void stream_transfer_task::start() {
using shard_id = net::messaging_service::shard_id;
using net::messaging_verb;
for (auto& x : files) {
auto& seq = x.first;
auto& msg = x.second;
auto id = shard_id{session->peer, 0};
do_with(std::move(id), [this, seq, &msg] (shard_id& id) {
return consume(msg.detail.mr, [this, seq, &id, &msg] (mutation&& m) {
auto fm = make_lw_shared<const frozen_mutation>(m);
return session->ms().send_message<void>(messaging_verb::STREAM_MUTATION, id, *fm, session->dst_cpu_id).then([this, fm] {
return stop_iteration::no;
});
});
}).then([this, seq] {
this->complete(seq);
});
}
}
} // namespace streaming