Skip to content

Commit 27ca06b

Browse files
nicer way of resolve snapshot name
1 parent 26f1737 commit 27ca06b

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,20 @@ protected void masterOperation(final CreateSnapshotRequest request, ClusterState
7575
final ActionListener<CreateSnapshotResponse> listener) {
7676
snapshotsService.createSnapshot(request, new SnapshotsService.CreateSnapshotListener() {
7777
@Override
78-
public void onResponse() {
78+
public void onResponse(Snapshot snapshotCreated) {
7979
if (request.waitForCompletion()) {
80-
final String snapshotName = indexNameExpressionResolver.resolveDateMathExpression(request.snapshot());
8180
snapshotsService.addListener(new SnapshotsService.SnapshotCompletionListener() {
8281
@Override
8382
public void onSnapshotCompletion(Snapshot snapshot, SnapshotInfo snapshotInfo) {
84-
if (snapshot.getRepository().equals(request.repository()) &&
85-
snapshot.getSnapshotId().getName().equals(snapshotName)) {
83+
if (snapshotCreated.equals(snapshot)) {
8684
listener.onResponse(new CreateSnapshotResponse(snapshotInfo));
8785
snapshotsService.removeListener(this);
8886
}
8987
}
9088

9189
@Override
9290
public void onSnapshotFailure(Snapshot snapshot, Exception e) {
93-
if (snapshot.getRepository().equals(request.repository()) &&
94-
snapshot.getSnapshotId().getName().equals(snapshotName)) {
91+
if (snapshotCreated.equals(snapshot)) {
9592
listener.onFailure(e);
9693
snapshotsService.removeListener(this);
9794
}

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected void doRun() {
377377
logger.info("snapshot [{}] started", snapshot.snapshot());
378378
if (snapshot.indices().isEmpty()) {
379379
// No indices in this snapshot - we are done
380-
userCreateSnapshotListener.onResponse();
380+
userCreateSnapshotListener.onResponse(snapshot.snapshot());
381381
endSnapshot(snapshot);
382382
return;
383383
}
@@ -465,7 +465,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
465465
// for processing. If client wants to wait for the snapshot completion, it can register snapshot
466466
// completion listener in this method. For the snapshot completion to work properly, the snapshot
467467
// should still exist when listener is registered.
468-
userCreateSnapshotListener.onResponse();
468+
userCreateSnapshotListener.onResponse(snapshot.snapshot());
469469

470470
// Now that snapshot completion listener is registered we can end the snapshot if needed
471471
// We should end snapshot only if 1) we didn't accept it for processing (which happens when there
@@ -1544,8 +1544,10 @@ public interface CreateSnapshotListener {
15441544

15451545
/**
15461546
* Called when snapshot has successfully started
1547+
*
1548+
* @param snapshot snapshot that was created
15471549
*/
1548-
void onResponse();
1550+
void onResponse(Snapshot snapshot);
15491551

15501552
/**
15511553
* Called if a snapshot operation couldn't start

0 commit comments

Comments
 (0)