mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-25 19:10:42 +00:00
gossip: Move code from gms/endpoint_state.hh to source file
This commit is contained in:
@@ -289,6 +289,7 @@ urchin_core = (['database.cc',
|
||||
'gms/gossip_digest_syn.cc',
|
||||
'gms/gossip_digest_ack.cc',
|
||||
'gms/gossip_digest_ack2.cc',
|
||||
'gms/endpoint_state.cc',
|
||||
'dht/i_partitioner.cc',
|
||||
'dht/murmur3_partitioner.cc',
|
||||
'dht/byte_ordered_partitioner.cc',
|
||||
|
||||
85
gms/endpoint_state.cc
Normal file
85
gms/endpoint_state.cc
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 "gms/endpoint_state.hh"
|
||||
#include <experimental/optional>
|
||||
#include <ostream>
|
||||
|
||||
namespace gms {
|
||||
|
||||
std::experimental::optional<versioned_value> endpoint_state::get_application_state(application_state key) const {
|
||||
auto it = _application_state.find(key);
|
||||
if (it == _application_state.end()) {
|
||||
return {};
|
||||
} else {
|
||||
return _application_state.at(key);
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const endpoint_state& x) {
|
||||
os << "EndpointState: HeartBeatState = " << x._heart_beat_state << ", AppStateMap = ";
|
||||
for (auto&entry : x._application_state) {
|
||||
const application_state& state = entry.first;
|
||||
const versioned_value& value = entry.second;
|
||||
os << " { " << int32_t(state) << " : " << value << " } ";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
void endpoint_state::serialize(bytes::iterator& out) const {
|
||||
/* serialize the HeartBeatState */
|
||||
_heart_beat_state.serialize(out);
|
||||
|
||||
/* serialize the map of ApplicationState objects */
|
||||
int32_t app_state_size = _application_state.size();
|
||||
serialize_int32(out, app_state_size);
|
||||
for (auto& entry : _application_state) {
|
||||
const application_state& state = entry.first;
|
||||
const versioned_value& value = entry.second;
|
||||
serialize_int32(out, int32_t(state));
|
||||
value.serialize(out);
|
||||
}
|
||||
}
|
||||
|
||||
endpoint_state endpoint_state::deserialize(bytes_view& v) {
|
||||
heart_beat_state hbs = heart_beat_state::deserialize(v);
|
||||
endpoint_state es = endpoint_state(hbs);
|
||||
int32_t app_state_size = read_simple<int32_t>(v);
|
||||
for (int32_t i = 0; i < app_state_size; ++i) {
|
||||
auto state = static_cast<application_state>(read_simple<int32_t>(v));
|
||||
auto value = versioned_value::deserialize(v);
|
||||
es.add_application_state(state, value);
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
size_t endpoint_state::serialized_size() const {
|
||||
long size = _heart_beat_state.serialized_size();
|
||||
size += serialize_int32_size;
|
||||
for (auto& entry : _application_state) {
|
||||
const versioned_value& value = entry.second;
|
||||
size += serialize_int32_size;
|
||||
size += value.serialized_size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,14 +73,7 @@ public:
|
||||
_heart_beat_state = hbs;
|
||||
}
|
||||
|
||||
std::experimental::optional<versioned_value> get_application_state(application_state key) const {
|
||||
auto it = _application_state.find(key);
|
||||
if (it == _application_state.end()) {
|
||||
return {};
|
||||
} else {
|
||||
return _application_state.at(key);
|
||||
}
|
||||
}
|
||||
std::experimental::optional<versioned_value> get_application_state(application_state key) const;
|
||||
|
||||
/**
|
||||
* TODO replace this with operations that don't expose private state
|
||||
@@ -118,54 +111,14 @@ public:
|
||||
_is_alive = false;
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator<<(std::ostream& os, const endpoint_state& x) {
|
||||
os << "EndpointState: HeartBeatState = " << x._heart_beat_state << ", AppStateMap = ";
|
||||
for (auto&entry : x._application_state) {
|
||||
const application_state& state = entry.first;
|
||||
const versioned_value& value = entry.second;
|
||||
os << " { " << int32_t(state) << " : " << value << " } ";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& os, const endpoint_state& x);
|
||||
|
||||
// The following replaces EndpointStateSerializer from the Java code
|
||||
void serialize(bytes::iterator& out) const {
|
||||
/* serialize the HeartBeatState */
|
||||
_heart_beat_state.serialize(out);
|
||||
void serialize(bytes::iterator& out) const;
|
||||
|
||||
/* serialize the map of ApplicationState objects */
|
||||
int32_t app_state_size = _application_state.size();
|
||||
serialize_int32(out, app_state_size);
|
||||
for (auto& entry : _application_state) {
|
||||
const application_state& state = entry.first;
|
||||
const versioned_value& value = entry.second;
|
||||
serialize_int32(out, int32_t(state));
|
||||
value.serialize(out);
|
||||
}
|
||||
}
|
||||
static endpoint_state deserialize(bytes_view& v);
|
||||
|
||||
static endpoint_state deserialize(bytes_view& v) {
|
||||
heart_beat_state hbs = heart_beat_state::deserialize(v);
|
||||
endpoint_state es = endpoint_state(hbs);
|
||||
int32_t app_state_size = read_simple<int32_t>(v);
|
||||
for (int32_t i = 0; i < app_state_size; ++i) {
|
||||
auto state = static_cast<application_state>(read_simple<int32_t>(v));
|
||||
auto value = versioned_value::deserialize(v);
|
||||
es.add_application_state(state, value);
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
size_t serialized_size() const {
|
||||
long size = _heart_beat_state.serialized_size();
|
||||
size += serialize_int32_size;
|
||||
for (auto& entry : _application_state) {
|
||||
const versioned_value& value = entry.second;
|
||||
size += serialize_int32_size;
|
||||
size += value.serialized_size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
size_t serialized_size() const;
|
||||
};
|
||||
|
||||
} // gms
|
||||
|
||||
Reference in New Issue
Block a user