sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ak...@apache.org
Subject sentry git commit: SENTRY-1756: Passive nodes should still follow latest notification ID (Sergio Pena, reviewed by Alex Kolbasov)
Date Thu, 11 May 2017 01:00:47 GMT
Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign d926483b7 -> 6d7677d94


SENTRY-1756: Passive nodes should still follow latest notification ID (Sergio Pena, reviewed
by Alex Kolbasov)


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/6d7677d9
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/6d7677d9
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/6d7677d9

Branch: refs/heads/sentry-ha-redesign
Commit: 6d7677d94f8681d9ffa63ca02ba91334f577b003
Parents: d926483
Author: Alexander Kolbasov <akolb@cloudera.com>
Authored: Wed May 10 18:00:28 2017 -0700
Committer: Alexander Kolbasov <akolb@cloudera.com>
Committed: Wed May 10 18:00:28 2017 -0700

----------------------------------------------------------------------
 .../sentry/service/thrift/HMSFollower.java      | 45 +++++++++++++++++---
 1 file changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/6d7677d9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
index e271ea4..9880c40 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
@@ -203,6 +203,13 @@ public class HMSFollower implements Runnable, AutoCloseable {
 
   @Override
   public void run() {
+    // Wake any clients connected to this service waiting for HMS already processed notifications.
+    try {
+      wakeUpWaitingClientsForSync(getLastProcessedNotificationID());
+    } catch (Exception e) {
+      LOGGER.error("Couldn't wake up HMS waiters because an error attempting to get the latest
notification ID.", e);
+    }
+
     // Only the leader should listen to HMS updates
     if ((leaderMonitor != null) && !leaderMonitor.isLeader()) {
       // Close any outstanding connections to HMS
@@ -210,6 +217,34 @@ public class HMSFollower implements Runnable, AutoCloseable {
       return;
     }
 
+    processHiveMetastoreUpdates();
+  }
+
+  /**
+   * Wakes up HMS waiters waiting for a specific event notification.
+   *
+   * @param eventID
+   */
+  private void wakeUpWaitingClientsForSync(long eventID) {
+    CounterWait counterWait = sentryStore.getCounterWait();
+
+    // Wake up any HMS waiters that are waiting for this ID.
+    // counterWait should never be null, but tests mock SentryStore and a mocked one
+    // doesn't have it.
+    if (counterWait != null) {
+      counterWait.update(eventID);
+    }
+  }
+
+  /**
+   * Processes new Hive Metastore notifications.
+   *
+   * If no notifications are processed yet, then it does a full initial snapshot of the Hive
Metastore
+   * followed by new notifications updates that could have happened after it.
+   *
+   * Clients connections waiting for an event notification will be woken up afterwards.
+   */
+  private void processHiveMetastoreUpdates() {
     if (client == null) {
       try {
         client = getMetaStoreClient(authzConf);
@@ -266,6 +301,9 @@ public class HMSFollower implements Runnable, AutoCloseable {
         needHiveSnapshot = false;
         currentEventID = eventIDAfter.getEventId();
         sentryStore.persistFullPathsImage(pathsFullSnapshot);
+
+        // Wake up any HMS waiters that could have been put on hold before getting the eventIDBefore
value.
+        wakeUpWaitingClientsForSync(currentEventID);
       }
 
       // HIVE-15761: Currently getNextNotification API may return an empty
@@ -365,7 +403,6 @@ public class HMSFollower implements Runnable, AutoCloseable {
    */
   void processNotificationEvents(List<NotificationEvent> events) throws Exception {
     SentryJSONMessageDeserializer deserializer = new SentryJSONMessageDeserializer();
-    final CounterWait counterWait = sentryStore.getCounterWait();
 
     for (NotificationEvent event : events) {
       String dbName;
@@ -540,11 +577,7 @@ public class HMSFollower implements Runnable, AutoCloseable {
       }
       currentEventID = event.getEventId();
       // Wake up any HMS waiters that are waiting for this ID.
-      // counterWait should never be null, but tests mock SentryStore and a mocked one
-      // doesn't have it.
-      if (counterWait != null) {
-        counterWait.update(currentEventID);
-      }
+      wakeUpWaitingClientsForSync(currentEventID);
     }
   }
 


Mime
View raw message