Minor code improvements

patch by Robert Stupp; reviewed by Stefania for CASSANDRA-10750
This commit is contained in:
Robert Stupp 2015-12-18 09:14:57 -08:00
parent a0f59dce5b
commit 0f5e780781
41 changed files with 227 additions and 276 deletions

View File

@ -213,10 +213,10 @@ public class PasswordAuthenticator implements IAuthenticator
}
}
if (user == null)
throw new AuthenticationException("Authentication ID must not be null");
if (pass == null)
throw new AuthenticationException("Password must not be null");
if (user == null)
throw new AuthenticationException("Authentication ID must not be null");
username = new String(user, StandardCharsets.UTF_8);
password = new String(pass, StandardCharsets.UTF_8);

View File

@ -815,11 +815,6 @@ public interface CQL3Type
return true;
}
public boolean isCollection()
{
return false;
}
public void freeze() throws InvalidRequestException
{
for (CQL3Type.Raw t : types)

View File

@ -137,24 +137,12 @@ final class PrimaryKeyRestrictionSet extends AbstractPrimaryKeyRestrictions
return in;
}
@Override
public boolean isOnToken()
{
return false;
}
@Override
public boolean isContains()
{
return contains;
}
@Override
public boolean isMultiColumn()
{
return false;
}
@Override
public Iterable<Function> getFunctions()
{

View File

@ -65,11 +65,6 @@ final class FieldSelector extends Selector
};
}
public boolean isAggregate()
{
return false;
}
public void addInput(int protocolVersion, ResultSetBuilder rs) throws InvalidRequestException
{
selected.addInput(protocolVersion, rs);

View File

@ -48,7 +48,7 @@ import static org.apache.cassandra.cql3.statements.RequestValidations.checkFalse
*/
public class BatchStatement implements CQLStatement
{
public static enum Type
public enum Type
{
LOGGED, UNLOGGED, COUNTER
}
@ -258,7 +258,7 @@ public class BatchStatement implements CQLStatement
/**
* Checks batch size to ensure threshold is met. If not, a warning is logged.
*
* @param cfs ColumnFamilies that will store the batch's mutations.
* @param updates - the batch mutations.
*/
public static void verifyBatchSize(Iterable<PartitionUpdate> updates) throws InvalidRequestException
{
@ -438,14 +438,7 @@ public class BatchStatement implements CQLStatement
private ResultMessage executeInternalWithoutCondition(QueryState queryState, QueryOptions options) throws RequestValidationException, RequestExecutionException
{
for (IMutation mutation : getMutations(BatchQueryOptions.withoutPerStatementVariables(options), true, queryState.getTimestamp()))
{
assert mutation instanceof Mutation || mutation instanceof CounterMutation;
if (mutation instanceof Mutation)
((Mutation) mutation).apply();
else if (mutation instanceof CounterMutation)
((CounterMutation) mutation).apply();
}
mutation.apply();
return null;
}

View File

@ -550,14 +550,7 @@ public abstract class ModificationStatement implements CQLStatement
public ResultMessage executeInternalWithoutCondition(QueryState queryState, QueryOptions options) throws RequestValidationException, RequestExecutionException
{
for (IMutation mutation : getMutations(options, true, queryState.getTimestamp()))
{
assert mutation instanceof Mutation || mutation instanceof CounterMutation;
if (mutation instanceof Mutation)
((Mutation) mutation).apply();
else if (mutation instanceof CounterMutation)
((CounterMutation) mutation).apply();
}
mutation.apply();
return null;
}

View File

@ -110,7 +110,7 @@ public class CounterMutation implements IMutation
*
* @return the applied resulting Mutation
*/
public Mutation apply() throws WriteTimeoutException
public Mutation applyCounterMutation() throws WriteTimeoutException
{
Mutation result = new Mutation(getKeyspaceName(), key());
Keyspace keyspace = Keyspace.open(getKeyspaceName());
@ -132,6 +132,11 @@ public class CounterMutation implements IMutation
}
}
public void apply()
{
applyCounterMutation();
}
private void grabCounterLocks(Keyspace keyspace, List<Lock> locks) throws WriteTimeoutException
{
long startTime = System.nanoTime();

View File

@ -17,7 +17,6 @@
*/
package org.apache.cassandra.db;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.UUID;
@ -25,6 +24,7 @@ import org.apache.cassandra.db.partitions.PartitionUpdate;
public interface IMutation
{
public void apply();
public String getKeyspaceName();
public Collection<UUID> getColumnFamilyIds();
public DecoratedKey key();

View File

@ -652,16 +652,18 @@ public abstract class LegacyLayout
protected LegacyCell computeNext()
{
if (currentRow.hasNext())
return currentRow.next();
while (true)
{
if (currentRow.hasNext())
return currentRow.next();
if (!iterator.hasNext())
return endOfData();
if (!iterator.hasNext())
return endOfData();
Pair<LegacyRangeTombstoneList, Iterator<LegacyCell>> row = fromRow(metadata, iterator.next());
deletions.addAll(row.left);
currentRow = row.right;
return computeNext();
Pair<LegacyRangeTombstoneList, Iterator<LegacyCell>> row = fromRow(metadata, iterator.next());
deletions.addAll(row.left);
currentRow = row.right;
}
}
};

View File

@ -34,15 +34,12 @@ import org.apache.cassandra.io.util.DataOutputPlus;
import org.apache.cassandra.net.MessageOut;
import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO convert this to a Builder pattern instead of encouraging M.add directly,
// which is less-efficient since we have to keep a mutable HashMap around
public class Mutation implements IMutation
{
public static final MutationSerializer serializer = new MutationSerializer();
private static final Logger logger = LoggerFactory.getLogger(Mutation.class);
public static final String FORWARD_TO = "FWD_TO";
public static final String FORWARD_FROM = "FWD_FRM";
@ -251,7 +248,7 @@ public class Mutation implements IMutation
buff.append(", modifications=[");
if (shallow)
{
List<String> cfnames = new ArrayList<String>(modifications.size());
List<String> cfnames = new ArrayList<>(modifications.size());
for (UUID cfid : modifications.keySet())
{
CFMetaData cfm = Schema.instance.getCFMetaData(cfid);
@ -261,7 +258,7 @@ public class Mutation implements IMutation
}
else
{
buff.append("\n ").append(StringUtils.join(modifications.values(), "\n ")).append("\n");
buff.append("\n ").append(StringUtils.join(modifications.values(), "\n ")).append('\n');
}
return buff.append("])").toString();
}

View File

@ -432,7 +432,7 @@ public abstract class UnfilteredDeserializer
return false;
}
}
return next != null;
return true;
}
private Unfiltered readRow(LegacyLayout.LegacyAtom first)

View File

@ -455,7 +455,7 @@ public class CommitLogReplayer
int uncompressedLength = replayEnd - replayPos;
if (uncompressedLength > uncompressedBuffer.length)
uncompressedBuffer = new byte[(int) (1.2 * uncompressedLength)];
compressedLength = compressor.uncompress(buffer, 0, compressedLength, uncompressedBuffer, 0);
compressor.uncompress(buffer, 0, compressedLength, uncompressedBuffer, 0);
sectionReader = new FileSegmentInputStream(ByteBuffer.wrap(uncompressedBuffer), reader.getPath(), replayPos);
errorContext = "compressed section at " + start + " in " + errorContext;
}

