[SERVER-34798] Replace subclasses of ServiceContext with decorations and flexible initialization code Created: 02/May/18  Updated: 29/Oct/23  Resolved: 22/Jun/18

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.0.3, 4.1.1

Type: Task Priority: Major - P3
Reporter: Andy Schwerin Assignee: Andy Schwerin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
causes SERVER-35784 Fix ambiguously named test fixture in... Closed
causes SERVER-35985 sessions_test and sharding_catalog_ma... Closed
causes SERVER-36351 ServiceContextMongoDTest doesn't pers... Closed
Related
related to SERVER-36400 Explicitly destroy the client on exit... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.0, v3.6
Participants:
Linked BF Score: 61

 Description   

The code in the subclasses of ServiceContext could be easily moved into a single, separate library of global free functions that operate on instances of ServiceContext. This would allow us to get rid of the various subclasses of ServiceContext, allowing us to simplify testing infrastructure.



 Comments   
Comment by Githook User [ 05/Nov/19 ]

Author:

{'username': 'bcaimano', 'email': 'ben.caimano@mongodb.com', 'name': 'Ben Caimano'}

Message: SERVER-44322 Fail gracefully when the storage engine has failed to initialize

This commit is only on v3.6 as an alternative to a full backport of SERVER-34798.
Branch: v3.6
https://github.com/mongodb/mongo/commit/20851234f3afa84a40d22ffe28a991a6c8b91e02

Comment by Githook User [ 13/Sep/18 ]

Author:

{'name': 'Henrik Edin', 'email': 'henrik.edin@mongodb.com', 'username': 'henrikedin'}

Message: SERVER-34798 Remove ServiceContext subclasses and use new ServiceContext in every unit test.

This patch does several loosely related and surprisingly hard to separate things.

1.) Make the ServiceContext class final

2.) Create a mechanism, called ConstructorActions, for running methods on
ServiceContexts immediately after they're built and immediately before they're
destroyed.

3.) Introduce / improve test fixture base classes for tests, giving them fresh
ServiceContext instances for each test case. There is one fixture for tests that
need a storage engine and another for those that do not.

4.) Make several remaining global variables SC decorations in support of (3)

5.) Replace many MONGO_INITIALIZERS that access getGlobalServiceContext with the
new constructor-actions system, which is needed for (3.)

6.) Fix up tests to use the fixtures from (3) and fix tests that silently used
different service contexts in together in a technically illegal fashion that now
breaks.

7.) Utilize (2) as necessary to simplify initialization of new ServiceContexts,
simplifying the fixtures in (3).

(cherry picked from commit d520be0814492c262515cf0a5d62a127ace70dce)

SERVER-35985 Destroy clients started in other threads.

(cherry picked from commit 9a68eb0cc65a93233b4ff5746330f9eb77de9b90)

SERVER-36258 Construct ServiceContext after mongo initializers complete.

(cherry picked from commit bfe170e49b1dc10b2badde45bc13c057a2f8ab61)

SERVER-36400 Explicitly destroy the client on exiting run() of each BackgroundJob

(cherry picked from commit b079e4713d897b5541c2804386025817ec720800)

SERVER-36351 Fix so ServiceContextMongoDTest removes the temp directory in its destructor.

(cherry picked from commit 4c16f0f336f4db77034e8aa594bbd4a5bac3f40c)

SERVER-36347 Fix parse_zone_info.py after ServiceContext refactor.

(cherry picked from commit c9d4204b6243e5eee6fe0b5e2c34d02af9ac5edb)
Branch: v4.0
https://github.com/mongodb/mongo/commit/58feaec9c55629ba253b1ff013736eb8b8e9c79d

Comment by Githook User [ 13/Sep/18 ]

Author:

{'name': 'Henrik Edin', 'email': 'henrik.edin@mongodb.com', 'username': 'henrikedin'}

Message: SERVER-34798 Remove ServiceContext subclasses and use new ServiceContext in every unit test.

(cherry picked from commit 7ba144c6d0e28282e47450634ca5370b270e3207)

SERVER-36258 Construct ServiceContext after mongo initializers complete.

(cherry picked from commit f9e131ad70d3103513e777cb2125daa1daae23ec)
Branch: v4.0
https://github.com/10gen/mongo-enterprise-modules/commit/c94b377a1c608177fb394f756df94fb8720d9746

Comment by Andy Schwerin [ 22/Jun/18 ]

Consider back port of this change to 4.0 branch to simplify other back ports.

Comment by Githook User [ 22/Jun/18 ]

Author:

{'username': 'amschwerin', 'name': 'Andy Schwerin', 'email': 'schwerin@mongodb.com'}

Message: SERVER-34798 Remove ServiceContext subclasses and use new ServiceContext in every unit test.

This patch does several loosely related and surprisingly hard to separate things.

1.) Make the ServiceContext class final

2.) Create a mechanism, called ConstructorActions, for running methods on
ServiceContexts immediately after they're built and immediately before they're
destroyed.

3.) Introduce / improve test fixture base classes for tests, giving them fresh
ServiceContext instances for each test case. There is one fixture for tests that
need a storage engine and another for those that do not.

4.) Make several remaining global variables SC decorations in support of (3)

5.) Replace many MONGO_INITIALIZERS that access getGlobalServiceContext with the
new constructor-actions system, which is needed for (3.)

6.) Fix up tests to use the fixtures from (3) and fix tests that silently used
different service contexts in together in a technically illegal fashion that now
breaks.

7.) Utilize (2) as necessary to simplify initialization of new ServiceContexts,
simplifying the fixtures in (3).
Branch: master
https://github.com/mongodb/mongo/commit/d520be0814492c262515cf0a5d62a127ace70dce

Comment by Githook User [ 22/Jun/18 ]

Author:

{'username': 'amschwerin', 'name': 'Andy Schwerin', 'email': 'schwerin@mongodb.com'}

Message: SERVER-34798 Remove ServiceContext subclasses and use new ServiceContext in every unit test.
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/7ba144c6d0e28282e47450634ca5370b270e3207

Comment by Githook User [ 05/May/18 ]

Author:

{'email': 'schwerin@mongodb.com', 'name': 'Andy Schwerin', 'username': 'amschwerin'}

Message: SERVER-34798 Move storage initialization behaviors out of ServiceContext subclasses to new library.
Branch: master
https://github.com/mongodb/mongo/commit/30994f3bacb6e814ae015d83693c549a3b924ccc

Comment by Githook User [ 05/May/18 ]

Author:

{'email': 'schwerin@mongodb.com', 'name': 'Andy Schwerin', 'username': 'amschwerin'}

Message: SERVER-34798 Move storage initialization behaviors out of ServiceContext subclasses to new library.
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/31e5cc574493506c86085e7b38211b81ab77eb17

Generated at Thu Feb 08 04:37:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.