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

Fix issue where query get interrupted during prepare. #973

Merged
merged 10 commits into from
Jan 31, 2025
Merged

Conversation

khanaffan
Copy link
Contributor

@khanaffan khanaffan commented Jan 22, 2025

itwinjs-core: iTwin/itwinjs-core#7592

Fixes: iTwin/itwinjs-core#7549

  • Do not interrupt the query during preparation. The query can only be interrupted during the step() function.
  • Add an option to prepare ECSQL using a thread database connection. Experimental.
    • Default to false. Not enabled.
    • Thread does not wait to acquire lock on primary connection to prepare statement. Enhance faster.
    • Side effect more memory as each connection load its on EC Schema when preparing ECSQL.
  • Query statistics now also return preparation time in nanoseconds.
  • Introduce a feature to automatically shut down concurrent queries when idle for a set time:
    • Defaults to 30 minutes.
    • Closes all threads and releases resources used by concurrent queries.
    • Automatically wakes up when a new request comes in.
    • New error code is added ShuttingDown which cause frontend to retry.
  • Allow setting the memory map I/O size for each connection, defaulting to 0 (not used):
    • This is an experimental option. It improves query performance on regular files but is untested with cloud SQLite.
  • The statement cache size per thread can now be configured, with the default remaining at 40 (unchanged from previous).
  • Fix a issue where delay use for testing cause every query to delay at least once even when not testing.
  • Added allowTestingArgs help simulate a condition for testing.
  • Found another issue which cause thread dead lock during closing connection. ConcurrentQuery config is not stored on db connection anymore.
    The default config look as following. Only new change is autoShutdowWhenIdealForSeconds: 1800
{
  workerThreads: 4,
  requestQueueSize: 2000,
  ignorePriority: false,
  ignoreDelay: true,
  doNotUsePrimaryConnToPrepare: false,
  autoShutdowWhenIdlelForSeconds: 1800,
  statementCacheSizePerWorker: 40,
  monitorPollInterval: 1000,
  memoryMapFileSize: 0,
  allowTestingArgs: false,
  globalQuota: { time: 60, memory: 8388608 }
}

@khanaffan khanaffan marked this pull request as ready for review January 23, 2025 20:55
@khanaffan
Copy link
Contributor Author

/azp run imodel-native

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@khanaffan
Copy link
Contributor Author

/azp run imodel-native

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@khanaffan
Copy link
Contributor Author

/azp run imodel-native

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@khanaffan
Copy link
Contributor Author

/azp run imodel-native

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@khanaffan khanaffan requested a review from bbastings as a code owner January 31, 2025 16:44
@khanaffan khanaffan merged commit d5e7430 into main Jan 31, 2025
19 checks passed
@khanaffan khanaffan deleted the affanK/ccq-fix branch January 31, 2025 20:19
@khanaffan
Copy link
Contributor Author

@Mergifyio backport release/4.11.x release/4.10.x

Copy link

mergify bot commented Feb 4, 2025

backport release/4.11.x release/4.10.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Feb 4, 2025
* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
(cherry picked from commit d5e7430)

# Conflicts:
#	iModelCore/ECDb/ECDb/ConcurrentQueryManagerImpl.cpp
#	iModelCore/ECDb/Tests/NonPublished/ConcurrentQueryTest_V2.cpp
#	iModelJsNodeAddon/IModelJsNative.cpp
mergify bot pushed a commit that referenced this pull request Feb 4, 2025
* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
(cherry picked from commit d5e7430)

# Conflicts:
#	iModelCore/ECDb/ECDb/ConcurrentQueryManagerImpl.cpp
#	iModelCore/ECDb/Tests/NonPublished/ConcurrentQueryTest_V2.cpp
#	iModelJsNodeAddon/IModelJsNative.cpp
khanaffan added a commit that referenced this pull request Feb 4, 2025
* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
khanaffan added a commit that referenced this pull request Feb 4, 2025
* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
@khanaffan
Copy link
Contributor Author

@Mergifyio backport release/4.10.x release/4.11.x

Copy link

mergify bot commented Feb 4, 2025

backport release/4.10.x release/4.11.x

❌ No backport have been created

GitHub error: Branch not found

aruniverse pushed a commit that referenced this pull request Feb 6, 2025
… [release/4.10.x] (#989)

* Fix issue where query get interrupted during prepare. (#973)

* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
(cherry picked from commit d5e7430)

# Conflicts:
#	iModelCore/ECDb/ECDb/ConcurrentQueryManagerImpl.cpp
#	iModelCore/ECDb/Tests/NonPublished/ConcurrentQueryTest_V2.cpp
#	iModelJsNodeAddon/IModelJsNative.cpp

* Fix issue where query get interrupted during prepare. (#973)

* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>

* unused

---------

Co-authored-by: affank <khanaffan@gmail.com>
Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
aruniverse pushed a commit that referenced this pull request Feb 6, 2025
… [release/4.11.x] (#988)

* Fix issue where query get interrupted during prepare. (#973)

* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
(cherry picked from commit d5e7430)

# Conflicts:
#	iModelCore/ECDb/ECDb/ConcurrentQueryManagerImpl.cpp
#	iModelCore/ECDb/Tests/NonPublished/ConcurrentQueryTest_V2.cpp
#	iModelJsNodeAddon/IModelJsNative.cpp

* Fix issue where query get interrupted during prepare. (#973)

* do not interrupt query during prepare

* fix

* add debug arg to simulate interrupt

* fix

* fix a thread lockup when reading config. Config is no more stored on connection.

* update api

---------

Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>

* fix

---------

Co-authored-by: affank <khanaffan@gmail.com>
Co-authored-by: Affan Khan <khanaffan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Concurrent query return INTERRUPT error when preparing ECSQL
4 participants