fn new(
        path: &Path,
        read_only: bool,
        log: ReplicaLogger,
    ) -> PersistentHeightIndexedPool<Artifact> {
        let type_keys = Artifact::type_keys();
        let mut builder = Environment::new();
        let mut builder_flags = EnvironmentFlags::NO_TLS;
        let mut permission = 0o644;
        if read_only {
            builder_flags |= EnvironmentFlags::READ_ONLY;
            builder_flags |= EnvironmentFlags::NO_LOCK;
            permission = 0o444;
        }
        builder.set_flags(builder_flags);
        builder.set_max_readers(MAX_READERS);
        builder.set_max_dbs((type_keys.len() + 2) as c_uint);
        builder.set_map_size(MAX_PERSISTENT_POOL_SIZE);
        let db_env = builder
            .open_with_permissions(path, permission)
            .unwrap_or_else(|err| {
                panic!("Error opening LMDB environment at {:?}: {:?}", path, err)
            });

        unsafe {
            // Mark fds created by lmdb as FD_CLOEXEC to prevent them from leaking into
            // canister sandbox process. Details in NODE-166
            let mut fd: lmdb_sys::mdb_filehandle_t = lmdb_sys::mdb_filehandle_t::default();
            lmdb_sys::mdb_env_get_fd(db_env.env(), &mut fd);
            nix::fcntl::fcntl(fd, nix::fcntl::F_SETFD(nix::fcntl::FdFlag::FD_CLOEXEC))
                .expect("Unable to mark FD_CLOEXEC");
        };

        // Create all databases.
        let meta = if read_only {
            db_env
                .open_db(Some("META"))
                .unwrap_or_else(|err| panic!("Error opening db for metadata: {:?}", err))
        } else {
            db_env
                .create_db(Some("META"), DatabaseFlags::empty())
                .unwrap_or_else(|err| panic!("Error creating db for metadata: {:?}", err))
        };
        let artifacts = if read_only {
            db_env
                .open_db(Some("ARTS"))
                .unwrap_or_else(|err| panic!("Error opening db for artifacts: {:?}", err))
        } else {
            db_env
                .create_db(Some("ARTS"), DatabaseFlags::empty())
                .unwrap_or_else(|err| panic!("Error creating db for artifacts: {:?}", err))
        };
        let indices = {
            type_keys
                .iter()
                .map(|type_key| {
                    // Use DUP_SORT to enable multi-value for each HeightKey.
                    let store = if read_only {
                        db_env.open_db(Some(type_key.name)).unwrap_or_else(|err| {
                            panic!("Error opening db {}: {:?}", type_key.name, err)
                        })
                    } else {
                        db_env
                            .create_db(Some(type_key.name), DatabaseFlags::DUP_SORT)
                            .unwrap_or_else(|err| {
                                panic!("Error creating db {}: {:?}", type_key.name, err)
                            })
                    };
                    (*type_key, store)
                })
                .collect()
        };
        Self {
            pool_type: PhantomData,
            db_env: Arc::new(db_env),
            meta,
            artifacts,
            indices,
            log,
        }
    }
