Skip to content

quincy: pybind/mgr: disable sqlite3/python autocommit - #57199

Merged
yuriw merged 12 commits into
ceph:quincyfrom
batrick:wip-65736-quincy
Aug 29, 2024
Merged

yuriw merged 12 commits into
ceph:quincyfrom
batrick:wip-65736-quincy

Conversation

@batrick

@batrick batrick commented May 1, 2024

Copy link
Copy Markdown
Member

batrick added 12 commits May 1, 2024 09:00
This avoids an assertion in ::drop_active.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 3fca118)
In the same epoch, to simplify testing.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit e044140)
Some are for development purposes and should be filtered out by the dashboard.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 0d94eeb)

Conflicts:
	qa/tasks/mgr/dashboard/test_mgr_module.py: no leader_dashboard
To catch unintentional autocommit by sqlite3.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit fdd0dde)
Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 8ac4bbc)
Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 1749edd)
Refactor common tasks and allow loading mgrmodules before unittests start.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 2f48dc9)
These should have been part of the commit adding the tests.

Fixes: 9ebcbdb
Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 440f25e)
Otherwise you cannot use LocalDaemon.check_status.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 9748d0c)
This mirrors teuthology and makes it possible to check the exit status of a
daemon.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit e2e2144)

Conflicts:
	qa/tasks/vstart_runner.py: minor code diff
That autocommit is properly turned off and that commits via context managers
work as expected.

Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit fb82b6d)
SQLite3 and python's binding were both committing transactions at unintended
points. Turn it off and stop using executescript.

Fixes: https://tracker.ceph.com/issues/65494
Signed-off-by: Patrick Donnelly <[email protected]>
(cherry picked from commit 6eacfe9)
@batrick
batrick requested a review from a team as a code owner May 1, 2024 13:04
@batrick batrick added this to the quincy milestone May 1, 2024
@batrick batrick added the pybind label May 1, 2024
@batrick

batrick commented May 1, 2024

Copy link
Copy Markdown
Member Author

jenkins test api

@ljflores

Copy link
Copy Markdown
Member

@epuertat can you review this and decide if it should go in quincy? If so, add the "needs-qa" label. If it is a blocker, additionally change the milestone to "v17.2.8".

@epuertat

Copy link
Copy Markdown
Member

@ljflores I can't say, as I'm not familiar with the core of this PR. I just helped @batrick with an API test failure in the original PR.

@batrick batrick modified the milestones: quincy, v17.2.8 Aug 22, 2024
@batrick

batrick commented Aug 22, 2024

Copy link
Copy Markdown
Member Author

@epuertat can you review this and decide if it should go in quincy? If so, add the "needs-qa" label. If it is a blocker, additionally change the milestone to "v17.2.8".

It should go in v17.2.8. The bug can leave the sqlite3 database in a state the mgr doesn't know how to recover from.

@batrick
batrick requested a review from phlogistonjohn August 22, 2024 12:41
@batrick

batrick commented Aug 22, 2024

Copy link
Copy Markdown
Member Author

@phlogistonjohn mind reviewing this?

@phlogistonjohn phlogistonjohn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python bits (and teuthology bits) look ok for backport.
c++ bits are over my head :-)

@ljflores

Copy link
Copy Markdown
Member

@yuriw
yuriw merged commit fe3e9d9 into ceph:quincy Aug 29, 2024
@hswong3i

Copy link
Copy Markdown
Contributor

My ceph-ceph-17.2.8 OBS packaging for Ubuntu 24.04 is broken with following error message:

root@ais3ua9thiem-1:~# ceph -s
  cluster:
    id:     8ef45e11-f70c-5cb6-8c83-b631cde550af
    health: HEALTH_ERR
            Module 'devicehealth' has failed: cannot start a transaction within a transaction
            1 mgr modules have recently crashed
 
  services:
    mon: 2 daemons, quorum ais3ua9thiem-2,ais3ua9thiem-1 (age 12m)
    mgr: ais3ua9thiem-1(active, since 4m)
    mds: 1/1 daemons up
    osd: 1 osds: 1 up (since 12m), 1 in (since 71m)
 
  data:
    volumes: 1/1 healthy
    pools:   4 pools, 145 pgs
    objects: 23 objects, 26 KiB
    usage:   300 MiB used, 9.7 GiB / 10 GiB avail
    pgs:     145 active+clean
