diff --git a/src/java/org/apache/cassandra/db/Directories.java b/src/java/org/apache/cassandra/db/Directories.java index 2737d0ce1c7b..de8f5ca18ca9 100644 --- a/src/java/org/apache/cassandra/db/Directories.java +++ b/src/java/org/apache/cassandra/db/Directories.java @@ -25,7 +25,13 @@ import java.nio.file.Path; import java.util.*; import java.util.concurrent.ThreadLocalRandom; + +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.BiFunction; +import java.util.function.Consumer; + import java.util.function.BiPredicate; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -46,6 +52,7 @@ import org.apache.cassandra.utils.DirectorySizeCalculator; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.Pair; +import org.apache.cassandra.utils.ByteConvertor; /** * Encapsulate handling of paths to the data files. @@ -385,7 +392,7 @@ public DataDirectory getWriteableLocation(long writeSize) // exclude directory if its total writeSize does not fit to data directory if (candidate.availableSpace < writeSize) { - logger.trace("removing candidate {}, usable={}, requested={}", candidate.dataDirectory.location, candidate.availableSpace, writeSize); + logger.trace("removing candidate {}, usable={}, requested={} MB", candidate.dataDirectory.location, candidate.availableSpace, ByteConvertor.bytesToMeg(writeSize)); tooBig = true; continue; } diff --git a/src/java/org/apache/cassandra/utils/ByteConvertor.java b/src/java/org/apache/cassandra/utils/ByteConvertor.java new file mode 100644 index 000000000000..9bda023b206d --- /dev/null +++ b/src/java/org/apache/cassandra/utils/ByteConvertor.java @@ -0,0 +1,28 @@ +/* + * 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; + +public class ByteConvertor +{ + private static final long MEGABYTE = 1024L * 1024L; + + public static long bytesToMeg(long bytes) { + return bytes / MEGABYTE ; + } +} \ No newline at end of file diff --git a/src/java/org/apache/cassandra/utils/memory/BufferPool.java b/src/java/org/apache/cassandra/utils/memory/BufferPool.java index 20e600630c4c..6e08ef810591 100644 --- a/src/java/org/apache/cassandra/utils/memory/BufferPool.java +++ b/src/java/org/apache/cassandra/utils/memory/BufferPool.java @@ -39,7 +39,7 @@ import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.NoSpamLogger; import org.apache.cassandra.utils.concurrent.Ref; - +import org.apache.cassandra.utils.ByteConvertor; /** * A pool of ByteBuffers that can be recycled. */ @@ -117,8 +117,12 @@ private static ByteBuffer takeFromPool(int size, boolean allocateOnHeapWhenExhau return ret; if (logger.isTraceEnabled()) + + logger.trace("Requested buffer size {} MB has been allocated directly due to lack of capacity", ByteConvertor.bytesToMeg(size)); + logger.trace("Requested buffer size {} has been allocated directly due to lack of capacity", FBUtilities.prettyPrintMemory(size)); + return localPool.get().allocate(size, allocateOnHeapWhenExhausted); } @@ -133,10 +137,14 @@ private static ByteBuffer maybeTakeFromPool(int size, boolean allocateOnHeapWhen if (size > CHUNK_SIZE) { if (logger.isTraceEnabled()) + + logger.trace("Requested buffer size {} MB is bigger than {}, allocating directly", ByteConvertor.bytesToMeg(size), CHUNK_SIZE); + logger.trace("Requested buffer size {} is bigger than {}, allocating directly", FBUtilities.prettyPrintMemory(size), FBUtilities.prettyPrintMemory(CHUNK_SIZE)); + return localPool.get().allocate(size, allocateOnHeapWhenExhausted); } diff --git a/test/unit/org/apache/cassandra/ByteConvertorTest.java b/test/unit/org/apache/cassandra/ByteConvertorTest.java new file mode 100644 index 000000000000..d9cb09f30ddd --- /dev/null +++ b/test/unit/org/apache/cassandra/ByteConvertorTest.java @@ -0,0 +1,37 @@ +/* + * 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; + +import org.junit.Test; +import org.apache.cassandra.utils.ByteConvertor; +import static junit.framework.Assert.assertEquals; + +public class ByteConvertorTest +{ + @Test + public void testByteToMegaByte() + { + int test1 = 100000000; + long test2= 200000000; + long test1_ans = 95; + long test2_ans = 190; + assertEquals(ByteConvertor.bytesToMeg(test1),test1_ans); + assertEquals(ByteConvertor.bytesToMeg(test2),test2_ans); + } +} diff --git a/tools/stress/src/org/apache/cassandra/stress/Stress.java b/tools/stress/src/org/apache/cassandra/stress/Stress.java index 3c0fa96fe274..b26a89e9de61 100644 --- a/tools/stress/src/org/apache/cassandra/stress/Stress.java +++ b/tools/stress/src/org/apache/cassandra/stress/Stress.java @@ -87,6 +87,7 @@ private static int run(String[] arguments) printHelpMessage(); return 1; } + MultiResultLogger logout = settings.log.getOutput();