The logger class constructor registers itself with the logger registry,
in order to enable dynamically setting log levels. However, since
thread_local variables may be (and are) initialized at the time of first
use, when the program starts up no loggers are registered.
Fix by making loggers global, not thread_local. This requires that the
registry use locking to prevent registration happening on different threads
from corrupting the registry.
Note that technically global variables can also be initialized at the
point of first use, and there is no portable way for classes to self-register.
However this is the best we can do.
Sometimes it is needed to include minimum token during wrap around while
iterating over all tokens. This support was omitted in initial
tokens_iterator implementation, add it now.
Add a pure virtual i_endpoint_snitch::get_name() method that
should return the corresponding Java-name of a snitch
class instance.
Patch is also available on dev:/snitch-get-name-v1
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
abstract_replication_strategy::get_natural_endpoints()
does some token calculations before calling strategy specific
calculate_natural_endpoints(), but system table may be read before
token metadata (needed for token calculations) is ready. Fix that by
specializing local_strategy's get_natural_endpoints() to skip token
calculation.
This is meant to exclude the exceptions throwing when we want to
branch on a specific instance type (Java's instanceof call).
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
"This series aims to add the network_topology_strategy class.
It adds a few things that were missing in the token_metadata and
abstract_replication_strategy classes on the way:
- Full topology (a.k.a. Topology) class implementation.
- ring_range (a.k.a. TokenMetadata.ringIterator). The implementation
is partial since we don't implement the "inclideMin" parameter.
- endpoints caching in the abstract_replication_strategy.
- Add-only Java's LinkedHashSet implementation - sequenced_set.
Then we add the network_topology_strategy class itself and the corresponding
unit test that validates the functionality of both the strategy class and of
the caching mechanism."
Conflicts:
locator/token_metadata.hh
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v2:
- Use new location of a sequenced_set.
- Indentation.
- Use all caps in a FIXME word.
_keyspace back reference is not used at the moment.
Not deleting since we may need it when we add more code (quite soon).
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Returns an iterable range object to traverse the token ring
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v2:
- Use boost::iterator_range instead of tokens_range class.
- Make tokens_iterator inherit from std::iterator<std::input_iterator_tag, token>.
This is meant to resolve to dependecy loop between token_metadata.hh
and system_keyspace.hh.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
This expose the _leaving_endpoints, _moving_endpoints and
_bootstrap_tokens.
It also changes the signature of get_endpoint_to_host_id_map_for_reading
from auto so the compiler will be able to resolve the method signature
outside of the cc file.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Snitch class semantics defined to be per-Node. To make it so we
introduce here a static member in an i_endpoint_snitch class that
has to contain the pointer to the relevant snitch class instance.
Since the snitch contents are not always pure const it has to be per
shard, therefore we'll make it a "distributed". All the I/O is going
to take place on a single shard and if there are changes - they are going
to be propagated to the rest of the shards.
The application is responsible to initialize this distributed<shnitch>
before it's used for the first time.
This patch effectively reverts most of the "locator: futurize
snitch creation" a2594015f9 patch - the part that modifies the
code that was creating the snitch instance. Since snitch is
created explicitly by the application and all the rest of the code
simply assumes that the above global is initialized we won't need
all those changes any more and the code will get back to be nice and simple
as it was before the patch above.
So, to summarize, this patch does the following:
- Reverts the changes introduced by a2594015f9 related to the fact that
every time a replication strategy was created there should have been created
a snitch that would have been stored in this strategy object. More specifically,
methods like keyspace::create_replication_strategy() do not return a future<>
any more and this allows to simplify the code that calls it significantly.
- Introduce the global distributed<snitch_ptr> object:
- It belongs to the i_endpoint_snitch class.
- There has been added a corresponding interface to access both global and
shard-local instances.
- locator::abstract_replication_strategy::create_replication_strategy() does
not accept snitch_ptr&& - it'll get and pass the corresponding shard-local
instance of the snitch to the replication strategy's constructor by itself.
- Adjusted the existing snitch infrastructure to the new semantics:
- Modified the create_snitch() to create and start all per-shard snitch
instances and update the global variable.
- Introduced a static i_endpoint_snitch::stop_snitch() function that properly
stops the global distributed snitch.
- Added the code to the gossiping_property_file_snitch that distributes the
changed data to all per-shard snitch objects.
- Made all existing snitches classes properly maintain their state in order
to be able to shut down cleanly.
- Patched both urchin and cql_query_test to initialize a snitch instance before
all other services.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v6:
- Rebased to the current master.
- Extended a commit message a little - the summary.
New in v5:
- database::create_keyspace(): added a missing _keyspaces.emplace()
New in v4:
- Kept the database::create_keyspace() to return future<> by Glauber's request
and added a description to this method that needs to be changed when Glauber
adds his bits that require this interface.
"local_strategy is used for system keyspaces to allow query / update of
tables without the need to have snitch or token metadata avilable
without this patch updating of system tables (e.g. insert system.local ...)
fails."
Snitches can be inialized based on short and long name format. In case a
short name is provided the "org.apache.cassandra.locator." is
contacenated to it. Out solution is simpler with double regitration.
Default cassandra.yaml includes "endpoint_snitch: SimpleSnitch"
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
Reads the configuration from cassandra-rackdc.properties.
This file may include the following fields:
- dc: Local Data Center name
- rack: Local Rack name
- prefer_local: A boolean value that defines if cluster should prefer
local address - relevant for AWS cloud.
Class will schedule a timer that will re-read the property file and inform a
Gossiper if there are changes in the local configuration.
Differences from the Origin C* implementation:
- No support for a legacy property_file_snitch.
- Class supports overriding the property file name in a constructor.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v4:
- Fix a debug compilation: define reload_property_file_period() to be a constexpr
method instead of a member.
- Don't stop() the snitch when snitch_is_ready is set to an exceptional state.
New in v2:
- Adjust to new file interface.
- Futurize reload_propery_file().
- Use trim() and split() from boost::algorithm.
- Read optimization and logging:
- Re-read the file only if it was changed since the last read.
- Use logging facilities from log.hh.
- Cleanups:
- Introduce bad_property_file_error exception.
- Remove unnecessary check after dma_read_exactly() call.
- Styling.
- Copyright.
- Move most of the functions implementation into the .cc file.
- Added stop() method.
- Implements the non-trivial versions of get_rack() and get_datacenter().
Performs a lookup in a following order:
1) Searches in a gossiper::endpoint_state_map.
2) Searches in a SystemTable.
3) If not found in any of the above returns a default value.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v2:
- Introduce db::system_keyspace::endpoint_dc_rack.
- Kill trim() and split().
- Added missing copyright and license statements.
- _my_rack and _my_dc are not optional anymore.
- Added a promiss that has to be set when snitch is stopped.
- Forbid explicit snitch creation with constructor.
- Allow the creation of snitches only with locator::make_snitch() template
function.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v4:
- Make sure the snitch is stopped before it's destroyed when _snitch_is_ready
is returned in an exceptional state.
New in v2:
- Change snitch_ptr to be std::unique_ptr<i_endpoint_snitch>
- abstract_replication_strategy::create_replication_strategy(): explicitly
specify (template) types of create_object() parameters.
- Re-arrange the loop in marge_keyspaces() so that lambdas that depend on
"this" complete before there is a chance that "this" gets destroyed.
- create_keyspace(): Don't add a new keyspace if a keyspace with this name
already exists.
- i_endpoint_snitch: added a stop() virtual method
- Added a stop() pure virtual method.
- Added an enum class snitch_state and a _state member initialized to snitch_state::initializing,
added an assert() in a destructor requiring _state to become snitch_state::stopped,
which should be set when stop() is complete.
- rack_inferring_snitch: added a stop() method.
- simple_snitch: added a stop() method.
- Added stop() methods to abstract_replication_strategy and keyspace.
- Updated database::stop() to wait for all keyspaces in _keyspaces to stop.
- Introduce snitch_base class that implements all snitch functionality
except for get_rack() and get_datacenter() methods.
- Requires the inheriting classes to initialize _my_rack and _my_dc fields.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v2:
- Returned copyright lines.
- Make _my_dc and _my_rack a non-optional for now.
- Styling and add an "override" qualifier to virtual functions implementations.
- Move most of snitch_base members into snitch_base.cc.
- snitch_base.hh: Add "Modified by Cloudius Systems" to a license.
- simple_snitch: copyright
- rack_inferring_snitch: copyright
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
New in v2:
- storage_service: add a non-const version of get_token_metadata().
- get_broadcast_address(): check if net::get_messaging_service().local_is_initialized()
before calling net::get_local_messaging_service().listen_address().
- get_broadcast_address(): return an inet_address by value.
- system_keyspace: introduce db::system_keyspace::endpoint_dc_rack
- fb_utilities: use listen_address as broadcast_address for now
Use std::unordered_map instead of boost:bimap. std::unordered_map is
much much easier to use. It is a premature optimization to user bimap.
We can iterate the map to check if host_id is unique. Modification of
host_id is not a frequent or performance sensitive operation anyway.