1- use crate :: engine:: enforcement_history:: EnforcementEvent ;
2- use crate :: engine:: policy_lifecycle:: PolicyDraft ;
3- use crate :: engine:: scheduler:: { AnalysisRun , AnalysisSchedule } ;
41use crate :: error:: { AegisError , AegisResult } ;
52use crate :: storage:: traits:: {
63 BackendType , IntegrityReport , PolicyVersion , StorageBackend , StorageMeta , StorageTransaction ,
@@ -12,12 +9,9 @@ use crate::types::{
129 TupleMutation ,
1310} ;
1411use chrono:: { DateTime , Utc } ;
15- use rocksdb:: {
16- BlockBasedOptions , Cache , ColumnFamily , ColumnFamilyDescriptor , DB , DBIterator , Direction ,
17- IteratorMode , Options ,
18- } ;
19- use serde_json;
12+ use rocksdb:: { BlockBasedOptions , Cache , ColumnFamily , DB , Direction , IteratorMode , Options } ;
2013use std:: collections:: HashMap ;
14+ use std:: sync:: Arc ;
2115use uuid:: Uuid ;
2216
2317const CF_META : & str = "meta" ;
@@ -59,7 +53,7 @@ fn tuple_from_value(value: &[u8]) -> AegisResult<RelationshipTuple> {
5953}
6054
6155pub struct RocksDbStorage {
62- db : DB ,
56+ db : Arc < DB > ,
6357 node_id : Uuid ,
6458 revision_mutex : std:: sync:: Mutex < ( ) > ,
6559 actor_identity : std:: sync:: Mutex < Option < String > > ,
@@ -91,8 +85,10 @@ impl RocksDbStorage {
9185 CF_ENFORCEMENT_EVENTS ,
9286 ] ;
9387
94- let db = DB :: open_cf ( & opts, path, cfs)
95- . map_err ( |e| AegisError :: StorageConnection ( e. to_string ( ) ) ) ?;
88+ let db = Arc :: new (
89+ DB :: open_cf ( & opts, path, cfs)
90+ . map_err ( |e| AegisError :: StorageConnection ( e. to_string ( ) ) ) ?,
91+ ) ;
9692
9793 // Initialize revision if not present
9894 let cf_meta = db
@@ -123,7 +119,7 @@ impl RocksDbStorage {
123119
124120 Ok ( Self {
125121 db,
126- node_id,
122+ node_id : Uuid :: new_v4 ( ) ,
127123 revision_mutex : std:: sync:: Mutex :: new ( ( ) ) ,
128124 actor_identity : std:: sync:: Mutex :: new ( None ) ,
129125 } )
@@ -276,7 +272,7 @@ impl RocksDbStorage {
276272 & self ,
277273 partition_id : & PartitionId ,
278274 tuple : & RelationshipTuple ,
279- revision : Revision ,
275+ _revision : Revision ,
280276 ) -> AegisResult < ( ) > {
281277 let cf_tuples = self
282278 . db
@@ -315,7 +311,7 @@ impl RocksDbStorage {
315311 & self ,
316312 partition_id : & PartitionId ,
317313 key : & TupleKey ,
318- revision : Revision ,
314+ _revision : Revision ,
319315 ) -> AegisResult < ( ) > {
320316 let cf_tuples = self
321317 . db
@@ -1092,7 +1088,7 @@ impl StorageBackend for RocksDbStorage {
10921088
10931089 let next_cursor = if ( offset as usize + tuples. len ( ) ) < total {
10941090 Some ( PaginationCursor {
1095- offset : offset + limit,
1091+ offset : offset + limit as u64 ,
10961092 revision,
10971093 } )
10981094 } else {
@@ -1111,7 +1107,7 @@ impl StorageBackend for RocksDbStorage {
11111107 }
11121108
11131109 fn current_token ( & self ) -> AegisResult < RevisionToken > {
1114- let revision = self . current_revision ( ) ?;
1110+ let revision = self . current_revision ( & PartitionId :: default ( ) ) ?;
11151111 Ok ( RevisionToken :: new ( revision, self . node_id ) )
11161112 }
11171113
@@ -1220,8 +1216,8 @@ impl StorageBackend for RocksDbStorage {
12201216 break ;
12211217 }
12221218
1219+ let event_obj = event[ "object" ] . as_str ( ) . unwrap_or ( "" ) . to_string ( ) ;
12231220 if let Some ( obj) = object {
1224- let event_obj = event[ "object" ] . as_str ( ) . unwrap_or ( "" ) ;
12251221 if event_obj != obj. as_str ( ) {
12261222 continue ;
12271223 }
@@ -1250,7 +1246,7 @@ impl StorageBackend for RocksDbStorage {
12501246 action,
12511247 subject : event[ "subject" ] . as_str ( ) . unwrap_or ( "" ) . to_string ( ) ,
12521248 relation : event[ "relation" ] . as_str ( ) . unwrap_or ( "" ) . to_string ( ) ,
1253- object : event_obj. to_string ( ) ,
1249+ object : event_obj,
12541250 timestamp,
12551251 metadata,
12561252 identity,
@@ -1733,7 +1729,7 @@ impl StorageBackend for RocksDbStorage {
17331729 while iter. valid ( ) {
17341730 if let ( Some ( key) , Some ( value) ) = ( iter. key ( ) , iter. value ( ) ) {
17351731 let key_str = String :: from_utf8_lossy ( key) ;
1736- if let Ok ( version_num ) = key_str. parse :: < u32 > ( ) {
1732+ if key_str. parse :: < u32 > ( ) . is_ok ( ) {
17371733 if let Ok ( pv) = serde_json:: from_slice :: < PolicyVersion > ( value) {
17381734 versions. push ( pv) ;
17391735 }
@@ -1904,7 +1900,7 @@ impl StorageBackend for RocksDbStorage {
19041900
19051901/// A RocksDB transaction using WriteBatch for atomicity.
19061902pub struct RocksDbTransaction {
1907- db : DB ,
1903+ db : Arc < DB > ,
19081904 partition_id : String ,
19091905 batch : rocksdb:: WriteBatch ,
19101906 cf_tuples : rocksdb:: ColumnFamily ,
0 commit comments