-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Narayana Transaction Logs QuickStart
- Loading branch information
1 parent
dd2d4dc
commit 289fcb9
Showing
19 changed files
with
1,431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
!target/*-runner | ||
!target/*-runner.jar | ||
!target/lib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Eclipse | ||
.project | ||
.classpath | ||
.settings/ | ||
bin/ | ||
|
||
# IntelliJ | ||
.idea | ||
*.ipr | ||
*.iml | ||
*.iws | ||
|
||
# NetBeans | ||
nb-configuration.xml | ||
|
||
# Visual Studio Code | ||
.vscode | ||
|
||
# OSX | ||
.DS_Store | ||
|
||
# Vim | ||
*.swp | ||
*.swo | ||
|
||
# patch | ||
*.orig | ||
*.rej | ||
|
||
# Maven | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
release.properties |
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
narayana-transaction-logs-quickstart/.mvn/wrapper/maven-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Quarkus - Narayana - Transaction logs | ||
======================== | ||
|
||
This QuickStart demonstrates how your Quarkus application can be configured for automatic transaction recovery. | ||
|
||
## Test crash recovery | ||
|
||
- build application: | ||
- `./mvnw clean package -DskipTests -DskipITs` | ||
- remove previous database volumes, so that we start with a clean sheet: | ||
- `docker-compose down --volumes` | ||
- start database: | ||
- `docker compose up` | ||
- wait until container has started and is ready to accept connections | ||
- start application: | ||
- `java -jar ./target/quarkus-app/quarkus-run.jar` | ||
- send a message to make transaction and crash application: | ||
- `curl -v localhost:8080/transaction-logs/transaction-recovery` | ||
- inspect JDBC Object Store: | ||
- connect to Postgres container: | ||
- execute `docker exec -it $(docker ps | grep 'postgres' | awk '{print $1}') psql -U quarkus_test -W narayana_transaction_logs_db` | ||
- enter password `quarkus_test` | ||
- now you can see that JDBC object store contains transaction waiting for recovery: | ||
- enter `SELECT * FROM quarkus_jbosststxtable;` | ||
- table we were trying to insert when application crashed is empty: | ||
- enter `SELECT * FROM audit_log;` | ||
- start application again: | ||
- `java -jar ./target/quarkus-app/quarkus-run.jar` | ||
- in a moment, you will see that the `audit_log` database table contains 2 inserts: | ||
- enter `SELECT * FROM audit_log;` | ||
``` | ||
id | message | datasource | ||
----+---------+----------------- | ||
1 | crash | <default> | ||
2 | crash | object-store-ds | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '2.4' | ||
|
||
services: | ||
postgres: | ||
container_name: narayana-transaction-logs-database | ||
image: "postgres:latest" | ||
restart: always | ||
volumes: | ||
- ./init-script.sql:/docker-entrypoint-initdb.d/init-script.sql | ||
command: "--max_prepared_transactions=100" | ||
environment: | ||
POSTGRES_USER: "quarkus_test" | ||
POSTGRES_PASSWORD: "quarkus_test" | ||
POSTGRES_DB: "narayana_transaction_logs_db" | ||
ports: | ||
- "5432:5432" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TABLE quarkus_jbosststxtable (statetype integer not null, hidden integer not null, typename character varying(255) not null, uidstring character varying(255) not null, objectstate bytea); | ||
CREATE TABLE quarkus_jbosststxtable_historical_data AS SELECT * FROM quarkus_jbosststxtable; | ||
CREATE OR REPLACE FUNCTION object_store_historical_data() RETURNS TRIGGER AS ' | ||
BEGIN | ||
INSERT INTO quarkus_jbosststxtable_historical_data(statetype, hidden, typename, uidstring, objectstate) VALUES (NEW.statetype, NEW.hidden, NEW.typename, NEW.uidstring, NEW.objectstate); | ||
RETURN NULL; | ||
END; | ||
' LANGUAGE plpgsql; | ||
CREATE TRIGGER object_store_historical_data_trigger AFTER INSERT ON quarkus_jbosststxtable FOR EACH ROW EXECUTE FUNCTION object_store_historical_data(); | ||
CREATE TABLE audit_log (id BIGSERIAL PRIMARY KEY, message VARCHAR(10), datasource VARCHAR(40)); | ||
CREATE TABLE example (data VARCHAR(6) NOT NULL); | ||
INSERT INTO example VALUES ('first'); | ||
INSERT INTO example VALUES ('second'); | ||
INSERT INTO example VALUES ('third'); |
Oops, something went wrong.