Skip to content

Query the event log through a static index - #6100

Merged
ramonsmits merged 2 commits into
masterfrom
event-log-static-index
Nov 11, 2026
Merged

ramonsmits merged 2 commits into
masterfrom
event-log-static-index

Conversation

@mauroservienti

Copy link
Copy Markdown
Member

The event log query was the last dynamic query in the error database. RavenDB served it with the auto index Auto/EventLogItems/ByRaisedAt. Same problem as #5953 for retry batches and #6099 for the throughput database.

Analysis

  • EventLogDataStore.GetEventLogItems ran session.Query<EventLogItem>() sorted by RaisedAt, without a static index. ServicePulse reads the event log, so the auto index exists on most error databases. A customer case reported it after migrating to Lucene.
  • An auto index follows the database setting Indexing.Auto.SearchEngineType and has no per-index search engine setting. The search engine custom check and the start-up warning keep reporting it after all static indexes use Lucene.
  • Sweep of the error database, by code: every other Query<T>, DocumentQuery<T> and by-query operation in ServiceControl.Persistence.RavenDB and ServiceControl.RavenDB uses a static index, or is a collection query without a filter or sort (ExternalIntegrationRequestsDataStore.TryDispatchEventBatch), which creates no index. Nothing outside the RavenDB persistence projects opens a session.
  • Sweep of the error database, by running the RavenDB persistence suite and listing the auto indexes each test leaves behind: Auto/EventLogItems/ByRaisedAt was the only one.

Changes

  • New static index EventLogItems_ByRaisedAt, mapping RaisedAt. GetEventLogItems queries through it.
  • PersistenceTestsContext.TearDown lists the auto indexes in the error database of each test and fails the test if there are any. This catches a new dynamic query in any data store that a test exercises. Without the index change, the EventLogDataStoreTests fail with Auto/EventLogItems/ByRaisedAt.
  • Approval files: the new index definition, and EventLogItem in RavenPersistedTypes.

Existing databases

  • RavenDB builds the new index once over the event log, which retention keeps small. No existing index is rebuilt.
  • The code does not delete the existing auto index. RavenDB marks it idle after 30 minutes without queries and deletes it 72 hours later. It can also be deleted in RavenDB Studio.
  • IndexDefinitionApprovals changed. Following docs/testing.md, the upgrade guide of the next release needs an entry in docs.particular.net.

Testing

  • ServiceControl.Persistence.Tests.RavenDB, full suite: 368/370. The two failures are setup failures with a refused connection to the shared embedded server on port 33334, which also happen on master, a different set on each run.

Open points

GetEventLogItems ran a dynamic query on EventLogItems sorted by
RaisedAt. RavenDB serves that with an Auto/EventLogItems/ByRaisedAt
index, which exists on every error database that ServicePulse has read
the event log from. An auto index has no per-index search engine
setting, so the "Error Database Search Engine" custom check keeps
failing after all static indexes are migrated to Lucene.

Add EventLogItems_ByRaisedAt and query through it.
Each test gets its own error database. Before deleting it, list the
auto indexes in it and fail the test if there are any, so a new dynamic
query in a data store is caught by the tests that exercise it. With the
event log query fixed, the suite creates no auto index in the error
database.

The throughput database is not checked yet: its licensing queries still
create auto indexes until #6099 is merged.
@ramonsmits
ramonsmits merged commit f1faa1e into master Nov 11, 2026
36 checks passed
@ramonsmits
ramonsmits deleted the event-log-static-index branch November 11, 2026 14:00
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.

3 participants