<commit_before>%% -------------------------------------------------------------------
%%
%% riak_core: Core Riak Application
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
%%
%% This file is provided 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.
%%
%% -------------------------------------------------------------------

%% @doc riak_core_ring manages a riak node's local view of partition ownership.
%%      The functions in this module revolve around use of the chstate record,
%%      which should be treated as opaque by other modules.  Riak nodes exchange
%%      instances of these records via gossip in order to converge on a common
%%      view of node/partition ownership.

-module(riak_core_ring).

-export([all_members/1,
         all_owners/1,
         all_preflists/2,
         diff_nodes/2,
         equal_rings/2,
         fresh/0,
         fresh/1,
         fresh/2,
         get_meta/2,
         get_buckets/1,
         index_owner/2,
         my_indices/1,
         num_partitions/1,
         owner_node/1,
         preflist/2,
         random_node/1,
         random_other_index/1,
         random_other_index/2,
         random_other_node/1,
         reconcile/2,
         rename_node/3,
         responsible_index/2,
         transfer_node/3,
         update_meta/3,
         remove_meta/2]).

-export([cluster_name/1,
         legacy_ring/1,
         legacy_reconcile/2,
         upgrade/1,
         downgrade/2,
         set_tainted/1,
         check_tainted/2,
         nearly_equal/2,
         claimant/1,
         member_status/2,
         pretty_print/2,
         all_member_status/1,
         update_member_meta/5,
         clear_member_meta/3,
         get_member_meta/3,
         add_member/3,
         remove_member/3,
         leave_member/3,
         exit_member/3,
         down_member/3,
         set_member/4,
         set_member/5,
         members/2,
         set_claimant/2,
         increment_vclock/2,
         ring_version/1,
         increment_ring_version/2,
         set_pending_changes/2,
         active_members/1,
         claiming_members/1,
         ready_members/1,
         random_other_active_node/1,
         down_members/1,
         set_owner/2,
         indices/2,
         future_indices/2,
         future_ring/1,
         disowning_indices/2,
         cancel_transfers/1,
         pending_changes/1,
         next_owner/1,
         next_owner/2,
         next_owner/3,
         completed_next_owners/2,
         all_next_owners/1,
         change_owners/2,
         handoff_complete/3,
         ring_ready/0,
         ring_ready/1,
         ring_ready_info/1,
         ring_changed/2,
         set_cluster_name/2,
         reconcile_names/2,
         reconcile_members/2,
         is_primary/2,
         chash/1,
         set_chash/2,
         resize/2,
         set_pending_resize/2,
         set_pending_resize_abort/1,
         maybe_abort_resize/1,
         schedule_resize_transfer/3,
         awaiting_resize_transfer/3,
         resize_transfer_status/4,
         resize_transfer_complete/4,
         complete_resize_transfers/3,
         reschedule_resize_transfers/3,
         is_resizing/1,
         is_post_resize/1,
         is_resize_complete/1,
         resized_ring/1,
         set_resized_ring/2,
         future_index/3,
         future_index/4,
         future_index/5,
         is_future_index/4,
         future_owner/2,
         future_num_partitions/1,
         vnode_type/2,
         deletion_complete/3]).

-export_type([riak_core_ring/0]).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.

