Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial searchable snapshot support for a frozen tier #68509

Merged
merged 34 commits into from
Feb 5, 2021
Merged

Conversation

ywelsch
Copy link
Contributor

@ywelsch ywelsch commented Feb 4, 2021

A frozen tier is backed by an external object store (like S3) and caches only a small portion of data on local disks. In this way, users can reduce hardware costs substantially for infrequently accessed data. For the frozen tier we only pull in the parts of the files that are actually needed to run a given search. Further, we don't require the node to have enough space to host all the files. We therefore have a cache that manages which file parts are available, and which ones not. This node-level shared cache is bounded in size (typically in relation to the disk size), and will evict items based on a LFU policy, as we expect some parts of the Lucene files to be used more frequently than other parts. The level of granularity for evictions is at the level of regions of a file, and does not require evicting full files. The on-disk representation that was chosen for the cold tier is not a good fit here, as it won't allow evicting parts of a file. Instead we are using fixed-size pre-allocated files and have implemented our own memory management logic to map regions of the shard's original Lucene files onto regions in these node-level shared files that are representing the on-disk cache.

This PR adds the core functionality to searchable snapshots to power such a frozen tier:

  • It adds the node-level shared cache that evicts file regions based on a LFU policy
  • It adds the machinery to dynamically download file regions into this cache and serve their contents when searches execute.
  • It extends the mount API with a new parameter, storage, which selects the kind of local storage used to accelerate
    searches of the mounted index. If set to full_copy (default, used for cold tier), each node holding a shard of the searchable snapshot index makes a full copy of the shard to its local storage. If set to shared_cache, the shard uses the newly introduced shared cache, only holding a partial copy of the index on disk (used for frozen tier).

Co-authored-by: Tanguy Leroux <...>
Co-authored-by: Armin Braun <...>
Co-authored-by: David Turner <...>

ywelsch and others added 29 commits January 25, 2021 11:08
This adds all the necessary infrastructure to use the reusable, single-file cache in practice:

* Create cache file in a data directory instead of a temp directory
* Fully pre-allocate it (the existing solution would at least on Linux still do a sparse allocation)
* Manage file channel resource by ref counting
* Add minimal abstraction in place of exposing `FileChannel` to allow for adjusting the concrete paging approach under the hood in a follow-up
This commit introduces a new flag, `?partial_local_copy`, indicating
that the local copy of a searchable snapshot should be partial rather
than complete, enabling the frozen tier functionality.
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

My overnight test run encountered no failures at all.

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I only managed to have ~100 runs, all successful so far. I wonder if we can enable partial caching on some more tests, I'll look at it but this is not a reason to block this PR.

@ywelsch ywelsch merged commit 50f4a0b into master Feb 5, 2021
@ywelsch ywelsch deleted the frozen-proto branch February 5, 2021 08:15
ywelsch added a commit that referenced this pull request Feb 5, 2021
A frozen tier is backed by an external object store (like S3) and caches only a
small portion of data on local disks. In this way, users can reduce hardware
costs substantially for infrequently accessed data. For the frozen tier we only
pull in the parts of the files that are actually needed to run a given search.
Further, we don't require the node to have enough space to host all the files.
We therefore have a cache that manages which file parts are available, and which
ones not. This node-level shared cache is bounded in size (typically in relation
to the disk size), and will evict items based on a LFU policy, as we expect some
parts of the Lucene files to be used more frequently than other parts. The level
of granularity for evictions is at the level of regions of a file, and does not
require evicting full files. The on-disk representation that was chosen for the
cold tier is not a good fit here, as it won't allow evicting parts of a file.
Instead we are using fixed-size pre-allocated files and have implemented our own
memory management logic to map regions of the shard's original Lucene files onto
regions in these node-level shared files that are representing the on-disk
cache.

This PR adds the core functionality to searchable snapshots to power such a
frozen tier:
- It adds the node-level shared cache that evicts file regions based on a LFU
  policy
- It adds the machinery to dynamically download file regions into this cache and
  serve their contents when searches execute.
- It extends the mount API with a new parameter, `storage`, which selects the
  kind of local storage used to accelerate searches of the mounted index. If set
  to `full_copy` (default, used for cold tier), each node holding a shard of the
  searchable snapshot index makes a full copy of the shard to its local storage.
  If set to `shared_cache`, the shard uses the newly introduced shared cache,
  only holding a partial copy of the index on disk (used for frozen tier).

