[NO ISSUE][RT] Use ThreadLocal date format to format dates - user model changes: no - storage format changes: no - interface changes: no
Details: - Instead of creating a new date format object for formatting trace logs, use a thread local instance. Change-Id: I361542815af7c93291fd6251d9b335c2eb01af56 Reviewed-on: https://asterix-gerrit.ics.uci.edu/2563 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Michael Blow <mb...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/3f4cb466 Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/3f4cb466 Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/3f4cb466 Branch: refs/heads/master Commit: 3f4cb466ac08c72e6cc4df927a075a6364559df1 Parents: 29a0cee Author: Abdullah Alamoudi <bamou...@gmail.com> Authored: Thu Apr 5 11:14:43 2018 -0700 Committer: abdullah alamoudi <bamou...@gmail.com> Committed: Thu Apr 5 18:17:47 2018 -0700 ---------------------------------------------------------------------- .../LSMPrimaryUpsertOperatorNodePushable.java | 39 ++++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/3f4cb466/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java index c767157..dba6760 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java @@ -21,6 +21,7 @@ package org.apache.asterix.runtime.operators; import java.io.DataOutput; import java.io.IOException; import java.nio.ByteBuffer; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -73,9 +74,14 @@ import org.apache.hyracks.storage.common.MultiComparator; import org.apache.hyracks.util.trace.ITracer; import org.apache.hyracks.util.trace.ITracer.Scope; import org.apache.hyracks.util.trace.TraceUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class LSMPrimaryUpsertOperatorNodePushable extends LSMIndexInsertUpdateDeleteOperatorNodePushable { + private static final Logger LOGGER = LogManager.getLogger(); + private static final ThreadLocal<DateFormat> DATE_FORMAT = + ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS")); private final PermutingFrameTupleReference key; private MultiComparator keySearchCmp; private ArrayTupleBuilder missingTupleBuilder; @@ -379,22 +385,31 @@ public class LSMPrimaryUpsertOperatorNodePushable extends LSMIndexInsertUpdateDe @Override public void close() throws HyracksDataException { + traceLastRecordIn(); + Throwable failure = CleanupUtils.close(frameOpCallback, null); + failure = CleanupUtils.destroy(failure, cursor); + failure = CleanupUtils.close(writer, failure); + failure = CleanupUtils.close(indexHelper, failure); + if (failure != null) { + throw HyracksDataException.create(failure); + } + } + + @SuppressWarnings({ "squid:S1181", "squid:S1166" }) + private void traceLastRecordIn() { try { - Throwable failure = CleanupUtils.close(frameOpCallback, null); - failure = CleanupUtils.destroy(failure, cursor); - failure = CleanupUtils.close(writer, failure); - failure = CleanupUtils.close(indexHelper, failure); - if (failure != null) { - throw HyracksDataException.create(failure); - } - } finally { - if (tracer.isEnabled(traceCategory) && lastRecordInTimeStamp > 0) { + if (tracer.isEnabled(traceCategory) && lastRecordInTimeStamp > 0 && indexHelper != null + && indexHelper.getIndexInstance() != null) { tracer.instant("UpsertClose", traceCategory, Scope.t, - "{\"last-record-in\":\"" - + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS") - .format(new Date(lastRecordInTimeStamp)) + "{\"last-record-in\":\"" + DATE_FORMAT.get().format(new Date(lastRecordInTimeStamp)) + "\", \"index\":" + indexHelper.getIndexInstance().toString() + "}"); } + } catch (Throwable traceFailure) { + try { + LOGGER.warn("Tracing last record in failed", traceFailure); + } catch (Throwable ignore) { + // Ignore logging failure + } } }