@@ -70,6 +70,8 @@ mod snapshot_storage_rebuilder;
70
70
pub use archive_format:: * ;
71
71
72
72
pub const SNAPSHOT_STATUS_CACHE_FILENAME : & str = "status_cache" ;
73
+ pub const SNAPSHOT_VERSION_FILENAME : & str = "version" ;
74
+ pub const SNAPSHOT_STATE_COMPLETE_FILENAME : & str = "state_complete" ;
73
75
pub const SNAPSHOT_ARCHIVE_DOWNLOAD_DIR : & str = "remote" ;
74
76
pub const DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS : Slot = 25_000 ;
75
77
pub const DEFAULT_INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS : Slot = 100 ;
@@ -430,6 +432,18 @@ pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef<Path>) {
430
432
}
431
433
}
432
434
435
+ /// Write the snapshot version as a file into the bank snapshot directory
436
+ pub fn write_snapshot_version_file (
437
+ version_file : impl AsRef < Path > ,
438
+ version : SnapshotVersion ,
439
+ ) -> Result < ( ) > {
440
+ let mut f = fs:: File :: create ( version_file)
441
+ . map_err ( |e| SnapshotError :: IoWithSource ( e, "create version file" ) ) ?;
442
+ f. write_all ( version. as_str ( ) . as_bytes ( ) )
443
+ . map_err ( |e| SnapshotError :: IoWithSource ( e, "write version file" ) ) ?;
444
+ Ok ( ( ) )
445
+ }
446
+
433
447
/// Make a snapshot archive out of the snapshot package
434
448
pub fn archive_snapshot_package (
435
449
snapshot_package : & SnapshotPackage ,
@@ -466,7 +480,7 @@ pub fn archive_snapshot_package(
466
480
467
481
let staging_accounts_dir = staging_dir. path ( ) . join ( "accounts" ) ;
468
482
let staging_snapshots_dir = staging_dir. path ( ) . join ( "snapshots" ) ;
469
- let staging_version_file = staging_dir. path ( ) . join ( "version" ) ;
483
+ let staging_version_file = staging_dir. path ( ) . join ( SNAPSHOT_VERSION_FILENAME ) ;
470
484
fs:: create_dir_all ( & staging_accounts_dir) . map_err ( |e| {
471
485
SnapshotError :: IoWithSourceAndFile ( e, "create staging path" , staging_accounts_dir. clone ( ) )
472
486
} ) ?;
@@ -498,14 +512,7 @@ pub fn archive_snapshot_package(
498
512
}
499
513
}
500
514
501
- // Write version file
502
- {
503
- let mut f = fs:: File :: create ( & staging_version_file) . map_err ( |e| {
504
- SnapshotError :: IoWithSourceAndFile ( e, "create version file" , staging_version_file)
505
- } ) ?;
506
- f. write_all ( snapshot_package. snapshot_version . as_str ( ) . as_bytes ( ) )
507
- . map_err ( |e| SnapshotError :: IoWithSource ( e, "write version file" ) ) ?;
508
- }
515
+ write_snapshot_version_file ( staging_version_file, snapshot_package. snapshot_version ) ?;
509
516
510
517
// Tar the staging directory into the archive at `archive_path`
511
518
let archive_path = tar_dir. join ( format ! (
@@ -522,7 +529,10 @@ pub fn archive_snapshot_package(
522
529
let mut archive = tar:: Builder :: new ( encoder) ;
523
530
// Serialize the version and snapshots files before accounts so we can quickly determine the version
524
531
// and other bank fields. This is necessary if we want to interleave unpacking with reconstruction
525
- archive. append_path_with_name ( staging_dir. as_ref ( ) . join ( "version" ) , "version" ) ?;
532
+ archive. append_path_with_name (
533
+ staging_dir. as_ref ( ) . join ( SNAPSHOT_VERSION_FILENAME ) ,
534
+ SNAPSHOT_VERSION_FILENAME ,
535
+ ) ?;
526
536
for dir in [ "snapshots" , "accounts" ] {
527
537
archive. append_dir_all ( dir, staging_dir. as_ref ( ) . join ( dir) ) ?;
528
538
}
@@ -1045,6 +1055,13 @@ pub fn add_bank_snapshot(
1045
1055
let status_cache_path = bank_snapshot_dir. join ( SNAPSHOT_STATUS_CACHE_FILENAME ) ;
1046
1056
serialize_status_cache ( slot, & slot_deltas, & status_cache_path) ?;
1047
1057
1058
+ let version_path = bank_snapshot_dir. join ( SNAPSHOT_VERSION_FILENAME ) ;
1059
+ write_snapshot_version_file ( version_path, snapshot_version) . unwrap ( ) ;
1060
+
1061
+ // Mark this directory complete so it can be used. Check this flag first before selecting for deserialization.
1062
+ let state_complete_path = bank_snapshot_dir. join ( SNAPSHOT_STATE_COMPLETE_FILENAME ) ;
1063
+ fs:: File :: create ( state_complete_path) ?;
1064
+
1048
1065
// Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE
1049
1066
datapoint_info ! (
1050
1067
"snapshot-bank-file" ,
@@ -2346,6 +2363,16 @@ pub fn verify_snapshot_archive<P, Q, R>(
2346
2363
}
2347
2364
std:: fs:: remove_dir_all ( accounts_hardlinks_dir) . unwrap ( ) ;
2348
2365
}
2366
+
2367
+ let version_path = snapshot_slot_dir. join ( SNAPSHOT_VERSION_FILENAME ) ;
2368
+ if version_path. is_file ( ) {
2369
+ std:: fs:: remove_file ( version_path) . unwrap ( ) ;
2370
+ }
2371
+
2372
+ let state_complete_path = snapshot_slot_dir. join ( SNAPSHOT_STATE_COMPLETE_FILENAME ) ;
2373
+ if state_complete_path. is_file ( ) {
2374
+ std:: fs:: remove_file ( state_complete_path) . unwrap ( ) ;
2375
+ }
2349
2376
}
2350
2377
2351
2378
assert ! ( !dir_diff:: is_different( & snapshots_to_verify, unpacked_snapshots) . unwrap( ) ) ;
0 commit comments