Files
scylladb/streaming/stream_transfer_task.cc
Asias He b7b0aa3318 streaming: Negotiate core to core connection.
In streaming code, we need core to core connection(the second connection
from B to A). That is when node A initiates a stream to node B, it is
possible that node A will transfer data to node B and vice verse, so we
need two connections. When node A creates a tcp connection (within the
messaging_service) to node B, we have a connection ip_a:core_a to
ip_b:core_b. When node B creates a connection to node B, we can not
guarantee it is ip_b:core_b to ip_a:core_a.

Current messaging_service does not support core to core connection yet,
although we use shard_id{ip, cpu_id} as the destination of the message.

We can solve the issue in upper layer. We can pass extra cpu_id as a
user msg.

Node A sends stream_init_message with my_cpu_id = current_cpu_id

Node B receives stream_init_message, it runs on whatever cpu this
connection goes to, then it sends response back with Node B's
current_cpu_id.

After this, each node knows which cpu_id to send to each other.

TODO: we need to handle the case when peer node reboots with different
number of cpus.
2015-07-09 15:52:28 +08:00

63 lines
2.3 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 {
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