pub async fn load(
        object_store: Arc<ObjectStore>,
        server_id: ServerId,
        db_name: String,
        state_data: S::EmptyInput,
    ) -> Result<Option<Self>> {
        // parse all paths into revisions
        let mut transactions: HashMap<u64, Uuid> = HashMap::new();
        let mut max_revision = None;
        for (_path, revision_counter, uuid) in
            list_transaction_files(&object_store, server_id, &db_name).await?
        {
            // keep track of the max
            max_revision = Some(
                max_revision
                    .map(|m: u64| m.max(revision_counter))
                    .unwrap_or(revision_counter),
            );

            // insert but check for duplicates
            match transactions.entry(revision_counter) {
                Occupied(o) => {
                    // sort for determinism
                    let (uuid1, uuid2) = if *o.get() < uuid {
                        (*o.get(), uuid)
                    } else {
                        (uuid, *o.get())
                    };

                    Fork {
                        revision_counter,
                        uuid1,
                        uuid2,
                    }
                    .fail()?;
                }
                Vacant(v) => {
                    v.insert(uuid);
                }
            }
        }

        // Check if there is any catalog stored at all
        if transactions.is_empty() {
            return Ok(None);
        }

        // read and replay revisions
        let max_revision = max_revision.expect("transactions list is not empty here");
        let mut state = Arc::new(CatalogState::new_empty(state_data));
        let mut last_tkey = None;
        for rev in 0..=max_revision {
            let uuid = transactions.get(&rev).context(MissingTransaction {
                revision_counter: rev,
            })?;
            let tkey = TransactionKey {
                revision_counter: rev,
                uuid: *uuid,
            };
            let tmp_state = S::clone_or_keep(&state);
            let transaction = OpenTransaction::load_and_apply(
                &object_store,
                server_id,
                &db_name,
                &tkey,
                tmp_state,
                &last_tkey,
            )
            .await?;
            last_tkey = Some(tkey);
            state = transaction.next_state;
        }

        let inner = PreservedCatalogInner {
            previous_tkey: last_tkey,
            state,
        };

        Ok(Some(Self {
            inner: RwLock::new(inner),
            transaction_semaphore: Semaphore::new(1),
            object_store,
            server_id,
            db_name,
        }))
    }
/// Load existing catalog from store, if it exists.
Load existing catalog from store, if it exists.
Load existing catalog from store if it exists .
pub async fn load(
        object_store: Arc<ObjectStore>,
        server_id: ServerId,
        db_name: String,
        state_data: S::EmptyInput,
    ) -> Result<Option<Self>> {
        // parse all paths into revisions
        let mut transactions: HashMap<u64, Uuid> = HashMap::new();
        let mut max_revision = None;
        for (_path, revision_counter, uuid) in
            list_transaction_files(&object_store, server_id, &db_name).await?
        {
            // keep track of the max
            max_revision = Some(
                max_revision
                    .map(|m: u64| m.max(revision_counter))
                    .unwrap_or(revision_counter),
            );
            // insert but check for duplicates
            match transactions.entry(revision_counter) {
                Occupied(o) => {
                    // sort for determinism
                    let (uuid1, uuid2) = if *o.get() < uuid {
                        (*o.get(), uuid)
                    } else {
                        (uuid, *o.get())
                    };
                    Fork {
                        revision_counter,
                        uuid1,
                        uuid2,
                    }
                    .fail()?;
                }
                Vacant(v) => {
                    v.insert(uuid);
                }
            }
        }
        // Check if there is any catalog stored at all
        if transactions.is_empty() {
            return Ok(None);
        }
        // read and replay revisions
        let max_revision = max_revision.expect("transactions list is not empty here");
        let mut state = Arc::new(CatalogState::new_empty(state_data));
        let mut last_tkey = None;
        for rev in 0..=max_revision {
            let uuid = transactions.get(&rev).context(MissingTransaction {
                revision_counter: rev,
            })?;
            let tkey = TransactionKey {
                revision_counter: rev,
                uuid: *uuid,
            };
            let tmp_state = S::clone_or_keep(&state);
            let transaction = OpenTransaction::load_and_apply(
                &object_store,
                server_id,
                &db_name,
                &tkey,
                tmp_state,
                &last_tkey,
            )
            .await?;
            last_tkey = Some(tkey);
            state = transaction.next_state;
        }
        let inner = PreservedCatalogInner {
            previous_tkey: last_tkey,
            state,
        };
        Ok(Some(Self {
            inner: RwLock::new(inner),
            transaction_semaphore: Semaphore::new(1),
            object_store,
            server_id,
            db_name,
        }))
    }
pub async fn load ( object_store : Arc < ObjectStore > , server_id : ServerId , db_name : String , state_data : S :: EmptyInput , ) -> Result < Option < Self > > { // parse all paths into revisions let mut transactions : HashMap < u64 , Uuid > = HashMap :: new ( ) ; let mut max_revision = None ; for ( _path , revision_counter , uuid ) in list_transaction_files ( & object_store , server_id , & db_name ) . await ? { // keep track of the max max_revision = Some ( max_revision . map ( | m : u64 | m . max ( revision_counter ) ) . unwrap_or ( revision_counter ) , ) ; // insert but check for duplicates match transactions . entry ( revision_counter ) { Occupied ( o ) => { // sort for determinism let ( uuid1 , uuid2 ) = if * o . get ( ) < uuid { ( * o . get ( ) , uuid ) } else { ( uuid , * o . get ( ) ) } ; Fork { revision_counter , uuid1 , uuid2 , } . fail ( ) ? ; } Vacant ( v ) => { v . insert ( uuid ) ; } } } // Check if there is any catalog stored at all if transactions . is_empty ( ) { return Ok ( None ) ; } // read and replay revisions let max_revision = max_revision . expect ( " " ) ; let mut state = Arc :: new ( CatalogState :: new_empty ( state_data ) ) ; let mut last_tkey = None ; for rev in 0 ..= max_revision { let uuid = transactions . get ( & rev ) . context ( MissingTransaction { revision_counter : rev , } ) ? ; let tkey = TransactionKey { revision_counter : rev , uuid : * uuid , } ; let tmp_state = S :: clone_or_keep ( & state ) ; let transaction = OpenTransaction :: load_and_apply ( & object_store , server_id , & db_name , & tkey , tmp_state , & last_tkey , ) . await ? ; last_tkey = Some ( tkey ) ; state = transaction . next_state ; } let inner = PreservedCatalogInner { previous_tkey : last_tkey , state , } ; Ok ( Some ( Self { inner : RwLock :: new ( inner ) , transaction_semaphore : Semaphore :: new ( 1 ) , object_store , server_id , db_name , } ) ) }
Load existing catalog from store, if it exists.
Load existing catalog from store if it exists .
object_store
Arc<ObjectStore>
server_id
ServerId
db_name
String
state_data
S::EmptyInput
object_store
Arc<ObjectStore>
server_id
ServerId
db_name
String
state_data
S::EmptyInput