-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
FileSystemMasterIntegrationTest.java
1399 lines (1273 loc) · 59.1 KB
/
FileSystemMasterIntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.client.fs;
import static org.junit.Assert.assertFalse;
import static org.junit.Assume.assumeFalse;
import alluxio.AlluxioURI;
import alluxio.AuthenticatedUserRule;
import alluxio.ClientContext;
import alluxio.Constants;
import alluxio.client.WriteType;
import alluxio.client.block.BlockMasterClient;
import alluxio.client.file.FileSystem;
import alluxio.client.file.FileSystemTestUtils;
import alluxio.conf.Configuration;
import alluxio.conf.PropertyKey;
import alluxio.exception.AccessControlException;
import alluxio.exception.DirectoryNotEmptyException;
import alluxio.exception.ExceptionMessage;
import alluxio.exception.FileAlreadyExistsException;
import alluxio.exception.FileDoesNotExistException;
import alluxio.exception.InvalidPathException;
import alluxio.exception.status.FailedPreconditionException;
import alluxio.grpc.CompleteFilePOptions;
import alluxio.grpc.CreateDirectoryPOptions;
import alluxio.grpc.CreateFilePOptions;
import alluxio.grpc.DeletePOptions;
import alluxio.grpc.FileSystemMasterCommonPOptions;
import alluxio.grpc.FreePOptions;
import alluxio.grpc.ListStatusPOptions;
import alluxio.grpc.LoadMetadataPType;
import alluxio.grpc.SetAttributePOptions;
import alluxio.grpc.TtlAction;
import alluxio.grpc.WritePType;
import alluxio.heartbeat.HeartbeatContext;
import alluxio.heartbeat.HeartbeatScheduler;
import alluxio.heartbeat.ManuallyScheduleHeartbeat;
import alluxio.master.MasterClientContext;
import alluxio.master.block.BlockMaster;
import alluxio.master.file.FileSystemMaster;
import alluxio.master.file.contexts.CompleteFileContext;
import alluxio.master.file.contexts.CreateDirectoryContext;
import alluxio.master.file.contexts.CreateFileContext;
import alluxio.master.file.contexts.DeleteContext;
import alluxio.master.file.contexts.FreeContext;
import alluxio.master.file.contexts.ListStatusContext;
import alluxio.master.file.contexts.RenameContext;
import alluxio.master.file.contexts.SetAttributeContext;
import alluxio.master.file.meta.TtlIntervalRule;
import alluxio.security.authentication.AuthenticatedClientUser;
import alluxio.security.authorization.Mode;
import alluxio.testutils.BaseIntegrationTest;
import alluxio.testutils.LocalAlluxioClusterResource;
import alluxio.testutils.master.FsMasterResource;
import alluxio.testutils.master.MasterTestUtils;
import alluxio.underfs.UfsMode;
import alluxio.util.CommonUtils;
import alluxio.util.IdUtils;
import alluxio.util.ShellUtils;
import alluxio.util.WaitForOptions;
import alluxio.util.io.FileUtils;
import alluxio.util.io.PathUtils;
import alluxio.wire.FileInfo;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
/**
* Test behavior of {@link FileSystemMaster}.
*
* For example, (concurrently) creating/deleting/renaming files.
*/
public class FileSystemMasterIntegrationTest extends BaseIntegrationTest {
private static final int DEPTH = 6;
private static final int FILES_PER_NODE = 4;
private static final int CONCURRENCY_DEPTH = 3;
private static final AlluxioURI ROOT_PATH = new AlluxioURI("/root");
private static final AlluxioURI ROOT_PATH2 = new AlluxioURI("/root2");
// Modify current time so that implementations can't accidentally pass unit tests by ignoring
// this specified time and always using System.currentTimeMillis()
private static final long TEST_TIME_MS = Long.MAX_VALUE;
private static final long TTL_CHECKER_INTERVAL_MS = 100;
private static final String TEST_USER = "test";
@ClassRule
public static ManuallyScheduleHeartbeat sManuallySchedule =
new ManuallyScheduleHeartbeat(HeartbeatContext.MASTER_TTL_CHECK);
@ClassRule
public static TtlIntervalRule sTtlIntervalRule = new TtlIntervalRule(TTL_CHECKER_INTERVAL_MS);
@Rule
public Timeout mGlobalTimeout = Timeout.seconds(60);
@ClassRule
public static LocalAlluxioClusterResource sLocalAlluxioClusterResource =
new LocalAlluxioClusterResource.Builder()
.setProperty(PropertyKey.USER_METRICS_COLLECTION_ENABLED, false)
.setProperty(PropertyKey.MASTER_TTL_CHECKER_INTERVAL_MS, TTL_CHECKER_INTERVAL_MS)
.setProperty(PropertyKey.WORKER_RAMDISK_SIZE, "10mb")
.setProperty(PropertyKey.MASTER_FILE_ACCESS_TIME_UPDATE_PRECISION, 0)
.setProperty(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT, "1kb")
.setProperty(PropertyKey.SECURITY_LOGIN_USERNAME, TEST_USER)
.setProperty(PropertyKey.MASTER_FILE_SYSTEM_OPERATION_RETRY_CACHE_ENABLED, false)
.build();
@Rule
public TestRule mResetRule = sLocalAlluxioClusterResource.getResetResource();
@Rule
public ExpectedException mThrown = ExpectedException.none();
@Rule
public AuthenticatedUserRule mAuthenticatedUser = new AuthenticatedUserRule(TEST_USER,
Configuration.global());
private FileSystemMaster mFsMaster;
@Before
public final void before() throws Exception {
mFsMaster = sLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess()
.getMaster(FileSystemMaster.class);
}
/**
* Tests the {@link FileInfo} of a directory.
*/
@Test
public void clientFileInfoDirectory() throws Exception {
AlluxioURI path = new AlluxioURI("/testFolder");
mFsMaster.createDirectory(path, CreateDirectoryContext.defaults());
long fileId = mFsMaster.getFileId(path);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("testFolder", fileInfo.getName());
Assert.assertEquals(0, fileInfo.getLength());
assertFalse(fileInfo.isCacheable());
Assert.assertTrue(fileInfo.isCompleted());
Assert.assertTrue(fileInfo.isFolder());
assertFalse(fileInfo.isPersisted());
assertFalse(fileInfo.isPinned());
Assert.assertEquals(TEST_USER, fileInfo.getOwner());
Assert.assertEquals(0755, (short) fileInfo.getMode());
}
/**
* Tests the {@link FileInfo} of an empty file.
*/
@Test
public void clientFileInfoEmptyFile() throws Exception {
FileInfo fileInfo =
mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileContext.defaults());
Assert.assertEquals("testFile", fileInfo.getName());
Assert.assertEquals(0, fileInfo.getLength());
Assert.assertTrue(fileInfo.isCacheable());
assertFalse(fileInfo.isCompleted());
assertFalse(fileInfo.isFolder());
assertFalse(fileInfo.isPersisted());
assertFalse(fileInfo.isPinned());
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
Assert.assertEquals(TtlAction.FREE, fileInfo.getTtlAction());
Assert.assertEquals(TEST_USER, fileInfo.getOwner());
Assert.assertEquals(0644, (short) fileInfo.getMode());
}
private FsMasterResource createFileSystemMasterFromJournal() throws Exception {
return MasterTestUtils.createLeaderFileSystemMasterFromJournalCopy();
}
/**
* Tests concurrent create of files.
*/
@Test
public void concurrentCreate() throws Exception {
ConcurrentCreator concurrentCreator =
new ConcurrentCreator(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH);
concurrentCreator.call();
}
/**
* Tests concurrent delete of files.
*/
@Test
public void concurrentDelete() throws Exception {
ConcurrentCreator concurrentCreator =
new ConcurrentCreator(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH);
concurrentCreator.call();
ConcurrentDeleter concurrentDeleter =
new ConcurrentDeleter(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH);
concurrentDeleter.call();
Assert.assertEquals(0, mFsMaster
.listStatus(new AlluxioURI("/"), ListStatusContext.defaults()).size());
}
/**
* Tests concurrent free of files.
*/
@Test
public void concurrentFree() throws Exception {
ConcurrentCreator concurrentCreator = new ConcurrentCreator(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH,
CreateFileContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
concurrentCreator.call();
ConcurrentFreer concurrentFreer = new ConcurrentFreer(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH);
concurrentFreer.call();
}
/**
* Tests concurrent rename of files.
*/
@Test
public void concurrentRename() throws Exception {
ConcurrentCreator concurrentCreator =
new ConcurrentCreator(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH);
concurrentCreator.call();
int numFiles =
mFsMaster.listStatus(ROOT_PATH, ListStatusContext.defaults()).size();
ConcurrentRenamer concurrentRenamer = new ConcurrentRenamer(DEPTH, CONCURRENCY_DEPTH, ROOT_PATH,
ROOT_PATH2, AlluxioURI.EMPTY_URI);
concurrentRenamer.call();
Assert.assertEquals(numFiles,
mFsMaster.listStatus(ROOT_PATH2, ListStatusContext.defaults()).size());
}
@Test
public void createAlreadyExistFile() throws Exception {
mThrown.expect(FileAlreadyExistsException.class);
mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileContext.defaults());
mFsMaster.createDirectory(new AlluxioURI("/testFile"), CreateDirectoryContext.defaults());
}
@Test
public void createDirectory() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
FileInfo fileInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder")));
Assert.assertTrue(fileInfo.isFolder());
Assert.assertEquals(TEST_USER, fileInfo.getOwner());
Assert.assertEquals(0755, (short) fileInfo.getMode());
}
@Test
public void createFileInvalidPath() throws Exception {
mThrown.expect(InvalidPathException.class);
mFsMaster.createFile(new AlluxioURI("testFile"), CreateFileContext.defaults());
}
@Test
public void createFileInvalidPathTest2() throws Exception {
mThrown.expect(FileAlreadyExistsException.class);
mFsMaster.createFile(new AlluxioURI("/"), CreateFileContext.defaults());
}
@Test
public void createFileInvalidPathTest3() throws Exception {
mThrown.expect(InvalidPathException.class);
mFsMaster.createFile(new AlluxioURI("/testFile1"), CreateFileContext.defaults());
mFsMaster.createFile(new AlluxioURI("/testFile1/testFile2"), CreateFileContext.defaults());
}
@Test
public void createFilePerf() throws Exception {
for (int k = 0; k < 200; k++) {
CreateDirectoryContext context = CreateDirectoryContext
.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
mFsMaster.createDirectory(
new AlluxioURI("/testFile").join(Constants.MASTER_COLUMN_FILE_PREFIX + k).join("0"),
context);
}
for (int k = 0; k < 200; k++) {
mFsMaster.getFileInfo(mFsMaster.getFileId(
new AlluxioURI("/testFile").join(Constants.MASTER_COLUMN_FILE_PREFIX + k).join("0")));
}
}
@Test
public void createFile() throws Exception {
mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileContext.defaults());
FileInfo fileInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFile")));
assertFalse(fileInfo.isFolder());
Assert.assertEquals(TEST_USER, fileInfo.getOwner());
Assert.assertEquals(0644, (short) fileInfo.getMode());
}
@Test
public void deleteUnsyncedDirectory() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.createDirectory(new AlluxioURI("/testFolder/child"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
String ufs = Configuration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
Files.createDirectory(Paths.get(ufs, "testFolder", "ufsOnlyDir"));
try {
mFsMaster.delete(new AlluxioURI("/testFolder"), DeleteContext
.mergeFrom(DeletePOptions.newBuilder().setUnchecked(false).setRecursive(true)));
Assert.fail("Expected deleting an out of sync directory to fail");
} catch (IOException e) {
// Expected
}
// Make sure the root folder still exists in Alluxio space.
mFsMaster.listStatus(new AlluxioURI("/testFolder"), ListStatusContext
.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER)));
// The child was in sync, so it should be deleted both from Alluxio and the UFS.
mThrown.expect(FileDoesNotExistException.class);
mFsMaster.listStatus(new AlluxioURI("/testFolder/child"), ListStatusContext
.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ALWAYS)));
}
@Test
public void deleteDirectoryWithDirectories() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
mFsMaster.createDirectory(new AlluxioURI("/testFolder/testFolder2"),
CreateDirectoryContext.defaults());
long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"),
CreateFileContext.defaults()).getFileId();
long fileId2 = mFsMaster.createFile(new AlluxioURI("/testFolder/testFolder2/testFile2"),
CreateFileContext.defaults()).getFileId();
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
Assert.assertEquals(fileId2,
mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2")));
mFsMaster.delete(new AlluxioURI("/testFolder"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
Assert.assertEquals(IdUtils.INVALID_FILE_ID,
mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2")));
}
@Test
public void deleteDirectoryWithDirectoriesTest2() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
mFsMaster.createDirectory(new AlluxioURI("/testFolder/testFolder2"),
CreateDirectoryContext.defaults());
long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"),
CreateFileContext.defaults()).getFileId();
long fileId2 = mFsMaster.createFile(new AlluxioURI("/testFolder/testFolder2/testFile2"),
CreateFileContext.defaults()).getFileId();
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
Assert.assertEquals(fileId2,
mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2")));
try {
mFsMaster.delete(new AlluxioURI("/testFolder/testFolder2"),
DeleteContext.defaults());
Assert.fail("Deleting a nonempty directory nonrecursively should fail");
} catch (DirectoryNotEmptyException e) {
Assert.assertEquals(
ExceptionMessage.DELETE_NONEMPTY_DIRECTORY_NONRECURSIVE.getMessage("testFolder2"),
e.getMessage());
}
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
Assert.assertEquals(fileId2,
mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2")));
}
@Test
public void deleteDirectoryWithFiles() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"),
CreateFileContext.defaults()).getFileId();
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
mFsMaster.delete(new AlluxioURI("/testFolder"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
Assert.assertEquals(IdUtils.INVALID_FILE_ID,
mFsMaster.getFileId(new AlluxioURI("/testFolder")));
}
@Test
public void deleteDirectoryWithFilesTest2() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"),
CreateFileContext.defaults()).getFileId();
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
try {
mFsMaster.delete(new AlluxioURI("/testFolder"), DeleteContext.defaults());
Assert.fail("Deleting a nonempty directory nonrecursively should fail");
} catch (DirectoryNotEmptyException e) {
Assert.assertEquals(
ExceptionMessage.DELETE_NONEMPTY_DIRECTORY_NONRECURSIVE.getMessage("testFolder"),
e.getMessage());
}
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
}
@Test
public void deleteEmptyDirectory() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
mFsMaster.delete(new AlluxioURI("/testFolder"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
Assert.assertEquals(IdUtils.INVALID_FILE_ID,
mFsMaster.getFileId(new AlluxioURI("/testFolder")));
}
@Test
public void deleteDirectoryWithPersistedAndNotPersistedSubfolders() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.createDirectory(new AlluxioURI("/testFolder/persisted"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.createDirectory(new AlluxioURI("/testFolder/inAlluxio1"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.createDirectory(new AlluxioURI("/testFolder/inAlluxio1/inAlluxio2"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.delete(new AlluxioURI("/testFolder"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
Assert.assertEquals(IdUtils.INVALID_FILE_ID,
mFsMaster.getFileId(new AlluxioURI("/testFolder")));
}
@Test
public void deleteDirectoryRecursive() throws Exception {
AlluxioURI dir = new AlluxioURI("/testFolder");
mFsMaster.createDirectory(dir, CreateDirectoryContext.defaults());
FileSystem fs = sLocalAlluxioClusterResource.get().getClient();
for (int i = 0; i < 3; i++) {
FileSystemTestUtils.createByteFile(fs, PathUtils.concatPath(dir, "file" + i), 100,
CreateFilePOptions.newBuilder().setWriteType(WritePType.MUST_CACHE).build());
}
fs.delete(dir, DeletePOptions.newBuilder().setRecursive(true).build());
assertFalse(fs.exists(dir));
// Make sure that the blocks are cleaned up
BlockMasterClient blockClient =
BlockMasterClient.Factory.create(MasterClientContext
.newBuilder(ClientContext.create(Configuration.global())).build());
CommonUtils.waitFor("data to be deleted", () -> {
try {
return blockClient.getUsedBytes() == 0;
} catch (Exception e) {
throw new RuntimeException(e);
}
}, WaitForOptions.defaults().setTimeoutMs(10 * Constants.SECOND_MS));
}
@Test
public void deleteFile() throws Exception {
long fileId =
mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileContext.defaults()).getFileId();
Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFile")));
mFsMaster.delete(new AlluxioURI("/testFile"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
Assert.assertEquals(IdUtils.INVALID_FILE_ID, mFsMaster.getFileId(new AlluxioURI("/testFile")));
}
@Test
public void deleteRoot() throws Exception {
mThrown.expect(InvalidPathException.class);
mThrown.expectMessage(ExceptionMessage.DELETE_ROOT_DIRECTORY.getMessage());
mFsMaster.delete(new AlluxioURI("/"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)
.setDeleteMountPoint(true)));
}
@Test
public void getCapacityBytes() {
BlockMaster blockMaster =
sLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess()
.getMaster(BlockMaster.class);
Assert.assertEquals(10 * Constants.MB, blockMaster.getCapacityBytes());
}
@Test
public void lastModificationTimeCompleteFile() throws Exception {
long fileId =
mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileContext.defaults()).getFileId();
long opTimeMs = TEST_TIME_MS;
mFsMaster.completeFile(new AlluxioURI("/testFile"), CompleteFileContext
.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(0)).setOperationTimeMs(opTimeMs));
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals(opTimeMs, fileInfo.getLastModificationTimeMs());
Assert.assertEquals(opTimeMs, fileInfo.getLastAccessTimeMs());
}
@Test
public void lastModificationTimeCreateFile() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long opTimeMs = TEST_TIME_MS;
CreateFileContext context = CreateFileContext.defaults().setOperationTimeMs(opTimeMs);
mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), context);
FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder")));
Assert.assertEquals(opTimeMs, folderInfo.getLastModificationTimeMs());
Assert.assertEquals(opTimeMs, folderInfo.getLastAccessTimeMs());
}
/**
* Tests that deleting a file from a folder updates the folder's last modification time.
*/
@Test
public void lastModificationTimeDelete() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), CreateFileContext.defaults());
long folderId = mFsMaster.getFileId(new AlluxioURI("/testFolder"));
long modificationTimeBeforeDelete = mFsMaster.getFileInfo(folderId).getLastModificationTimeMs();
long accessTimeBeforeDelete = mFsMaster.getFileInfo(folderId).getLastAccessTimeMs();
CommonUtils.sleepMs(2);
mFsMaster.delete(new AlluxioURI("/testFolder/testFile"),
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
long modificationTimeAfterDelete = mFsMaster.getFileInfo(folderId).getLastModificationTimeMs();
long accessTimeAfterDelete = mFsMaster.getFileInfo(folderId).getLastAccessTimeMs();
Assert.assertTrue(modificationTimeBeforeDelete < modificationTimeAfterDelete);
Assert.assertTrue(accessTimeBeforeDelete < accessTimeAfterDelete);
}
@Test
public void lastModificationTimeRename() throws Exception {
AlluxioURI srcPath = new AlluxioURI("/testFolder/testFile1");
AlluxioURI dstPath = new AlluxioURI("/testFolder/testFile2");
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
mFsMaster.createFile(srcPath, CreateFileContext.defaults());
mFsMaster.rename(srcPath, dstPath, RenameContext.defaults().setOperationTimeMs(TEST_TIME_MS));
FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder")));
Assert.assertEquals(TEST_TIME_MS, folderInfo.getLastModificationTimeMs());
Assert.assertEquals(TEST_TIME_MS, folderInfo.getLastAccessTimeMs());
}
@Test
public void listFiles() throws Exception {
CreateFileContext options =
CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(64));
HashSet<Long> ids = new HashSet<>();
HashSet<Long> dirIds = new HashSet<>();
for (int i = 0; i < 10; i++) {
AlluxioURI dir = new AlluxioURI("/i" + i);
mFsMaster.createDirectory(dir, CreateDirectoryContext.defaults());
dirIds.add(mFsMaster.getFileId(dir));
for (int j = 0; j < 10; j++) {
ids.add(mFsMaster.createFile(dir.join("j" + j), options).getFileId());
}
}
HashSet<Long> listedIds = new HashSet<>();
HashSet<Long> listedDirIds = new HashSet<>();
List<FileInfo> infoList =
mFsMaster.listStatus(new AlluxioURI("/"), ListStatusContext.defaults());
for (FileInfo info : infoList) {
long id = info.getFileId();
listedDirIds.add(id);
for (FileInfo fileInfo : mFsMaster.listStatus(new AlluxioURI(info.getPath()),
ListStatusContext.defaults())) {
listedIds.add(fileInfo.getFileId());
}
}
Assert.assertEquals(ids, listedIds);
Assert.assertEquals(dirIds, listedDirIds);
}
@Test
public void listStatus() throws Exception {
CreateFileContext options =
CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(64));
for (int i = 0; i < 10; i++) {
mFsMaster.createDirectory(new AlluxioURI("/i" + i), CreateDirectoryContext.defaults());
for (int j = 0; j < 10; j++) {
mFsMaster.createFile(new AlluxioURI("/i" + i + "/j" + j), options);
}
}
Assert.assertEquals(1,
mFsMaster
.listStatus(new AlluxioURI("/i0/j0"), ListStatusContext.defaults())
.size());
for (int i = 0; i < 10; i++) {
Assert.assertEquals(10,
mFsMaster
.listStatus(new AlluxioURI("/i" + i), ListStatusContext.defaults())
.size());
}
Assert.assertEquals(10, mFsMaster
.listStatus(new AlluxioURI("/"), ListStatusContext.defaults()).size());
}
@Test
public void notFileCompletion() throws Exception {
mThrown.expect(FileDoesNotExistException.class);
mFsMaster.createDirectory(new AlluxioURI("/testFile"), CreateDirectoryContext.defaults());
mFsMaster.completeFile(new AlluxioURI("/testFile"), CompleteFileContext.defaults());
}
@Test
public void renameExistingDst() throws Exception {
mFsMaster.createFile(new AlluxioURI("/testFile1"), CreateFileContext.defaults());
mFsMaster.createFile(new AlluxioURI("/testFile2"), CreateFileContext.defaults());
try {
mFsMaster.rename(new AlluxioURI("/testFile1"), new AlluxioURI("/testFile2"),
RenameContext.defaults());
Assert.fail("Should not be able to rename to an existing file");
} catch (Exception e) {
// expected
}
}
@Test
public void renameNonexistent() throws Exception {
mFsMaster.createFile(new AlluxioURI("/testFile1"), CreateFileContext.defaults());
Assert.assertEquals(IdUtils.INVALID_FILE_ID, mFsMaster.getFileId(new AlluxioURI("/testFile2")));
}
@Test
public void renameToDeeper() throws Exception {
CreateFileContext createFileOptions =
CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setRecursive(true));
CreateDirectoryContext createDirectoryContext = CreateDirectoryContext
.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
mThrown.expect(InvalidPathException.class);
mFsMaster.createDirectory(new AlluxioURI("/testDir1/testDir2"), createDirectoryContext);
mFsMaster.createFile(new AlluxioURI("/testDir1/testDir2/testDir3/testFile3"),
createFileOptions);
mFsMaster.rename(new AlluxioURI("/testDir1/testDir2"),
new AlluxioURI("/testDir1/testDir2/testDir3/testDir4"), RenameContext.defaults());
}
@Test
public void ttlCreateFile() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long ttl = 100;
CreateFileContext context = CreateFileContext
.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions
.newBuilder().setTtl(ttl).setTtlAction(alluxio.grpc.TtlAction.FREE)));
mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), context);
FileInfo folderInfo =
mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
Assert.assertEquals(ttl, folderInfo.getTtl());
Assert.assertEquals(TtlAction.FREE, folderInfo.getTtlAction());
}
@Test
public void ttlExpiredCreateFile() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long ttl = 1;
CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder()
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl)))
.setWriteType(WriteType.CACHE_THROUGH);
long fileId =
mFsMaster.createFile(new AlluxioURI("/testFolder/testFile1"), context).getFileId();
FileInfo folderInfo =
mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile1")));
Assert.assertEquals(fileId, folderInfo.getFileId());
Assert.assertEquals(ttl, folderInfo.getTtl());
// Sleep for the ttl expiration.
CommonUtils.sleepMs(2 * TTL_CHECKER_INTERVAL_MS);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
HeartbeatScheduler.await(HeartbeatContext.MASTER_TTL_CHECK, 10, TimeUnit.SECONDS);
HeartbeatScheduler.schedule(HeartbeatContext.MASTER_TTL_CHECK);
HeartbeatScheduler.await(HeartbeatContext.MASTER_TTL_CHECK, 10, TimeUnit.SECONDS);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
Assert.assertEquals(TtlAction.DELETE, fileInfo.getTtlAction());
}
@Test
public void ttlExpiredCreateFileWithFreeAction() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long ttl = 1;
CreateFileContext context = CreateFileContext
.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions
.newBuilder().setTtl(ttl).setTtlAction(alluxio.grpc.TtlAction.FREE)))
.setWriteType(WriteType.CACHE_THROUGH);
long fileId =
mFsMaster.createFile(new AlluxioURI("/testFolder/testFile1"), context).getFileId();
FileInfo folderInfo =
mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile1")));
Assert.assertEquals(fileId, folderInfo.getFileId());
Assert.assertEquals(ttl, folderInfo.getTtl());
Assert.assertEquals(TtlAction.FREE, folderInfo.getTtlAction());
// Sleep for the ttl expiration.
CommonUtils.sleepMs(2 * TTL_CHECKER_INTERVAL_MS);
HeartbeatScheduler.await(HeartbeatContext.MASTER_TTL_CHECK, 10, TimeUnit.SECONDS);
HeartbeatScheduler.schedule(HeartbeatContext.MASTER_TTL_CHECK);
HeartbeatScheduler.await(HeartbeatContext.MASTER_TTL_CHECK, 10, TimeUnit.SECONDS);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
Assert.assertEquals(TtlAction.DELETE, fileInfo.getTtlAction());
}
@Test
public void ttlRename() throws Exception {
AlluxioURI srcPath = new AlluxioURI("/testFolder/testFile1");
AlluxioURI dstPath = new AlluxioURI("/testFolder/testFile2");
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
long ttl = 1;
CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder()
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl)));
mFsMaster.createFile(srcPath, context);
mFsMaster.rename(srcPath, dstPath, RenameContext.defaults().setOperationTimeMs(TEST_TIME_MS));
FileInfo folderInfo =
mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile2")));
Assert.assertEquals(ttl, folderInfo.getTtl());
}
@Test
public void ufsModeCreateFile() throws Exception {
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
// Alluxio only should not be affected
mFsMaster.createFile(new AlluxioURI("/in_alluxio"),
CreateFileContext.defaults().setWriteType(WriteType.MUST_CACHE));
// Ufs file creation should throw an exception
mThrown.expect(AccessControlException.class);
mFsMaster.createFile(new AlluxioURI("/in_ufs"),
CreateFileContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
}
@Test
public void ufsModeCreateDirectory() throws Exception {
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
// Alluxio only should not be affected
mFsMaster.createDirectory(new AlluxioURI("/in_alluxio"),
CreateDirectoryContext.defaults().setWriteType(WriteType.MUST_CACHE));
// Ufs file creation should throw an exception
mThrown.expect(AccessControlException.class);
mFsMaster.createDirectory(new AlluxioURI("/in_ufs"),
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
}
@Test
public void ufsModeDeleteFile() throws Exception {
AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
mFsMaster.createFile(alluxioFile, CreateFileContext.defaults()
.setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
mThrown.expect(FailedPreconditionException.class);
mFsMaster.delete(alluxioFile, DeleteContext.defaults());
}
@Test
public void ufsModeDeleteDirectory() throws Exception {
AlluxioURI alluxioDirectory = new AlluxioURI("/in_ufs_dir");
mFsMaster.createDirectory(alluxioDirectory,
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
AlluxioURI alluxioFile = new AlluxioURI("/in_ufs_dir/in_ufs_file");
mFsMaster.createFile(alluxioFile, CreateFileContext.defaults()
.setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
mThrown.expect(FailedPreconditionException.class);
mFsMaster.delete(alluxioDirectory,
DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
// Check Alluxio entries exist after failed delete
long dirId = mFsMaster.getFileId(alluxioDirectory);
Assert.assertNotEquals(-1, dirId);
long fileId = mFsMaster.getFileId(alluxioFile);
Assert.assertNotEquals(-1, fileId);
}
@Test
public void ufsModeRenameFile() throws Exception {
mFsMaster.createFile(new AlluxioURI("/in_ufs_src"),
CreateFileContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
mThrown.expect(AccessControlException.class);
mFsMaster.rename(new AlluxioURI("/in_ufs_src"), new AlluxioURI("/in_ufs_dst"),
RenameContext.defaults());
}
@Test
public void ufsModeRenameDirectory() throws Exception {
AlluxioURI alluxioDirectory = new AlluxioURI("/in_ufs_dir");
mFsMaster.createDirectory(alluxioDirectory,
CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
AlluxioURI alluxioFile = new AlluxioURI("/in_ufs_dir/in_ufs_file");
mFsMaster.createFile(alluxioFile, CreateFileContext.defaults()
.setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
mThrown.expect(AccessControlException.class);
mFsMaster.rename(alluxioDirectory, new AlluxioURI("/in_ufs_dst"), RenameContext.defaults());
// Check Alluxio entries exist after failed rename
long dirId = mFsMaster.getFileId(alluxioDirectory);
Assert.assertNotEquals(-1, dirId);
long fileId = mFsMaster.getFileId(alluxioFile);
Assert.assertNotEquals(-1, fileId);
}
@Test
public void ufsModeSetAttribute() throws Exception {
AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
mFsMaster.createFile(alluxioFile, CreateFileContext.defaults()
.setWriteType(WriteType.CACHE_THROUGH));
mFsMaster.updateUfsMode(new AlluxioURI(mFsMaster.getUfsAddress()),
UfsMode.READ_ONLY);
long opTimeMs = TEST_TIME_MS;
mFsMaster.completeFile(alluxioFile, CompleteFileContext
.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(0))
.setOperationTimeMs(opTimeMs));
mThrown.expect(AccessControlException.class);
mFsMaster.setAttribute(alluxioFile, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
}
@Test
public void setModeOwnerNoWritePermission() throws Exception {
AlluxioURI root = new AlluxioURI("/");
mFsMaster.setAttribute(root, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
try (AutoCloseable closeable =
new AuthenticatedUserRule("foo", Configuration.global()).toResource()) {
AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
FileInfo file = mFsMaster.createFile(alluxioFile, CreateFileContext.defaults());
long opTimeMs = TEST_TIME_MS;
mFsMaster.completeFile(alluxioFile, CompleteFileContext
.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(0))
.setOperationTimeMs(opTimeMs));
mFsMaster.setAttribute(alluxioFile, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0407).toProto())));
Assert.assertEquals(0407, mFsMaster.getFileInfo(file.getFileId()).getMode());
mFsMaster.setAttribute(alluxioFile, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
Assert.assertEquals(0777, mFsMaster.getFileInfo(file.getFileId()).getMode());
}
}
@Test
public void setModeNoOwner() throws Exception {
AlluxioURI root = new AlluxioURI("/");
mFsMaster.setAttribute(root, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
try (AutoCloseable closeable =
new AuthenticatedUserRule("foo", Configuration.global()).toResource()) {
FileInfo file = mFsMaster.createFile(alluxioFile, CreateFileContext.defaults());
long opTimeMs = TEST_TIME_MS;
mFsMaster.completeFile(alluxioFile, CompleteFileContext
.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(0))
.setOperationTimeMs(opTimeMs));
mFsMaster.setAttribute(alluxioFile, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
Assert.assertEquals(0777, mFsMaster.getFileInfo(file.getFileId()).getMode());
}
mThrown.expect(AccessControlException.class);
try (AutoCloseable closeable =
new AuthenticatedUserRule("bar", Configuration.global()).toResource()) {
mFsMaster.setAttribute(alluxioFile, SetAttributeContext
.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0677).toProto())));
}
}
/**
* Tests creating a directory in a nested directory load the UFS status of Inodes on the path.
*/
@Test
public void createDirectoryInNestedDirectories() throws Exception {
String ufs = Configuration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String targetPath = Paths.get(ufs, "d1", "d2", "d3").toString();
FileUtils.createDir(targetPath);
FileUtils.changeLocalFilePermission(targetPath, new Mode((short) 0755).toString());
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0700).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3", "d4").toString());
mFsMaster.createDirectory(path,
CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true)
.setMode(new Mode((short) 0755).toProto())).setWriteType(WriteType.CACHE_THROUGH));
long fileId = mFsMaster.getFileId(new AlluxioURI("/d1"));
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("d1", fileInfo.getName());
Assert.assertTrue(fileInfo.isFolder());
Assert.assertTrue(fileInfo.isPersisted());
Assert.assertEquals(0700, (short) fileInfo.getMode());
}
/**
* Tests listing a directory in a nested directory load the UFS status of Inodes on the path.
*/
@Test
public void loadMetadataInNestedDirectories() throws Exception {
String ufs = Configuration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String targetPath = Paths.get(ufs, "d1", "d2", "d3").toString();
FileUtils.createDir(targetPath);
FileUtils.changeLocalFilePermission(targetPath, new Mode((short) 0755).toString());
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0700).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3").toString());
mFsMaster.listStatus(path, ListStatusContext
.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ONCE)));
long fileId = mFsMaster.getFileId(new AlluxioURI("/d1"));
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("d1", fileInfo.getName());
Assert.assertTrue(fileInfo.isFolder());
Assert.assertTrue(fileInfo.isPersisted());
Assert.assertEquals(0700, (short) fileInfo.getMode());
}
/**
* Tests creating nested directories.
*/
@Test
public void createNestedDirectories() throws Exception {
String ufs = Configuration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.createDir(parentPath);
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0755).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3", "d4").toString());
String ufsPath = Paths.get(ufs, "d1", "d2", "d3", "d4").toString();
mFsMaster.createDirectory(path,
CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true)
.setMode(new Mode((short) 0700).toProto())).setWriteType(WriteType.CACHE_THROUGH));
long fileId = mFsMaster.getFileId(path);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("d4", fileInfo.getName());
Assert.assertTrue(fileInfo.isFolder());
Assert.assertTrue(fileInfo.isPersisted());
Assert.assertEquals(0700, (short) fileInfo.getMode());
Assert.assertTrue(FileUtils.exists(ufsPath));
Assert.assertEquals(0700, FileUtils.getLocalFileMode(ufsPath));
}
/**
* Tests creating a directory in a nested directory without execute permission.
*/
@Test(expected = IOException.class)
public void createDirectoryInNestedDirectoriesWithoutExecutePermission() throws Exception {
// Assume the user is not root. This test doesn't work as root because root *is* allowed to
// create subdirectories even without execute permission on the parent directory.
assumeFalse(ShellUtils.execCommand("id", "-u").trim().equals("0"));
String ufs = Configuration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.createDir(parentPath);
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0600).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3", "d4").toString());
// this should fail
mFsMaster.createDirectory(path,
CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true)
.setMode(new Mode((short) 0755).toProto())).setWriteType(WriteType.CACHE_THROUGH));
}
/**
* Tests loading ufs last modified time for directories.
*/
@Test
public void loadDirectoryTimestamps() throws Exception {
String name = "d1";
String ufs = Configuration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String ufsPath = Paths.get(ufs, name).toString();
FileUtils.createDir(ufsPath);
File file = new File(ufsPath);
long ufsTime = file.lastModified();
Thread.sleep(100);
AlluxioURI path = new AlluxioURI("/" + name);
long fileId = mFsMaster.getFileId(path);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
long alluxioTime = fileInfo.getLastModificationTimeMs();
Assert.assertEquals(name, fileInfo.getName());
Assert.assertTrue(fileInfo.isFolder());
Assert.assertTrue(fileInfo.isPersisted());
Assert.assertEquals(ufsTime, alluxioTime);