Files
scylladb/streaming/stream_manager.cc
Asias He fd5f3cff47 streaming: Fix stream_manager progress api
For each stream_session, we pretend we are sending/receiving one file,
to make it compatible with nodetool. For receiving_files, the file name
is "rxnofile". For sending_files, the file name is "txnofile".

stream_manager::update_all_progress_info is introduced to update the
progress info of all the stream_sessions in the node. We need this
because streaming mutations are received on all the cores, but the
stream_session object is only on one of the cores. It adds overhead if
we update progress info in stream_session object whenever we receive a
streaming mutation. So, what we do now is when we really need the
progress info, we update the progress info in stream_session object.

With http://127.0.0.$i:10000/stream_manager/, it looks like below when
decommission node 3 in a 3 nodes cluster.

=========== GET NODE 1
[{"plan_id": "935a2cc0-dc6b-11e5-bdbf-000000000000", "description":
"Unbootstrap", "sessions": [{"receiving_files": [{"value": {"direction":
"IN", "file_name": "rxnofile", "session_index": 0, "total_bytes":
16876296, "peer": "127.0.0.3", "current_bytes": 16876296}, "key":
"rxnofile"}], "receiving_summaries": [{"files": 1, "total_size": 0,
"cf_id": "869d8630-dc6b-11e5-bdbf-000000000000"}], "session_index": 0,
"state": "PREPARING", "connecting": "127.0.0.3", "peer": "127.0.0.3"}]}]

=========== GET NODE 2

[{"plan_id": "935a2cc0-dc6b-11e5-bdbf-000000000000", "description":
"Unbootstrap", "sessions": [{"receiving_files": [{"value": {"direction":
"IN", "file_name": "rxnofile", "session_index": 0, "total_bytes":
16755552, "peer": "127.0.0.3", "current_bytes": 16755552}, "key":
"rxnofile"}], "receiving_summaries": [{"files": 1, "total_size": 0,
"cf_id": "869d8630-dc6b-11e5-bdbf-000000000000"}], "session_index": 0,
"state": "PREPARING", "connecting": "127.0.0.3", "peer": "127.0.0.3"}]}]

=========== GET NODE 3
[{"plan_id": "935a2cc0-dc6b-11e5-bdbf-000000000000", "description":
"Unbootstrap", "sessions": [{"sending_files": [{"value": {"direction":
"OUT", "file_name": "txnofile", "session_index": 0, "total_bytes":
16876296, "peer": "127.0.0.1", "current_bytes": 16876296}, "key":
"txnofile"}], "sending_summaries": [{"files": 1, "total_size": 0,
"cf_id": "869d8630-dc6b-11e5-bdbf-000000000000"}], "session_index": 0,
"state": "PREPARING", "connecting": "127.0.0.1", "peer":
"127.0.0.1"},{"sending_files": [{"value": {"direction": "OUT",
"file_name": "txnofile", "session_index": 0, "total_bytes": 16755552,
"peer": "127.0.0.2", "current_bytes": 16755552}, "key": "txnofile"}],
"sending_summaries": [{"files": 1, "total_size": 0, "cf_id":
"869d8630-dc6b-11e5-bdbf-000000000000"}], "session_index": 0, "state":
"PREPARING", "connecting": "127.0.0.2", "peer": "127.0.0.2"}]}]
2016-02-26 17:38:37 +08:00

