You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2022/03/07 06:46:38 UTC

[ranger] branch ranger-2.3 updated: RANGER-3644: updated FileTagSource to retry when Ranger is not reachable

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch ranger-2.3
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/ranger-2.3 by this push:
     new 2db9fe2  RANGER-3644: updated FileTagSource to retry when Ranger is not reachable
2db9fe2 is described below

commit 2db9fe2ed461ba55b9be6948dd17b27cf5956b88
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Thu Feb 24 20:48:49 2022 -0800

    RANGER-3644: updated FileTagSource to retry when Ranger is not reachable
    
    (cherry picked from commit bf18c50f1c04e2a5319d0533c6707110b5b62092)
---
 .../ranger/tagsync/source/file/FileTagSource.java  | 45 +++++++++-------------
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/tagsync/src/main/java/org/apache/ranger/tagsync/source/file/FileTagSource.java b/tagsync/src/main/java/org/apache/ranger/tagsync/source/file/FileTagSource.java
index 90adef2..8af15f9 100644
--- a/tagsync/src/main/java/org/apache/ranger/tagsync/source/file/FileTagSource.java
+++ b/tagsync/src/main/java/org/apache/ranger/tagsync/source/file/FileTagSource.java
@@ -51,7 +51,6 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 	private Thread myThread = null;
 
 	public static void main(String[] args) {
-
 		FileTagSource fileTagSource = new FileTagSource();
 
 		TagSyncConfig config = TagSyncConfig.getInstance();
@@ -100,7 +99,6 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 
 	@Override
 	public boolean initialize(Properties props) {
-
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> FileTagSource.initialize()");
 		}
@@ -196,7 +194,6 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 
 	@Override
 	public boolean start() {
-
 		myThread = new Thread(this);
 		myThread.setDaemon(true);
 		myThread.start();
@@ -218,33 +215,31 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 		}
 
 		while (true) {
-
 			try {
 				synchUp();
-
+			} catch (Exception e) {
+				LOG.error("Caught exception..", e);
+			} finally {
 				LOG.debug("Sleeping for [" + fileModTimeCheckIntervalInMs + "] milliSeconds");
 
-				Thread.sleep(fileModTimeCheckIntervalInMs);
-			}
-			catch (InterruptedException exception) {
-				LOG.error("Interrupted..: ", exception);
-				return;
-			}
-			catch (Exception e) {
-				LOG.error("Caught exception..", e);
-				return;
+				try {
+					Thread.sleep(fileModTimeCheckIntervalInMs);
+				} catch (InterruptedException exception) {
+					LOG.error("Interrupted..: ", exception);
+
+					break;
+				}
 			}
 		}
 	}
 
 	private boolean isChanged() {
-
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> FileTagSource.isChanged()");
 		}
-		boolean ret = false;
 
-		long modificationTime = getModificationTime();
+		boolean ret              = false;
+		long    modificationTime = getModificationTime();
 
 		if (modificationTime > lastModifiedTimeInMillis) {
 			if (LOG.isDebugEnabled()) {
@@ -252,7 +247,7 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 				Date lastModifiedDate = new Date(lastModifiedTimeInMillis);
 				LOG.debug("File modified at " + modifiedDate + "last-modified at " + lastModifiedDate);
 			}
-			lastModifiedTimeInMillis = modificationTime;
+
 			ret = true;
 		}
 
@@ -269,12 +264,14 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 			}
 
 			ServiceTags serviceTags = readFromFile();
+
 			updateSink(serviceTags);
 
+			lastModifiedTimeInMillis = getModificationTime();
+
 			if (LOG.isDebugEnabled()) {
 				LOG.debug("End: update tags from source==>sink");
 			}
-
 		} else {
 			if (LOG.isDebugEnabled()) {
 				LOG.debug("FileTagSource: no change found for synchronization.");
@@ -282,7 +279,6 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 		}
 	}
 	private ServiceTags readFromFile() {
-
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> FileTagSource.readFromFile(): sourceFileName=" + serviceTagsFileName);
 		}
@@ -290,13 +286,10 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 		ServiceTags ret = null;
 
 		if (serviceTagsFileURL != null) {
-			try (
-					InputStream serviceTagsFileStream = serviceTagsFileURL.openStream();
-					Reader reader = new InputStreamReader(serviceTagsFileStream, Charset.forName("UTF-8"))
-			) {
+			try (InputStream inputStream = serviceTagsFileURL.openStream();
+			     Reader      reader      = new InputStreamReader(inputStream, Charset.forName("UTF-8"))) {
 
 				ret = gsonBuilder.fromJson(reader, ServiceTags.class);
-
 			} catch (IOException e) {
 				LOG.warn("Error processing input file: or no privilege for reading file " + serviceTagsFileName, e);
 			}
@@ -315,8 +308,8 @@ public class FileTagSource extends AbstractTagSource implements Runnable {
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> FileTagSource.getLastModificationTime(): sourceFileName=" + serviceTagsFileName);
 		}
-		long ret = 0L;
 
+		long ret        = 0L;
 		File sourceFile = new File(serviceTagsFileName);
 
 		if (sourceFile.exists() && sourceFile.isFile() && sourceFile.canRead()) {