SENTRY-2035: Metrics should move to destination atomically (Alex Kolbasov, reviewed by Sergio Pena and Kalyan Kalvagadda)
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/913be9a9 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/913be9a9 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/913be9a9 Branch: refs/heads/akolb-cli Commit: 913be9a9d38fe737a89835fe39799a68c427fa75 Parents: 0c4f5e7 Author: Alexander Kolbasov <[email protected]> Authored: Tue Nov 7 17:09:18 2017 -0800 Committer: Alexander Kolbasov <[email protected]> Committed: Tue Nov 7 17:09:49 2017 -0800 ---------------------------------------------------------------------- .../sentry/provider/db/service/thrift/SentryMetrics.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/913be9a9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java index 86cae64..1056fa7 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java @@ -375,7 +375,11 @@ public final class SentryMetrics { } // Move temp file to the destination file - Files.move(tmpFile, path, StandardCopyOption.REPLACE_EXISTING); + try { + Files.move(tmpFile, path, StandardCopyOption.ATOMIC_MOVE); + } catch (Exception e) { + LOGGER.error("Failed to move temp metrics file to {}: {}", path, e.getMessage()); + } } catch (Throwable t) { // catch all errors (throwable and execptions to prevent subsequent tasks from being suppressed) LOGGER.error("Error executing scheduled task ", t);
