Skip to content

Commit a45a70a

Browse files
committed
Add code comments around rollover logic
1 parent cd184c3 commit a45a70a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • x-pack/plugins/rule_registry/server/rule_data_client

x-pack/plugins/rule_registry/server/rule_data_client/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ export class RuleDataClient implements IRuleDataClient {
107107
const clusterClient = await this.getClusterClient();
108108
let simulatedRollover: IndicesRolloverResponse;
109109
try {
110+
// By simulating the rollover here first, we can easily retrieve the current write index name
111+
// and the prospective new write index name. These index names will be used to check if the new
112+
// write index would have any mapping differences from the current write index, and if so, we
113+
// trigger an actual rollover.
110114
({ body: simulatedRollover } = await clusterClient.indices.rollover({
111115
alias,
112116
dry_run: true,
@@ -143,6 +147,10 @@ export class RuleDataClient implements IRuleDataClient {
143147
const needRollover = this.indexNeedsRollover(currentVersions, targetVersions);
144148
if (needRollover) {
145149
try {
150+
// We specify the new_index name explicitly here to avoid races that would cause us to roll
151+
// the index multiple times. If another function rolls the index in between the simulated rollover
152+
// above and this rollover, then this rollover will fail with a resource_already_exists_exception - so
153+
// we catch and suppress that exception. Any other exceptions are rethrown.
146154
await clusterClient.indices.rollover({
147155
alias,
148156
new_index: simulatedRollover.new_index,

0 commit comments

Comments
 (0)