root@ais3ua9thiem-1:~# tail -f -n 500 /var/log/ceph/ceph-mgr.ais3ua9thiem-1.log
2024-11-19T06:04:53.965+0000 74652c0006c0 -1 Traceback (most recent call last):
  File "/usr/share/ceph/mgr/mgr_module.py", line 513, in check
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/devicehealth/module.py", line 364, in _do_serve
    if self.db_ready() and self.enable_monitoring:
       ^^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1282, in db_ready
    return self.db is not None
           ^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1294, in db
    self._db = self.open_db()
               ^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1275, in open_db
    self.configure_db(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1249, in configure_db
    self.load_schema(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1228, in load_schema
    db.execute('BEGIN;')
sqlite3.OperationalError: cannot start a transaction within a transaction

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/share/ceph/mgr/devicehealth/module.py", line 408, in serve
    self._do_serve()
  File "/usr/share/ceph/mgr/mgr_module.py", line 521, in check
    self.open_db();
    ^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1275, in open_db
    self.configure_db(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1249, in configure_db
    self.load_schema(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1228, in load_schema
    db.execute('BEGIN;')
sqlite3.OperationalError: cannot start a transaction within a transaction

Once partly rollback with https://github.com/alvistack/ceph-ceph/blob/5ecb79fdfc03f2050b7472f86f4b1335132d6e27/debian/patches/0027-57199-revert-wip-65736-quincy.patch and recompile the packages, now error gone and running normally:

root@ais3ua9thiem-1:~# ceph -s
  cluster:
    id:     8ef45e11-f70c-5cb6-8c83-b631cde550af
    health: HEALTH_ERR
            Module 'devicehealth' has failed: cannot start a transaction within a transaction
            1 mgr modules have recently crashed
 
  services:
    mon: 2 daemons, quorum ais3ua9thiem-2,ais3ua9thiem-1 (age 12m)
    mgr: ais3ua9thiem-1(active, since 4m)
    mds: 1/1 daemons up
    osd: 1 osds: 1 up (since 12m), 1 in (since 71m)
 
  data:
    volumes: 1/1 healthy
    pools:   4 pools, 145 pgs
    objects: 23 objects, 26 KiB
    usage:   300 MiB used, 9.7 GiB / 10 GiB avail
    pgs:     145 active+clean

@batrick
batrick deleted the wip-65736-quincy branch November 19, 2024 15:16
@batrick

batrick commented Nov 19, 2024

Copy link
Copy Markdown
Member Author

My ceph-ceph-17.2.8 OBS packaging for Ubuntu 24.04 is broken with following error message:

root@ais3ua9thiem-1:~# ceph -s
  cluster:
    id:     8ef45e11-f70c-5cb6-8c83-b631cde550af
    health: HEALTH_ERR
            Module 'devicehealth' has failed: cannot start a transaction within a transaction
            1 mgr modules have recently crashed
 
  services:
    mon: 2 daemons, quorum ais3ua9thiem-2,ais3ua9thiem-1 (age 12m)
    mgr: ais3ua9thiem-1(active, since 4m)
    mds: 1/1 daemons up
    osd: 1 osds: 1 up (since 12m), 1 in (since 71m)
 
  data:
    volumes: 1/1 healthy
    pools:   4 pools, 145 pgs
    objects: 23 objects, 26 KiB
    usage:   300 MiB used, 9.7 GiB / 10 GiB avail
    pgs:     145 active+clean
root@ais3ua9thiem-1:~# tail -f -n 500 /var/log/ceph/ceph-mgr.ais3ua9thiem-1.log
2024-11-19T06:04:53.965+0000 74652c0006c0 -1 Traceback (most recent call last):
  File "/usr/share/ceph/mgr/mgr_module.py", line 513, in check
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/devicehealth/module.py", line 364, in _do_serve
    if self.db_ready() and self.enable_monitoring:
       ^^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1282, in db_ready
    return self.db is not None
           ^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1294, in db
    self._db = self.open_db()
               ^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1275, in open_db
    self.configure_db(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1249, in configure_db
    self.load_schema(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1228, in load_schema
    db.execute('BEGIN;')
sqlite3.OperationalError: cannot start a transaction within a transaction

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/share/ceph/mgr/devicehealth/module.py", line 408, in serve
    self._do_serve()
  File "/usr/share/ceph/mgr/mgr_module.py", line 521, in check
    self.open_db();
    ^^^^^^^^^^^^^^
  File "/usr/share/ceph/mgr/mgr_module.py", line 1275, in open_db
    self.configure_db(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1249, in configure_db
    self.load_schema(db)
  File "/usr/share/ceph/mgr/mgr_module.py", line 1228, in load_schema
    db.execute('BEGIN;')
sqlite3.OperationalError: cannot start a transaction within a transaction

Once partly rollback with https://github.com/alvistack/ceph-ceph/blob/5ecb79fdfc03f2050b7472f86f4b1335132d6e27/debian/patches/0027-57199-revert-wip-65736-quincy.patch and recompile the packages, now error gone and running normally:

root@ais3ua9thiem-1:~# ceph -s
  cluster:
    id:     8ef45e11-f70c-5cb6-8c83-b631cde550af
    health: HEALTH_ERR
            Module 'devicehealth' has failed: cannot start a transaction within a transaction
            1 mgr modules have recently crashed
 
  services:
    mon: 2 daemons, quorum ais3ua9thiem-2,ais3ua9thiem-1 (age 12m)
    mgr: ais3ua9thiem-1(active, since 4m)
    mds: 1/1 daemons up
    osd: 1 osds: 1 up (since 12m), 1 in (since 71m)
 
  data:
    volumes: 1/1 healthy
    pools:   4 pools, 145 pgs
    objects: 23 objects, 26 KiB
    usage:   300 MiB used, 9.7 GiB / 10 GiB avail
    pgs:     145 active+clean

this one is weird. My current theory is this is a quirk to an older version of sqlite3 I don't understand, specifically with how the database connection is opened (isolation_level). Any idea?

@hswong3i

Copy link
Copy Markdown
Contributor

this one is weird. My current theory is this is a quirk to an older version of sqlite3 I don't understand, specifically with how the database connection is opened (isolation_level). Any idea?

I don't really think so, because I didn't patch the sqlite3 package but just using the official Ubuntu [sqlite3 (3.45.1-1ubuntu2)](24.04 https://packages.ubuntu.com/noble/sqlite3), which shouldn't be too old :-(

P.S. Still, once this PR partly reverted, bug gone immediately :-(

@hvenev

hvenev commented Jan 25, 2025

Copy link
Copy Markdown

To me it looks like this is the normal behavior of Python's sqlite library. As documented in https://docs.python.org/3/library/sqlite3.html#transaction-control-via-the-autocommit-attribute, setting autocommit=False ensures we are always in a transaction.

autocommit=False:

>>> import sqlite3
>>> db = sqlite3.Connection(':memory:', autocommit=False)
>>> db.in_transaction
True
>>> c = db.cursor()
>>> c.execute('BEGIN;')
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    c.execute('BEGIN;')
    ~~~~~~~~~^^^^^^^^^^
sqlite3.OperationalError: cannot start a transaction within a transaction
>>> 

autocommit=False again:

>>> import sqlite3
>>> db = sqlite3.Connection(':memory:', autocommit=False)
>>> db.in_transaction
True
>>> db.commit()
>>> db.in_transaction
True
>>> db.commit()
>>> db.in_transaction
True

autocommit=True:

>>> import sqlite3
>>> db = sqlite3.Connection(':memory:', autocommit=True)
>>> db.in_transaction
False
>>> c = db.cursor()
>>> c.execute('BEGIN;')
<sqlite3.Cursor object at 0x7fb71453f7c0>
>>> db.in_transaction
True
>>> c.execute('COMMIT')
<sqlite3.Cursor object at 0x7fb71453f7c0>
>>> db.in_transaction
False
>>> 

@batrick

batrick commented Feb 12, 2025

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants