@@ -54,7 +54,7 @@ use libsql_wal::registry::WalRegistry;
5454use libsql_wal:: segment:: sealed:: SealedSegment ;
5555use libsql_wal:: storage:: async_storage:: { AsyncStorage , AsyncStorageInitConfig } ;
5656use libsql_wal:: storage:: backend:: s3:: S3Backend ;
57- use libsql_wal:: storage:: NoStorage ;
57+ use libsql_wal:: storage:: { NoStorage , Storage } ;
5858use namespace:: meta_store:: MetaStoreHandle ;
5959use namespace:: NamespaceName ;
6060use net:: Connector ;
@@ -1119,6 +1119,47 @@ where
11191119 None => Ok ( None ) ,
11201120 }
11211121 }
1122+
1123+ /// perform migration from bottomless_wal to libsql_wal if necessary. This only happens if
1124+ /// all:
1125+ /// - bottomless is enabled
1126+ /// - this is a primary
1127+ /// - we are operating in libsql-wal mode
1128+ /// - migrate_bottomless flag is raised
1129+ /// - there hasn't been a previous successfull migration (wals directory is either absent,
1130+ /// or emtpy)
1131+ async fn maybe_migrate_bottomless < S > (
1132+ & self ,
1133+ meta_store : MetaStore ,
1134+ storage : Arc < S > ,
1135+ base_config : & BaseNamespaceConfig ,
1136+ primary_config : & PrimaryConfig ,
1137+ ) -> anyhow:: Result < ( ) >
1138+ where S : Storage < Segment = SealedSegment < std:: fs:: File > > ,
1139+ {
1140+ let is_previous_migration_successful = self . check_previous_migration_success ( ) ?;
1141+ let is_libsql_wal = matches ! ( self . use_custom_wal, Some ( CustomWAL :: LibsqlWal ) ) ;
1142+ let is_bottomless_enabled = self . db_config . bottomless_replication . is_some ( ) ;
1143+ let is_primary = self . rpc_client_config . is_none ( ) ;
1144+ let should_attempt_migration = self . migrate_bottomless
1145+ && is_primary
1146+ && is_bottomless_enabled
1147+ && !is_previous_migration_successful
1148+ && is_libsql_wal;
1149+
1150+ if should_attempt_migration {
1151+ }
1152+
1153+ Ok ( ( ) )
1154+ }
1155+
1156+ fn check_previous_migration_success ( & self ) -> anyhow:: Result < bool > {
1157+ let wals_path = self . path . join ( "wals" ) ;
1158+ let dir = std:: fs:: read_dir ( & wals_path) ?;
1159+
1160+ // wals dir exist and is not empty
1161+ Ok ( wals_path. try_exists ( ) ? && dir. count ( ) != 0 )
1162+ }
11221163}
11231164
11241165/// Setup sqlite to use the same allocator as sqld.
0 commit comments