Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/java/org/apache/cassandra/db/Directories.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
28 changes: 28 additions & 0 deletions src/java/org/apache/cassandra/utils/ByteConvertor.java
Original file line number Diff line number Diff line change
@@ -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 ;
}
}
10 changes: 9 additions & 1 deletion src/java/org/apache/cassandra/utils/memory/BufferPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
37 changes: 37 additions & 0 deletions test/unit/org/apache/cassandra/ByteConvertorTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions tools/stress/src/org/apache/cassandra/stress/Stress.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private static int run(String[] arguments)
printHelpMessage();
return 1;
}


MultiResultLogger logout = settings.log.getOutput();

Expand Down