← Back to Pull requests

DBZ-1558 DB2 tutorial #77

Closed
lga-zurich closed this pull request without merging on Feb 10, 2020 09:33 UTC
View on GitHub
lga-zurich lga-zurich commented on Nov 22, 2019 12:34 UTC
Author

This adds a tutorial for DB2

Diff: 1141 lines (+1140 / -1) across 14 files Reviewer: gunnarmorling Review duration: 115018m
All Vouch review confidence checks passed
Residual risk 0.11 = Change Risk (0.68) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.68 · 1141 lines diff across 14 files
0.68
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.71 · 5 substantive comment(s)
0.71
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Empty Description empty_description
0.060
Real PR Conversation Timeline
28 items
gunnarmorling gunnarmorling commented on code on Nov 22, 2019 13:03 UTC
Code Review
tutorial/debezium-db2-init/db2connect/Dockerfile:1
@@ -0,0 +1,12 @@
+ARG DEBEZIUM_VERSION
+FROM debezium/connect:$DEBEZIUM_VERSION
+ENV KAFKA_CONNECT_JDBC_DIR=$KAFKA_CONNECT_PLUGINS_DIR/kafka-connect-jdbc
+ENV INSTANT_CLIENT_DIR=/instant_client/
+
+USER root
+RUN yum -y install libaio curl && yum clean all
+
+USER kafka
+# Deploy db2 client and drivers
+
+run curl https://repo1.maven.org/maven2/com/ibm/db2/jcc/11.5.0.0/jcc-11.5.0.0.jar --output /kafka/libs/jcc-11.5.0.0.jar

