Skip to content

Commit

Permalink
working jooq example
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Ervits authored and Artem Ervits committed Nov 1, 2023
1 parent 0a62da0 commit 102ae01
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 130 deletions.
3 changes: 1 addition & 2 deletions jooq/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ ENV REFRESHED_AT 2023_11_01
COPY ./jooq-basic-sample /jooq-basic-sample
WORKDIR /jooq-basic-sample
RUN mvn compile
#RUN mvn exec:java -Dexec.mainClass=com.cockroachlabs.Sample
#RUN mvn exec:java -Dexec.mainClass="org.jooq.example.Main" -Dexec.args="jdbc:postgresql://localhost:5432/postgres postgres postgres"
RUN mvn exec:java -Dexec.mainClass=com.cockroachlabs.Sample
129 changes: 1 addition & 128 deletions jooq/README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,2 @@
# Sample 3 node *insecure* CockroachDB cluster with HAProxy acting as load balancer and PostgreSQL client, which includes `psql`, `pgbench`, etc.
# jOOQ and CockroachDB [tutorial](https://www.cockroachlabs.com/docs/stable/build-a-java-app-with-cockroachdb-jooq)

Prerequisites:

## Services
* `roach-0` - CockroachDB node
* `roach-1` - CockroachDB node
* `roach-2` - CockroachDB node
* `lb` - HAProxy acting as load balancer
* `postgresql` - PostgreSQL container including psql and pgbench
* `client` - client machine containing `cockroach` binary

## Getting started
>If you are using Google Chrome as your browser, you may want to navigate here `chrome://flags/#allow-insecure-localhost` and set this flag to `Enabled`.
1. Start the tutorial with a helper script from the parent directory.

```bash
cd cockroach-docker
./up.sh docker-compose-postgresql.yml

Creating network "cockroach-docker_default" with the default driver
Creating roach-0 ... done
Creating roach-1 ... done
Creating roach-2 ... done
Creating lb ... done
Creating postgresql ... done
Creating client ... done
Cluster successfully initialized
```

### Connect as root

```bash
docker exec -it client cockroach sql --insecure --url 'postgres://root@lb:26000/defaultdb?sslmode=disable'
```

2. visit the [HAProxy UI](http://localhost:8081)

### Open Interactive Shells
```bash
docker exec -ti roach-0 /bin/bash
docker exec -ti roach-1 /bin/bash
docker exec -ti roach-2 /bin/bash
docker exec -ti lb /bin/sh
docker exec -ti client /bin/bash
docker exec -ti postgresql /bin/bash

# cli inside the container
cockroach sql --insecure --host=lb

# directly
docker exec -ti client cockroach sql --insecure --host=roach-0
```

3. Inspect the pgbench logs

```bash
docker logs postgresql
```

4. Inspect all of the container logs

```bash
docker compose -f docker-compose-postgresql.yml logs --follow
```

5. Run the workload

```bash
docker exec -it postgresql bash
```

Initialize

```bash
docker exec -it postgresql \
pgbench \
--initialize \
--host=${PGHOST} \
--username=${PGUSER} \
--port=${PGPORT} \
--no-vacuum \
--scale=10 \
--foreign-keys \
${PGDATABASE}
```

Run the default `tpcb-like` workload

```bash
docker exec -it postgresql \
pgbench \
--host=${PGHOST} \
--no-vacuum \
--file=tpcb-original.sql@1 \
--client=8 \
--jobs=8 \
--username=${PGUSER} \
--port=${PGPORT} \
--scale=10 \
--failures-detailed \
--verbose-errors \
--max-tries=3 \
${PGDATABASE} \
-T 60 \
-P 5
```

Run the optimized workload

```bash
docker exec -it postgresql \
pgbench \
--host=${PGHOST} \
--no-vacuum \
--file=tpcb-cockroach.sql@1 \
--client=8 \
--jobs=8 \
--username=${PGUSER} \
--port=${PGPORT} \
--scale=10 \
--failures-detailed \
--verbose-errors \
--max-tries=3 \
${PGDATABASE} \
-T 60 \
-P 5
```

0 comments on commit 102ae01

Please sign in to comment.