async fn register_volume(
    etcd_client: &EtcdDelegate,
    node_id: u64,
    volume_info: &str,
) -> anyhow::Result<()> {
    let lock_key = etcd_client
        .lock(ETCD_VOLUME_INFO_LOCK.as_bytes(), 10)
        .await
        .with_context(|| "lock fail while register volume")?;

    let volume_info_key = &format!("{}{}", ETCD_VOLUME_INFO_PREFIX, volume_info);
    let volume_node_list: Option<Vec<u8>> = etcd_client
        .get_at_most_one_value(volume_info_key)
        .await
        .with_context(|| format!("get {} from etcd fail", ETCD_NODE_ID_COUNTER_KEY))?;

    let node_id_str = node_id.to_string();
    let volume_node_list = match volume_node_list {
        Some(node_list) => {
            let list_str = std::str::from_utf8(node_list.as_slice())?;
            if list_str.split(',').filter(|s| &node_id_str == s).count() == 0 {
                format!("{},{}", list_str, node_id_str)
            } else {
                node_id_str
            }
        }
        None => node_id_str,
    };

    etcd_client
        .write_or_update_kv(volume_info_key, &volume_node_list)
        .await
        .with_context(|| {
            format!(
                "Update Volume to Node Id mapping failed, volume:{}, node id: {}",
                volume_info, node_id
            )
        })?;

    etcd_client
        .unlock(lock_key)
        .await
        .with_context(|| "unlock fail while register volume")?;
    Ok(())
}
/// Register volume information, add the volume to `node_id` list mapping
Register volume information, add the volume to `node_id` list mapping
Register volume information add the volume to ` node_id ` list mapping
async fn register_volume(
    etcd_client: &EtcdDelegate,
    node_id: u64,
    volume_info: &str,
) -> anyhow::Result<()> {
    let lock_key = etcd_client
        .lock(ETCD_VOLUME_INFO_LOCK.as_bytes(), 10)
        .await
        .with_context(|| "lock fail while register volume")?;
    let volume_info_key = &format!("{}{}", ETCD_VOLUME_INFO_PREFIX, volume_info);
    let volume_node_list: Option<Vec<u8>> = etcd_client
        .get_at_most_one_value(volume_info_key)
        .await
        .with_context(|| format!("get {} from etcd fail", ETCD_NODE_ID_COUNTER_KEY))?;
    let node_id_str = node_id.to_string();
    let volume_node_list = match volume_node_list {
        Some(node_list) => {
            let list_str = std::str::from_utf8(node_list.as_slice())?;
            if list_str.split(',').filter(|s| &node_id_str == s).count() == 0 {
                format!("{},{}", list_str, node_id_str)
            } else {
                node_id_str
            }
        }
        None => node_id_str,
    };
    etcd_client
        .write_or_update_kv(volume_info_key, &volume_node_list)
        .await
        .with_context(|| {
            format!(
                "Update Volume to Node Id mapping failed, volume:{}, node id: {}",
                volume_info, node_id
            )
        })?;
    etcd_client
        .unlock(lock_key)
        .await
        .with_context(|| "unlock fail while register volume")?;
    Ok(())
}
async fn register_volume ( etcd_client : & EtcdDelegate , node_id : u64 , volume_info : & str , ) -> anyhow :: Result < ( ) > { let lock_key = etcd_client . lock ( ETCD_VOLUME_INFO_LOCK . as_bytes ( ) , 10 ) . await . with_context ( | | " " ) ? ; let volume_info_key = & format ! ( " " ETCD_VOLUME_INFO_PREFIX volume_info ) ; let volume_node_list : Option < Vec < u8 > > = etcd_client . get_at_most_one_value ( volume_info_key ) . await . with_context ( | | format ! ( " " ETCD_NODE_ID_COUNTER_KEY ) ) ? ; let node_id_str = node_id . to_string ( ) ; let volume_node_list = match volume_node_list { Some ( node_list ) => { let list_str = std :: str :: from_utf8 ( node_list . as_slice ( ) ) ? ; if list_str . split ( ',' ) . filter ( | s | & node_id_str == s ) . count ( ) == 0 { format ! ( " " list_str node_id_str ) } else { node_id_str } } None => node_id_str , } ; etcd_client . write_or_update_kv ( volume_info_key , & volume_node_list ) . await . with_context ( | | { format ! ( " " volume_info node_id ) } ) ? ; etcd_client . unlock ( lock_key ) . await . with_context ( | | " " ) ? ; Ok ( ( ) ) }
Register volume information, add the volume to `node_id` list mapping
Register volume information add the volume to ` node_id ` list mapping
etcd_client
&EtcdDelegate
node_id
u64
volume_info
&str
etcd_client
&EtcdDelegate
node_id
u64
volume_info
&str