Skip to content

Query the throughput endpoints through a static index - #6099

Open
mauroservienti wants to merge 5 commits into
masterfrom
throughput-static-indexes
Open

mauroservienti wants to merge 5 commits into
masterfrom
throughput-static-indexes

Conversation

@mauroservienti

@mauroservienti mauroservienti commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

The licensing queries on EndpointDocuments were dynamic. RavenDB served them with auto indexes in the throughput database, for example Auto/EndpointDocuments/ByEndpointId.ThroughputSource. Same problem as #5953 for retry batches.

Analysis

  • An auto index follows the database setting Indexing.Auto.SearchEngineType and has no per-index search engine setting. The migration procedure in the docs changes the engine per index, so it cannot change these indexes. The search engine custom check and the start-up warning keep reporting them after all static indexes use Lucene.
  • EndpointIndex existed, but DatabaseSetup deployed every index in the assembly to the error database, which has no endpoint documents. The throughput database had no static index.
  • Its fields were named ThroughputSource and Name. The client maps a query on EndpointId.ThroughputSource to the field EndpointId_ThroughputSource, so the index could not serve the queries even in the right database.
  • Without this change, the new test finds four auto indexes in the throughput database.

Changes

  • IndexDeployment.CreateIndexesAsync takes an optional database name. IndexDeployment.FindIndexes exposes the discovery, which TestHelper.IndexDefinitionText now reuses.
  • DatabaseSetup deploys the indexes in the Throughput.Indexes namespace to the throughput database and all others to the error database.
  • EndpointIndex maps EndpointId_ThroughputSource, EndpointId_Name, SanitizedName and EndpointIndicators.
  • The filtered queries in LicensingDataStore go through EndpointIndex. Queries without a filter, or only on the document id, stay collection queries, which create no index and are never stale.
  • Every query through EndpointIndex waits for non-stale results, through one helper. The callers read their own writes: a usage report reads the throughput that was just recorded, the monitoring connection test checks for throughput that just arrived, and UpdateUserIndicatorOnEndpoints updates the documents the query returns. Before, the first dynamic query on a new database created the auto index and RavenDB waited for it. Without the wait, EndpointsTests and When_creating_a_usage_report_on_a_non_broker_transport failed on the Windows build. The index has one entry per endpoint and source, so the wait is short. If it stays stale for longer than the default 15 seconds, the query throws instead of returning stale results.
  • New test LicensingDataStoreIndexTests.Licensing_queries_create_no_auto_index. It fails without the change and passes with it.
  • DatabaseSetup deletes the throughput indexes from the error database, if they are there, before deploying the indexes. A locked index is unlocked first: RavenDB ignores the deletion of a LockedIgnore index and rejects that of a LockedError index, and an operator might have locked it after migrating it to Lucene. New test ThroughputIndexPlacementTests.Setup_should_delete_the_throughput_index_from_the_error_database, for each lock mode.

Existing databases

  • No index is rebuilt. EndpointIndex in the throughput database is new and covers one document per endpoint and source.
  • The EndpointIndex in the error database is deleted at start-up. The auto indexes in the throughput database are deleted by RavenDB once idle, or can be deleted in RavenDB Studio.
  • IndexDefinitionApprovals changed because of the new EndpointIndex definition. Following docs/testing.md, the upgrade guide of the next release needs an entry, which belongs in docs.particular.net.

Testing

  • ServiceControl.Persistence.Tests.RavenDB, filter Throughput|IndexDefinitionApprovals|IndexSetupTests: all pass except tests that fail in setup with a refused connection to the shared embedded server on port 33334, which also happens on master.
  • ServiceControl.Audit.Persistence.Tests.RavenDB, filter IndexSetupTests|IndexDefinitionApprovals|DatabaseSettingsTests: 26/26.

Open points

  • Add an upgrade guide entry for the changed index definitions in docs.particular.net, as docs/testing.md asks.

IndexDeployment always deployed to the default database of the store.
The throughput indexes belong to the throughput database, which shares
the store with the error database. Take an optional database name, and
expose the index discovery so callers can split the indexes by database.
The licensing queries on EndpointDocuments were dynamic, so RavenDB
created auto indexes in the throughput database, for example
Auto/EndpointDocuments/ByEndpointId.ThroughputSource. An auto index has
no per-index search engine setting, so the search engine custom check
keeps failing after all static indexes use Lucene.

EndpointIndex existed but was deployed to the error database, which has
no endpoint documents, and its field names did not match the queries.
Deploy it to the throughput database, map the fields the queries filter
on with the names the client uses for nested properties, and query
through it. Queries without a filter, or only on the document id, stay
collection queries, which create no index.

UpdateUserIndicatorOnEndpoints writes based on its query results, so it
waits for non-stale results instead of skipping endpoints that were
just saved.
The licensing queries read their own writes: a usage report reads the throughput that was just recorded, and the connection test checks for throughput that just arrived from monitoring. Before, the first dynamic query on a new database created the auto index and RavenDB waited for it. A static index that already exists can be stale, which failed EndpointsTests and the usage report acceptance test on the Windows build.

Query EndpointIndex through one helper that waits for non-stale results. The index has one entry per endpoint and source, so the wait is short.
@mauroservienti
mauroservienti marked this pull request as ready for review November 10, 2026 16:16
ramonsmits pushed a commit that referenced this pull request Nov 11, 2026
* Query the event log through a static index

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.

* Fail RavenDB persistence tests that create an auto index

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.
Earlier versions deployed all indexes in the assembly to the error database, including the throughput EndpointIndex that no query there uses.
…g it

RavenDB ignores the deletion of a LockedIgnore index and rejects that of a LockedError index. An operator might have locked the index after migrating it to Lucene.
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.

2 participants