Open andreidan opened 3 years ago
Pinging @elastic/es-docs (Team:Docs)
Pinging @elastic/es-distributed (Team:Distributed)
Pinging @elastic/es-core-features (Team:Core/Features)
ILM policies and index templates need to be manually applied to follower clusters. This would be done anyway if configuring the follower for HA, though it would be helpful to explicitly mention it in the docs.
I've written a step-by-step tutorial, is it ok for @debadair to also look into converting this into a doc page?
CCR as it is designed today does not replicate searchable snapshot indices. Fortunately, the cold/frozen indices are expected to be read-only, so the following procedure outlines what is the solution to have data ageing through ILM policies and still be “replicated” across clusters.
The key points are:
index.lifecycle.indexing_complete
set to true
(can be activated by rollover
action)unfollow
the leader, then it will convert the index into a searchable snapshot and move into the cold/frozen phase.The end results are:
Ensure both of your clusters have the required data tiers and snapshot repository set up.
Data streams with rename follower patterns, as of writing (8.0.1), does not support CCR ^1. The following example was written with timeseries data without data streams using rollover alias based on https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index-lifecycle-management.html#manage-time-series-data-without-data-streams
On the leader cluster, create an ILM policy containing rollover in the hot phase and searchable snapshot in the frozen phase.
The following policy means 1 min after index creation, the index (with the -000001
appendix) will be rollover into a new index with incremental appendix (ie -000002
). They will both remain on the hot tier until after 5 mins from index creation time, it will move data into snapshot repository, and mount a partial index partial-<my-index>-000001
on the frozen node.
### On the leader cluster
PUT _ilm/policy/timeseries_policy
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover": {
"max_age": "1m"
}
}
},
"frozen": {
"min_age": "5m",
"actions": {
"searchable_snapshot" : {
"snapshot_repository" : "my-leader-snapshots-repo"
}
}
}
}
}
}
### Execute on both the leader and follower cluster
PUT _cluster/settings
{
"transient": {
"indices.lifecycle.poll_interval": "10s"
}
}
On the leader cluster, create an index template to apply the lifecycle policy. This is taken from https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index-lifecycle-management.html
### On the leader cluster
PUT _index_template/timeseries_template
{
"index_patterns": ["timeseries-*"],
"template": {
"settings": {
"index.lifecycle.name": "timeseries_policy",
"index.lifecycle.rollover_alias": "timeseries"
}
}
}
To get things started, you need to bootstrap an initial index and designate it as the write index for the rollover alias specified in your index template. The name of this index must match the template’s index pattern and end with a number. On rollover, this value is incremented to generate a name for the new index.
For example, the following request creates an index called timeseries-000001
and makes it the write index for the timeseries alias.
### On the leader cluster
PUT timeseries-000001
{
"aliases": {
"timeseries": {
"is_write_index": true
}
}
}
On the follower cluster, we need to set up ILM policy similar (but not identical) to step 2. Note index age and ILM policies are independent on both clusters. The additional action in the follower cluster is the unfollow
action in the frozen
phase.
### On the follower cluster
PUT _ilm/policy/timeseries_policy
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover": {
"max_age": "1m"
}
}
},
"frozen": {
"min_age": "5m",
"actions": {
"unfollow" : {},
"searchable_snapshot" : {
"snapshot_repository" : "my-follower-snapshots-repo"
}
}
}
}
}
}
On the follower cluster, we need to set up an index template similar to step 3.
### On the follower cluster
PUT _index_template/timeseries_template
{
"index_patterns": ["timeseries"],
"template": {
"settings": {
"index.lifecycle.name": "timeseries_policy"
}
}
}
On the follower cluster, set up a remote cluster pointing to the leader cluster. More details can be found in https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-getting-started-tutorial.html
### On the follower cluster
PUT _cluster/settings
{
"persistent": {
"cluster" : {
"remote" : {
"my_leader" : {
"seeds" : [
"127.0.0.1:9300"
]
}
}
}
}
}
Configure the following settings to replicate timeseries data from the leader cluster to the follower cluster. It’s optional to have the -copy
appendix in the follow_index_pattern
.
### On the follower cluster
PUT /_ccr/auto_follow/timeseries_pattern
{
"remote_cluster" : "my_leader",
"leader_index_patterns" :
[
"timeseries*"
],
"follow_index_pattern" : "{{leader_index}}-copy"
}
Now we are ready to ingest data on the leader cluster. This can be done via Beats or Logstash or any other clients you have. Make sure to point to the alias timeseries
for the data ingestion.
POST timeseries/_doc
{
"message": "logged the request",
"@timestamp": "1591890611"
}
GET timeseries/_search
GET timeseries/_search
...Continue putting data into timeseries…
GET timeseries/_search
→ Observe the name of the _index has now changedGET timeseries/_search
→ Observe the name of the _index has now changed...Continue putting data into timeseries…
timeseries-000001
index will become partial-timeseries-000001
(a searchable snapshot index) on the leader cluster.
GET _cat/shards
to observe this index now lives on the frozen tiertimeseries-000001-copy
index will become partial-timeseries-000001-copy
(a searchable snapshot index) on the follower cluster.
GET _cat/shards
to observe this index now lives on the frozen tierGET partial-timeseries-000001/_count
on the leader clusterGET partial-timeseries-000001-copy/_count
on the follower cluster@andreidan @Leaf-Lin
The unfollow is injected on the leader side, but if you want to use the delete phase you still have to add this setting to the follower.
https://support.elastic.dev/knowledge/view/d1d8aae7
Otherwise you will see this on the leader side:
The follower can do ILM deletes without problems, but if you deleted the follower indices then this auto follow error should go away I think.
Pinging @elastic/es-data-management (Team:Data Management)
When indices in a CCR environment are managed by ILM the follower indices must be converted to regular indices. This is taken care of by the unfollow action and is injected automatically if
rollover
,shrink
or thesearchable_snapshot
action are configured. However, the leader index must have theindex.lifecycle.indexing_complete
setting configured totrue
in order for theunfollow
action to succeed. ILM takes care of managing theindexing_complete
setting as part of therollover
action. Namely, after the index is rolled over the setting for the managed index is configured to true (as the next generation index is the write index). This subtlety is not explicitly documented and I think we should document it in the ILM docs. Also, the CCR docs should define a full guide on managing indices with ILM.