From 846c3da4ab2e94c17c39e636cb2ba10f174ec3e2 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Thu, 19 Dec 2013 13:21:41 -0800 Subject: [PATCH] Empty task intervals, and empty lock intervals, aren't useful. So prevent them from being created, through checks in AbstractFixedIntervalTask and TaskLockbox.tryLock. --- .../indexing/common/task/AbstractFixedIntervalTask.java | 4 +++- .../main/java/io/druid/indexing/overlord/TaskLockbox.java | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractFixedIntervalTask.java b/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractFixedIntervalTask.java index d1d494f5c83..2d6687ed920 100644 --- a/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractFixedIntervalTask.java +++ b/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractFixedIntervalTask.java @@ -21,6 +21,7 @@ package io.druid.indexing.common.task; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; import io.druid.indexing.common.actions.LockTryAcquireAction; import io.druid.indexing.common.actions.TaskActionClient; import org.joda.time.Interval; @@ -58,7 +59,8 @@ public abstract class AbstractFixedIntervalTask extends AbstractTask ) { super(id, groupId, taskResource, dataSource); - this.interval = interval; + this.interval = Preconditions.checkNotNull(interval, "interval"); + Preconditions.checkArgument(interval.toDurationMillis() > 0, "interval empty"); } @Override diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java b/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java index d486f37c0fc..7b3ffb09087 100644 --- a/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java @@ -19,6 +19,7 @@ package io.druid.indexing.overlord; +import com.google.api.client.repackaged.com.google.common.base.Preconditions; import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Optional; @@ -109,6 +110,11 @@ public class TaskLockbox for (final Pair taskAndLock : byVersionOrdering.sortedCopy(storedLocks)) { final Task task = taskAndLock.lhs; final TaskLock savedTaskLock = taskAndLock.rhs; + if (savedTaskLock.getInterval().toDurationMillis() <= 0) { + // "Impossible", but you never know what crazy stuff can be restored from storage. + log.warn("WTF?! Got lock with empty interval for task: %s", task.getId()); + continue; + } uniqueTaskIds.add(task.getId()); final Optional acquiredTaskLock = tryLock( task, @@ -205,6 +211,7 @@ public class TaskLockbox giant.lock(); try { + Preconditions.checkArgument(interval.toDurationMillis() > 0, "interval empty"); final String dataSource = task.getDataSource(); final List foundPosses = findLockPossesForInterval(dataSource, interval); final TaskLockPosse posseToUse;