# Data Access Based on a Guide Map of the Underwater Wireless Sensor Network
## 4 The DAGM Framework and Method of UWSN Data Storage and Query
### Building Method and Processing Mechanism of the Data Map
#### 4.2.2 Diffusion and Synchronization of Metadata  
After the metadata is generated by the storage node, it will be diffused and synchronized to the center ring node. In this process, the metadata is sent to the center ring node that is the nearest from it after metadata \(MD_{i}\) is generated in the storage node. The center ring node will compare \(MD_{i}\) with the existing metadata set \(MD\)-_Set_ that has been stored. If the existing metadata set contains the metadata \(MD_{i}\), \(MD_{i}\) is discarded; if the existing metadata set does not contain the \(MD_{i}\), \(MD_{i}\) is incorporated into the existed metadata set and then the metadata \(MD_{i}\) is sent to the next node along both clockwise and counterclockwise directions according to the center ring routing. The same process is performed on the other center ring nodes to complete the diffusion and synchronization of metadata. In the processing of metadata diffusion and synchronization, the center ring node will record the increment of hop number (\(Rh_{i}=Rh_{i}+1\) or \(LH_{i}=LH_{i}+1\)). If the number of center ring node is \(k\), diffusion and synchronization are stopped when \(Rh_{i}\) or \(LH_{i}\) is equal to \(\lceil k/2\rceil\). The processing of metadata diffusion and synchronization is described as Algorithm 1:  
```
receive mete data \(MD_{i}\) from other sensor nodes; If (\(MD_{i}\) not exist in \(MD\)-_Set_) \(MD_{i}\) merge into \(MD\)-_Set_; If (not exist \(Rh_{i}\) or \(LH_{i}\)) \(Rh_{i}=0\), \(LH_{i}=0\); else if (exist \(Rh_{i}\) or \(LH_{i}\) and \(Rh_{i}>\lceil k/2\rceil\) or \(LH_{i}>\lceil k/2\rceil\)) \(Rh_{i}=Rh_{i}+1\) or \(LH_{i}=LH_{i}+1\); send \(MD_{i}\) and \(Rh_{i}\) to right ring sensor node; or send \(MD_{i}\) and \(LH_{i}\) to left ring sensor node; else delete \(MD_{i}\); end if.
```  
**Algorithm 1**Metadata diffusion and synchronization on DAGM  
Figure 5: The inside division of the center ring (upper right quarter of Figure 3). (**a**) The center ring does not belong to IR-1; (**b**) The center ring belongs to IR-1.  
4.2.3. The Data Query Sentences Process Mechanism  
With each node queries user data from the network, it will send the query sentence to the nearest center ring node from it. Data query sentences include data types, granularity, QoS etc., At first, the query sentence is split into meta-query (\(MQ\)) sentences in accordance with the metadata where the center ring node receives the data query sentence. Then, the meta-query is compared with the metadata that is stored in this node. If it is found that the data exists in the network, data transmission routing is generated, and the query result \"_ready to receive data_\" and data transmission routing are returned to the user. In the meantime, the specific data requests and data transmission routing are sent to the data storage node. If there is no data in the network, the query will be ended and the result \"_query failed_\" is returned to the user. The processing of data query and data transmission routing generation are described as Algorithm 2:  
```
receive data query \(DQ\) from other sensor nodes; decompose \(DQ\) into meta query \(DMQ_{i}\); If (\(DMQ_{i}\) not exist in \(MD\)-\(Set\)) send query failed to user; else generate data transmit routing \(DTR\) based on GPSR; send \(DTR\) and \(DMQ_{i}\) to the storage node; send \(DTR\) and ready to receive data to user; end if.
```  
**Algorithm 2**Data query and data transmission routing generation on DAGM