You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by va...@apache.org on 2017/06/14 00:56:57 UTC
[19/52] [abbrv] sentry git commit: SENTRY-1765: CounterWait.update
throw exception when input is old (ALex Kolbasov, reviewed by Na Li,
Kalyan Kalvagadda and Vamsee Yarlagadda)
SENTRY-1765: CounterWait.update throw exception when input is old (ALex Kolbasov, reviewed by Na Li, Kalyan Kalvagadda and Vamsee Yarlagadda)
Change-Id: Ie16f0461f79e73a7ba48762bbf48f134bde1a0d2
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/22613
Tested-by: Jenkins User
Reviewed-by: Alexander Kolbasov <ak...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/14e9ac72
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/14e9ac72
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/14e9ac72
Branch: refs/for/cdh5-1.5.1_ha
Commit: 14e9ac72bb333c4af66779ac41ef22f9c9d8ebb5
Parents: 18feedf
Author: Alexander Kolbasov <ak...@cloudera.com>
Authored: Fri May 12 15:43:25 2017 -0700
Committer: Alexander Kolbasov <ak...@cloudera.com>
Committed: Fri May 12 17:07:25 2017 -0700
----------------------------------------------------------------------
.../sentry/service/thrift/CounterWait.java | 28 +++++++++++++-------
1 file changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/14e9ac72/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/CounterWait.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/CounterWait.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/CounterWait.java
index 2b4ee84..9c9bb69 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/CounterWait.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/CounterWait.java
@@ -19,6 +19,8 @@
package org.apache.sentry.service.thrift;
import org.apache.http.annotation.ThreadSafe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.Semaphore;
@@ -70,6 +72,8 @@ public final class CounterWait {
// NOTE: We use PriorityBlockingQueue for waiters because it is thread-safe,
// we are not using its blocking queue semantics.
+ private static final Logger LOGGER = LoggerFactory.getLogger(CounterWait.class);
+
/** Counter value. May only increase. */
private final AtomicLong currentId = new AtomicLong(0);
@@ -87,20 +91,26 @@ public final class CounterWait {
* value or any value below it.
* <p>
* The counter value should only increase.
- * An attempt to decrease the value is raising
- * {@link IllegalArgumentException}.
- * The usual case is to have a single updater thread, but we enforce this
- * by synchronizing the call.
+ * An attempt to decrease the value is ignored.
*
* @param newValue the new counter value
*/
public synchronized void update(long newValue) {
- // Make sure the counter is never decremented
- if (newValue < currentId.get()) {
- throw new IllegalArgumentException("new counter value " +
- String.valueOf(newValue) +
- "is smaller then the previous one " + currentId);
+ // update() is synchronized so the value can't change.
+ long oldValue = currentId.get();
+
+ // Avoid doing extra work if not needed
+ if (oldValue == newValue) {
+ return; // no-op
}
+
+ // Make sure the counter is never decremented.
+ if (newValue < oldValue) {
+ LOGGER.error("new counter value {} is smaller then the previous one {}",
+ newValue, oldValue);
+ return; // no-op
+ }
+
currentId.set(newValue);
// Wake up any threads waiting for a counter to reach this value.