Watcher: Ensure non duplicate Wid ids (elastic/elasticsearch#4423)

Removing the WatchLockService could result in duplication of wids, because of a wrong
call to replace underscores with dashes. As UUIDs.createBase64UUID() can contain underscores
but they are kind of reserved in the Wid class due to handling of watch ids, this just uses
the toString() representation of a random UUID.

Closes elastic/elasticsearch#4422

Original commit: elastic/x-pack-elasticsearch@dceb01ae5e
This commit is contained in:
Alexander Reelsen 2016-12-20 14:02:00 +01:00 committed by GitHub
parent b9a38d9b97
commit b994f16f4a
1 changed files with 14 additions and 3 deletions

View File

@ -5,24 +5,35 @@
*/
package org.elasticsearch.xpack.watcher.execution;
import org.elasticsearch.common.UUIDs;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import java.util.UUID;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
/**
* A representation class of a watch id, its execution time and a random UUID
* This class exists to be able to store several events from the same possible execution time and the same watch
* in the triggered store index or the history store
*
* One 'specialty' of this class is the handling of the underscore in the value. Nothing except the watchId should contain an
* underscore, otherwise this class will not be able to extract the proper watch id, when a a single string is handed over in its ctor
*
* This is also the reason why UUID.randomUUID() is used instead of UUIDs.base64UUID(), as the latter one contains underscores. Also this
* is not dependant on having time based uuids here, as the time is already included in the value
*/
public class Wid {
private static final DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
private final String watchId;
private final String value;
public Wid(String watchId, DateTime executionTime) {
this.watchId = watchId;
this.value = watchId + "_" + UUIDs.base64UUID().replaceAll("_", "-") + "-" + formatter.print(executionTime);
this.value = watchId + "_" + UUID.randomUUID().toString() + "-" + formatter.print(executionTime);
}
public Wid(String value) {