-
Notifications
You must be signed in to change notification settings - Fork 3.9k
putShortVolatile is not volatile in InMemoryTrie #4820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,7 @@ protected AbstractSSTableIterator(SSTableReader sstable, | |
| } | ||
| else | ||
| { | ||
| Reader reader = null; | ||
|
iamaleksey marked this conversation as resolved.
|
||
| boolean shouldCloseFile = file == null; | ||
| try | ||
| { | ||
|
|
@@ -119,15 +120,18 @@ protected AbstractSSTableIterator(SSTableReader sstable, | |
|
|
||
| // Note that this needs to be called after file != null and after the partitionDeletion has been set, but before readStaticRow | ||
| // (since it uses it) so we can't move that up (but we'll be able to simplify as soon as we drop support for the old file format). | ||
| this.reader = createReader(indexEntry, file, shouldCloseFile); | ||
| reader = createReader(indexEntry, file, shouldCloseFile); | ||
| this.staticRow = readStaticRow(sstable, file, helper, columns.fetchedColumns().statics); | ||
| } | ||
| else | ||
| { | ||
| this.partitionLevelDeletion = indexEntry.deletionTime(); | ||
| this.staticRow = Rows.EMPTY_STATIC_ROW; | ||
| this.reader = createReader(indexEntry, file, shouldCloseFile); | ||
| reader = createReader(indexEntry, file, shouldCloseFile); | ||
| } | ||
|
|
||
| this.reader = reader; | ||
|
|
||
| if (!partitionLevelDeletion.validate()) | ||
| UnfilteredValidation.handleInvalid(metadata(), key, sstable, "partitionLevelDeletion="+partitionLevelDeletion.toString()); | ||
|
|
||
|
|
@@ -137,9 +141,25 @@ protected AbstractSSTableIterator(SSTableReader sstable, | |
| if (reader == null && file != null && shouldCloseFile) | ||
| file.close(); | ||
| } | ||
| catch (IOException e) | ||
| catch (CorruptSSTableException | IOException e) | ||
|
iamaleksey marked this conversation as resolved.
|
||
| { | ||
| sstable.markSuspect(); | ||
|
|
||
| if (reader != null) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when an exception occurs, we have a reader that might not get closed properly |
||
| { | ||
| try | ||
| { | ||
| reader.close(); | ||
| // reader will close the file internally, so there's no | ||
| // need to close it in the next block | ||
| shouldCloseFile = false; | ||
| } | ||
| catch (IOException suppressed) | ||
| { | ||
| e.addSuppressed(suppressed); | ||
| } | ||
| } | ||
|
|
||
| String filePath = file.getPath(); | ||
| if (shouldCloseFile) | ||
|
iamaleksey marked this conversation as resolved.
|
||
| { | ||
|
|
@@ -152,6 +172,8 @@ protected AbstractSSTableIterator(SSTableReader sstable, | |
| e.addSuppressed(suppressed); | ||
| } | ||
| } | ||
| if (e instanceof CorruptSSTableException) | ||
| throw (CorruptSSTableException)e; | ||
|
iamaleksey marked this conversation as resolved.
|
||
| throw new CorruptSSTableException(e, filePath); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,13 +330,16 @@ protected SequentialWriter openDataWriter() | |
| { | ||
| checkState(!dataWriterOpened, "Data writer has been already opened."); | ||
|
|
||
| return DataComponent.buildWriter(descriptor, | ||
| getTableMetadataRef().getLocal(), | ||
| getIOOptions().writerOptions, | ||
| getMetadataCollector(), | ||
| ensuringInBuildInternalContext(operationType), | ||
| getIOOptions().flushCompression, | ||
| getCompressionDictionaryManager()); | ||
| SequentialWriter sequentialWriter = DataComponent.buildWriter(descriptor, | ||
| getTableMetadataRef().getLocal(), | ||
| getIOOptions().writerOptions, | ||
| getMetadataCollector(), | ||
| ensuringInBuildInternalContext(operationType), | ||
| getIOOptions().flushCompression, | ||
| getCompressionDictionaryManager()); | ||
| dataWriterOpened = true; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is missing setting |
||
|
|
||
| return sequentialWriter; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, both here and for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This minimizes the diff, but it actually makes more sense to handle it at the contractor instead |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * 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.io.tries; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import org.apache.cassandra.io.util.DataOutputBuffer; | ||
| import org.apache.cassandra.io.util.Rebufferer; | ||
| import org.apache.cassandra.utils.bytecomparable.ByteComparable; | ||
| import org.apache.cassandra.utils.bytecomparable.ByteSource; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| /** | ||
| * Reproducer: ReverseValueIterator leaks Rebufferer on constructor exception | ||
| * | ||
| * <p>If initializeWithRightBound() or initializeNoRightBound() throws after the Walker | ||
| * super-constructor acquires a Rebufferer, the Rebufferer is never closed. Compare with | ||
| * ValueIterator which wraps initialization in try-catch with super.close(). | ||
| * | ||
| * Expected: Rebufferer.closeReader() is called when initialization throws. | ||
| * Actual (buggy): Rebufferer leaks — closeReader() never called. | ||
| * Failure criterion: closeReader() not called after constructor exception. | ||
| */ | ||
| @SuppressWarnings({"unchecked", "RedundantSuppression"}) | ||
| public class ReverseValueIteratorLeakTest extends AbstractTrieTestBase | ||
| { | ||
| // ORACLE: Rebufferer.closeReader() must be called if constructor throws | ||
| @Test | ||
| public void testRebuffererClosedOnInitWithRightBoundFailure() throws IOException | ||
| { | ||
| // HARNESS: build a valid trie, wrap its Rebufferer with close tracking, | ||
| // then trigger a failure during initializeWithRightBound | ||
| DataOutputBuffer buf = new DataOutputBufferPaged(); | ||
| IncrementalTrieWriter<Integer> builder = newTrieWriter(serializer, buf); | ||
| builder.add(source("aaa"), 1); | ||
| builder.add(source("bbb"), 2); | ||
| long root = builder.complete(); | ||
|
|
||
| AtomicBoolean closeReaderCalled = new AtomicBoolean(false); | ||
| Rebufferer trackingSource = new TrackingRebufferer(buf.asNewBuffer(), closeReaderCalled); | ||
|
|
||
| // TRIGGER: provide a ByteComparable whose ByteSource throws during iteration, | ||
| // causing initializeWithRightBound to fail after Walker acquires the Rebufferer | ||
| ByteComparable throwingEnd = v -> new ByteSource() | ||
| { | ||
| private int calls = 0; | ||
|
|
||
| @Override | ||
| public int next() | ||
| { | ||
| if (++calls > 1) | ||
| throw new RuntimeException("simulated failure during trie traversal"); | ||
| return 'b'; | ||
| } | ||
| }; | ||
|
|
||
| try | ||
| { | ||
| new ReverseValueIterator<>(trackingSource, root, source("aaa"), throwingEnd, false); | ||
| fail("Constructor should have thrown"); | ||
| } | ||
| catch (RuntimeException e) | ||
| { | ||
| assertTrue("Expected simulated failure", e.getMessage().contains("simulated failure")); | ||
| } | ||
|
|
||
| // ORACLE: Rebufferer must have been closed despite the constructor failure | ||
| assertTrue("Rebufferer.closeReader() must be called when ReverseValueIterator " + | ||
| "constructor fails during initializeWithRightBound — without the fix, " + | ||
| "the Rebufferer leaks", | ||
| closeReaderCalled.get()); | ||
| } | ||
|
|
||
| private static class TrackingRebufferer extends ByteBufRebufferer | ||
| { | ||
| private final AtomicBoolean closeReaderCalled; | ||
|
|
||
| TrackingRebufferer(ByteBuffer buffer, AtomicBoolean closeReaderCalled) | ||
| { | ||
| super(buffer); | ||
| this.closeReaderCalled = closeReaderCalled; | ||
| } | ||
|
|
||
| @Override | ||
| public void closeReader() | ||
| { | ||
| closeReaderCalled.set(true); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially a copy-paste bug