You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by am...@apache.org on 2018/06/12 05:33:25 UTC
asterixdb git commit: [NO ISSUE] Improve Span
Repository: asterixdb
Updated Branches:
refs/heads/master d8ed19620 -> 99e4d2644
[NO ISSUE] Improve Span
Change-Id: I4378332af6b18720f5abc60259bb9af81f22219b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2694
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mb...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/99e4d264
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/99e4d264
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/99e4d264
Branch: refs/heads/master
Commit: 99e4d26441ad512a087194fd723edddf646dfee0
Parents: d8ed196
Author: Abdullah Alamoudi <ba...@gmail.com>
Authored: Sun Jun 10 04:39:17 2018 -0700
Committer: abdullah alamoudi <ba...@gmail.com>
Committed: Mon Jun 11 22:32:38 2018 -0700
----------------------------------------------------------------------
asterixdb/asterix-active/pom.xml | 4 ++
.../apache/asterix/active/CountRetryPolicy.java | 39 ---------------
.../asterix/active/CountRetryPolicyFactory.java | 3 ++
.../org/apache/asterix/active/IRetryPolicy.java | 29 -----------
.../asterix/active/IRetryPolicyFactory.java | 2 +
.../asterix/active/InfiniteRetryPolicy.java | 2 +
.../active/InfiniteRetryPolicyFactory.java | 2 +
.../asterix/active/NoRetryPolicyFactory.java | 6 ++-
.../apache/asterix/app/active/RecoveryTask.java | 2 +-
.../org/apache/hyracks/api/util/InvokeUtil.java | 32 +++++++++++-
.../apache/hyracks/util/ComputingAction.java | 24 +++++++++
.../apache/hyracks/util/CountRetryPolicy.java | 39 +++++++++++++++
.../java/org/apache/hyracks/util/IDelay.java | 26 ++++++++++
.../org/apache/hyracks/util/IRetryPolicy.java | 29 +++++++++++
.../org/apache/hyracks/util/NoRetryPolicy.java | 32 ++++++++++++
.../main/java/org/apache/hyracks/util/Span.java | 51 +++++++++++++++++++-
16 files changed, 248 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/pom.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/pom.xml b/asterixdb/asterix-active/pom.xml
index a6f6a38..922a0e8 100644
--- a/asterixdb/asterix-active/pom.xml
+++ b/asterixdb/asterix-active/pom.xml
@@ -35,6 +35,10 @@
</dependency>
<dependency>
<groupId>org.apache.hyracks</groupId>
+ <artifactId>hyracks-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hyracks</groupId>
<artifactId>hyracks-api</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicy.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicy.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicy.java
deleted file mode 100644
index b964430..0000000
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicy.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.active;
-
-public class CountRetryPolicy implements IRetryPolicy {
-
- private final int count;
- private int attempted = 0;
-
- public CountRetryPolicy(int count) {
- this.count = count;
- }
-
- @Override
- public boolean retry(Throwable failure) {
- if (attempted < count) {
- attempted++;
- return true;
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicyFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicyFactory.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicyFactory.java
index 5e26ae4..477bb5a 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicyFactory.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/CountRetryPolicyFactory.java
@@ -18,6 +18,9 @@
*/
package org.apache.asterix.active;
+import org.apache.hyracks.util.CountRetryPolicy;
+import org.apache.hyracks.util.IRetryPolicy;
+
public class CountRetryPolicyFactory implements IRetryPolicyFactory {
private final int count;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicy.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicy.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicy.java
deleted file mode 100644
index 1daf07e..0000000
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicy.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.active;
-
-@FunctionalInterface
-public interface IRetryPolicy {
- /**
- * @param failure
- * the cause of the active entity failure
- * @return true if one more attempt should be done
- */
- boolean retry(Throwable failure);
-}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicyFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicyFactory.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicyFactory.java
index a946337..82b1d5e 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicyFactory.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/IRetryPolicyFactory.java
@@ -18,6 +18,8 @@
*/
package org.apache.asterix.active;
+import org.apache.hyracks.util.IRetryPolicy;
+
@FunctionalInterface
public interface IRetryPolicyFactory {
/**
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicy.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicy.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicy.java
index fde67e6..6f43c64 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicy.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicy.java
@@ -18,6 +18,8 @@
*/
package org.apache.asterix.active;
+import org.apache.hyracks.util.IRetryPolicy;
+
public class InfiniteRetryPolicy implements IRetryPolicy {
private final IActiveEntityEventsListener listener;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicyFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicyFactory.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicyFactory.java
index b31d245..d33e1da 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicyFactory.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/InfiniteRetryPolicyFactory.java
@@ -18,6 +18,8 @@
*/
package org.apache.asterix.active;
+import org.apache.hyracks.util.IRetryPolicy;
+
public class InfiniteRetryPolicyFactory implements IRetryPolicyFactory {
@Override
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/NoRetryPolicyFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/NoRetryPolicyFactory.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/NoRetryPolicyFactory.java
index a48283a..b8af32b 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/NoRetryPolicyFactory.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/NoRetryPolicyFactory.java
@@ -18,15 +18,17 @@
*/
package org.apache.asterix.active;
+import org.apache.hyracks.util.IRetryPolicy;
+import org.apache.hyracks.util.NoRetryPolicy;
+
public class NoRetryPolicyFactory implements IRetryPolicyFactory {
public static final NoRetryPolicyFactory INSTANCE = new NoRetryPolicyFactory();
- private static final IRetryPolicy policy = failure -> false;
private NoRetryPolicyFactory() {
}
@Override
public IRetryPolicy create(IActiveEntityEventsListener listener) {
- return policy;
+ return NoRetryPolicy.INSTANCE;
}
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/RecoveryTask.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/RecoveryTask.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/RecoveryTask.java
index 1f72856..3024dc6 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/RecoveryTask.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/RecoveryTask.java
@@ -21,7 +21,6 @@ package org.apache.asterix.app.active;
import java.util.concurrent.Callable;
import org.apache.asterix.active.ActivityState;
-import org.apache.asterix.active.IRetryPolicy;
import org.apache.asterix.active.IRetryPolicyFactory;
import org.apache.asterix.active.NoRetryPolicyFactory;
import org.apache.asterix.common.api.IClusterManagementWork.ClusterState;
@@ -34,6 +33,7 @@ import org.apache.asterix.metadata.utils.DatasetUtil;
import org.apache.asterix.metadata.utils.MetadataLockUtil;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.util.IRetryPolicy;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java
index b2dd680..9413d1b 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java
@@ -26,8 +26,12 @@ import java.util.concurrent.TimeoutException;
import java.util.function.BooleanSupplier;
import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.util.ComputingAction;
+import org.apache.hyracks.util.IDelay;
import org.apache.hyracks.util.IOInterruptibleAction;
+import org.apache.hyracks.util.IRetryPolicy;
import org.apache.hyracks.util.InterruptibleAction;
+import org.apache.hyracks.util.Span;
import org.apache.hyracks.util.ThrowingAction;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
@@ -217,7 +221,7 @@ public class InvokeUtil {
}
/**
- * Runs the supplied action, after suspending any pending interruption. An error will be logged if
+ * Runs the supplied action, after suspending any pending interruption. An error will be logged if
* the action is itself interrupted.
*/
public static void runUninterruptible(ThrowingAction action) throws Exception {
@@ -251,4 +255,30 @@ public class InvokeUtil {
}
}
}
+
+ public static <T> T retryUntilSuccessOrExhausted(Span span, ComputingAction<T> action, IRetryPolicy policy,
+ IDelay delay) throws HyracksDataException {
+ Throwable failure;
+ int attempt = 0;
+ do {
+ attempt++;
+ try {
+ return action.compute();
+ } catch (Throwable th) {
+ failure = th;
+ if (!policy.retry(th)) {
+ break;
+ }
+ try {
+ LOGGER.log(Level.WARN, "Failure executing action {} for the {} time", action, attempt, failure);
+ span.sleep(delay.calculate(attempt), TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw HyracksDataException.create(e);
+ }
+ }
+ } while (!span.elapsed());
+ LOGGER.log(Level.WARN, "Final Failure executing action {} after {} attempts", action, attempt, failure);
+ throw HyracksDataException.create(failure);
+ }
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ComputingAction.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ComputingAction.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ComputingAction.java
new file mode 100644
index 0000000..147e871
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ComputingAction.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+public interface ComputingAction<T> {
+ @SuppressWarnings("squid:S00112")
+ T compute() throws Throwable;
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CountRetryPolicy.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CountRetryPolicy.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CountRetryPolicy.java
new file mode 100644
index 0000000..d2023e1
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CountRetryPolicy.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+public class CountRetryPolicy implements IRetryPolicy {
+
+ private final int count;
+ private int attempted = 0;
+
+ public CountRetryPolicy(int count) {
+ this.count = count;
+ }
+
+ @Override
+ public boolean retry(Throwable failure) {
+ if (attempted < count) {
+ attempted++;
+ return true;
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IDelay.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IDelay.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IDelay.java
new file mode 100644
index 0000000..b266f01
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IDelay.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+@FunctionalInterface
+public interface IDelay {
+
+ long calculate(long attempt);
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IRetryPolicy.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IRetryPolicy.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IRetryPolicy.java
new file mode 100644
index 0000000..29469d5
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IRetryPolicy.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+@FunctionalInterface
+public interface IRetryPolicy {
+ /**
+ * @param failure
+ * the cause of the failure
+ * @return true if one more attempt should be done
+ */
+ boolean retry(Throwable failure);
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/NoRetryPolicy.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/NoRetryPolicy.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/NoRetryPolicy.java
new file mode 100644
index 0000000..3040fb1
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/NoRetryPolicy.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+public class NoRetryPolicy implements IRetryPolicy {
+ public static final NoRetryPolicy INSTANCE = new NoRetryPolicy();
+
+ private NoRetryPolicy() {
+ }
+
+ @Override
+ public boolean retry(Throwable failure) {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/99e4d264/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
index d8d6bb1..e75a961 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
@@ -41,14 +41,27 @@ public class Span {
return unit.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
}
+ /**
+ * Sleep for the minimum of the duration or the remaining of this span
+ *
+ * @param sleep
+ * the amount to sleep
+ * @param unit
+ * the unit of the amount
+ * @throws InterruptedException
+ */
public void sleep(long sleep, TimeUnit unit) throws InterruptedException {
- TimeUnit.NANOSECONDS.sleep(Math.min(elapsed(TimeUnit.NANOSECONDS), unit.toNanos(sleep)));
+ TimeUnit.NANOSECONDS.sleep(Math.min(remaining(TimeUnit.NANOSECONDS), unit.toNanos(sleep)));
}
public long remaining(TimeUnit unit) {
return unit.convert(Long.max(spanNanos - elapsed(TimeUnit.NANOSECONDS), 0L), TimeUnit.NANOSECONDS);
}
+ public void wait(Object monitor) throws InterruptedException {
+ TimeUnit.NANOSECONDS.timedWait(monitor, remaining(TimeUnit.NANOSECONDS));
+ }
+
public void loopUntilExhausted(ThrowingAction action) throws Exception {
loopUntilExhausted(action, 0, TimeUnit.NANOSECONDS);
}
@@ -59,7 +72,41 @@ public class Span {
if (elapsed(delayUnit) < delay) {
break;
}
- delayUnit.sleep(delay);
+ sleep(delay, delayUnit);
+ }
+ }
+
+ @Override
+ public String toString() {
+ long nanos = spanNanos % 1000;
+ long micros = TimeUnit.MICROSECONDS.convert(spanNanos, TimeUnit.NANOSECONDS) % 1000;
+ long millis = TimeUnit.MILLISECONDS.convert(spanNanos, TimeUnit.NANOSECONDS) % 1000;
+ long seconds = TimeUnit.SECONDS.convert(spanNanos, TimeUnit.NANOSECONDS) % 60;
+ long minutes = TimeUnit.MINUTES.convert(spanNanos, TimeUnit.NANOSECONDS) % 60;
+ long hours = TimeUnit.HOURS.convert(spanNanos, TimeUnit.NANOSECONDS) % 24;
+ long days = TimeUnit.DAYS.convert(spanNanos, TimeUnit.NANOSECONDS);
+ StringBuilder builder = new StringBuilder();
+ if (days > 0) {
+ builder.append(days).append("d");
+ }
+ if (hours > 0) {
+ builder.append(hours).append("hr");
+ }
+ if (minutes > 0) {
+ builder.append(minutes).append("m");
+ }
+ if (seconds > 0) {
+ builder.append(seconds).append("s");
+ }
+ if (millis > 0) {
+ builder.append(millis).append("ms");
+ }
+ if (micros > 0) {
+ builder.append(micros).append("us");
+ }
+ if (nanos > 0 || builder.length() == 0) {
+ builder.append(nanos).append("ns");
}
+ return builder.toString();
}
}