This is an automated email from the ASF dual-hosted git repository. marcuse pushed a commit to branch cassandra-4.0 in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-4.0 by this push: new b9d8700 Avoid trying to acquire 0 permits from the rate limiter when taking snapshot b9d8700 is described below commit b9d8700355bf0ecabe1ca7e3f139d0ad52c4bdc4 Author: Marcus Eriksson <marc...@apache.org> AuthorDate: Fri Aug 20 13:54:36 2021 +0200 Avoid trying to acquire 0 permits from the rate limiter when taking snapshot Patch by marcuse; reviewed by Alex Petrov for CASSANDRA-16872 --- CHANGES.txt | 1 + .../org/apache/cassandra/db/ColumnFamilyStore.java | 3 +- .../cassandra/io/sstable/format/SSTableReader.java | 14 ++++++- .../unit/org/apache/cassandra/db/SnapshotTest.java | 46 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 109cff7..c72dd0e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0.2 + * Avoid trying to acquire 0 permits from the rate limiter when taking snapshot (CASSANDRA-16872) * Upgrade Caffeine to 2.5.6 (CASSANDRA-15153) * Include SASI components to snapshots (CASSANDRA-15134) * Fix missed wait latencies in the output of `nodetool tpstats -F` (CASSANDRA-16938) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 113a916..4855d7c 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -1846,8 +1846,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean for (SSTableReader ssTable : currentView.sstables) { File snapshotDirectory = Directories.getSnapshotDirectory(ssTable.descriptor, snapshotName); - rateLimiter.acquire(SSTableReader.componentsFor(ssTable.descriptor).size()); - ssTable.createLinks(snapshotDirectory.getPath()); // hard links + ssTable.createLinks(snapshotDirectory.getPath(), rateLimiter); // hard links filesJSONArr.add(ssTable.descriptor.relativeFilenameFor(Component.DATA)); if (logger.isTraceEnabled()) diff --git a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java index ea40f34..45297ef 100644 --- a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java @@ -1598,16 +1598,28 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS public void createLinks(String snapshotDirectoryPath) { - createLinks(descriptor, components, snapshotDirectoryPath); + createLinks(snapshotDirectoryPath, null); + } + + public void createLinks(String snapshotDirectoryPath, RateLimiter rateLimiter) + { + createLinks(descriptor, components, snapshotDirectoryPath, rateLimiter); } public static void createLinks(Descriptor descriptor, Set<Component> components, String snapshotDirectoryPath) { + createLinks(descriptor, components, snapshotDirectoryPath, null); + } + + public static void createLinks(Descriptor descriptor, Set<Component> components, String snapshotDirectoryPath, RateLimiter limiter) + { for (Component component : components) { File sourceFile = new File(descriptor.filenameFor(component)); if (!sourceFile.exists()) continue; + if (null != limiter) + limiter.acquire(); File targetLink = new File(snapshotDirectoryPath, sourceFile.getName()); FileUtils.createHardLink(sourceFile, targetLink); } diff --git a/test/unit/org/apache/cassandra/db/SnapshotTest.java b/test/unit/org/apache/cassandra/db/SnapshotTest.java new file mode 100644 index 0000000..a406048 --- /dev/null +++ b/test/unit/org/apache/cassandra/db/SnapshotTest.java @@ -0,0 +1,46 @@ +/* + * 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.db; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; + +import org.junit.Test; + +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.io.sstable.Component; +import org.apache.cassandra.io.sstable.format.SSTableReader; + +public class SnapshotTest extends CQLTester +{ + @Test + public void testEmptyTOC() throws Throwable + { + createTable("create table %s (id int primary key, k int)"); + execute("insert into %s (id, k) values (1,1)"); + getCurrentColumnFamilyStore().forceBlockingFlush(); + for (SSTableReader sstable : getCurrentColumnFamilyStore().getLiveSSTables()) + { + File toc = new File(sstable.descriptor.filenameFor(Component.TOC)); + Files.write(toc.toPath(), new byte[0], StandardOpenOption.TRUNCATE_EXISTING); + } + getCurrentColumnFamilyStore().snapshot("hello"); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org