Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new GitHub workflow check designed to execute JDBC tests in parallel query mode #1926

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/composite-actions/install-extensions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: 'Database migration mode'
required: no
default: "single-db"
parallel_query_mode:
description: 'Postgres Parallel Query Mode'
required: no
default: false

runs:
using: "composite"
Expand All @@ -26,6 +30,6 @@ runs:
sudo echo "host all all $ipaddress/32 trust" >> pg_hba.conf
~/${{inputs.install_dir}}/bin/pg_ctl -D ~/${{inputs.install_dir}}/data/ -l logfile restart
cd ~/work/babelfish_extensions/babelfish_extensions/
sudo ~/${{inputs.install_dir}}/bin/psql -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -v migration_mode=${{inputs.migration_mode}} -f .github/scripts/create_extension.sql
sudo ~/${{inputs.install_dir}}/bin/psql -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -v migration_mode=${{inputs.migration_mode}} -v parallel_query_mode=${{inputs.parallel_query_mode}} -f .github/scripts/create_extension.sql
sqlcmd -S localhost -U "jdbc_user" -P 12345678 -Q "SELECT @@version GO"
shell: bash
10 changes: 10 additions & 0 deletions .github/scripts/create_extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@ GRANT ALL ON SCHEMA sys to :user;
ALTER USER :user CREATEDB;
ALTER SYSTEM SET babelfishpg_tsql.database_name = :db;
ALTER SYSTEM SET babelfishpg_tsql.migration_mode = :'migration_mode';

\if :parallel_query_mode
ALTER SYSTEM SET parallel_setup_cost = 0;
ALTER SYSTEM SET parallel_tuple_cost = 0;
ALTER SYSTEM SET min_parallel_index_scan_size = 0;
ALTER SYSTEM SET min_parallel_table_scan_size = 0;
ALTER SYSTEM SET force_parallel_mode = 1;
ALTER SYSTEM SET max_parallel_workers_per_gather = 4;
\endif

SELECT pg_reload_conf();
CALL SYS.INITIALIZE_BABELFISH(:'user');
86 changes: 86 additions & 0 deletions .github/workflows/jdbc-tests-with-parallel-query.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: JDBC Tests With Parallel Query
on: [push, pull_request]

jobs:
run-babelfish-jdbc-tests-with-parallel-query-mode:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
id: checkout

- name: Install Dependencies
id: install-dependencies
if: always()
uses: ./.github/composite-actions/install-dependencies

- name: Build Modified Postgres
id: build-modified-postgres
if: always() && steps.install-dependencies.outcome == 'success'
uses: ./.github/composite-actions/build-modified-postgres

- name: Compile ANTLR
id: compile-antlr
if: always() && steps.build-modified-postgres.outcome == 'success'
uses: ./.github/composite-actions/compile-antlr

- name: Build Extensions
id: build-extensions
if: always() && steps.compile-antlr.outcome == 'success'
uses: ./.github/composite-actions/build-extensions

- name: Install Extensions
id: install-extensions
if: always() && steps.build-extensions.outcome == 'success'
uses: ./.github/composite-actions/install-extensions
with:
parallel_query_mode: true

- name: Run JDBC Tests
id: jdbc
if: always() && steps.install-extensions.outcome == 'success'
timeout-minutes: 60
run: |
cd test/JDBC/
# set env variable isParallelQueryMode to true to let jdbc know not to run tests of file parallel_query_jdbc_schedule
export isParallelQueryMode=true
mvn test
# reset env variable
unset isParallelQueryMode

- name: Cleanup babelfish database
id: cleanup
if: always() && steps.install-extensions.outcome == 'success'
run: |
sudo ~/postgres/bin/psql -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -f .github/scripts/cleanup_babelfish_database.sql

- name: Upload Log
if: always() && steps.jdbc.outcome == 'failure'
uses: actions/upload-artifact@v2
with:
name: postgres-log
path: ~/psql/data/logfile

# The test summary files contain paths with ':' characters, which is not allowed with the upload-artifact actions
- name: Rename Test Summary Files
id: test-file-rename
if: always() && steps.jdbc.outcome == 'failure'
run: |
cd test/JDBC/Info
timestamp=`ls -Art | tail -n 1`
cd $timestamp
mv $timestamp.diff ../output-diff.diff
mv "$timestamp"_runSummary.log ../run-summary.log

- name: Upload Run Summary
if: always() && steps.test-file-rename == 'success'
uses: actions/upload-artifact@v2
with:
name: run-summary.log
path: test/JDBC/Info/run-summary.log