View File

@ -190,9 +190,8 @@ public class CompactionController implements AutoCloseable
{
// if we don't have bloom filter(bf_fp_chance=1.0 or filter file is missing),
// we check index file instead.
if (sstable.getBloomFilter() instanceof AlwaysPresentFilter && sstable.getPosition(key, SSTableReader.Operator.EQ, false) != null)
min = Math.min(min, sstable.getMinTimestamp());
else if (sstable.getBloomFilter().isPresent(key))
if ((sstable.getBloomFilter() instanceof AlwaysPresentFilter && sstable.getPosition(key, SSTableReader.Operator.EQ, false) != null)
|| sstable.getBloomFilter().isPresent(key))
min = Math.min(min, sstable.getMinTimestamp());
}
return min;

View File

@ -177,12 +177,6 @@ public abstract class UnfilteredPartitionIterators
{
private final List<UnfilteredRowIterator> toMerge = new ArrayList<>(iterators.size());
@Override
public boolean trivialReduceIsTrivial()
{
return false;
}
public void reduce(int idx, UnfilteredRowIterator current)
{
toMerge.add(current);

View File

@ -4,6 +4,8 @@ import java.util.Arrays;
class Stack
{
public static final Transformation[] EMPTY_TRANSFORMATIONS = new Transformation[0];
public static final MoreContentsHolder[] EMPTY_MORE_CONTENTS_HOLDERS = new MoreContentsHolder[0];
static final Stack EMPTY = new Stack();
Transformation[] stack;
@ -24,8 +26,8 @@ class Stack
Stack()
{
stack = new Transformation[0];
moreContents = new MoreContentsHolder[0];
stack = EMPTY_TRANSFORMATIONS;
moreContents = EMPTY_MORE_CONTENTS_HOLDERS;
}
Stack(Stack copy)

View File

@ -164,7 +164,7 @@ public class Range<T extends RingPosition<T>> extends AbstractBounds<T> implemen
boolean thatwraps = isWrapAround(that.left, that.right);
if (!thiswraps && !thatwraps)
{
// neither wraps. the straightforward case.
// neither wraps: the straightforward case.
if (!(left.compareTo(that.right) < 0 && that.left.compareTo(right) < 0))
return Collections.emptySet();
return rangeSet(new Range<T>(ObjectUtils.max(this.left, that.left),
@ -172,7 +172,7 @@ public class Range<T extends RingPosition<T>> extends AbstractBounds<T> implemen
}
if (thiswraps && thatwraps)
{
// if the starts are the same, one contains the other, which we have already ruled out.
//both wrap: if the starts are the same, one contains the other, which we have already ruled out.
assert !this.left.equals(that.left);
// two wrapping ranges always intersect.
// since we have already determined that neither this nor that contains the other, we have 2 cases,
@ -186,9 +186,9 @@ public class Range<T extends RingPosition<T>> extends AbstractBounds<T> implemen
? intersectionBothWrapping(this, that)
: intersectionBothWrapping(that, this);
}
if (thiswraps && !thatwraps)
if (thiswraps) // this wraps, that does not wrap
return intersectionOneWrapping(this, that);
assert (!thiswraps && thatwraps);
// the last case: this does not wrap, that wraps
return intersectionOneWrapping(that, this);
}

View File

@ -21,9 +21,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.ClusteringIndexNamesFilter;
@ -41,8 +38,6 @@ import org.apache.cassandra.utils.concurrent.OpOrder;
public class CompositesSearcher extends CassandraIndexSearcher
{
private static final Logger logger = LoggerFactory.getLogger(CompositesSearcher.class);
public CompositesSearcher(ReadCommand command,
RowFilter.Expression expression,
CassandraIndex index)
@ -95,70 +90,75 @@ public class CompositesSearcher extends CassandraIndexSearcher
private boolean prepareNext()
{
if (next != null)
return true;
if (nextEntry == null)
while (true)
{
if (!indexHits.hasNext())
return false;
if (next != null)
return true;
nextEntry = index.decodeEntry(indexKey, indexHits.next());
}
// Gather all index hits belonging to the same partition and query the data for those hits.
// TODO: it's much more efficient to do 1 read for all hits to the same partition than doing
// 1 read per index hit. However, this basically mean materializing all hits for a partition
// in memory so we should consider adding some paging mechanism. However, index hits should
// be relatively small so it's much better than the previous code that was materializing all
// *data* for a given partition.
BTreeSet.Builder<Clustering> clusterings = BTreeSet.builder(index.baseCfs.getComparator());
List<IndexEntry> entries = new ArrayList<>();
DecoratedKey partitionKey = index.baseCfs.decorateKey(nextEntry.indexedKey);
while (nextEntry != null && partitionKey.getKey().equals(nextEntry.indexedKey))
{
// We're queried a slice of the index, but some hits may not match some of the clustering column constraints
if (isMatchingEntry(partitionKey, nextEntry, command))
if (nextEntry == null)
{
clusterings.add(nextEntry.indexedEntryClustering);
entries.add(nextEntry);
if (!indexHits.hasNext())
return false;
nextEntry = index.decodeEntry(indexKey, indexHits.next());
}
nextEntry = indexHits.hasNext() ? index.decodeEntry(indexKey, indexHits.next()) : null;
// Gather all index hits belonging to the same partition and query the data for those hits.
// TODO: it's much more efficient to do 1 read for all hits to the same partition than doing
// 1 read per index hit. However, this basically mean materializing all hits for a partition
// in memory so we should consider adding some paging mechanism. However, index hits should
// be relatively small so it's much better than the previous code that was materializing all
// *data* for a given partition.
BTreeSet.Builder<Clustering> clusterings = BTreeSet.builder(index.baseCfs.getComparator());
List<IndexEntry> entries = new ArrayList<>();
DecoratedKey partitionKey = index.baseCfs.decorateKey(nextEntry.indexedKey);
while (nextEntry != null && partitionKey.getKey().equals(nextEntry.indexedKey))
{
// We're queried a slice of the index, but some hits may not match some of the clustering column constraints
if (isMatchingEntry(partitionKey, nextEntry, command))
{
clusterings.add(nextEntry.indexedEntryClustering);
entries.add(nextEntry);
}
nextEntry = indexHits.hasNext() ? index.decodeEntry(indexKey, indexHits.next()) : null;
}
// Because we've eliminated entries that don't match the clustering columns, it's possible we added nothing
if (clusterings.isEmpty())
{
continue;
}
// Query the gathered index hits. We still need to filter stale hits from the resulting query.
ClusteringIndexNamesFilter filter = new ClusteringIndexNamesFilter(clusterings.build(), false);
SinglePartitionReadCommand dataCmd = SinglePartitionReadCommand.create(index.baseCfs.metadata,
command.nowInSec(),
command.columnFilter(),
command.rowFilter(),
DataLimits.NONE,
partitionKey,
filter);
@SuppressWarnings("resource") // We close right away if empty, and if it's assign to next it will be called either
// by the next caller of next, or through closing this iterator is this come before.
UnfilteredRowIterator dataIter = filterStaleEntries(dataCmd.queryMemtableAndDisk(index.baseCfs,
executionController.baseReadOpOrderGroup()),
indexKey.getKey(),
entries,
executionController.writeOpOrderGroup(),
command.nowInSec());
if (dataIter.isEmpty())
{
dataIter.close();
continue;
}
next = dataIter;
return true;
}
// Because we've eliminated entries that don't match the clustering columns, it's possible we added nothing
if (clusterings.isEmpty())
return prepareNext();
// Query the gathered index hits. We still need to filter stale hits from the resulting query.
ClusteringIndexNamesFilter filter = new ClusteringIndexNamesFilter(clusterings.build(), false);
SinglePartitionReadCommand dataCmd = SinglePartitionReadCommand.create(index.baseCfs.metadata,
command.nowInSec(),
command.columnFilter(),
command.rowFilter(),
DataLimits.NONE,
partitionKey,
filter);
@SuppressWarnings("resource") // We close right away if empty, and if it's assign to next it will be called either
// by the next caller of next, or through closing this iterator is this come before.
UnfilteredRowIterator dataIter = filterStaleEntries(dataCmd.queryMemtableAndDisk(index.baseCfs,
executionController.baseReadOpOrderGroup()),
indexKey.getKey(),
entries,
executionController.writeOpOrderGroup(),
command.nowInSec());
if (dataIter.isEmpty())
{
dataIter.close();
return prepareNext();
}
next = dataIter;
return true;
}
public void remove()

View File

@ -139,24 +139,27 @@ public abstract class SSTableSimpleIterator extends AbstractIterator<Unfiltered>
protected Unfiltered computeNext()
{
try
while (true)
{
if (!deserializer.hasNext())
return endOfData();
Unfiltered unfiltered = deserializer.readNext();
if (metadata.isStaticCompactTable() && unfiltered.kind() == Unfiltered.Kind.ROW)
try
{
Row row = (Row) unfiltered;
ColumnDefinition def = metadata.getColumnDefinition(LegacyLayout.encodeClustering(metadata, row.clustering()));
if (def != null && def.isStatic())
return computeNext();
if (!deserializer.hasNext())
return endOfData();
Unfiltered unfiltered = deserializer.readNext();
if (metadata.isStaticCompactTable() && unfiltered.kind() == Unfiltered.Kind.ROW)
{
Row row = (Row) unfiltered;
ColumnDefinition def = metadata.getColumnDefinition(LegacyLayout.encodeClustering(metadata, row.clustering()));
if (def != null && def.isStatic())
continue;
}
return unfiltered;
}
catch (IOException e)
{
throw new IOError(e);
}
return unfiltered;
}
catch (IOException e)
{
throw new IOError(e);
}
}

View File

@ -818,7 +818,7 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS
while ((indexPosition = primaryIndex.getFilePointer()) != indexSize)
{
ByteBuffer key = ByteBufferUtil.readWithShortLength(primaryIndex);
RowIndexEntry indexEntry = rowIndexSerializer.deserialize(primaryIndex);
/*RowIndexEntry indexEntry = */rowIndexSerializer.deserialize(primaryIndex);
DecoratedKey decoratedKey = decorateKey(key);
if (first == null)
first = decoratedKey;

View File

@ -68,12 +68,6 @@ public class FileSegmentInputStream extends DataInputBuffer implements FileDataI
buffer.position((int) (pos - offset));
}
@Override
public boolean markSupported()
{
return false;
}
public FileMark mark()
{
throw new UnsupportedOperationException();

View File

@ -275,16 +275,4 @@ public abstract class RebufferingInputStream extends InputStream implements Data
return -1;
}
}
@Override
public void reset() throws IOException
{
throw new IOException("mark/reset not supported");
}
@Override
public boolean markSupported()
{
return false;
}
}

View File

@ -223,10 +223,4 @@ public class NetworkTopologyStrategy extends AbstractReplicationStrategy
validateReplicationFactor(e.getValue());
}
}
public Collection<String> recognizedOptions()
{
// We explicitely allow all options
return null;
}
}

