blambov commented on code in PR #2689:
URL: https://github.com/apache/cassandra/pull/2689#discussion_r1327228953
##########
src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java:
##########
@@ -405,13 +414,13 @@ public MmappedRegionsCache getMmappedRegionsCache()
}
@Override
- public SequentialWriter getDataWriter()
+ public LazyCloseableRef<SequentialWriter> getDataWriter()
Review Comment:
I would switch the interface back to returning the objects, but create them
here (if necessary, implemented as calling the reference's `get` method).
##########
src/java/org/apache/cassandra/io/sstable/format/SSTableWriter.java:
##########
@@ -104,11 +107,21 @@ protected SSTableWriter(Builder<?, ?> builder,
LifecycleNewTracker lifecycleNewT
this.mmappedRegionsCache = builder.getMmappedRegionsCache();
this.lifecycleNewTracker = lifecycleNewTracker;
- Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
+ List<Component> existingsComponents = components.stream().filter(c ->
descriptor.fileFor(c).exists()).collect(Collectors.toList());
+ if (!existingsComponents.isEmpty())
Review Comment:
We could use `anyMatch` instead of making a collection during the normal
path (if necessary, gathering for the error message).
##########
src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java:
##########
@@ -439,14 +448,14 @@ protected BigTableWriter
buildInternal(LifecycleNewTracker lifecycleNewTracker,
{
mmappedRegionsCache = new MmappedRegionsCache();
rowIndexEntrySerializer = new
RowIndexEntry.Serializer(descriptor.version, getSerializationHeader(), owner !=
null ? owner.getMetrics() : null);
- dataWriter = DataComponent.buildWriter(descriptor,
-
getTableMetadataRef().getLocal(),
-
getIOOptions().writerOptions,
- getMetadataCollector(),
-
lifecycleNewTracker.opType(),
-
getIOOptions().flushCompression);
- indexWriter = new IndexWriter(this);
- partitionWriter = new
BigFormatPartitionWriter(getSerializationHeader(), dataWriter,
descriptor.version, rowIndexEntrySerializer.indexInfoSerializer());
+ dataWriter = LazyCloseableRef.create(() ->
DataComponent.buildWriter(descriptor,
Review Comment:
Could this logic be in the `getDataWriter` method? (Renamed to
`openDataWriter` for clarity.)
##########
src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java:
##########
@@ -80,14 +80,23 @@ public class BigTableWriter extends
SortedTableWriter<BigFormatPartitionWriter>
public BigTableWriter(Builder builder, LifecycleNewTracker
lifecycleNewTracker, SSTable.Owner owner)
{
super(builder, lifecycleNewTracker, owner);
- checkNotNull(builder.getRowIndexEntrySerializer());
- checkNotNull(builder.getIndexWriter());
-
- this.rowIndexEntrySerializer = builder.getRowIndexEntrySerializer();
- this.indexWriter = builder.getIndexWriter();
- this.shouldMigrateKeyCache =
DatabaseDescriptor.shouldMigrateKeycacheOnCompaction()
- && lifecycleNewTracker instanceof
ILifecycleTransaction
- && !((ILifecycleTransaction)
lifecycleNewTracker).isOffline();
+
+ try
+ {
+ this.rowIndexEntrySerializer =
builder.getRowIndexEntrySerializer();
+ this.indexWriter = builder.getIndexWriter().get();
+
+ checkNotNull(builder.getRowIndexEntrySerializer());
+ checkNotNull(builder.getIndexWriter());
Review Comment:
I don't think this is doing the intended check, `this.indexWriter` is the
one that should not be null.
##########
src/java/org/apache/cassandra/utils/LazyCloseableRef.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.cassandra.utils;
+
+import java.util.function.Supplier;
+import javax.annotation.concurrent.NotThreadSafe;
+
+public abstract class LazyCloseableRef<T extends AutoCloseable> implements
Closeable, Supplier<T>
Review Comment:
Why do we need this to be closeable? The builders don't manage these
resources.
I think changing the getters to `open...` as described above will add
clarity and make it less likely for incorrect resource management to be
introduced later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]