Github user jtstorck commented on a diff in the pull request: https://github.com/apache/nifi/pull/1202#discussion_r88509784 --- Diff: nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/AbstractRecordWriter.java --- @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.provenance; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.apache.nifi.provenance.serialization.RecordWriter; +import org.apache.nifi.provenance.toc.TocWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AbstractRecordWriter implements RecordWriter { + private static final Logger logger = LoggerFactory.getLogger(AbstractRecordWriter.class); + + private final File file; + private final TocWriter tocWriter; + private final Lock lock = new ReentrantLock(); + + private volatile boolean dirty = false; + private volatile boolean closed = false; + + private int recordsWritten = 0; + + public AbstractRecordWriter(final File file, final TocWriter writer) throws IOException { + logger.trace("Creating Record Writer for {}", file); + + this.file = file; + this.tocWriter = writer; + } + + @Override + public synchronized void close() throws IOException { + closed = true; + + logger.trace("Closing Record Writer for {}", file == null ? null : file.getName()); + + lock(); --- End diff -- I'm confused about the call to lock() as well... I thought it might be to guard tocWriter and the other methods used within close(), but methods like isDirty() are called elsewhere without calling lock(), and there's a getter for tocWriter. What is actually being protected by the lock that's not covered by the method being synchronized?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---