View File

@ -42,6 +42,9 @@ import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
*/
public class TableMetrics
{
public static final long[] EMPTY = new long[0];
/** Total amount of data stored in the memtable that resides on-heap, including column related overhead and partitions overwritten. */
public final Gauge<Long> memtableOnHeapSize;
/** Total amount of data stored in the memtable that resides off-heap, including column related overhead and partitions overwritten. */
@ -171,7 +174,7 @@ public class TableMetrics
Iterator<SSTableReader> iterator = sstables.iterator();
if (!iterator.hasNext())
{
return new long[0];
return EMPTY;
}
long[] firstBucket = getHistogram.getHistogram(iterator.next()).getBuckets(false);
long[] values = new long[firstBucket.length];

View File

@ -35,7 +35,7 @@ public class AsciiSerializer extends AbstractTextSerializer
for (int i = bytes.position(); i < bytes.limit(); i++)
{
byte b = bytes.get(i);
if (b < 0 || b > 127)
if (b < 0)
throw new MarshalException("Invalid byte for ascii: " + Byte.toString(b));
}
}

View File

@ -93,10 +93,8 @@ public class UTF8Serializer extends AbstractTextSerializer
if (b == (byte)0xf0)
// 0xf0, 0x90-0xbf, 0x80-0xbf, 0x80-0xbf
state = State.FOUR_90bf;
else if (b == (byte)0xf4)
// 0xf4, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf
state = State.FOUR_80bf_3;
else
// 0xf4, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf
// 0xf1-0xf3, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf
state = State.FOUR_80bf_3;
break;

