68
68
import java .util .UUID ;
69
69
70
70
import static org .assertj .core .api .Assertions .assertThat ;
71
+ import static org .junit .jupiter .api .Assumptions .assumeFalse ;
71
72
72
73
/** Unit test for {@link ReusableDataTransferStrategy}. */
73
74
@ ExtendWith (ParameterizedTestExtension .class )
@@ -169,6 +170,10 @@ private byte[] genRandomBytes(int length) {
169
170
}
170
171
171
172
private void createDbFiles (List <String > fileNames ) throws IOException {
173
+ createDbFiles (fileNames , 2048 );
174
+ }
175
+
176
+ private void createDbFiles (List <String > fileNames , int fileLength ) throws IOException {
172
177
for (String fileName : fileNames ) {
173
178
Path dir =
174
179
FileOwnershipDecider .shouldAlwaysBeLocal (new Path (fileName ))
@@ -177,7 +182,7 @@ private void createDbFiles(List<String> fileNames) throws IOException {
177
182
FSDataOutputStream output =
178
183
dbDelegateFileSystem .create (
179
184
new Path (dir , fileName ), FileSystem .WriteMode .OVERWRITE );
180
- output .write (genRandomBytes (2048 ));
185
+ output .write (genRandomBytes (fileLength ));
181
186
output .sync ();
182
187
output .close ();
183
188
dbFilePaths .put (fileName , new Path (dir , fileName ));
@@ -253,13 +258,18 @@ private void assertFilesReusedToCheckpoint(List<HandleAndLocalPath> checkpointHa
253
258
}
254
259
255
260
private DBFilesSnapshot snapshot (DataTransferStrategy strategy ) throws IOException {
261
+ return snapshot (strategy , Long .MAX_VALUE );
262
+ }
263
+
264
+ private DBFilesSnapshot snapshot (DataTransferStrategy strategy , long maxTransferBytes )
265
+ throws IOException {
256
266
DBFilesSnapshot snapshot = new DBFilesSnapshot ();
257
267
for (String fileName : dbFilePaths .keySet ()) {
258
268
Path dbFilePath = dbFilePaths .get (fileName );
259
269
HandleAndLocalPath handleAndLocalPath =
260
270
strategy .transferToCheckpoint (
261
271
dbFilePath ,
262
- MAX_TRANSFER_BYTES ,
272
+ maxTransferBytes ,
263
273
checkpointStreamFactory ,
264
274
CheckpointedStateScope .SHARED ,
265
275
closeableRegistry ,
@@ -395,8 +405,6 @@ public static List<Object[]> parameters() {
395
405
396
406
@ TempDir static java .nio .file .Path tempDir ;
397
407
398
- private static final long MAX_TRANSFER_BYTES = Long .MAX_VALUE ;
399
-
400
408
private DBFilesContainer createDb (
401
409
JobID jobID ,
402
410
int subtaskIndex ,
@@ -638,4 +646,41 @@ void testUncompletedCheckpoint() throws IOException {
638
646
lastSnapshot .checkFilesExist (false , dbDirUnderCpDir );
639
647
lastSnapshot .checkFilesExist (true , false );
640
648
}
649
+
650
+ private void createDbFilesWithExactSize (
651
+ DBFilesContainer db , List <String > newDbFileNames , int fileLength ) throws IOException {
652
+ db .createDbFiles (newDbFileNames , fileLength );
653
+ for (String fileName : newDbFileNames ) {
654
+ long fileLen =
655
+ db .dbDelegateFileSystem .getFileStatus (db .dbFilePaths .get (fileName )).getLen ();
656
+ assertThat (fileLen ).isEqualTo (fileLength );
657
+ }
658
+ db .checkDbFilesExist (newDbFileNames );
659
+ }
660
+
661
+ @ TestTemplate
662
+ public void testSnapshotWithMaxTransferBytes () throws IOException {
663
+ FileNameGenerator fileNameGenerator = new FileNameGenerator ();
664
+ JobID jobID = new JobID ();
665
+ Tuple2 <DBFilesContainer , DataTransferStrategy > dbAndStrategy =
666
+ createOrRestoreDb (jobID , 0 , 1 , dbDirUnderCpDir , recoveryClaimMode , pathCopying );
667
+ DBFilesContainer db = dbAndStrategy .f0 ;
668
+ DataTransferStrategy strategy = dbAndStrategy .f1 ;
669
+
670
+ // skip the cases when db files are reused for snapshots
671
+ assumeFalse (strategy instanceof ReusableDataTransferStrategy );
672
+ System .out .println (strategy .getClass ());
673
+
674
+ // create new files for DB
675
+ createDbFilesWithExactSize (db , fileNameGenerator .genMultipleFileNames (4 , 4 ), 2048 );
676
+ createDbFilesWithExactSize (db , fileNameGenerator .genMultipleFileNames (4 , 4 ), 128 );
677
+
678
+ // create a snapshot
679
+ DBFilesSnapshot lastSnapshot = db .snapshot (strategy , 1024 );
680
+ db .assertFilesReusedToCheckpoint (lastSnapshot .getStateHandles ());
681
+
682
+ for (Tuple2 <Path , HandleAndLocalPath > tuple : lastSnapshot .dbSnapshotFiles .values ()) {
683
+ assertThat (tuple .f1 .getStateSize ()).isLessThanOrEqualTo (1024 );
684
+ }
685
+ }
641
686
}
0 commit comments