-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Allow date math for naming newly-created snapshots (#7939) #30479
Conversation
Pinging @elastic/es-distributed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a description to your PR to explain what it does? Also remove the backport_pending label please, it should only be used if you've merged the PR into master but not backported the change (e.g. due to some complication)
@@ -282,7 +282,8 @@ PUT /_snapshot/my_backup/snapshot_2?wait_for_completion=true | |||
// TEST[continued] | |||
|
|||
The list of indices that should be included into the snapshot can be specified using the `indices` parameter that | |||
supports <<multi-index,multi index syntax>>. The snapshot request also supports the | |||
supports <<multi-index,multi index syntax>>. It can be useful to use <<date-math-index-names,date math>> to name the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This links to docs on using date math for index names. This can be confusing. I think you need to clarify here that the same date math expression that is used for indices can be used for snapshot names. I think it would be better to put this info into a separate paragraph, together with an example. I wonder if we need to support date math not only for snapshot creation, but also for other operations.
@@ -176,4 +177,30 @@ public void testSnapshotStatusWithBlocks() { | |||
setClusterReadOnly(false); | |||
} | |||
} | |||
|
|||
public void testSnapshotWithDateMath() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this is exactly testing. There are no assertions that check that the date math functionality has worked in a meaningful way. Also why is this testing blocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it tests that it is possible to create snapshot with name <snapshot-{now/d}>
and it is resolved into smth like snapshot-2018.05.11
using nameExpressionResolver.resolveDateMathExpression(snapshotName)
- I assume that nameExpressionResolver
works.
Agree - it is worth to move test to DedicatedClusterSnapshotRestoreIT
- is that ok ?
move test case to DedicatedClusterSnapshotRestoreIT
extended doc: example is added. referring to indices date math more clearly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few more comments. Can you also adapt the PR title so that it reflects more closely what's implemented here:
Allow date math for naming newly-created snapshots
and make it clear in the description that this only allows date math when creating new snapshots (it does not implement date math when resolving snapshot names, for exampling when asking for the snapshots that currently exist in the repo).
@@ -176,4 +176,6 @@ public void testSnapshotStatusWithBlocks() { | |||
setClusterReadOnly(false); | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you revert this?
|
||
final IndexNameExpressionResolver nameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY); | ||
final String snapshotName = "<snapshot-{now/d}>"; | ||
final String expression = nameExpressionResolver.resolveDateMathExpression(snapshotName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if there is a day rollover between resolving the expression here and taking the snapshot, the test will fail. A fix might be to resolve the expression a second time after the snapshot was taken, and then use both resolved expressions when asking for the snapshot status.
admin.cluster().prepareCreateSnapshot(repo, snapshotName) | ||
.setIncludeGlobalState(true) | ||
.setWaitForCompletion(true) | ||
.execute().actionGet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just .get()
will do. Also no need for setIncludeGlobalState(true)
, that's irrelevant for the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, just copy-n-pasted from another place
@@ -289,6 +289,19 @@ By setting `include_global_state` to false it's possible to prevent the cluster | |||
the snapshot. By default, the entire snapshot will fail if one or more indices participating in the snapshot don't have | |||
all primary shards available. This behaviour can be changed by setting `partial` to `true`. | |||
|
|||
Snapshot could be named according to the date that the snapshot made in a similar way as indices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the following:
Snapshot names can be automatically derived using <<date-math-index-names,date math expressions>>, similarly as when creating new indices. Note that special characters need to be URI encoded. For example, creating a snapshot with the current day in the name, like snapshot-2018.05.11
, can be achieved with the following command:
...
@ywelsch thank you for the feedback - I made relevant amendments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @vladimirdolzhenko - LGTM. I've added version labels to the PR.
final String expression2 = nameExpressionResolver.resolveDateMathExpression(snapshotName); | ||
|
||
SnapshotsStatusResponse response = admin.cluster().prepareSnapshotStatus(repo) | ||
.setSnapshots(Sets.newHashSet(expression1, expression2).toArray(Strings.EMPTY_ARRAY)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a varargs method, so just .setSnapshots(expression1, expression2)
is good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w/o a day rollover it requests two statuses with two identical names - and the result is 2 snapshot statuses - that's why I used set here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
test this please |
…bad-mkay * elastic/6.x: [ML] Wait for ML indices in rolling upgrade tests (elastic#30615) Watcher: Ensure secrets integration tests also run triggered watch (elastic#30478) Move allocation awareness attributes to list setting (elastic#30626) [Docs] Update code snippet in has-child-query.asciidoc (elastic#30510) Allow date math for naming newly-created snapshots (elastic#7939) (elastic#30479) Awaits fix a failing test Switch many QA projects to use new style requests (elastic#30574) QA: System property to override distribution (elastic#30591)
thanks @ywelsch |
Use date math expression (same as used for indices naming) for naming newly-created snapshots