219 lines
6.8 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.
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/distributed.hh"
#include "streaming/stream_manager.hh"
#include "streaming/stream_result_future.hh"
#include "log.hh"
namespace streaming {
extern logging::logger sslog;
distributed<stream_manager> _the_stream_manager;
void stream_manager::register_sending(shared_ptr<stream_result_future> result) {
#if 0
result.addEventListener(notifier);
// Make sure we remove the stream on completion (whether successful or not)
result.addListener(new Runnable()
{
public void run()
{
initiatedStreams.remove(result.planId);
}
}, MoreExecutors.sameThreadExecutor());
#endif
_initiated_streams[result->plan_id] = std::move(result);
}
void stream_manager::register_receiving(shared_ptr<stream_result_future> result) {
#if 0
result->add_event_listener(notifier);
// Make sure we remove the stream on completion (whether successful or not)
result.addListener(new Runnable()
{
public void run()
{
receivingStreams.remove(result.planId);
}
}, MoreExecutors.sameThreadExecutor());
#endif
_receiving_streams[result->plan_id] = std::move(result);
}
shared_ptr<stream_result_future> stream_manager::get_sending_stream(UUID plan_id) {
auto it = _initiated_streams.find(plan_id);
if (it != _initiated_streams.end()) {
return it->second;
}
return {};
}
shared_ptr<stream_result_future> stream_manager::get_receiving_stream(UUID plan_id) {
auto it = _receiving_streams.find(plan_id);
if (it != _receiving_streams.end()) {
return it->second;
}
return {};
}
void stream_manager::remove_stream(UUID plan_id) {
sslog.debug("stream_manager: removing plan_id={}", plan_id);
_initiated_streams.erase(plan_id);
_receiving_streams.erase(plan_id);
// FIXME: Do not ignore the future
remove_progress_on_all_shards(plan_id).handle_exception([plan_id] (auto ep) {
sslog.info("stream_manager: Fail to remove progress for plan_id={}: {}", plan_id, ep);
});
}
void stream_manager::show_streams() {
for (auto& x : _initiated_streams) {
sslog.debug("stream_manager:initiated_stream: plan_id={}", x.first);
}
for (auto& x : _receiving_streams) {
sslog.debug("stream_manager:receiving_stream: plan_id={}", x.first);
}
}
std::vector<shared_ptr<stream_result_future>> stream_manager::get_all_streams() const {
std::vector<shared_ptr<stream_result_future>> result;
for (auto& x : _initiated_streams) {
result.push_back(x.second);
}
for (auto& x : _receiving_streams) {
result.push_back(x.second);
}
return result;
}
void stream_manager::update_progress(UUID cf_id, gms::inet_address peer, progress_info::direction dir, size_t fm_size) {
auto& sbytes = _stream_bytes[cf_id];
if (dir == progress_info::direction::OUT) {
sbytes[peer].bytes_sent += fm_size;
} else {
sbytes[peer].bytes_received += fm_size;
}
}
future<> stream_manager::update_all_progress_info() {
return seastar::async([this] {
for (auto sr: get_all_streams()) {
for (auto session : sr->get_coordinator()->get_all_stream_sessions()) {
session->update_progress().get();
}
}
});
}
void stream_manager::remove_progress(UUID plan_id) {
_stream_bytes.erase(plan_id);
}
stream_bytes stream_manager::get_progress(UUID plan_id, gms::inet_address peer) {
auto& sbytes = _stream_bytes[plan_id];
return sbytes[peer];
}
stream_bytes stream_manager::get_progress(UUID plan_id) {
stream_bytes ret;
for (auto& x : _stream_bytes[plan_id]) {
ret += x.second;
}
return ret;
}
future<> stream_manager::remove_progress_on_all_shards(UUID plan_id) {
return get_stream_manager().invoke_on_all([plan_id] (auto& sm) {
sm.remove_progress(plan_id);
});
}
future<stream_bytes> stream_manager::get_progress_on_all_shards(UUID plan_id, gms::inet_address peer) {
return get_stream_manager().map_reduce0(
[plan_id, peer] (auto& sm) {
return sm.get_progress(plan_id, peer);
},
stream_bytes(),
std::plus<stream_bytes>()
);
}
future<stream_bytes> stream_manager::get_progress_on_all_shards(UUID plan_id) {
return get_stream_manager().map_reduce0(
[plan_id] (auto& sm) {
return sm.get_progress(plan_id);
},
stream_bytes(),
std::plus<stream_bytes>()
);
}
future<stream_bytes> stream_manager::get_progress_on_all_shards(gms::inet_address peer) {
return get_stream_manager().map_reduce0(
[peer] (auto& sm) {
stream_bytes ret;
for (auto& sbytes : sm._stream_bytes) {
ret += sbytes.second[peer];
}
return ret;
},
stream_bytes(),
std::plus<stream_bytes>()
);
}
future<stream_bytes> stream_manager::get_progress_on_all_shards() {
return get_stream_manager().map_reduce0(
[] (auto& sm) {
stream_bytes ret;
for (auto& sbytes : sm._stream_bytes) {
for (auto& sb : sbytes.second) {
ret += sb.second;
}
}
return ret;
},
stream_bytes(),
std::plus<stream_bytes>()
);
}
} // namespace streaming