# Design and Analysis of an Efficient Energy Algorithm in Wireless Social Sensor Networks
## 6 Checkpointing and Recovery Algorithms
### Algorithm for Failure Recovery
When \(Pi\) rolls back to \(CKP_{i}\) for failure or rollback request, \(CH_{k}\) is sure to require \(\text{P}_{\text{j}}\) to roll back to \(CKP_{j}\) because there is edge started by \(CKP_{i}\) and ended by \(CKP_{j}\) in S_InterCDGk. So, it follows that the assumption for rollback strategy does not set up. The rollback strategy meets the correctness criteria. ```
eq i\)) do  SEND_IntraCDGreq(\(P_{j}\));//sendIntraCDG request  BUILD_IntraCDG(\(IntraCDGglobal\));  Traverse(\(IntraCDGglobal\), \(CKP_{i}\)); //traverse\(IntraCDGglobal\) by depth-first for(\(P_{j}\in PL_{k}\wedge j\
eq i\))do  SEND_ERS(\(P_{j}\)); for(\(P_{j}\in PL_{k}\))do if(\(CKP_{s}\in ERS_{i}\wedge CKP_{s}\in P_{j}\))then  Rollback(\(P_{j}\), \(CKP_{s}\)); for(\(CKP_{s}\in ERS_{i}\wedge CKP_{s}\in S\_InterCDG_{k}\))do if(\(\exists\)Edge(\(CKP_{s}\), \(DC_{j}\)))then  SEND_RollReq(\(DC_{j}\)); //send rollback request to process related to \(DC_{j}\)
```
**Algorithm 4****\(\text{\bf{CKP}\_Rollback(\)}\)**

## 7 Processing of Handoffs

A MH leaves one cluster and enters another cluster in the ad hoc network, namely a handoff occurs, then the relations of the MH in same cluster and different clusters all change. We call this MH that passes the handoff as the HandOff Host (HOH). The cluster that HOH leaves is called old cluster and the cluster that HOH enters is called new cluster. After the handoff has happened, there will be some situations. If the old cluster does not deal with this change in time, then any checkpointing procedure of processes in old cluster may fail to accomplish because of the absence of HOH. The rollback of processes may also not be realized, because the processes could not obtain all of dependence relations of checkpoints. If the new cluster does not deal with this change in time, then the _DCs_ of HOH may not be able to be cleared away and affects the elimination of more checkpoints further. What is more, the checkpointing in new cluster will ignore the entering of HOH and so cause the incoordination of checkpoints. Hence, the HOH, old cluster and new cluster all must deal with this change relatively for assuring the correctness of checkpoints when the handoff happens. ### Process States and Treatment

For the processes running in the HOH, they stay one of the following states when the handoff happens. Figure 8 is the transition figure of states. 1. Running state. The process runs or communicates normally. 2. Checkpoint state. The process is taking checkpoint. The process can be divided to _CKP_ Initiator or _CKP_ Participant. The _CKP_ Initiator means that the checkpointing procedure is initialized by this process, while the _CKP_ Participant means that this process just take part in the checkpointing procedure initialized by other process. 3. Rollback state. The process is just dealing with the rollback recovery. This state can be divided to Active Rollback and Reactive Rollback state. The Active Rollback state indicates that the process is the failure process, namely the initiator of rollback. While the Reactive Rollback state means that the process rolls back because of the cascade rollback caused by rollback request of another process. When the HOH leaves the old cluster, and enters the new cluster, the processes running in HOH should be able to handle according to their different states. Despite the processes staying normal state, all processes running in HOH have to finish the current work (checkpointing or rollback operation) with the processes in old cluster together for assuring the consistency of checkpoints. Hence, the HOH informs its location and state to the _CH_ of old cluster when it enters the new cluster. Then the _CH_ judges whether it is needful to notice the processes in its cluster. #### 7.1.1 The Process Stays in the Rollback State

Active Rollback. The HOH goes on obtaining the _IntraCDG_ of processes in the old cluster and calculates the _ERS_ according to _IntraCDG_. The _LCH_ sends the cluster _id_ of new cluster to the CH of old cluster.