/// Return a persistent pool located the given directory path.
/// Create the pool if it does not already exist.
/// Panic if initialization fails.
Return a persistent pool located the given directory path.
Create the pool if it does not already exist.
Panic if initialization fails.
Return a persistent pool located the given directory path . Create the pool if it does not already exist . Panic if initialization fails .
fn new(
        path: &Path,
        read_only: bool,
        log: ReplicaLogger,
    ) -> PersistentHeightIndexedPool<Artifact> {
        let type_keys = Artifact::type_keys();
        let mut builder = Environment::new();
        let mut builder_flags = EnvironmentFlags::NO_TLS;
        let mut permission = 0o644;
        if read_only {
            builder_flags |= EnvironmentFlags::READ_ONLY;
            builder_flags |= EnvironmentFlags::NO_LOCK;
            permission = 0o444;
        }
        builder.set_flags(builder_flags);
        builder.set_max_readers(MAX_READERS);
        builder.set_max_dbs((type_keys.len() + 2) as c_uint);
        builder.set_map_size(MAX_PERSISTENT_POOL_SIZE);
        let db_env = builder
            .open_with_permissions(path, permission)
            .unwrap_or_else(|err| {
                panic!("Error opening LMDB environment at {:?}: {:?}", path, err)
            });
        unsafe {
            // Mark fds created by lmdb as FD_CLOEXEC to prevent them from leaking into
            // canister sandbox process. Details in NODE-166
            let mut fd: lmdb_sys::mdb_filehandle_t = lmdb_sys::mdb_filehandle_t::default();
            lmdb_sys::mdb_env_get_fd(db_env.env(), &mut fd);
            nix::fcntl::fcntl(fd, nix::fcntl::F_SETFD(nix::fcntl::FdFlag::FD_CLOEXEC))
                .expect("Unable to mark FD_CLOEXEC");
        };
        // Create all databases.
        let meta = if read_only {
            db_env
                .open_db(Some("META"))
                .unwrap_or_else(|err| panic!("Error opening db for metadata: {:?}", err))
        } else {
            db_env
                .create_db(Some("META"), DatabaseFlags::empty())
                .unwrap_or_else(|err| panic!("Error creating db for metadata: {:?}", err))
        };
        let artifacts = if read_only {
            db_env
                .open_db(Some("ARTS"))
                .unwrap_or_else(|err| panic!("Error opening db for artifacts: {:?}", err))
        } else {
            db_env
                .create_db(Some("ARTS"), DatabaseFlags::empty())
                .unwrap_or_else(|err| panic!("Error creating db for artifacts: {:?}", err))
        };
        let indices = {
            type_keys
                .iter()
                .map(|type_key| {
                    // Use DUP_SORT to enable multi-value for each HeightKey.
                    let store = if read_only {
                        db_env.open_db(Some(type_key.name)).unwrap_or_else(|err| {
                            panic!("Error opening db {}: {:?}", type_key.name, err)
                        })
                    } else {
                        db_env
                            .create_db(Some(type_key.name), DatabaseFlags::DUP_SORT)
                            .unwrap_or_else(|err| {
                                panic!("Error creating db {}: {:?}", type_key.name, err)
                            })
                    };
                    (*type_key, store)
                })
                .collect()
        };
        Self {
            pool_type: PhantomData,
            db_env: Arc::new(db_env),
            meta,
            artifacts,
            indices,
            log,
        }
    }
fn new ( path : & Path , read_only : bool , log : ReplicaLogger , ) -> PersistentHeightIndexedPool < Artifact > { let type_keys = Artifact :: type_keys ( ) ; let mut builder = Environment :: new ( ) ; let mut builder_flags = EnvironmentFlags :: NO_TLS ; let mut permission = 0o644 ; if read_only { builder_flags |= EnvironmentFlags :: READ_ONLY ; builder_flags |= EnvironmentFlags :: NO_LOCK ; permission = 0o444 ; } builder . set_flags ( builder_flags ) ; builder . set_max_readers ( MAX_READERS ) ; builder . set_max_dbs ( ( type_keys . len ( ) + 2 ) as c_uint ) ; builder . set_map_size ( MAX_PERSISTENT_POOL_SIZE ) ; let db_env = builder . open_with_permissions ( path , permission ) . unwrap_or_else ( | err | { panic ! ( " " path err ) } ) ; unsafe { // Mark fds created by lmdb as FD_CLOEXEC to prevent them from leaking into // canister sandbox process. Details in NODE-166 let mut fd : lmdb_sys :: mdb_filehandle_t = lmdb_sys :: mdb_filehandle_t :: default ( ) ; lmdb_sys :: mdb_env_get_fd ( db_env . env ( ) , & mut fd ) ; nix :: fcntl :: fcntl ( fd , nix :: fcntl :: F_SETFD ( nix :: fcntl :: FdFlag :: FD_CLOEXEC ) ) . expect ( " " ) ; } ; // Create all databases. let meta = if read_only { db_env . open_db ( Some ( " " ) ) . unwrap_or_else ( | err | panic ! ( " " err ) ) } else { db_env . create_db ( Some ( " " ) , DatabaseFlags :: empty ( ) ) . unwrap_or_else ( | err | panic ! ( " " err ) ) } ; let artifacts = if read_only { db_env . open_db ( Some ( " " ) ) . unwrap_or_else ( | err | panic ! ( " " err ) ) } else { db_env . create_db ( Some ( " " ) , DatabaseFlags :: empty ( ) ) . unwrap_or_else ( | err | panic ! ( " " err ) ) } ; let indices = { type_keys . iter ( ) . map ( | type_key | { // Use DUP_SORT to enable multi-value for each HeightKey. let store = if read_only { db_env . open_db ( Some ( type_key . name ) ) . unwrap_or_else ( | err | { panic ! ( " " type_key name err ) } ) } else { db_env . create_db ( Some ( type_key . name ) , DatabaseFlags :: DUP_SORT ) . unwrap_or_else ( | err | { panic ! ( " " type_key name err ) } ) } ; ( * type_key , store ) } ) . collect ( ) } ; Self { pool_type : PhantomData , db_env : Arc :: new ( db_env ) , meta , artifacts , indices , log , } }
Return a persistent pool located the given directory path.
Return a persistent pool located the given directory path .
path
&Path
read_only
bool
log
ReplicaLogger
path
&Path
read_only
bool
log
ReplicaLogger