Unless anything speaks against it in terms of licensing, the driver should rather be part of the DB2 connector archive (see how it's done for other connectors).

gunnarmorling gunnarmorling commented on code on Nov 22, 2019 13:03 UTC
Code Review
tutorial/debezium-db2-init/db2server/asncdcaddremove.sql:1
@@ -0,0 +1,199 @@
+
+--#SET TERMINATOR @
+CREATE OR REPLACE PROCEDURE ASNCDC.REMOVETABLE(
+in  tableschema VARCHAR(128),
+in  tablename VARCHAR(128)
+)
+LANGUAGE SQL
+P1:
+BEGIN
+
+DECLARE stmtSQL VARCHAR(2048);
+
+DECLARE SQLCODE INT; 
+DECLARE SQLSTATE CHAR(5);  
+DECLARE RC_SQLCODE INT DEFAULT 0; 
+DECLARE RC_SQLSTATE CHAR(5) DEFAULT '00000';
+
+
+
+DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND  VALUES (SQLCODE, SQLSTATE) INTO RC_SQLCODE, RC_SQLSTATE; 
+

Could you remove the repeated new lines (here and in a few other places)?

gunnarmorling gunnarmorling commented on code on Nov 22, 2019 13:04 UTC
Code Review
tutorial/debezium-db2-init/db2server/asncdcaddremove.sql:1
@@ -0,0 +1,199 @@
+

Could you add a comment at the beginning of the file describing its general purpose?

gunnarmorling gunnarmorling commented on code on Nov 22, 2019 13:05 UTC
Code Review
tutorial/docker-compose-db2.yaml:1
@@ -0,0 +1,49 @@
+version: '2'
+services:
+  zookeeper:
+    image: debezium/zookeeper:${DEBEZIUM_VERSION}
+    ports:
+     - 2181:2181
+     - 2888:2888
+     - 3888:3888
+  kafka:
+    image: debezium/kafka:${DEBEZIUM_VERSION}
+    ports:
+     - 9092:9092
+    links:
+     - zookeeper
+    environment:
+     - ZOOKEEPER_CONNECT=zookeeper:2181
+  db2server:
+    image: debezium/db2-cdc:${DEBEZIUM_VERSION}
+    build:
+      context: ./debezium-db2-init/db2server
+    privileged: True
+    ports:
+     - 50000:50000
+    environment:
+     - LICENSE=accept 
+     - DBNAME=TESTDB
+     - DB2INST1_PASSWORD==Password!
+    volumes: 
+     - ${DEBEZIUM_DB2_VOLUME}:/database
+  connect:
+    image: debezium/connect-db2:${DEBEZIUM_VERSION}
+    build:
+      context: ./debezium-db2-init/db2connect
+      args:
+        DEBEZIUM_VERSION: ${DEBEZIUM_VERSION}
+    ports:
+     - 8083:8083
+    links:
+     - kafka
+     - db2server
+    environment:
+     - BOOTSTRAP_SERVERS=kafka:9092
+     - GROUP_ID=1
+     - CONFIG_STORAGE_TOPIC=my_connect_configs
+     - OFFSET_STORAGE_TOPIC=my_connect_offsets
+     - STATUS_STORAGE_TOPIC=my_connect_statuses
+
+volumes:
+  db-data:

New line at EOF is missing.

gunnarmorling gunnarmorling commented on code on Nov 22, 2019 13:06 UTC
Code Review
tutorial/README.md:1
@@ -205,6 +205,36 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2 Database Server

Could you also add the link to this to the ToC?

gunnarmorling gunnarmorling commented on Nov 22, 2019 13:07 UTC
Contributor

@lga-zurich, very nice, this helps a lot for playing with and testing the connector! A few comments inline. Could you also use an email to author the commit that's associated to your GH account? Thanks!

lga-zurich lga-zurich commented on Nov 22, 2019 13:22 UTC
Author

@lga-zurich, very nice, this helps a lot for playing with and testing the connector! A few comments inline. Could you also use an email to author the commit that's associated to your GH account? Thanks!

Oh, I guess that has to do with my e-mail address being private. I have made it public now.

gunnarmorling gunnarmorling commented on Nov 22, 2019 13:25 UTC
Contributor

Hum, hum. The commit still isn't attributed to your GH account (see the gray octo icon next to the commit. If things are correct, your account gravatar would be shown).

lga-zurich lga-zurich commented on Nov 22, 2019 13:33 UTC
Author

That commit would be from @zrlurb . I'll ask him to fix his profile when he's back.

gunnarmorling gunnarmorling commented on Nov 22, 2019 13:38 UTC
Contributor

Ok, thanks!

>

gunnarmorling gunnarmorling commented on Dec 03, 2019 08:14 UTC
Contributor

Hey @lga-zurich, any update on this one?

gunnarmorling gunnarmorling commented on code on Jan 30, 2020 06:42 UTC
Code Review
tutorial/debezium-db2-init/db2connect/Dockerfile:1
@@ -0,0 +1,12 @@
+ARG DEBEZIUM_VERSION
+FROM debezium/connect:$DEBEZIUM_VERSION
+ENV KAFKA_CONNECT_JDBC_DIR=$KAFKA_CONNECT_PLUGINS_DIR/kafka-connect-jdbc
+ENV INSTANT_CLIENT_DIR=/instant_client/
+
+USER root
+RUN yum -y install libaio curl && yum clean all
+
+USER kafka
+# Deploy db2 client and drivers
+
+run curl https://repo1.maven.org/maven2/com/ibm/db2/jcc/11.5.0.0/jcc-11.5.0.0.jar --output /kafka/libs/jcc-11.5.0.0.jar

@lga-zurich This one is still open, could you change it? Same goes for a few other comments.

gunnarmorling gunnarmorling commented on Jan 30, 2020 06:43 UTC
Reviewer

@lga-zurich Circling back to this one. I was wondering: would it be possible we provide a ready-made image under the Debezium organization (as we e.g. do for MySQL)? Or wouldn't it be allowed in terms of license?

And can you add a comment on the purpose of that binary file that's part of the PR? Thanks!

gunnarmorling gunnarmorling commented on Jan 30, 2020 11:58 UTC
Contributor

@lga-zurich, pushed a commit to this PR with a few fixes in the README.

gunnarmorling gunnarmorling commented on code on Jan 30, 2020 11:59 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS
+
+# Modify records in the database via DB2 client 
+docker-compose -f docker-compose-db2.yaml exec db2server bash -c 'su - db2inst1'

Can you add the instructions for actually doing an update? I.e. which client to use after su?

gunnarmorling gunnarmorling commented on code on Jan 30, 2020 11:59 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS

How is casing handled in DB2? Is there any difference between CUSTOMERS and customers? If not, could we change the topic as well as field names in messages to lower-case? It'll be more consistent with what we have elsewhere. In any case that can be done as a follow-up.

gunnarmorling gunnarmorling commented on Jan 30, 2020 12:00 UTC
Reviewer

Two more questions/comments.

zrlurb zrlurb commented on code on Jan 30, 2020 12:56 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS

DB2 is case sensitive. Standart all tables without quoted SCHEMA TABLE name will be automatically UPPERCASE.
We have to be careful here because of the ASNCDC.IBMSNAP_REGISTER entry and SQL UDF ADDTABLE / REMOVETABLE are absolutely case sensitive.

gunnarmorling gunnarmorling commented on code on Feb 04, 2020 15:24 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS
+
+# Modify records in the database via DB2 client 
+docker-compose -f docker-compose-db2.yaml exec db2server bash -c 'su - db2inst1'
+
+# Shut down the cluster
+docker-compose -f docker-compose-sqlserver.yaml down

sqlserver -> db2

gunnarmorling gunnarmorling commented on code on Feb 04, 2020 15:24 UTC
Code Review
tutorial/debezium-db2-init/db2connect/Dockerfile:1
@@ -0,0 +1,12 @@
+ARG DEBEZIUM_VERSION
+FROM debezium/connect:$DEBEZIUM_VERSION
+ENV KAFKA_CONNECT_JDBC_DIR=$KAFKA_CONNECT_PLUGINS_DIR/kafka-connect-jdbc
+ENV INSTANT_CLIENT_DIR=/instant_client/
+
+USER root
+RUN yum -y install libaio curl && yum clean all
+
+USER kafka
+# Deploy db2 client and drivers
+
+run curl https://repo1.maven.org/maven2/com/ibm/db2/jcc/11.5.0.0/jcc-11.5.0.0.jar --output /kafka/libs/jcc-11.5.0.0.jar

Ok, got clarification we cannot redistribute the driver for the time being.

gunnarmorling gunnarmorling commented on code on Feb 04, 2020 19:55 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS

Ok, thanks for clariying. What we have seems to make most sense then indeed.

gunnarmorling gunnarmorling commented on Feb 04, 2020 19:57 UTC
Contributor

@lga-zurich, any chance to get this one wrapped up for this week? On the binary file I was thinking that it'd actually be better to compile this as part of the Docker build (e.g. using a multi-stage build) instead of baking in a pre-built binary, which is rather intransparent. Could you do that change? Thx!

lga-zurich lga-zurich commented on Feb 05, 2020 09:21 UTC
Author

@lga-zurich, any chance to get this one wrapped up for this week? On the binary file I was thinking that it'd actually be better to compile this as part of the Docker build (e.g. using a multi-stage build) instead of baking in a pre-built binary, which is rather intransparent. Could you do that change? Thx!

@gunnarmorling yes, no problem, that is actually what we do for the integration tests, I just need to grab the code from the incubator.

lga-zurich lga-zurich commented on code on Feb 05, 2020 14:14 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS
+
+# Modify records in the database via DB2 client 
+docker-compose -f docker-compose-db2.yaml exec db2server bash -c 'su - db2inst1'

Done.

lga-zurich lga-zurich commented on code on Feb 05, 2020 14:14 UTC
Code Review
tutorial/README.md:1
@@ -206,6 +207,35 @@ docker-compose -f docker-compose-sqlserver.yaml exec sqlserver bash -c '/opt/mss
 docker-compose -f docker-compose-sqlserver.yaml down
 ```
 
+## Using DB2
+
+```shell
+# Start the topology as defined in http://debezium.io/docs/tutorial/
+export DEBEZIUM_VERSION=1.1
+
+# DEBEZIUM_DB2_VOLUME is an empty local directory;
+# Must be given as relative path, e.g. ./db2data
+export DEBEZIUM_DB2_VOLUME=<local persistent volume directory>
+
+docker-compose -f docker-compose-db2.yaml up
+
+# Start DB2 connector
+curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-db2.json
+
+# Consume messages from a Debezium topic
+docker-compose -f docker-compose-db2.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
+    --bootstrap-server kafka:9092 \
+    --from-beginning \
+    --property print.key=true \
+    --topic db2server.DB2INST1.CUSTOMERS
+
+# Modify records in the database via DB2 client 
+docker-compose -f docker-compose-db2.yaml exec db2server bash -c 'su - db2inst1'
+
+# Shut down the cluster
+docker-compose -f docker-compose-sqlserver.yaml down

You're right.

lga-zurich lga-zurich commented on Feb 05, 2020 15:00 UTC
Author

Hi @gunnarmorling I think this is done.

  • The binary code is not there anymore, it is compiled inside DB2 now and the source is in the repo instead.

  • There is an example inserting a row in DB2

  • The tutorial runs on a customized version of the debezium/connect image, called connect-db2, which is generated locally when the tutorial is run and adds the JDBC driver at build time.
  • We tried it with the nightly build of the connect image (which includes the DB2 connector now) and it seems to work.

    gunnarmorling gunnarmorling commented on Feb 10, 2020 09:33 UTC
    Contributor

    Thanks, @lga-zurich! I've rebased this (please avoid merge commits), squashed everything and opened up PR #95. Looking good overall, but I'm not seeing any change event after the insert/update as described in the README. Could you take a look at this? Let's continue over in #95, I'm going to close this one. Thanks again!

    Reviewers
    Assignees
    lga-zurich lga-zurich
    Labels
    risk: low confidence: 83.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 68% (HIGH) · Higher = larger blast radius
    68%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.6% · Lower = rushed or shallow review
    83.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 11.2% · Safe to merge
    11.2%