# Module dht_node_state

- Description
- Data Types
- Function Index
- Function Details

State of a dht_node.

Copyright © 2007-2015 Zuse Institute Berlin

Version: $Id$

Authors: Thorsten Schuett (`schuett@zib.de`).

## Description

State of a dht_node.

## Data Types

### db_selector()

    db_selector() =
        kv_db | {tx_id, pos_integer()} | {lease_db, pos_integer()}

### name()

    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 |
        load |
        slide_pred |
        slide_succ |
        msg_fwd |
        rm_state |
        prbr_state

### slide_data()

    slide_data() =
        {{MovingData :: db_dht:db_as_list(), slide_snap()},
         [{db_selector(), db_prbr:db_as_list()}]}

### slide_delta()

    slide_delta() =
        {{ChangedData :: db_dht:db_as_list(),
          DeletedKeys :: [rt_chord:key()]},
         [{db_selector(),
           {Changed :: db_prbr:db_as_list(),
            Deleted :: [rt_chord:key()]}}],
         {MRDelta :: orddict:orddict(),
          MRMasterDelta :: orddict:orddict()}}

### slide_snap()

    slide_snap() =
        {snapshot_state:snapshot_state(), db_dht:db_as_list()} |
        {false}

### state()

abstract datatype: `state()`

userdevguide-end dht_node_state:state

## Function Index

add_db_range/3 |
delete_for_rejoin/1 | Clean up tables before rejoining with a new state.
delete_mr_master_state/2 |
delete_mr_state/2 |
details/1 | Gets the following details about the current node: predecessor and successor lists, the node itself, its load, hostname, routing table size, memory usage.
details/2 | Gets the requested details about the current node.
dump/1 |
get/2 | Gets the given property from the dht_node state.
get_mr_master_state/2 |
get_mr_state/2 |
get_slide/2 | Tries to find a slide operation with the given MoveFullId and returns it including its type (pred or succ) if successful and its pred/succ info is correct.
get_split_key/5 | Returns a key so that there are no more than TargetLoad entries between Begin and this key in the DBs.
has_left/1 | Checks whether the current node has already left the ring, i.e.
is_db_responsible/2 | Checks whether the node is responsible for the given key either by its current range or for a range the node is temporarily responsible for during a slide operation, i.e.
is_db_responsible__no_msg_fwd_check/2 | Checks whether the node is responsible for the given key either by its current range or for a range the node is temporarily responsible for during a slide operation, i.e.
new/3 |
new_on_recover/6 |
rm_db_range/2 |
set_db/2 |
set_lease_list/2 |
set_mr_master_state/3 |
set_mr_state/3 |
set_prbr_state/3 |
set_rm/2 |
set_rt/2 |
set_slide/3 |
set_snapshot_state/2 |
set_tx_tp_db/2 |
slide_add_data/2 | Adds data from slide_get_data_start_record/2 to the local DB.
slide_add_delta/2 | Adds delta infos from slide_take_delta_stop_record/2 to the local DB.
slide_get_data_start_record/2 | Gets all entries to transfer (slide) in the given range and starts delta recording on the DB for changes in this interval.
slide_stop_record/3 | Stops recording changes in the given interval.
slide_take_delta_stop_record/2 | Gets all DB changes in the given interval, stops recording delta infos and removes the entries in this range from the DB.

## Function Details

### new/3

    new(RT :: rt_chord:external_rt(),
        RMState :: rm_loop:state(),
        DB :: db_dht:db()) ->
           state()

### new_on_recover/6

    new_on_recover(RT :: rt_chord:external_rt(),
                   RMState :: rm_loop:state(),
                   PRBR_KV_DB :: prbr:state(),
                   TXID_DBs :: [prbr:state()],
                   Lease_DBs :: [prbr:state()],
                   LeaseList :: lease_list:lease_list()) ->
                      state()

### delete_for_rejoin/1

    delete_for_rejoin(State :: state()) -> ok

Clean up tables before rejoining with a new state.

### get/2

    get(State :: state(), Key :: rt) -> rt_chord:external_rt()

Gets the given property from the dht_node state. Allowed keys include:

- rt = routing table,
- rt_size = size of the routing table (provided for convenience),
- succlist = successor list,
- succ = successor (provided for convenience),
- succ_id = ID of the successor (provided for convenience),
- succ_pid = PID of the successor (provided for convenience),
- predlist = predecessor list,
- pred = predecessor (provided for convenience),
- pred_id = ID of the predecessor (provided for convenience),
- pred_pid = PID of the predecessor (provided for convenience),
- node = the own node,
- node_id = the ID of the own node (provided for convenience),
- my_range = the range of the own node,
- succ_range = the range of the successor,
- db_range = temporarily added range (during slides),
- msg_fwd = temporarily removed range and their current destination (during slides),
- full_range = the real responsibility range of the own node (see is_db_responsible/2),
- join_time = the time the node was created, i.e. joined the system,
- db = DB storing the items,
- tx_tp_db = transaction participant DB,
- load = the load (items) of the own node (provided for convenience).
- load2 = the load (see in config lb_active_load_metric) of the own node (provided for convenience).
- load3 = the load (see in config lb_active_request_metric) of the own node (provided for convenience).
- slide_pred = information about the node's current slide operation with its predecessor.
- slide_succ = information about the node's current slide operation with its successor.
- snapshot_state = snapshot algorithm state information
- lease_list = the list of all leases
- mr_state = a dictionary containing all map reduce states currently running on this node

Beware of race conditions since the neighborhood may have changed at the next call.

