@@ -61,9 +61,20 @@ impl<KV: kvapi::KVApi<Error = MetaError>> RowAccessPolicyApi for KV {
6161
6262 let name_ident = & req. name ;
6363
64- let id = fetch_id ( self , IdGenerator :: row_access_id ( ) ) . await ?;
64+ let mask_name_ident = DataMaskNameIdent :: new (
65+ name_ident. tenant ( ) . clone ( ) ,
66+ name_ident. row_access_name ( ) . to_string ( ) ,
67+ ) ;
68+ if self . get_pb ( & mask_name_ident) . await ?. is_some ( ) {
69+ return Ok ( Err (
70+ name_ident. exist_error ( "name conflicts with an existing masking policy" )
71+ ) ) ;
72+ }
73+
74+ let row_access_id = fetch_id ( self , IdGenerator :: row_access_id ( ) ) . await ?;
75+ let policy_id = RowAccessPolicyId :: new ( row_access_id) ;
6576 let mut trials = txn_backoff ( None , func_name ! ( ) ) ;
66- let id = loop {
77+ loop {
6778 trials. next ( ) . unwrap ( ) ?. await ;
6879
6980 let mut txn = TxnRequest :: default ( ) ;
@@ -87,22 +98,11 @@ impl<KV: kvapi::KVApi<Error = MetaError>> RowAccessPolicyApi for KV {
8798 }
8899 }
89100
90- let mask_name_ident = DataMaskNameIdent :: new (
91- name_ident. tenant ( ) . clone ( ) ,
92- name_ident. row_access_name ( ) . to_string ( ) ,
93- ) ;
94- if self . get_pb ( & mask_name_ident) . await ?. is_some ( ) {
95- return Ok ( Err (
96- name_ident. exist_error ( "name conflicts with an existing masking policy" )
97- ) ) ;
98- }
99-
100101 // Create row policy by inserting these record:
101102 // name -> id
102103 // id -> policy
103104
104- let id = RowAccessPolicyId :: new ( id) ;
105- let id_ident = RowAccessPolicyIdIdent :: new_generic ( name_ident. tenant ( ) , id) ;
105+ let id_ident = RowAccessPolicyIdIdent :: new_generic ( name_ident. tenant ( ) , policy_id) ;
106106
107107 debug ! (
108108 id : ? =( & id_ident) ,
@@ -115,8 +115,8 @@ impl<KV: kvapi::KVApi<Error = MetaError>> RowAccessPolicyApi for KV {
115115 txn. condition . push ( txn_cond_eq_seq ( name_ident, curr_seq) ) ;
116116 txn. condition . push ( txn_cond_eq_seq ( & mask_name_ident, 0 ) ) ;
117117 txn. if_then . extend ( vec ! [
118- txn_op_put_pb( name_ident, & id , None ) ?, // name -> policy_id
119- txn_op_put_pb( & id_ident, & meta, None ) ?, // id -> meta
118+ txn_op_put_pb( name_ident, & policy_id , None ) ?, // name -> policy_id
119+ txn_op_put_pb( & id_ident, & meta, None ) ?, // id -> meta
120120 ] ) ;
121121
122122 let ( succ, _responses) = send_txn ( self , txn) . await ?;
@@ -129,12 +129,12 @@ impl<KV: kvapi::KVApi<Error = MetaError>> RowAccessPolicyApi for KV {
129129 ) ;
130130
131131 if succ {
132- break id ;
132+ break ;
133133 }
134134 }
135135 } ;
136136
137- Ok ( Ok ( CreateRowAccessPolicyReply { id : * id } ) )
137+ Ok ( Ok ( CreateRowAccessPolicyReply { id : row_access_id } ) )
138138 }
139139
140140 async fn drop_row_access_policy (
0 commit comments