- name: Upload Output Diff
if: always() && steps.jdbc.outcome == 'failure'
uses: actions/upload-artifact@v2
with:
name: output-diff.diff
path: test/JDBC/Info/output-diff.diff
32 changes: 32 additions & 0 deletions test/JDBC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The JDBC test framework for Babelfish uses the JDBC Driver for SQL Server for da
- [IMPORTANT](#important)
- [Adding the test cases](#adding-the-test-cases)
- [Reading the console output and diff](#reading-the-console-output-and-diff)
- [Running Tests with Parallel Query Enabled](#running-tests-with-parallel-query-enabled)

## Running the test framework

Expand Down Expand Up @@ -382,3 +383,34 @@ You will also be provided with the location of the `.diff` file containing the d
- `mm` → minutes
- `ss` → seconds
- `SSS` → milliseconds


## Running Tests with Parallel Query Enabled

After building the modified PostgreSQL engine and Babelfish extensions using the [online instructions](../../contrib/README.md), you must:
1. Create a PostgreSQL database and initialize Babelfish (if you already have a database with Babelfish initialized, you can omit this step or perform the cleanup steps before you initialize) to enable parallel query mode pass -enable_parallel_query flag when running ./init.sh

```bash
./init.sh -enable_parallel_query
```
3. Before running JDBC tests, please take note that currently not all JDBC tests runs sucessfully with parallel query mode on. Certain JDBC tests are encountering issues, such as crashes, failures, or timeouts when executed with parallel query mode enabled. So we need these problematic tests to be excluded from running via jdbc framework. File `parallel_query_jdbc_schedule` contains test-cases names with prefix `ignore#!#` that are problematic and needs to be avoided from being run. To exclude these problematic tests from running via the JDBC framework, use the `isParallelQueryMode` environment variable. You can set it to `true`:

```bash
export isParallelQueryMode=true
# Verify if isParallelQueryMode is set to true
echo $isParallelQueryMode
```
4. Now Run the tests:
```bash
mvn test
```
5. Cleanup all the objects, users, roles and databases created while running the tests:
```bash
./cleanup.sh
```
6. Please note that when you have completed testing with parallel query mode enabled, you should unset the `isParallelQueryMode` environment variable that was previously set to `true`. This ensures that all tests run in the normal Babelfish mode (without parallel query):

```bash
unset isParallelQueryMode
```
If you encounter failing or crashing tests in the "JDBC tests with parallel query" GitHub workflow, consider adding the names of these problematic test cases to the `parallel_query_jdbc_schedule` file. Prefix these test case names with `ignore#!#`. As we work towards resolving these issues in the future, we will gradually remove these excluded tests from the `parallel_query_jdbc_schedule` scheduling file.
51 changes: 49 additions & 2 deletions test/JDBC/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@

#create test user and database from psql terminal
# Default values
parallel_query_mode=false

# Parse command-line flags/arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-enable_parallel_query)
parallel_query_mode=true
shift
;;
*)
# Unknown option
exit 1
;;
esac
shift
done

# create test user and database from psql terminal
if [[ $parallel_query_mode = false ]]; then
echo "============================== CREATING USER AND DATABASE =============================="
psql -U "$USER" -d postgres -a << EOF
CREATE USER jdbc_user WITH SUPERUSER CREATEDB CREATEROLE PASSWORD '12345678' INHERIT;
Expand All @@ -17,3 +36,31 @@ show babelfishpg_tsql.database_name;
CALL sys.initialize_babelfish('jdbc_user');
EOF
echo "============================= BUILDING JDBC TEST FRAMEWORK ============================="
fi

# create test user and database from psql terminal when parallel query mode is on
if [[ $parallel_query_mode = true ]]; then
echo "============================== CREATING USER AND DATABASE =============================="
psql -U "$USER" -d postgres -a << EOF
CREATE USER jdbc_user WITH SUPERUSER CREATEDB CREATEROLE PASSWORD '12345678' INHERIT;
DROP DATABASE IF EXISTS jdbc_testdb;
CREATE DATABASE jdbc_testdb OWNER jdbc_user;
\c jdbc_testdb
CREATE EXTENSION IF NOT EXISTS "babelfishpg_tds" CASCADE;
GRANT ALL ON SCHEMA sys to jdbc_user;
ALTER USER jdbc_user CREATEDB;
\c jdbc_testdb
ALTER SYSTEM SET babelfishpg_tsql.database_name = 'jdbc_testdb';
ALTER SYSTEM SET parallel_setup_cost = 0;
ALTER SYSTEM SET parallel_tuple_cost = 0;
ALTER SYSTEM SET min_parallel_index_scan_size = 0;
ALTER SYSTEM SET min_parallel_table_scan_size = 0;
ALTER SYSTEM SET force_parallel_mode = 1;
ALTER SYSTEM SET max_parallel_workers_per_gather = 4;
SELECT pg_reload_conf();
\c jdbc_testdb
show babelfishpg_tsql.database_name;
CALL sys.initialize_babelfish('jdbc_user');
EOF
echo "============================= BUILDING JDBC TEST FRAMEWORK ============================="
fi
Loading
Loading