View File

@ -64,7 +64,7 @@ public class CacheService implements CacheServiceMBean
public static final String MBEAN_NAME = "org.apache.cassandra.db:type=Caches";
public static enum CacheType
public enum CacheType
{
KEY_CACHE("KeyCache"),
ROW_CACHE("RowCache"),
@ -72,7 +72,7 @@ public class CacheService implements CacheServiceMBean
private final String name;
private CacheType(String typeName)
CacheType(String typeName)
{
name = typeName;
}
@ -430,9 +430,9 @@ public class CacheService implements CacheServiceMBean
//Keyspace and CF name are deserialized by AutoSaving cache and used to fetch the CFS provided as a
//parameter so they aren't deserialized here, even though they are serialized by this serializer
final ByteBuffer buffer = ByteBufferUtil.readWithLength(in);
final int rowsToCache = cfs.metadata.params.caching.rowsPerPartitionToCache();
if (cfs == null || !cfs.isRowCacheEnabled())
return null;
final int rowsToCache = cfs.metadata.params.caching.rowsPerPartitionToCache();
assert(!cfs.isIndex());//Shouldn't have row cache entries for indexes
return StageManager.getStage(Stage.READ).submit(new Callable<Pair<RowCacheKey, IRowCacheEntry>>()

View File

@ -1393,7 +1393,7 @@ public class StorageProxy implements StorageProxyMBean
{
assert mutation instanceof CounterMutation;
Mutation result = ((CounterMutation) mutation).apply();
Mutation result = ((CounterMutation) mutation).applyCounterMutation();
responseHandler.response(null);
Set<InetAddress> remotes = Sets.difference(ImmutableSet.copyOf(targets),

View File

@ -32,6 +32,7 @@ import org.apache.cassandra.utils.UUIDGen;
*/
public class StreamPlan
{
public static final String[] EMPTY_COLUMN_FAMILIES = new String[0];
private final UUID planId = UUIDGen.getTimeUUID();
private final String description;
private final List<StreamEventHandler> handlers = new ArrayList<>();
@ -75,7 +76,7 @@ public class StreamPlan
*/
public StreamPlan requestRanges(InetAddress from, InetAddress connecting, String keyspace, Collection<Range<Token>> ranges)
{
return requestRanges(from, connecting, keyspace, ranges, new String[0]);
return requestRanges(from, connecting, keyspace, ranges, EMPTY_COLUMN_FAMILIES);
}
/**
@ -116,7 +117,7 @@ public class StreamPlan
*/
public StreamPlan transferRanges(InetAddress to, InetAddress connecting, String keyspace, Collection<Range<Token>> ranges)
{
return transferRanges(to, connecting, keyspace, ranges, new String[0]);
return transferRanges(to, connecting, keyspace, ranges, EMPTY_COLUMN_FAMILIES);
}
/**

View File

@ -88,7 +88,7 @@ public class Ring extends NodeToolCmd
}
catch (IllegalArgumentException ex)
{
System.out.printf("%nError: " + ex.getMessage() + "%n");
System.out.printf("%nError: %s%n", ex.getMessage());
return;
}
@ -174,4 +174,4 @@ public class Ring extends NodeToolCmd
}
System.out.println();
}
}
}

View File

@ -81,7 +81,7 @@ public class Status extends NodeToolCmd
}
catch (IllegalArgumentException ex)
{
System.out.printf("%nError: " + ex.getMessage() + "%n");
System.out.printf("%nError: %s%n", ex.getMessage());
System.exit(1);
}
@ -204,4 +204,4 @@ public class Status extends NodeToolCmd
return format;
}
}
}

View File

@ -25,6 +25,9 @@ import java.util.Arrays;
public class HistogramBuilder
{
public static final long[] EMPTY_LONG_ARRAY = new long[]{};
public static final long[] ZERO = new long[]{ 0 };
public HistogramBuilder() {}
public HistogramBuilder(long[] values)
{
@ -73,7 +76,7 @@ public class HistogramBuilder
final long[] values = this.values;
if (count == 0)
return new EstimatedHistogram(new long[] { }, new long[] { 0 });
return new EstimatedHistogram(EMPTY_LONG_ARRAY, ZERO);
long min = Long.MAX_VALUE, max = Long.MIN_VALUE;
double sum = 0, sumsq = 0;
@ -114,7 +117,7 @@ public class HistogramBuilder
// minormax == mean we have no range to produce, but given the exclusive starts
// that begin at zero by default (or -Inf) in EstimatedHistogram we have to generate a min range
// to indicate where we start from
return ismin ? new long[] { mean - 1 } : new long[0];
return ismin ? new long[] { mean - 1 } : EMPTY_LONG_ARRAY;
if (stdev < 1)
{

View File

@ -272,20 +272,21 @@ public class IntervalTree<C extends Comparable<? super C>, D, I extends Interval
protected I computeNext()
{
if (current != null && current.hasNext())
return current.next();
while (true)
{
if (current != null && current.hasNext())
return current.next();
IntervalNode node = stack.pollFirst();
if (node == null)
return endOfData();
IntervalNode node = stack.pollFirst();
if (node == null)
return endOfData();
current = node.intersectsLeft.iterator();
current = node.intersectsLeft.iterator();
// We know this is the smaller not returned yet, but before doing
// its parent, we must do everyone on it's right.
gotoMinOf(node.right);
return computeNext();
// We know this is the smaller not returned yet, but before doing
// its parent, we must do everyone on it's right.
gotoMinOf(node.right);
}
}
private void gotoMinOf(IntervalNode node)

View File

@ -17,11 +17,8 @@
*/
package org.apache.cassandra.utils;
import java.io.Closeable;
import java.util.*;
import org.apache.cassandra.utils.AbstractIterator;
/** Merges sorted input iterators which individually contain unique items. */
public abstract class MergeIterator<In,Out> extends AbstractIterator<Out> implements IMergeIterator<In, Out>
{

View File

@ -326,19 +326,28 @@ public class MerkleTree implements Serializable
TreeRange getHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t)
{
if (hashable instanceof Leaf)
while (true)
{
// we've reached a hash: wrap it up and deliver it
return new TreeRange(this, pleft, pright, depth, hashable);
}
// else: node.
if (hashable instanceof Leaf)
{
// we've reached a hash: wrap it up and deliver it
return new TreeRange(this, pleft, pright, depth, hashable);
}
// else: node.
Inner node = (Inner)hashable;
if (Range.contains(pleft, node.token, t))
// left child contains token
return getHelper(node.lchild, pleft, node.token, inc(depth), t);
// else: right child contains token
return getHelper(node.rchild, node.token, pright, inc(depth), t);
Inner node = (Inner) hashable;
depth = inc(depth);
if (Range.contains(pleft, node.token, t))
{ // left child contains token
hashable = node.lchild;
pright = node.token;
}
else
{ // else: right child contains token
hashable = node.rchild;
pleft = node.token;
}
}
}
/**
@ -404,33 +413,42 @@ public class MerkleTree implements Serializable
*/
private Hashable findHelper(Hashable current, Range<Token> activeRange, Range<Token> find) throws StopRecursion
{
if (current instanceof Leaf)
while (true)
{
if (!find.contains(activeRange))
// we are not fully contained in this range!
if (current instanceof Leaf)
{
if (!find.contains(activeRange))
// we are not fully contained in this range!
throw new StopRecursion.BadRange();
return current;
}
// else: node.
Inner node = (Inner) current;
Range<Token> leftRange = new Range<>(activeRange.left, node.token);
Range<Token> rightRange = new Range<>(node.token, activeRange.right);
if (find.contains(activeRange))
// this node is fully contained in the range
return node.calc();
// else: one of our children contains the range
if (leftRange.contains(find))
{ // left child contains/matches the range
current = node.lchild;
activeRange = leftRange;
}
else if (rightRange.contains(find))
{ // right child contains/matches the range
current = node.rchild;
activeRange = rightRange;
}
else
{
throw new StopRecursion.BadRange();
return current;
}
}
// else: node.
Inner node = (Inner)current;
Range<Token> leftRange = new Range<Token>(activeRange.left, node.token);
Range<Token> rightRange = new Range<Token>(node.token, activeRange.right);
if (find.contains(activeRange))
// this node is fully contained in the range
return node.calc();
// else: one of our children contains the range
if (leftRange.contains(find))
// left child contains/matches the range
return findHelper(node.lchild, leftRange, find);
else if (rightRange.contains(find))
// right child contains/matches the range
return findHelper(node.rchild, rightRange, find);
else
throw new StopRecursion.BadRange();
}
/**

View File

@ -219,8 +219,7 @@ class TreeCursor<K> extends NodeCursor<K>
return;
}
NodeCursor<K> cur = this.cur;
cur = root();
NodeCursor<K> cur = root();
assert cur.nodeOffset == 0;
while (true)
{

View File

@ -1,4 +1,4 @@
/**
/*
* 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
@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.stress;
import java.io.IOException;
@ -24,7 +25,6 @@ import java.util.List;
import com.google.common.util.concurrent.RateLimiter;
import org.apache.cassandra.stress.generate.*;
import org.apache.cassandra.stress.settings.OptionDistribution;
import org.apache.cassandra.stress.settings.OptionRatioDistribution;
import org.apache.cassandra.stress.settings.SettingsLog;
import org.apache.cassandra.stress.settings.StressSettings;
@ -141,11 +141,13 @@ public abstract class Operation
*/
public abstract void run(ThriftClient client) throws IOException;
public void run(SimpleClient client) throws IOException {
public void run(SimpleClient client) throws IOException
{
throw new UnsupportedOperationException();
}
public void run(JavaDriverClient client) throws IOException {
public void run(JavaDriverClient client) throws IOException
{
throw new UnsupportedOperationException();
}

View File

@ -49,6 +49,9 @@ import org.apache.thrift.TException;
public abstract class CqlOperation<V> extends PredefinedOperation
{
public static final ByteBuffer[][] EMPTY_BYTE_BUFFERS = new ByteBuffer[0][];
public static final byte[][] EMPTY_BYTE_ARRAYS = new byte[0][];
protected abstract List<Object> getQueryParameters(byte[] key);
protected abstract String buildQuery();
protected abstract CqlRunOp<V> buildRunOp(ClientWrapper client, String query, Object queryId, List<Object> params, ByteBuffer key);
@ -455,7 +458,7 @@ public abstract class CqlOperation<V> extends PredefinedOperation
public ByteBuffer[][] apply(ResultSet result)
{
if (result == null)
return new ByteBuffer[0][];
return EMPTY_BYTE_BUFFERS;
List<Row> rows = result.all();
ByteBuffer[][] r = new ByteBuffer[rows.size()][];
@ -481,7 +484,7 @@ public abstract class CqlOperation<V> extends PredefinedOperation
public ByteBuffer[][] apply(ResultMessage result)
{
if (!(result instanceof ResultMessage.Rows))
return new ByteBuffer[0][];
return EMPTY_BYTE_BUFFERS;
ResultMessage.Rows rows = ((ResultMessage.Rows) result);
ByteBuffer[][] r = new ByteBuffer[rows.result.size()][];
@ -536,7 +539,7 @@ public abstract class CqlOperation<V> extends PredefinedOperation
{
if (result == null)
return new byte[0][];
return EMPTY_BYTE_ARRAYS;
List<Row> rows = result.all();
byte[][] r = new byte[rows.size()][];
for (int i = 0 ; i < r.length ; i++)

View File

@ -34,6 +34,7 @@ import org.apache.cassandra.thrift.SliceRange;
public abstract class PredefinedOperation extends Operation
{
public static final byte[] EMPTY_BYTE_ARRAY = {};
public final Command type;
private final Distribution columnCount;
private Object cqlCache;
@ -106,7 +107,7 @@ public abstract class PredefinedOperation extends Operation
{
predicate.setSlice_range(new SliceRange()
.setStart(settings.columns.names.get(lb))
.setFinish(new byte[] {})
.setFinish(EMPTY_BYTE_ARRAY)
.setReversed(false)
.setCount(count())
);

View File

@ -20,8 +20,6 @@ package org.apache.cassandra.stress.operations.userdefined;
*
*/
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@ -37,7 +35,6 @@ import org.apache.cassandra.stress.generate.Row;
import org.apache.cassandra.stress.settings.StressSettings;
import org.apache.cassandra.stress.util.JavaDriverClient;
import org.apache.cassandra.stress.util.Timer;
import org.apache.cassandra.transport.SimpleClient;
public abstract class SchemaStatement extends Operation
{
@ -91,12 +88,6 @@ public abstract class SchemaStatement extends Operation
return args;
}
@Override
public void run(SimpleClient client) throws IOException
{
throw new UnsupportedOperationException();
}
abstract class Runner implements RunOp
{
int partitionCount;

View File

@ -26,7 +26,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import com.datastax.driver.core.*;
@ -42,13 +41,11 @@ import org.apache.cassandra.thrift.Compression;
import org.apache.cassandra.thrift.CqlResult;
import org.apache.cassandra.thrift.CqlRow;
import org.apache.cassandra.thrift.ThriftConversion;
import org.apache.cassandra.transport.SimpleClient;
import org.apache.cassandra.utils.Pair;
import org.apache.thrift.TException;
public class ValidatingSchemaQuery extends Operation
{
final Random random = new Random();
private Pair<Row, Row> bounds;
final int clusteringComponents;
@ -57,12 +54,6 @@ public class ValidatingSchemaQuery extends Operation
final int[] argumentIndex;
final Object[] bindBuffer;
@Override
public void run(SimpleClient client) throws IOException
{
throw new UnsupportedOperationException();
}
private ValidatingSchemaQuery(Timer timer, StressSettings settings, PartitionGenerator generator, SeedManager seedManager, ValidatingStatement[] statements, ConsistencyLevel cl, int clusteringComponents)
{
super(timer, settings, new DataSpec(generator, seedManager, new DistributionFixed(1), settings.insert.rowPopulationRatio.get(), 1));
@ -280,14 +271,14 @@ public class ValidatingSchemaQuery extends Operation
{
StringBuilder cc = new StringBuilder();
StringBuilder arg = new StringBuilder();
cc.append("("); arg.append("(");
cc.append('('); arg.append('(');
for (int d = 0 ; d <= depth ; d++)
{
if (d > 0) { cc.append(","); arg.append(","); }
if (d > 0) { cc.append(','); arg.append(','); }
cc.append(metadata.getClusteringColumns().get(d).getName());
arg.append("?");
arg.append('?');
}
cc.append(")"); arg.append(")");
cc.append(')'); arg.append(')');
ValidatingStatement[] statements = new ValidatingStatement[depth < maxDepth ? 1 : 4];
int i = 0;

View File

@ -27,6 +27,7 @@ import java.util.concurrent.ThreadLocalRandom;
// used for both single timer results and merged timer results
public final class TimingInterval
{
public static final long[] EMPTY_SAMPLE = new long[0];
// nanos
private final long start;
private final long end;
@ -56,7 +57,7 @@ public final class TimingInterval
maxLatency = totalLatency = 0;
partitionCount = rowCount = operationCount = errorCount = 0;
pauseStart = pauseLength = 0;
sample = new SampleOfLongs(new long[0], 1d);
sample = new SampleOfLongs(EMPTY_SAMPLE, 1d);
}
TimingInterval(long start, long end, long maxLatency, long pauseStart, long pauseLength, long partitionCount,