babelfish-for-postgresql / babelfish_extensions

Babelfish for PostgreSQL provides the capability for PostgreSQL to work with applications written for Microsoft SQL Server. Babelfish understands the SQL Server wire-protocol and T-SQL, the Microsoft SQL Server query and procedural language, so you don’t have to switch database drivers or rewrite all of your application queries.
https://babelfishpg.org/
Apache License 2.0
274 stars 93 forks source link

Fix tsql_stat_get_activity() and tsql_read_current_status() to consider only valid tds backends #2905

Closed shah-nirmit closed 4 weeks ago

shah-nirmit commented 1 month ago

Description

Fixed the tsql_read_current_status to increment LocalNumBackends only when it has a valid pid, also fixed tsql_stat_get_activity to use numbackends as calculated by TDS extension insteand of pg_stat_activity.

Issue

When idle Babelfish sessions are killed one-by-one, after killing a certain number of sessions (usually 8-9), other yet-unkilled sessions suddenly disappear from sys.dm_exec_sessions. They still do appear in pg_stat_activity.

RCA

There seems to be 2 issues

  1. We are incorrectly setting numLocalBackends(Static variable) for TDS in function tdsstat_read_current_status Check link vs how pg does it (Basic if logic bug)

  2. We are using pg_stat_fetch_numbackends Function in tsql_stat_get_activity , which seems wrong because the status Array for pg vs tds BackendStatus are different so are the numLocalBackends variable. Check Link

These bugs seem to exist from this commit onwards

Issues Resolved

BABEL-5219

Test Scenarios Covered

Signed-off-by: Nirmit Shah nirmisha@amazon.com

Check List

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 10714050807

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tds/src/backend/tds/tds.c 2 92.84%
contrib/babelfishpg_tds/src/backend/tds/tdstypeio.c 4 87.13%
contrib/babelfishpg_tsql/src/schemacmds.c 4 92.54%
contrib/babelfishpg_tsql/src/hooks.c 14 80.35%
contrib/babelfishpg_common/src/varchar.c 24 85.96%
contrib/babelfishpg_tsql/src/extendedproperty.c 26 94.83%
contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c 37 71.45%
contrib/babelfishpg_tsql/src/catalog.c 51 87.2%
contrib/babelfishpg_tsql/src/dbcmds.c 64 74.85%
contrib/babelfishpg_tsql/src/pltsql_coerce.c 87 80.56%
<!-- Total: 439 -->
Totals Coverage Status
Change from base Build 10665086919: 0.006%
Covered Lines: 44683
Relevant Lines: 60194

💛 - Coveralls