Skip to content

Let drivers handle thread-safe access to the Database object in AdbcConnectionInit #2791

@felipecrv

Description

@felipecrv

What feature or improvement would you like to see?

Let drivers handle thread-safe access to the Database object in AdbcConnectionInit

This would make locking more fine-grained and remove the need for a pessimistic lock around the entire AdbcConnectionInit call.

For instance, this is how Rust's driver manager wraps the FFI call today:

    /// Initialize the given connection using the loaded driver.
    fn connection_init(
        &self,
        mut connection: ffi::FFI_AdbcConnection,
    ) -> Result<ffi::FFI_AdbcConnection> {
        let driver = self.ffi_driver();
        let mut database = self.inner.database.lock().unwrap();

        // ConnectionInit
        let mut error = ffi::FFI_AdbcError::with_driver(driver);
        let method = driver_method!(driver, ConnectionInit);
        let status = unsafe { method(&mut connection, &mut *database, &mut error) };
        check_status(status, error)?;

        Ok(connection)
    }

As connection initialization can mutate the database object that initializes the connection, a lock on self.inner.database must be acquired before the call.

A driver performing multi-step auth actions might be waiting on slow HTTP requests during the AdbcConnectionInit call. If the driver took responsibility of the locking, it could let these HTTP calls happen in parallel and only synchronize the actual mutations to the database object (e.g. caching obtained info for re-use).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions