From 679bfd5cdf0b974642f75071e33806c185b9c9c4 Mon Sep 17 00:00:00 2001 From: Alexander Kolbasov Date: Wed, 1 Nov 2017 12:23:42 -0700 Subject: [PATCH] HIVE-17953 Metrics should move to destination atomically --- .../hadoop/hive/common/metrics/metrics2/JsonFileMetricsReporter.java | 4 ++-- .../java/org/apache/hadoop/hive/metastore/metrics/JsonReporter.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/src/java/org/apache/hadoop/hive/common/metrics/metrics2/JsonFileMetricsReporter.java b/common/src/java/org/apache/hadoop/hive/common/metrics/metrics2/JsonFileMetricsReporter.java index b9be8bd182..2e6420c383 100644 --- a/common/src/java/org/apache/hadoop/hive/common/metrics/metrics2/JsonFileMetricsReporter.java +++ b/common/src/java/org/apache/hadoop/hive/common/metrics/metrics2/JsonFileMetricsReporter.java @@ -170,9 +170,9 @@ public void run() { return; } - // Move temp file to the destination file + // Atomically move temp file to the destination file try { - Files.move(tmpFile, path, StandardCopyOption.REPLACE_EXISTING); + Files.move(tmpFile, path, StandardCopyOption.ATOMIC_MOVE); } catch (Exception e) { LOGGER.error("Unable to rename temp file {} to {}", tmpFile, path); LOGGER.error("Exception during rename", e); diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/metrics/JsonReporter.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/metrics/JsonReporter.java index 04a5f02a91..e198fbc401 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/metrics/JsonReporter.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/metrics/JsonReporter.java @@ -163,9 +163,10 @@ public void report(SortedMap sortedMap, SortedMap