11package org .apache .hadoop .hdfs .db .ignite ;
22
3+ import java .io .File ;
34import java .util .List ;
45import java .util .TreeSet ;
56import java .util .Set ;
67import java .util .Map ;
7- import org .apache .ignite .IgniteCache ;
8+ import java .util .HashMap ;
9+ import java .util .HashSet ;
10+ import javax .cache .Cache ;
811import org .apache .ignite .Ignite ;
12+ import org .apache .ignite .IgniteCache ;
13+ import org .apache .ignite .cache .query .ScanQuery ;
914import org .apache .ignite .lang .IgniteClosure ;
15+ import org .apache .ignite .lang .IgniteBiPredicate ;
1016import org .apache .ignite .internal .IgniteEx ;
1117import org .apache .ignite .internal .processors .cache .persistence .wal .FileWriteAheadLogManager ;
1218import org .apache .ignite .resources .IgniteInstanceResource ;
1319import org .apache .ignite .binary .BinaryObject ;
1420import org .apache .ignite .binary .BinaryObjectBuilder ;
1521import org .apache .ignite .cache .query .SqlFieldsQuery ;
22+ import org .apache .ignite .transactions .Transaction ;
23+ import org .apache .ignite .transactions .TransactionConcurrency ;
24+ import org .apache .ignite .transactions .TransactionIsolation ;
1625
1726public class SetPermissions implements IgniteClosure <PermissionsPayload , String > {
1827
@@ -23,12 +32,51 @@ public class SetPermissions implements IgniteClosure<PermissionsPayload, String>
2332 public String apply (PermissionsPayload payload ) {
2433 IgniteCache <BinaryObject , BinaryObject > inodesBinary = ignite .cache ("inodes" ).withKeepBinary ();
2534
26- // Using EntryProcessor.invokeAll to set every permission value in place.
27- inodesBinary .invokeAll (payload .keys , (entry , object ) -> {
28- BinaryObject inode = entry .getValue ().toBuilder ().setField ("permission" , payload .permission ).build ();
29- entry .setValue (inode );
30- return null ;
31- });
35+ File file = new File (payload .path );
36+ String parent = file .getParent ();
37+ String name = file .getName ();
38+
39+ Transaction tx = ignite .transactions ().txStart (
40+ TransactionConcurrency .PESSIMISTIC , TransactionIsolation .SERIALIZABLE );
41+
42+ // 1. query subtree inodes
43+ List <Cache .Entry <BinaryObject , BinaryObject >> result ;
44+ ScanQuery <BinaryObject , BinaryObject > scanAddress = new ScanQuery <>(
45+ new IgniteBiPredicate <BinaryObject , BinaryObject >() {
46+ @ Override
47+ public boolean apply (BinaryObject binaryKey , BinaryObject binaryObject ) {
48+ return ((String )binaryKey .field ("parentName" )).startsWith (parent );
49+ }
50+ }
51+ );
52+ result = inodesBinary .query (scanAddress ).getAll ();
53+
54+ // 2. update subtree permission
55+ Map <BinaryObject , BinaryObject > map = new HashMap <>();
56+ BinaryObjectBuilder inodeKeyBuilder = ignite .binary ().builder ("InodeKey" );
57+ for (Cache .Entry <BinaryObject , BinaryObject > entry : result ) {
58+ BinaryObject inodeValue = entry .getValue ();
59+ inodeValue = inodeValue .toBuilder ()
60+ .setField ("permission" , payload .permission )
61+ .build ();
62+ map .put (entry .getKey (), inodeValue );
63+ }
64+
65+ // 3. update subtree to DB
66+ inodesBinary .putAll (map );
67+
68+ BinaryObject rootKey = inodeKeyBuilder
69+ .setField ("parentName" , parent )
70+ .setField ("name" , name )
71+ .build ();
72+ BinaryObject inodeValue = inodesBinary .get (rootKey );
73+ inodeValue = inodeValue .toBuilder ()
74+ .setField ("permission" , payload .permission )
75+ .build ();
76+ inodesBinary .put (rootKey , inodeValue );
77+
78+ tx .commit ();
79+ tx .close ();
3280
3381 FileWriteAheadLogManager walMgr = (FileWriteAheadLogManager )(
3482 ((IgniteEx )ignite ).context ().cache ().context ().wal ());
0 commit comments