Co-authored-by: Tanguy Leroux <tlrx.dev@gmail.com>
Co-authored-by: Armin Braun <me@obrown.io>
Co-authored-by: David Turner <david.turner@elastic.co>
ywelsch added a commit that referenced this pull request Feb 5, 2021
dakrone added a commit to dakrone/elasticsearch that referenced this pull request Feb 8, 2021
This commit adds support for the recently introduced partial searchable snapshot (elastic#68509) to ILM.

Searchable snapshot ILM actions may now be specified with a `storage` option, specifying either
`full_copy` or `shared_cache` (similar to the "mount" API) to mount either a full or partial
searchable snapshot:

```json
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "cold": {
        "actions": {
          "searchable_snapshot" : {
            "snapshot_repository" : "backing_repo",
            "storage": "shared_cache"
          }
        }
      }
    }
  }
}
```

Internally, If more than one searchable snapshot action is specified (for example, a full searchable
snapshot in the "cold" phase and a partial searchable snapshot in the "frozen" phase) ILM will
re-use the existing snapshot when doing the second mount since a second snapshot is not required.

Currently this is allowed for actions that use the same repository, however, multiple
`searchable_snapshot` actions for the same index that use different repositories is not allowed (the
ERROR state is entered). We plan to allow this in the future in subsequent work.

If the `storage` option is not specified in the `searchable_snapshot` action, the mount type
defaults to "shared_cache" in the frozen phase and "full_copy" in all other phases.

Relates to elastic#68605
elasticmachine pushed a commit to costin/elasticsearch that referenced this pull request Feb 9, 2021
This commit adds support for the recently introduced partial searchable snapshot (elastic#68509) to ILM.

Searchable snapshot ILM actions may now be specified with a `storage` option, specifying either
`full_copy` or `shared_cache` (similar to the "mount" API) to mount either a full or partial
searchable snapshot:

```json
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "cold": {
        "actions": {
          "searchable_snapshot" : {
            "snapshot_repository" : "backing_repo",
            "storage": "shared_cache"
          }
        }
      }
    }
  }
}
```

Internally, If more than one searchable snapshot action is specified (for example, a full searchable
snapshot in the "cold" phase and a partial searchable snapshot in the "frozen" phase) ILM will
re-use the existing snapshot when doing the second mount since a second snapshot is not required.

Currently this is allowed for actions that use the same repository, however, multiple
`searchable_snapshot` actions for the same index that use different repositories is not allowed (the
ERROR state is entered). We plan to allow this in the future in subsequent work.

If the `storage` option is not specified in the `searchable_snapshot` action, the mount type
defaults to "shared_cache" in the frozen phase and "full_copy" in all other phases.

Relates to elastic#68605
dakrone added a commit to dakrone/elasticsearch that referenced this pull request Feb 9, 2021
This commit adds support for the recently introduced partial searchable snapshot (elastic#68509) to ILM.

Searchable snapshot ILM actions may now be specified with a `storage` option, specifying either
`full_copy` or `shared_cache` (similar to the "mount" API) to mount either a full or partial
searchable snapshot:

```json
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "cold": {
        "actions": {
          "searchable_snapshot" : {
            "snapshot_repository" : "backing_repo",
            "storage": "shared_cache"
          }
        }
      }
    }
  }
}
```

Internally, If more than one searchable snapshot action is specified (for example, a full searchable
snapshot in the "cold" phase and a partial searchable snapshot in the "frozen" phase) ILM will
re-use the existing snapshot when doing the second mount since a second snapshot is not required.

Currently this is allowed for actions that use the same repository, however, multiple
`searchable_snapshot` actions for the same index that use different repositories is not allowed (the
ERROR state is entered). We plan to allow this in the future in subsequent work.

If the `storage` option is not specified in the `searchable_snapshot` action, the mount type
defaults to "shared_cache" in the frozen phase and "full_copy" in all other phases.

Relates to elastic#68605
dakrone added a commit that referenced this pull request Feb 9, 2021
…68762)

This commit adds support for the recently introduced partial searchable snapshot (#68509) to ILM.

Searchable snapshot ILM actions may now be specified with a `storage` option, specifying either
`full_copy` or `shared_cache` (similar to the "mount" API) to mount either a full or partial
searchable snapshot:

`json
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "cold": {
        "actions": {
          "searchable_snapshot" : {
            "snapshot_repository" : "backing_repo",
            "storage": "shared_cache"
          }
        }
      }
    }
  }
}
`

Internally, If more than one searchable snapshot action is specified (for example, a full searchable
snapshot in the "cold" phase and a partial searchable snapshot in the "frozen" phase) ILM will
re-use the existing snapshot when doing the second mount since a second snapshot is not required.

Currently this is allowed for actions that use the same repository, however, multiple
`searchable_snapshot` actions for the same index that use different repositories is not allowed (the
ERROR state is entered). We plan to allow this in the future in subsequent work.

If the `storage` option is not specified in the `searchable_snapshot` action, the mount type
defaults to "shared_cache" in the frozen phase and "full_copy" in all other phases.

Relates to #68605
ywelsch added a commit that referenced this pull request Mar 16, 2021
Reenables BWC for the searchable snapshot usage stats test.

Relates #68509
ywelsch added a commit to ywelsch/elasticsearch that referenced this pull request Mar 16, 2021
Reenables BWC for the searchable snapshot usage stats test.

Relates elastic#68509
ywelsch added a commit that referenced this pull request Mar 16, 2021
Reenables BWC for the searchable snapshot usage stats test.

Relates #68509
ywelsch added a commit that referenced this pull request Mar 16, 2021
Reenables BWC for the searchable snapshot usage stats test.

Relates #68509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
das awesome :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >feature release highlight Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants