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.
58 lines
2.4 KiB
C++
58 lines
2.4 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/messages/stream_init_message.hh"
|
|
#include "streaming/connection_handler.hh"
|
|
#include "streaming/stream_session.hh"
|
|
#include "message/messaging_service.hh"
|
|
#include "utils/fb_utilities.hh"
|
|
|
|
namespace streaming {
|
|
|
|
future<> connection_handler::initiate() {
|
|
using shard_id = net::messaging_service::shard_id;
|
|
using net::messaging_verb;
|
|
#if 0
|
|
logger.debug("[Stream #{}] Sending stream init for incoming stream", session.planId());
|
|
Socket incomingSocket = session.createConnection();
|
|
incoming.start(incomingSocket, StreamMessage.CURRENT_VERSION);
|
|
incoming.sendInitMessage(incomingSocket, true);
|
|
|
|
logger.debug("[Stream #{}] Sending stream init for outgoing stream", session.planId());
|
|
Socket outgoingSocket = session.createConnection();
|
|
outgoing.start(outgoingSocket, StreamMessage.CURRENT_VERSION);
|
|
outgoing.sendInitMessage(outgoingSocket, false);
|
|
#endif
|
|
auto from = utils::fb_utilities::get_broadcast_address();
|
|
bool is_for_outgoing = true;
|
|
messages::stream_init_message msg(from, _session.session_index(),
|
|
_session.plan_id(), _session.description(),
|
|
is_for_outgoing, _session.keep_ss_table_level());
|
|
auto id = shard_id{from, 0};
|
|
_session.src_cpu_id = engine().cpu_id();
|
|
return _session.ms().send_message<unsigned>(net::messaging_verb::STREAM_INIT_MESSAGE,
|
|
std::move(id), std::move(msg), _session.src_cpu_id).then([this] (unsigned dst_cpu_id) {
|
|
_session.dst_cpu_id = dst_cpu_id;
|
|
});
|
|
}
|
|
|
|
} // namespace streaming
|