### set_prbr_state/3

    set_prbr_state(State :: state(),
                   WhichDB :: db_selector(),
                   Value :: prbr:state()) ->
                      state()

### set_lease_list/2

    set_lease_list(State :: state(),
                   LeaseList :: lease_list:lease_list()) ->
                      state()

### has_left/1

    has_left(State :: state()) -> boolean()

Checks whether the current node has already left the ring, i.e. the has already changed his ID in order to leave or jump.

### is_db_responsible/2

    is_db_responsible(Key :: intervals:key(), State :: state()) ->
                         boolean()

Checks whether the node is responsible for the given key either by its current range or for a range the node is temporarily responsible for during a slide operation, i.e. we temporarily read/modify data a neighbor is responsible for but hasn't yet received the data from us.

### is_db_responsible__no_msg_fwd_check/2

    is_db_responsible__no_msg_fwd_check(Key :: intervals:key(),
                                        State :: state()) ->
                                           boolean()

Checks whether the node is responsible for the given key either by its current range or for a range the node is temporarily responsible for during a slide operation, i.e. we temporarily read/modify data a neighbor is responsible for but hasn't yet received the data from us.

### get_slide/2

    get_slide(State :: state(), MoveFullId :: slide_op:id()) ->
                 {Type :: pred | succ, SlideOp :: slide_op:slide_op()} |
                 not_found

Tries to find a slide operation with the given MoveFullId and returns it including its type (pred or succ) if successful and its pred/succ info is correct. Otherwise returns {fail, wrong_pred} if the predecessor info is wrong (slide with pred) and {fail, wrong_succ} if the successor info is wrong (slide with succ). If not found, {fail, not_found} is returned.

### set_tx_tp_db/2

    set_tx_tp_db(State :: state(), NewTxTpDb :: any()) -> state()

### set_db/2

    set_db(State :: state(), NewDB :: db_dht:db()) -> state()

### set_rt/2

    set_rt(State :: state(), NewRT :: rt_chord:external_rt()) ->
              state()

### set_rm/2

    set_rm(State :: state(), NewRMState :: rm_loop:state()) -> state()

### set_slide/3

    set_slide(State :: state(),
              X2 :: pred | succ,
              SlidePred :: slide_op:slide_op() | null) ->
                 state()

### set_snapshot_state/2

    set_snapshot_state(State :: state(),
                       NewInfo :: snapshot_state:snapshot_state()) ->
                          state()

### get_mr_state/2

    get_mr_state(State :: state(), JobId :: mr_state:jobid()) ->
                    {value, mr_state:state()} | error

### set_mr_state/3

    set_mr_state(State :: state(),
                 JobId :: nonempty_string(),
                 MRState :: mr_state:state()) ->
                    state()

### delete_mr_state/2

    delete_mr_state(State :: state(), JobId :: nonempty_string()) ->
                       state()

### get_mr_master_state/2

    get_mr_master_state(State :: state(), JobId :: mr_state:jobid()) ->
                           mr_master_state:state()

### set_mr_master_state/3

    set_mr_master_state(State :: state(),
                        JobId :: nonempty_string(),
                        MRMState :: mr_master_state:state()) ->
                           state()

### delete_mr_master_state/2

    delete_mr_master_state(State :: state(),
                           JobId :: nonempty_string()) ->
                              state()

### add_db_range/3

    add_db_range(State :: state(),
                 Interval :: intervals:interval(),
                 SlideId :: slide_op:id()) ->
                    state()

### rm_db_range/2

    rm_db_range(State :: state(), SlideId :: slide_op:id()) -> state()

### dump/1

    dump(State :: state()) -> ok

### details/2

    details(State :: state(),
            Which :: [node_details:node_details_name()]) ->
               node_details:node_details()

Gets the requested details about the current node.

### details/1

    details(State :: state()) -> node_details:node_details()

Gets the following details about the current node: predecessor and successor lists, the node itself, its load, hostname, routing table size, memory usage.

### slide_get_data_start_record/2

    slide_get_data_start_record(State :: state(),
                                MovingInterval :: intervals:interval()) ->
                                   {state(), slide_data()}

Gets all entries to transfer (slide) in the given range and starts delta recording on the DB for changes in this interval.

### slide_add_data/2

    slide_add_data(State :: state(), X2 :: slide_data()) -> state()

Adds data from slide_get_data_start_record/2 to the local DB.

### slide_take_delta_stop_record/2

    slide_take_delta_stop_record(State :: state(),
                                 MovingInterval ::
                                     intervals:interval()) ->
                                    {state(), slide_delta()}

Gets all DB changes in the given interval, stops recording delta infos and removes the entries in this range from the DB.

### slide_add_delta/2

    slide_add_delta(State :: state(), X2 :: slide_delta()) -> state()

Adds delta infos from slide_take_delta_stop_record/2 to the local DB.

### slide_stop_record/3

    slide_stop_record(State :: state(),
                      MovingInterval :: intervals:interval(),
                      RemoveDataInInterval :: boolean()) ->
                         state()

Stops recording changes in the given interval. Optionally, the data in this range can be deleted.

### get_split_key/5

    get_split_key(State :: state(),
                  Begin :: rt_chord:key(),
                  End :: rt_chord:key(),
                  TargetLoad :: pos_integer(),
                  Direction :: forward | backward) ->
                     {rt_chord:key(), TakenLoad :: pos_integer()}

Returns a key so that there are no more than TargetLoad entries between Begin and this key in the DBs.

Generated by EDoc, Feb 29 2016, 16:12:18.