<commit_before>% @copyright 2007-2013 Zuse Institute Berlin

%   Licensed 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.

%% @author <NAME> <<EMAIL>>
%% @doc State of a dht_node.
%% @version $Id$
-module(dht_node_state).
-author('<EMAIL>').
-vsn('$Id$').

-include("scalaris.hrl").
-include("record_helpers.hrl").

%-define(TRACE(X,Y), log:pal(X,Y)).
-define(TRACE(X,Y), ok).
-define(TRACE_MR_SLIDE(X,Y), ?TRACE(X, Y)).

-export([new/3,
         get/2,
         dump/1,
         set_rt/2, set_rm/2, set_db/2, set_lease_list/2,
         details/1, details/2]).
%% node responsibility:
-export([has_left/1, is_db_responsible/2, is_db_responsible__no_msg_fwd_check/2]).
%% transactions:
-export([set_tx_tp_db/2]).
%% node moves:
-export([get_slide/2, set_slide/3,
         slide_get_data_start_record/2, slide_add_data/2,
         slide_take_delta_stop_record/2, slide_add_delta/2,
         slide_stop_record/3,
         get_split_key/5,
         add_db_range/3, rm_db_range/2]).
%% bulk owner:
-export([add_bulkowner_reply_msg/5,
        take_bulkowner_reply_msgs/1,
        get_bulkowner_reply_timer/1,
        set_bulkowner_reply_timer/2]).
%% prbr DBs and states:
-export([get_prbr_state/2]).
-export([set_prbr_state/3]).
%% snapshots
-export([set_snapshot_state/2]).
%% map reduce
-export([set_mr_state/3,
         get_mr_state/2,
         delete_mr_state/2,
         set_mr_master_state/3,
         get_mr_master_state/2,
         delete_mr_master_state/2]).


-ifdef(with_export_type_support).
-export_type([state/0, name/0, db_selector/0, slide_data/0, slide_delta/0]).
-endif.

-type db_selector() :: kv |
                       txid_1 | txid_2 | txid_3 | txid_4 |
                       leases_1 | leases_2 | leases_3 | leases_4.
-type name() :: rt | rt_size | neighbors | succlist | succ | succ_id
              | succ_pid | predlist | pred | pred_id | pred_pid | node
              | node_id | my_range | db_range | succ_range | join_time
              | db | tx_tp_db | proposer | load | slide_pred | slide_succ
              | msg_fwd | rm_state | monitor_proc | prbr_state.

-type slide_snap() :: {snapshot_state:snapshot_state(), db_dht:db_as_list()} | {false}.

-type slide_data() :: {{MovingData::db_dht:db_as_list(), slide_snap()},
                       [{db_selector(), db_prbr:db_as_list()}],
                       MovingMRState::orddict:orddict()}.
-type slide_delta() :: {{ChangedData::db_dht:db_as_list(), DeletedKeys::[?RT:key()]},
                        [{db_selector(), {Changed::db_prbr:db_as_list(),
                                          Deleted::[?RT:key()]}}],
                        {MRDelta::orddict:orddict(),
                         MRMasterDelta::orddict:orddict()}}.

