Commit Graph

62 Commits

Author SHA1 Message Date
Tomasz Grabiec
cce2c648c5 Merge branch 'dev/gleb/for_urchin' from seastar-dev.git
Beginning of read implementation for range queries from Gleb.
2015-07-15 12:53:43 +03:00
Avi Kivity
99a15de9e5 logger: de-thread_local-ize logger
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.
2015-07-14 17:18:11 +03:00
Gleb Natapov
7fbe154a26 token_metadata: add include_min handling in tokens_iterator
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.
2015-07-14 12:22:37 +03:00
Calle Wilund
806fc04b37 token_metadata.hh : implement get_all_endpoints
+ add number_of_endpoints()
2015-07-08 10:50:46 +02:00
Vlad Zolotarov
f8d2679728 locator: add a virtual get_name() method to snitch classes
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>
2015-07-06 10:11:30 +02:00
Gleb Natapov
b175d276ab implement get_natural_endpoints for local_strategy
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.
2015-07-06 09:57:14 +02:00
Vlad Zolotarov
fa60555ddd locator: network_topology_strategy: make get_datacenters() public
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-07-02 13:01:00 +03:00
Vlad Zolotarov
888a33f9d2 locator: add a replication strategy type field to abstract_replication_strategy
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>
2015-07-02 12:26:34 +03:00
Avi Kivity
5b00c72137 Merge "locator: network_topology_strategy" from Vlad
"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
2015-06-29 18:54:40 +03:00
Vlad Zolotarov
9a6e6b4ae1 locator: added network_topology_strategy class
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.
2015-06-29 18:50:49 +03:00
Vlad Zolotarov
5a19187802 locator: simple_strategy: use ring_range and sequenced_set in calculate_natural_endpoints()
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>

New in v2:
   - Use new location of sequenced_set.
2015-06-29 18:45:09 +03:00
Vlad Zolotarov
310f4b6724 locator: abstract_replication_strategy: added a counter for natural endpoints cache hits
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 18:43:58 +03:00
Vlad Zolotarov
d03122fdaf locator: abstract_replication_strategy: added natural endpoints caching
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 18:43:58 +03:00
Vlad Zolotarov
314710b766 locator: abstract_replication_strategy: added replication_strategy_logger
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 18:43:58 +03:00
Vlad Zolotarov
4b0cec624e locator: added abstract_replication_strategy::validate_replication_factor()
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 18:43:58 +03:00
Vlad Zolotarov
f3dbdf758f locator: abstract_replication_strategy: Comment out an unused member
_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>
2015-06-29 18:43:58 +03:00
Vlad Zolotarov
214343036e locator: token_metadata: added ring_range() method
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>.
2015-06-29 18:43:45 +03:00
Vlad Zolotarov
61657bebe6 locator: token_metadata::update_normal_tokens() - call _topology.add_endpoint(endpoint)
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 14:35:47 +03:00
Vlad Zolotarov
b9631f5ff0 locator: token_metadata: added a get_topology() method
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 14:35:47 +03:00
Vlad Zolotarov
306287a5d5 locator: added topology class implementation
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 14:35:47 +03:00
Vlad Zolotarov
ebce44e20c locator: abstract_replication_strategy::abstract_replication_strategy(): remove a class name padding
We are registering short names instead

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 14:35:47 +03:00
Vlad Zolotarov
d17494a7e3 locator: simple_strategy: register a short name and optimize get_replication_factor()
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 14:35:47 +03:00
Vlad Zolotarov
7e73afccab locator: local_strategy: register a short name creator
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-29 14:35:47 +03:00
Vlad Zolotarov
e47e0dcde9 locator: moved endpoint_dc_rack from db::system_keyspace to locator namespace
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>
2015-06-29 14:35:47 +03:00
Amnon Heiman
b4d2180b9b Token metadata: Enhencing the API
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>
2015-06-25 11:48:58 +03:00
Vlad Zolotarov
67bb1ba132 gossiping_property_file_snitch: Register creators for all parameters set options.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-22 23:18:40 +03:00
Vlad Zolotarov
3520d4de10 locator: introduce a global distributed<snitch_ptr> i_endpoint_snitch::snitch_instance()
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.
2015-06-22 23:18:31 +03:00
Avi Kivity
acb56b580f abstract_replication_strategy: work around missing _snitch in cql_query_test 2015-06-22 15:28:22 +03:00
Avi Kivity
de26b3a75c Merge "Update system keyspace rs to local_strategy" from Shlomi
"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."
2015-06-22 14:27:57 +03:00
Shlomi Livne
afe0f7dc85 Add support for local_strategy
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-06-22 13:19:37 +03:00
Vlad Zolotarov
ea274a0eda locator: Fix a typo in a token_metadata constructor
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-22 09:16:24 +02:00
Shlomi Livne
3e31c56ed9 Support snitch registration on long and short format
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>
2015-06-15 15:33:40 +03:00
Gleb Natapov
8fd7c45d4c make get_replication_factor a virtual function of abstract_replication_strategy 2015-06-15 12:51:09 +03:00
Gleb Natapov
5f3f8e641f add token_metadata::pending_enpoints_for() stub function 2015-06-15 12:51:09 +03:00
Gleb Natapov
2d409250f2 remove ad-hoc token_metadata creation 2015-06-15 12:51:09 +03:00
Vlad Zolotarov
2f14c53f4e gossiping_property_file_snitch: use a logger from i_endpoint_snitch
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-14 15:31:58 +03:00
Vlad Zolotarov
03ffaea768 locator: introduce i_endpoint_snitch::create_snitch()
- Kill make_snitch().
   - i_endpoint_snitch::create_snitch() uses the utilities from class_registrator.hh.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-14 15:31:49 +03:00
Vlad Zolotarov
cbbdcad649 locator: gossiping_property_file_snitch
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.
2015-06-09 15:33:38 +03:00
Vlad Zolotarov
aa11ebca41 locator: added a production_snitch_base implementation
- 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.
2015-06-09 15:33:38 +03:00
Vlad Zolotarov
a2594015f9 locator: futurize snitch creation
- 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.
2015-06-09 15:33:38 +03:00
Vlad Zolotarov
aecc2b4279 locator: reworked the snitch'es infrastructure
- 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
2015-06-09 15:33:38 +03:00
Vlad Zolotarov
73278798a9 added missing methods (stubs) required for snitch implementation
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
2015-06-09 15:33:29 +03:00
Asias He
8467db11aa token_metadata: Print _sorted_tokens in debug
_sorted_tokens is used by replication code.
2015-06-04 17:12:10 +08:00
Asias He
0c98a4413f token_metadata: Add _leaving_endpoints and _moving_endpoints 2015-06-04 17:12:09 +08:00
Asias He
42a2f24c77 token_metadata: Add add_bootstrap_tokens and remove_bootstrap_tokens 2015-06-04 17:12:09 +08:00
Asias He
6b263e46eb token_metadata: Add is_member 2015-06-04 17:12:09 +08:00
Asias He
06a792d6be token_metadata: Add get_host_id and friends 2015-06-04 17:12:09 +08:00
Asias He
05939af7c7 token_metadata: Move update_host_id to source file 2015-06-01 11:33:11 +08:00
Asias He
4c23121b47 token_metadata: Add helper to print debug info for _token_metadata 2015-06-01 11:24:39 +08:00
Asias He
6bffee5e11 token_metadata: Add update_host_id
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.
2015-06-01 11:24:38 +08:00