Skip to content

More about the Spark connector

Options for the Spark connector beyond Create the destination: other access modes and runtimes, the connection, the connector's parameters, and TLS to the Stelo Capture Db2.

Standard access mode

With Unity Catalog, a cluster in Standard (formerly shared) access mode needs more setup than Dedicated: Databricks installs only allowlisted JAR files there, and the IBM Db2 JDBC driver library, through which the Spark connector reads the Db2 rows, needs SELECT ON ANY FILE for the identity that runs the notebook (it lets that identity read files directly, outside Unity Catalog permissions). A metastore admin (or another user with MANAGE ALLOWLIST) allowlists the libraries' volume and grants the privilege when the libraries are installed, once Stelo Capture is installed. See Microsoft: Allowlist libraries and init scripts on compute with standard access mode.

When you install the libraries:

  • In step 1, put the user who installs the libraries in place of notebook_identity in the READ VOLUME grant.
  • Before step 4, a user with MANAGE ALLOWLIST (a metastore admin) adds the volume to the allowlist: click Catalog, the gear icon, and the metastore name, select Allowed JARs/Init Scripts, and click Add. Choose the Type JAR and the Source Type Volume, and enter /Volumes/mycatalog/myschema/sqdr_libs/.
  • Grant the identity that runs the notebook the privilege a JDBC driver library needs on Standard compute:

    GRANT SELECT ON ANY FILE TO `notebook_identity`;
    

Install the libraries without Unity Catalog

Upload the files to the workspace files and install them with the Library Source Workspace: Databricks installs JAR files from workspace files only on compute with No isolation shared access mode (Databricks Runtime 14.1 and above). Otherwise, install them from cloud storage. See Microsoft: Install libraries (which sources each access mode supports).

On older Databricks runtimes, install the libraries from DBFS instead (Libraries, Install new, Library Source DBFS).

More about the connection

Both templates also set SSL=1 and ThriftTransport=2 (HTTP). The token template sets AuthMech=3 (user name and password); the OAuth template sets AuthMech=11 and Auth_Flow=1 (OAuth client credentials).

Another Apply extension, com.starquest.sqdr.apply.databricks.AutoLoaderProcessor, writes the changes as files to Azure storage for Databricks Auto Loader instead (see Apply extensions); ask Stelo Support before you use it.

Parameters of ApplyJdbc.apply

Pass the optional ones by name, for example ApplyJdbc.apply(spark, destinationName, jdbcUsername, jdbcPassword, jdbcHostname, unity = false).

Parameter Default What it does
destinationName (required) The Databricks destination's name in the Data Replicator Manager (case doesn't matter).
jdbcUsername, jdbcPassword (required) The Stelo Capture Db2 user and its password.
jdbcHostname (required) The Stelo VM's host name or IP address, as Databricks reaches it.
jdbcPort 50000 The Db2 port. Change it for the Db2 TLS port, or when a gateway forwards another port.
jdbcDatabase SQDRC The control database.
controlDbSchema SQDR The schema of the control tables in the control database.
unity true Unity Catalog: three-part table names, with the subscription's destination database as the catalog. Set false for a workspace without Unity Catalog.
catalogFilter none Handle only the tables of this destination catalog (database), for example to split the work between notebooks on different clusters. Use it with Unity Catalog.
continuousOperation true false ends the notebook after five minutes without work, once the baselines are done.
pollInterval 15 Seconds between polls for new work.
incrementalThreads, snapshotThreads 10, 10 How many tables each worker applies changes to, and loads baselines into, at the same time. Lower them on small clusters to use less memory.
exitOnError false true ends the notebook with the error when a worker fails, for example so that a job retries or alerts.
name the destination name The connector's name in the status shown in the SQDR Control Center (see Check the destination).
extraJdbcProperties empty IBM Db2 JDBC driver properties added to the connection URL, ending with ;, for example for TLS.
useAppend true Keep the default.

To save compute costs when low latency doesn't matter, pass continuousOperation = false and schedule the job, for example daily: each run applies what has accumulated and ends after five minutes without work.

ApplyJdbc.run is an older entry point that connects to one staging database directly (jdbcDatabase is the staging database, controlDbSchema its schema), so it serves a single Capture Agent. Use ApplyJdbc.apply.

TLS to the Stelo Capture Db2

To encrypt the Spark connector's connection, configure TLS on the Stelo VM's Db2 instance (a TLS port, SSL_SVCENAME; see IBM's Db2 documentation), open that port to the compute, and pass it with sslConnection=true:

val jdbcTlsPort = 50448   // the Db2 TLS port

ApplyJdbc.apply(spark, destinationName, jdbcUsername, jdbcPassword, jdbcHostname, jdbcTlsPort,
  extraJdbcProperties = "sslConnection=true;")

If a private certificate authority signed the Db2 server certificate, give the compute the CA certificate: write it to a file in a cluster init script, and name that file with sslCertLocation:

#!/bin/bash
cat << 'EOF' > /usr/local/share/ca-certificates/myca.crt
-----BEGIN CERTIFICATE-----
<contents of the CA certificate>
-----END CERTIFICATE-----
EOF
ApplyJdbc.apply(spark, destinationName, jdbcUsername, jdbcPassword, jdbcHostname, jdbcTlsPort,
  extraJdbcProperties = "sslConnection=true;sslCertLocation=/usr/local/share/ca-certificates/myca.crt;")

See Microsoft: What are init scripts?