%% userdevguide-begin dht_node_state:state
-record(state, {rt         = ?required(state, rt)        :: ?RT:external_rt(),
                rm_state   = ?required(state, rm_state)  :: rm_loop:state(),
                join_time  = ?required(state, join_time) :: erlang_timestamp(),
                db         = ?required(state, db)        :: db_dht:db(),
                tx_tp_db   = ?required(state, tx_tp_db)  :: any(),
                proposer   = ?required(state, proposer)  :: pid(),
                % slide with pred (must not overlap with 'slide with succ'!):
                slide_pred              = null :: slide_op:slide_op() | null,
                % slide with succ (must not overlap with 'slide with pred'!):
                slide_succ              = null :: slide_op:slide_op() | null,
                % additional range to respond to during a move:
                db_range   = []   :: [{intervals:interval(), slide_op:id()}],
                bulkowner_reply_timer   = null :: null | reference(),
                bulkowner_reply_ids     = []   :: [uid:global_uid()],
                monitor_proc            = ?required(state, monitor_proc) :: pid(),
                prbr_kv_db = ?required(state, prbr_state) :: prbr:state(),
                txid_db1 = ?required(state, prbr_state) :: prbr:state(),
                txid_db2 = ?required(state, prbr_state) :: prbr:state(),
                txid_db3 = ?required(state, prbr_state) :: prbr:state(),
                txid_db4 = ?required(state, prbr_state) :: prbr:state(),
                lease_db1 = ?required(state, prbr_state) :: prbr:state(),
                lease_db2 = ?required(state, prbr_state) :: prbr:state(),
                lease_db3 = ?required(state, prbr_state) :: prbr:state(),
                lease_db4 = ?required(state, prbr_state) :: prbr:state(),
                lease_list = ?required(state, lease_list) :: lease_list:lease_list(),
                snapshot_state   = null :: snapshot_state:snapshot_state() | null,
                mr_state   = ?required(state, mr_state)  :: orddict:orddict(),
                mr_master_state   = ?required(state, mr_master_state)  :: orddict:orddict()<commit_msg>dht_node_state: fix ?required() calls for record fields.<commit_after>% @copyright 2007-2014 Zuse Institute Berlin

%   Licensed 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.

%% @author <NAME> <<EMAIL>>
%% @doc State of a dht_node.
%% @version $Id$
-module(dht_node_state).
-author('<EMAIL>').
-vsn('$Id$').

-include("scalaris.hrl").
-include("record_helpers.hrl").

%-define(TRACE(X,Y), log:pal(X,Y)).
-define(TRACE(X,Y), ok).
-define(TRACE_MR_SLIDE(X,Y), ?TRACE(X, Y)).

-export([new/3,
         get/2,
         dump/1,
         set_rt/2, set_rm/2, set_db/2, set_lease_list/2,
         details/1, details/2]).
%% node responsibility:
-export([has_left/1, is_db_responsible/2, is_db_responsible__no_msg_fwd_check/2]).
%% transactions:
-export([set_tx_tp_db/2]).
%% node moves:
-export([get_slide/2, set_slide/3,
         slide_get_data_start_record/2, slide_add_data/2,
         slide_take_delta_stop_record/2, slide_add_delta/2,
         slide_stop_record/3,
         get_split_key/5,
         add_db_range/3, rm_db_range/2]).
%% bulk owner:
-export([add_bulkowner_reply_msg/5,
        take_bulkowner_reply_msgs/1,
        get_bulkowner_reply_timer/1,
        set_bulkowner_reply_timer/2]).
%% prbr DBs and states:
-export([get_prbr_state/2]).
-export([set_prbr_state/3]).
%% snapshots
-export([set_snapshot_state/2]).
%% map reduce
-export([set_mr_state/3,
         get_mr_state/2,
         delete_mr_state/2,
         set_mr_master_state/3,
         get_mr_master_state/2,
         delete_mr_master_state/2]).


-ifdef(with_export_type_support).
-export_type([state/0, name/0, db_selector/0, slide_data/0, slide_delta/0]).
-endif.

-type db_selector() :: kv |
                       txid_1 | txid_2 | txid_3 | txid_4 |
                       leases_1 | leases_2 | leases_3 | leases_4.
-type name() :: rt | rt_size | neighbors | succlist | succ | succ_id
              | succ_pid | predlist | pred | pred_id | pred_pid | node
              | node_id | my_range | db_range | succ_range | join_time
              | db | tx_tp_db | proposer | load | slide_pred | slide_succ
              | msg_fwd | rm_state | monitor_proc | prbr_state.

-type slide_snap() :: {snapshot_state:snapshot_state(), db_dht:db_as_list()} | {false}.

-type slide_data() :: {{MovingData::db_dht:db_as_list(), slide_snap()},
                       [{db_selector(), db_prbr:db_as_list()}],
                       MovingMRState::orddict:orddict()}.
-type slide_delta() :: {{ChangedData::db_dht:db_as_list(), DeletedKeys::[?RT:key()]},
                        [{db_selector(), {Changed::db_prbr:db_as_list(),
                                          Deleted::[?RT:key()]}}],
                        {MRDelta::orddict:orddict(),
                         MRMasterDelta::orddict:orddict()}}.

%% userdevguide-begin dht_node_state:state
-record(state, {rt         = ?required(state, rt)        :: ?RT:external_rt(),
                rm_state   = ?required(state, rm_state)  :: rm_loop:state(),
                join_time  = ?required(state, join_time) :: erlang_timestamp(),
                db         = ?required(state, db)        :: db_dht:db(),
                tx_tp_db   = ?required(state, tx_tp_db)  :: any(),
                proposer   = ?required(state, proposer)  :: pid(),
                % slide with pred (must not overlap with 'slide with succ'!):
                slide_pred              = null :: slide_op:slide_op() | null,
                % slide with succ (must not overlap with 'slide with pred'!):
                slide_succ              = null :: slide_op:slide_op() | null,
                % additional range to respond to during a move:
                db_range   = []   :: [{intervals:interval(), slide_op:id()}],
                bulkowner_reply_timer   = null :: null | reference(),
                bulkowner_reply_ids     = []   :: [uid:global_uid()],
                monitor_proc            = ?required(state, monitor_proc) :: pid(),
                prbr_kv_db = ?required(state, prbr_kv_db) :: prbr:state(),
                txid_db1 = ?required(state, txid_db1) :: prbr:state(),
                txid_db2 = ?required(state, txid_db2) :: prbr:state(),
                txid_db3 = ?required(state, txid_db3) :: prbr:state(),
                txid_db4 = ?required(state, txid_db4) :: prbr:state(),
                lease_db1 = ?required(state, lease_db1) :: prbr:state(),
                lease_db2 = ?required(state, lease_db2) :: prbr:state(),
                lease_db3 = ?required(state, lease_db3) :: prbr:state(),
                lease_db4 = ?required(state, lease_db4) :: prbr:state(),
                lease_list = ?required(state, lease_list) :: lease_list:lease_list(),
                snapshot_state   = null :: snapshot_state:snapshot_state() | null,
                mr_state   = ?required(state, mr_state)  :: orddict:orddict(),
                mr_master_state   = ?required(state, mr_master_state)  :: orddict:orddict()
{'fraction_non_alphanumeric': 0.1358801220978633, 'fraction_numerical': 0.013504763666635835, 'mean_word_length': 2.4653846153846155, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5683714', 'n_tokens_mistral': 3585, 'n_tokens_neox': 3502, 'n_words': 709}