Skip to content

Fix for determining write index

Terri Chu requested to merge 428070-fix-for-determining-write-index into master

What does this MR do and why?

Related to #428070 (closed)

Found while working on implementing indexing all projects in: !134456 (merged)

This was causing spec failures when trying to get a document count from Elasticsearch for a specific index.

  • refactors logic which determines which index is the write index
  • adds a spec for the method changed

Screenshots or screen recordings

N/A - backend change only

How to set up and validate locally

  1. setup gdk for elasticsearch
  2. checkout master branch
  3. create 2 test indexes, using the same alias, with one set to the write index
curl --request PUT \
  --url http://localhost:9200/test-index-2 \
  --header 'Content-Type: application/json' \
  --data '{
	"aliases": {
		"test_alias": {
			"is_write_index": false
		}
	}
}'
curl --request PUT \
  --url http://localhost:9200/test-index-1 \
  --header 'Content-Type: application/json' \
  --data '{
	"aliases": {
		"test_alias": {
			"is_write_index": true
		}
	}
}'
  1. in rails console, run the method to find each index. only one should be the write index <-- this is the bug
> elastic_helper = Gitlab::Elastic::Helper.default
> elastic_helper.target_index_names(target: 'test_alias')
=> {"test-index-1"=>true, "test-index-2"=>true}
  1. checkout this (428070-fix-for-determining-write-index) branch
  2. run the same method in rails console
> elastic_helper = Gitlab::Elastic::Helper.default
> elastic_helper.target_index_names(target: 'test_alias')
=> {"test-index-1"=>true, "test-index-2"=>false}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Terri Chu

Merge request reports