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

Improve snapshot creation and deletion performance on repositories with large number of snapshots #8969

Merged
merged 1 commit into from Jun 2, 2015

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Dec 15, 2014

Fixes #8958

@imotov imotov added :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >bug v2.0.0-beta1 review labels Dec 15, 2014
@imotov imotov force-pushed the issue-8958-snapshot-scaling branch from 39a6e57 to ee3c3d1 Compare January 23, 2015 17:10
try (InputStream stream = blobContainer.openInput(SNAPSHOT_INDEX_PREFIX + latest)) {
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(stream)) {
parser.nextToken();
return new Tuple<>(BlobStoreIndexShardSnapshots.fromXContent(parser), latest);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use the method readSnapshot(stream) again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot reuse it here because this method reads multiple snapshots. But I can definitely add a new method readSnapshots() similiar to readSnapshot() and use it here.

@tlrx
Copy link
Member

tlrx commented Jan 26, 2015

LGTM, left some comments.

@imotov
Copy link
Contributor Author

imotov commented Jan 26, 2015

@tlrx Thanks! I have updated the PR with your suggestions.

@tlrx
Copy link
Member

tlrx commented Jan 29, 2015

LGTM, just a typo in documentation.

@tlrx tlrx removed the review label Jan 29, 2015
@tlrx tlrx removed their assignment Jan 29, 2015
@@ -250,13 +266,37 @@ public static void writeSnapshot(BlobStoreIndexShardSnapshot snapshot, OutputStr
* @throws IOException if an IOException occurs
* */
public static BlobStoreIndexShardSnapshot readSnapshot(InputStream stream) throws IOException {
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(stream)) {
byte[] data = ByteStreams.toByteArray(stream);
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to close the stream after reading it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's responsibility of whoever opened it (caller).

if (currentGen > generation) {
generation = currentGen;
}
} catch (NumberFormatException e) {
logger.warn("file [{}] does not conform to the '__' schema");
logger.warn("file [{}] does not conform to the '" + DATA_BLOB_PREFIX + "' schema");
Copy link
Member

Choose a reason for hiding this comment

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

Can use the '{}' syntax here for DATA_BLOB_PREFIX

@dakrone
Copy link
Member

dakrone commented May 4, 2015

@imotov left some more comments on this

}


List<SnapshotFiles> snapshots = Lists.newArrayList();
Copy link
Member

Choose a reason for hiding this comment

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

This is fallback right? For older repos that don't have the new snapshot index file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Added a comment.

@dakrone
Copy link
Member

dakrone commented Jun 2, 2015

@imotov left some more minor comments, mostly around documentation, exceptions, and renaming a var

@imotov
Copy link
Contributor Author

imotov commented Jun 2, 2015

@dakrone thanks! pushed an update.

@dakrone
Copy link
Member

dakrone commented Jun 2, 2015

Thanks @imotov, LGTM!

…th large number of snapshots

Each shard repository consists of snapshot file for each snapshot - this file contains a map between original physical file that is snapshotted and its representation in repository. This data includes original filename, checksum and length. When a new snapshot is created, elasticsearch needs to read all these snapshot files to figure which file are already present in the repository and which files still have to be copied there. This change adds a new index file that contains all this information combined into a single file. So, if a repository has 1000 snapshots with 1000 shards elasticsearch will only need to read 1000 blobs (one per shard) instead of 1,000,000 to delete a snapshot. This change should also improve snapshot creation speed on repositories with large number of snapshot and high latency.

Fixes elastic#8958
@imotov imotov force-pushed the issue-8958-snapshot-scaling branch from 0e8834e to 59d9f7e Compare June 2, 2015 22:39
@imotov imotov merged commit 59d9f7e into elastic:master Jun 2, 2015
@imotov imotov removed the review label Jun 2, 2015
@clintongormley clintongormley changed the title Improve snapshot creation and deletion performance on repositories with ... Improve snapshot creation and deletion performance on repositories with large number of snapshots Jun 3, 2015
@niemyjski
Copy link
Contributor

Will this be back ported to 1.x?

@imotov
Copy link
Contributor Author

imotov commented Mar 21, 2016

@niemyjski this was a significant change that required changing the snapshot file format and it was too big of a change for a patch level release. So we didn't port to 1.x and there are no current plans to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snapshot deletion and creation slow down as number of snapshots in repository grows
5 participants