@@ -37,25 +37,17 @@ pub(crate) fn validate_ids(
3737///
3838/// BeeGFS doesn't really support meta targets at the moment, so there always must be exactly one
3939/// meta target per meta node with their IDs being the same.
40- pub ( crate ) fn insert_meta (
41- tx : & Transaction ,
42- target_id : TargetId ,
43- alias : Option < Alias > ,
44- ) -> Result < ( ) > {
40+ pub ( crate ) fn insert_meta ( tx : & Transaction , target_id : TargetId ) -> Result < ( ) > {
4541 let target_id = if target_id == 0 {
4642 misc:: find_new_id ( tx, "targets" , "target_id" , NodeType :: Meta , 1 ..=0xFFFF ) ?
47- } else if try_resolve_num_id ( tx, EntityType :: Target , NodeType :: Meta , target_id. into ( ) ) ?
48- . is_some ( )
49- {
50- bail ! ( TypedError :: value_exists( "numeric target id" , target_id) ) ;
5143 } else {
5244 target_id
5345 } ;
5446
5547 insert (
5648 tx,
5749 target_id,
58- alias ,
50+ None ,
5951 NodeTypeServer :: Meta ,
6052 Some ( target_id. into ( ) ) ,
6153 ) ?;
@@ -78,45 +70,36 @@ pub(crate) fn insert_meta(
7870pub ( crate ) fn insert_storage (
7971 tx : & Transaction ,
8072 target_id : TargetId ,
81- alias : Option < Alias > ,
73+ reg_token : Option < & str > ,
8274) -> Result < TargetId > {
8375 let target_id = if target_id == 0 {
8476 misc:: find_new_id ( tx, "targets" , "target_id" , NodeType :: Storage , 1 ..=0xFFFF ) ?
85- } else if try_resolve_num_id ( tx, EntityType :: Target , NodeType :: Storage , target_id. into ( ) ) ?
86- . is_some ( )
87- {
88- return Ok ( target_id) ;
8977 } else {
9078 target_id
9179 } ;
9280
93- insert ( tx, target_id, alias , NodeTypeServer :: Storage , None ) ?;
81+ insert ( tx, target_id, reg_token , NodeTypeServer :: Storage , None ) ?;
9482
9583 Ok ( target_id)
9684}
9785
98- pub ( crate ) fn insert (
86+ fn insert (
9987 tx : & Transaction ,
10088 target_id : TargetId ,
101- alias : Option < Alias > ,
89+ reg_token : Option < & str > ,
10290 node_type : NodeTypeServer ,
10391 // This is optional because storage targets come "unmapped"
10492 node_id : Option < NodeId > ,
10593) -> Result < ( ) > {
10694 anyhow:: ensure!( target_id > 0 , "A target id must be > 0" ) ;
10795
108- let alias = if let Some ( alias) = alias {
109- alias
110- } else {
111- format ! ( "target_{}_{}" , node_type. user_str( ) , target_id) . try_into ( ) ?
112- } ;
113-
96+ let alias = format ! ( "target_{}_{target_id}" , node_type. user_str( ) ) . try_into ( ) ?;
11497 let new_uid = entity:: insert ( tx, EntityType :: Target , & alias) ?;
11598
11699 tx. execute (
117100 sql ! (
118- "INSERT INTO targets (target_uid, node_type, target_id, node_id, pool_id)
119- VALUES (?1, ?2, ?3, ?4, ?5)"
101+ "INSERT INTO targets (target_uid, node_type, target_id, node_id, pool_id, reg_token )
102+ VALUES (?1, ?2, ?3, ?4, ?5, ?6 )"
120103 ) ,
121104 params ! [
122105 new_uid,
@@ -127,7 +110,8 @@ pub(crate) fn insert(
127110 Some ( 1 )
128111 } else {
129112 None
130- }
113+ } ,
114+ reg_token
131115 ] ,
132116 ) ?;
133117
@@ -287,11 +271,10 @@ mod test {
287271 #[ test]
288272 fn set_get_meta ( ) {
289273 with_test_data ( |tx| {
290- super :: insert_meta ( tx, 1 , Some ( "existing_meta_target" . try_into ( ) . unwrap ( ) ) )
291- . unwrap_err ( ) ;
292- super :: insert_meta ( tx, 99 , Some ( "new_meta_target" . try_into ( ) . unwrap ( ) ) ) . unwrap ( ) ;
293- // existing alias
294- super :: insert_meta ( tx, 99 , Some ( "new_meta_target" . try_into ( ) . unwrap ( ) ) ) . unwrap_err ( ) ;
274+ super :: insert_meta ( tx, 1 ) . unwrap_err ( ) ;
275+ super :: insert_meta ( tx, 99 ) . unwrap ( ) ;
276+ // existing id
277+ super :: insert_meta ( tx, 99 ) . unwrap_err ( ) ;
295278
296279 let targets: i64 = tx
297280 . query_row ( sql ! ( "SELECT COUNT(*) FROM meta_targets" ) , [ ] , |row| {
@@ -306,15 +289,11 @@ mod test {
306289 #[ test]
307290 fn set_get_storage_and_map ( ) {
308291 with_test_data ( |tx| {
309- let new_target_id =
310- super :: insert_storage ( tx, 0 , Some ( "new_storage_target" . try_into ( ) . unwrap ( ) ) )
311- . unwrap ( ) ;
312- super :: insert_storage ( tx, 1000 , Some ( "new_storage_target_2" . try_into ( ) . unwrap ( ) ) )
313- . unwrap ( ) ;
292+ let new_target_id = super :: insert_storage ( tx, 0 , Some ( "new_storage_target" ) ) . unwrap ( ) ;
293+ super :: insert_storage ( tx, 1000 , Some ( "new_storage_target_2" ) ) . unwrap ( ) ;
314294
315- // existing alias
316- super :: insert_storage ( tx, 0 , Some ( "new_storage_target" . try_into ( ) . unwrap ( ) ) )
317- . unwrap_err ( ) ;
295+ // existing id
296+ super :: insert_storage ( tx, 1000 , Some ( "new_storage_target" ) ) . unwrap_err ( ) ;
318297
319298 super :: update_storage_node_mappings ( tx, & [ new_target_id, 1000 ] , 1 ) . unwrap ( ) ;
320299
0 commit comments