-define(CHSTATE, #chstate_v2).
-record(chstate_v2, {
    nodename :: term(),          % the Node responsible for this chstate
    vclock   :: vclock:vclock(), % for this chstate object, entries are
                                 % {Node, Ctr}
    chring   :: chash:chash(),   % chash ring of {IndexAsInt, Node} mappings
    meta     :: dict(),          % dict of cluster-wide other data (primarily
                                 % bucket N-value, etc)

    clustername :: {term(), term()},
    next     :: [{integer(), term(), term(), [module()], awaiting | complete}],
    members  :: [{node(), {member_status(), vclock:vclock(), [{atom(), term()}]}}],
    claimant :: term(),
    seen     :: [{term(), vclock:vclock()}],
    rvsn     :: vclock:vclock()
}). 

%% Legacy chstate
-record(chstate, {
    nodename :: node(), % the Node responsible for this chstate
    vclock,   % for this chstate object, entries are {Node, Ctr}
    chring :: chash:chash(),   % chash ring of {IndexAsInt, Node} mappings
    meta      % dict of cluster-wide other data (primarily bucket N-value, etc)
}). 

-type member_status() :: joining | valid | invalid | leaving | exiting | down.

%% type meta_entry(). Record for each entry in #chstate.meta
-record(meta_entry, {
    value,    % The value stored under this entry
    lastmod   % The last modified time of this entry, 
              %  from calendar:datetime_to_gregorian_seconds(
              %                             calendar:universal_time()), 
}).

%% riak_core_ring() is the opaque data type used for partition ownership
-type riak_core_ring() :: ?CHSTATE{}.<commit_msg>Loosen the type for entries in chstate() that nearly_equal/2 modifies.<commit_after>%% -------------------------------------------------------------------
%%
%% riak_core: Core Riak Application
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
%%
%% This file is provided 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.
%%
%% -------------------------------------------------------------------

%% @doc riak_core_ring manages a riak node's local view of partition ownership.
%%      The functions in this module revolve around use of the chstate record,
%%      which should be treated as opaque by other modules.  Riak nodes exchange
%%      instances of these records via gossip in order to converge on a common
%%      view of node/partition ownership.

-module(riak_core_ring).

-export([all_members/1,
         all_owners/1,
         all_preflists/2,
         diff_nodes/2,
         equal_rings/2,
         fresh/0,
         fresh/1,
         fresh/2,
         get_meta/2,
         get_buckets/1,
         index_owner/2,
         my_indices/1,
         num_partitions/1,
         owner_node/1,
         preflist/2,
         random_node/1,
         random_other_index/1,
         random_other_index/2,
         random_other_node/1,
         reconcile/2,
         rename_node/3,
         responsible_index/2,
         transfer_node/3,
         update_meta/3,
         remove_meta/2]).

-export([cluster_name/1,
         legacy_ring/1,
         legacy_reconcile/2,
         upgrade/1,
         downgrade/2,
         set_tainted/1,
         check_tainted/2,
         nearly_equal/2,
         claimant/1,
         member_status/2,
         pretty_print/2,
         all_member_status/1,
         update_member_meta/5,
         clear_member_meta/3,
         get_member_meta/3,
         add_member/3,
         remove_member/3,
         leave_member/3,
         exit_member/3,
         down_member/3,
         set_member/4,
         set_member/5,
         members/2,
         set_claimant/2,
         increment_vclock/2,
         ring_version/1,
         increment_ring_version/2,
         set_pending_changes/2,
         active_members/1,
         claiming_members/1,
         ready_members/1,
         random_other_active_node/1,
         down_members/1,
         set_owner/2,
         indices/2,
         future_indices/2,
         future_ring/1,
         disowning_indices/2,
         cancel_transfers/1,
         pending_changes/1,
         next_owner/1,
         next_owner/2,
         next_owner/3,
         completed_next_owners/2,
         all_next_owners/1,
         change_owners/2,
         handoff_complete/3,
         ring_ready/0,
         ring_ready/1,
         ring_ready_info/1,
         ring_changed/2,
         set_cluster_name/2,
         reconcile_names/2,
         reconcile_members/2,
         is_primary/2,
         chash/1,
         set_chash/2,
         resize/2,
         set_pending_resize/2,
         set_pending_resize_abort/1,
         maybe_abort_resize/1,
         schedule_resize_transfer/3,
         awaiting_resize_transfer/3,
         resize_transfer_status/4,
         resize_transfer_complete/4,
         complete_resize_transfers/3,
         reschedule_resize_transfers/3,
         is_resizing/1,
         is_post_resize/1,
         is_resize_complete/1,
         resized_ring/1,
         set_resized_ring/2,
         future_index/3,
         future_index/4,
         future_index/5,
         is_future_index/4,
         future_owner/2,
         future_num_partitions/1,
         vnode_type/2,
         deletion_complete/3]).

-export_type([riak_core_ring/0]).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.

-define(CHSTATE, #chstate_v2).
-record(chstate_v2, {
    nodename :: term(),          % the Node responsible for this chstate
    vclock   :: vclock:vclock() | undefined, % for this chstate object, entries are
                                 % {Node, Ctr}
    chring   :: chash:chash(),   % chash ring of {IndexAsInt, Node} mappings
    meta     :: dict() | undefined,  % dict of cluster-wide other data (primarily
                                 % bucket N-value, etc)

    clustername :: {term(), term()},
    next     :: [{integer(), term(), term(), [module()], awaiting | complete}],
    members  :: [{node(), {member_status(), vclock:vclock(), [{atom(), term()}]}}],
    claimant :: term(),
    seen     :: [{term(), vclock:vclock()}],
    rvsn     :: vclock:vclock()
}). 

%% Legacy chstate
-record(chstate, {
    nodename :: node(), % the Node responsible for this chstate
    vclock,   % for this chstate object, entries are {Node, Ctr}
    chring :: chash:chash(),   % chash ring of {IndexAsInt, Node} mappings
    meta      % dict of cluster-wide other data (primarily bucket N-value, etc)
}). 

-type member_status() :: joining | valid | invalid | leaving | exiting | down.

%% type meta_entry(). Record for each entry in #chstate.meta
-record(meta_entry, {
    value,    % The value stored under this entry
    lastmod   % The last modified time of this entry, 
              %  from calendar:datetime_to_gregorian_seconds(
              %                             calendar:universal_time()), 
}).

%% riak_core_ring() is the opaque data type used for partition ownership
-type riak_core_ring() :: ?CHSTATE{}.
{'fraction_non_alphanumeric': 0.12095032397408208, 'fraction_numerical': 0.0208207343412527, 'mean_word_length': 1.9144008056394763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '884414', 'n_tokens_mistral': 3512, 'n_tokens_neox': 3473, 'n_words': 826}