From 85c9bda6532af3b40c149a83d90f8e881f6fcdeb Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Mon, 6 Apr 2009 17:56:01 +0000 Subject: [PATCH] r/m redundant or unused code. patch by jbellis; reviewed by johano for #56 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@762441 13f79535-47bb-0310-9956-ffa450edef68 --- .../cassandra/db/ColumnFamilyStore.java | 24 +++---- src/org/apache/cassandra/db/Memtable.java | 4 +- .../cassandra/db/MinorCompactionManager.java | 22 ++----- src/org/apache/cassandra/db/Table.java | 42 ++---------- src/org/apache/cassandra/dht/Range.java | 4 +- src/org/apache/cassandra/io/SSTable.java | 66 ++----------------- src/org/apache/cassandra/io/SequenceFile.java | 2 +- .../service/HttpRequestVerbHandler.java | 9 +-- .../cassandra/service/StorageService.java | 21 +++--- 9 files changed, 39 insertions(+), 155 deletions(-) diff --git a/src/org/apache/cassandra/db/ColumnFamilyStore.java b/src/org/apache/cassandra/db/ColumnFamilyStore.java index d737f9172e..dd659b250f 100644 --- a/src/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/org/apache/cassandra/db/ColumnFamilyStore.java @@ -356,8 +356,8 @@ public class ColumnFamilyStore */ String getTempFileName( List files) { - int lowestIndex = 0 ; - int index = 0; + int lowestIndex; + int index; Collections.sort(files, new FileNameComparator(FileNameComparator.Ascending)); if( files.size() <= 1) @@ -515,7 +515,7 @@ public class ColumnFamilyStore { SSTable ssTable = new SSTable(ssTableFile); long start = System.currentTimeMillis(); - DataInputBuffer bufIn = null; + DataInputBuffer bufIn; bufIn = filter.next(key, cf, ssTable); logger_.debug("DISK ssTable.next TIME: " + (System.currentTimeMillis() - start) + " ms."); if (bufIn.getLength() == 0) @@ -746,7 +746,7 @@ public class ColumnFamilyStore List files = new ArrayList(ssTables_); try { - int count = 0; + int count; for(List fileList : getCompactionBuckets(files, 50L*1024L*1024L)) { Collections.sort( fileList , new FileNameComparator( FileNameComparator.Ascending)); @@ -781,7 +781,7 @@ public class ColumnFamilyStore } } - void doMajorCompaction(long skip) throws IOException + void doMajorCompaction(long skip) { doMajorCompactionInternal( skip ); } @@ -796,7 +796,7 @@ public class ColumnFamilyStore { isCompacting_.set(true); List filesInternal = new ArrayList(ssTables_); - List files = null; + List files; try { if( skip > 0L ) @@ -948,11 +948,11 @@ public class ColumnFamilyStore * @throws IOException */ /* TODO: Take care of the comments later. */ - void doCleanup(String file) throws IOException + void doCleanup(String file) { if(file == null ) return; - List myRanges = null; + List myRanges; List files = new ArrayList(); files.add(file); List newFiles = new ArrayList(); @@ -1002,8 +1002,8 @@ public class ColumnFamilyStore long totalBytesWritten = 0; long totalkeysRead = 0; long totalkeysWritten = 0; - String rangeFileLocation = null; - String mergedFileName = null; + String rangeFileLocation; + String mergedFileName; try { // Calculate the expected compacted filesize @@ -1053,7 +1053,7 @@ public class ColumnFamilyStore else { Collections.sort(lfs, new FileStructComparator()); - ColumnFamily columnFamily = null; + ColumnFamily columnFamily; bufOut.reset(); if(lfs.size() > 1) { @@ -1295,7 +1295,7 @@ public class ColumnFamilyStore else { Collections.sort(lfs, new FileStructComparator()); - ColumnFamily columnFamily = null; + ColumnFamily columnFamily; bufOut.reset(); if(lfs.size() > 1) { diff --git a/src/org/apache/cassandra/db/Memtable.java b/src/org/apache/cassandra/db/Memtable.java index 9f0a7a81dd..7048d906ae 100644 --- a/src/org/apache/cassandra/db/Memtable.java +++ b/src/org/apache/cassandra/db/Memtable.java @@ -82,7 +82,7 @@ public class Memtable implements MemtableMBean, Comparable /* Lock and Condition for notifying new clients about Memtable switches */ Lock lock_ = new ReentrantLock(); - Memtable(String table, String cfName) throws IOException + Memtable(String table, String cfName) { if ( apartments_.get(cfName) == null ) { @@ -315,7 +315,7 @@ public class Memtable implements MemtableMBean, Comparable * is not respected and a forceFlush() needs to be invoked to flush * the contents to disk. */ - void putOnRecovery(String key, ColumnFamily columnFamily) throws IOException + void putOnRecovery(String key, ColumnFamily columnFamily) { if(!key.equals(Memtable.flushKey_)) resolve(key, columnFamily); diff --git a/src/org/apache/cassandra/db/MinorCompactionManager.java b/src/org/apache/cassandra/db/MinorCompactionManager.java index 5f564668f7..a424bea7fa 100644 --- a/src/org/apache/cassandra/db/MinorCompactionManager.java +++ b/src/org/apache/cassandra/db/MinorCompactionManager.java @@ -101,12 +101,6 @@ class MinorCompactionManager implements IComponentShutdown private EndPoint target_; private List fileList_; - FileCompactor2(ColumnFamilyStore columnFamilyStore, List ranges) - { - columnFamilyStore_ = columnFamilyStore; - ranges_ = ranges; - } - FileCompactor2(ColumnFamilyStore columnFamilyStore, List ranges, EndPoint target,List fileList) { columnFamilyStore_ = columnFamilyStore; @@ -117,7 +111,7 @@ class MinorCompactionManager implements IComponentShutdown public Boolean call() { - boolean result = true; + boolean result; logger_.debug("Started compaction ..."+columnFamilyStore_.columnFamily_); result = columnFamilyStore_.doAntiCompaction(ranges_, target_,fileList_); logger_.debug("Finished compaction ..."+columnFamilyStore_.columnFamily_); @@ -138,17 +132,9 @@ class MinorCompactionManager implements IComponentShutdown public void run() { - try - { - logger_.debug("Started Major compaction ..."+columnFamilyStore_.columnFamily_); - columnFamilyStore_.doMajorCompaction(skip_); - logger_.debug("Finished Major compaction ..."+columnFamilyStore_.columnFamily_); - } - catch (IOException e) - { - logger_.debug( LogUtil.throwableToString(e) ); - } - return ; + logger_.debug("Started Major compaction ..."+columnFamilyStore_.columnFamily_); + columnFamilyStore_.doMajorCompaction(skip_); + logger_.debug("Finished Major compaction ..."+columnFamilyStore_.columnFamily_); } } diff --git a/src/org/apache/cassandra/db/Table.java b/src/org/apache/cassandra/db/Table.java index e3f3fe6600..56caf30f32 100644 --- a/src/org/apache/cassandra/db/Table.java +++ b/src/org/apache/cassandra/db/Table.java @@ -65,11 +65,6 @@ public class Table { /* Name of the column family */ public final static String cfName_ = "TableMetadata"; - /* - * Name of one of the columns. The other columns are the individual - * column families in the system. - */ - public static final String cardinality_ = "PrimaryCardinality"; private static ICompactSerializer serializer_; static { @@ -173,11 +168,6 @@ public class Table return cfTypeMap_.get(cfName); } - void setColumnFamilyType(String cfName, String type) - { - cfTypeMap_.put(cfName, type); - } - Set getColumnFamilies() { return cfIdMap_.keySet(); @@ -208,13 +198,7 @@ public class Table logger_.debug(LogUtil.throwableToString(ex)); } } - - public void reset() throws IOException - { - writer_.seek(0L); - apply(); - } - + public String toString() { StringBuilder sb = new StringBuilder(""); @@ -380,19 +364,7 @@ public class Table return fileNames; } - - private boolean isStreamContextForThisColumnFamily(StreamContextManager.StreamContext streamContext, String cf) - { - String[] peices = FBUtilities.strip(streamContext.getTargetFile(), "-"); - return peices[1].equals(cf); - } - - private String getColumnFamilyFromFile(String file) - { - String[] peices = FBUtilities.strip(file, "-"); - return peices[1]; - } - + private void addStreamContext(String host, StreamContextManager.StreamContext streamContext, StreamContextManager.StreamStatus streamStatus) { logger_.debug("Adding stream context " + streamContext + " for " + host + " ..."); @@ -401,7 +373,6 @@ public class Table } private static Logger logger_ = Logger.getLogger(Table.class); - public static final String newLine_ = System.getProperty("line.separator"); public static final String recycleBin_ = "RecycleColumnFamily"; public static final String hints_ = "HintsColumnFamily"; @@ -467,11 +438,6 @@ public class Table return cfType; } - public void setColumnFamilyType(String cfName, String type) - { - tableMetadata_.setColumnFamilyType(cfName, type); - } - /* * This method is called to obtain statistics about * the table. It will return statistics about all @@ -562,7 +528,7 @@ public class Table * do a complete compaction since we can figure out based on the ranges * whether the files need to be split. */ - public boolean forceCompaction(List ranges, EndPoint target, List fileList) throws IOException + public boolean forceCompaction(List ranges, EndPoint target, List fileList) { boolean result = true; Set columnFamilies = tableMetadata_.getColumnFamilies(); @@ -585,7 +551,7 @@ public class Table * This method is an ADMIN operation to force compaction * of all SSTables on disk. */ - public void forceCompaction() throws IOException + public void forceCompaction() { Set columnFamilies = tableMetadata_.getColumnFamilies(); for ( String columnFamily : columnFamilies ) diff --git a/src/org/apache/cassandra/dht/Range.java b/src/org/apache/cassandra/dht/Range.java index e17a79f195..b4313f65f6 100644 --- a/src/org/apache/cassandra/dht/Range.java +++ b/src/org/apache/cassandra/dht/Range.java @@ -69,8 +69,8 @@ public class Range implements Comparable } - private BigInteger left_; - private BigInteger right_; + private final BigInteger left_; + private final BigInteger right_; public Range(BigInteger left, BigInteger right) { diff --git a/src/org/apache/cassandra/io/SSTable.java b/src/org/apache/cassandra/io/SSTable.java index 4e2fd5b434..8edf0ce22c 100644 --- a/src/org/apache/cassandra/io/SSTable.java +++ b/src/org/apache/cassandra/io/SSTable.java @@ -193,7 +193,7 @@ public class SSTable public int compareTo(KeyPositionInfo kPosInfo) { - int value = 0; + int value; PartitionerType pType = StorageService.getPartitionerType(); switch( pType ) { @@ -513,7 +513,7 @@ public class SSTable bufIn.readInt(); /* Number of keys in the block. */ int keys = bufIn.readInt(); - String largestKeyInBlock = null; + String largestKeyInBlock; for ( int i = 0; i < keys; ++i ) { String keyInBlock = bufIn.readUTF(); @@ -660,7 +660,7 @@ public class SSTable return currentPosition; } - private void afterAppend(String key, long position, long size) throws IOException + private void afterAppend(String key, long position, long size) { ++indexKeysWritten_; lastWrittenKey_ = key; @@ -673,7 +673,7 @@ public class SSTable } } - private void afterAppend(BigInteger hash, long position, long size) throws IOException + private void afterAppend(BigInteger hash, long position, long size) { ++indexKeysWritten_; String key = hash.toString(); @@ -760,14 +760,6 @@ public class SSTable dataWriter_.append(key, value); afterAppend(key, currentPosition, value.length ); } - - public void append(String key, BigInteger hash, byte[] value) throws IOException - { - long currentPosition = beforeAppend(hash); - /* Use as key - hash + ":" + key */ - dataWriter_.append(hash + ":" + key, value); - afterAppend(hash, currentPosition, value.length); - } private Coordinate getCoordinates(String key, IFileReader dataReader) throws IOException { @@ -894,56 +886,6 @@ public class SSTable List columnNames = (values.length == 1) ? null : Arrays.asList(values[1]); return next(key, columnFamilyName, columnNames, null); } - - long getSeekPosition(String key, long start) - { - Long seekStart = touchCache_.get(dataFile_ + ":" + key); - if( seekStart != null) - { - return seekStart; - } - return start; - } - - /* - * Given a key we are interested in this method gets the - * closest index before the key on disk. - * - * param @ key - key we are interested in. - * return position of the closest index before the key - * on disk or -1 if this key is not on disk. - */ - private long getClosestIndexPositionToKeyOnDisk(String key) - { - long position = -1L; - List indexInfo = indexMetadataMap_.get(dataFile_); - int size = indexInfo.size(); - int index = Collections.binarySearch(indexInfo, new KeyPositionInfo(key)); - if ( index < 0 ) - { - /* - * We are here which means that the requested - * key is not an index. - */ - index = (++index)*(-1); - /* this means key is not present at all */ - if ( index >= size ) - return position; - /* a scan is in order. */ - position = (index == 0) ? 0 : indexInfo.get(index - 1).position(); - } - else - { - /* - * If we are here that means the key is in the index file - * and we can retrieve it w/o a scan. In reality we would - * like to have a retreive(key, fromPosition) but for now - * we use scan(start, start + 1) - a hack. - */ - position = indexInfo.get(index).position(); - } - return position; - } public void close() throws IOException { diff --git a/src/org/apache/cassandra/io/SequenceFile.java b/src/org/apache/cassandra/io/SequenceFile.java index cb91cbcba3..9e23b76c52 100644 --- a/src/org/apache/cassandra/io/SequenceFile.java +++ b/src/org/apache/cassandra/io/SequenceFile.java @@ -421,7 +421,7 @@ public class SequenceFile { Method getCleanerMethod = buffer.getClass().getMethod("cleaner", new Class[0]); getCleanerMethod.setAccessible(true); - sun.misc.Cleaner cleaner = (sun.misc.Cleaner) getCleanerMethod.invoke(buffer, new Object[0]); + sun.misc.Cleaner cleaner = (sun.misc.Cleaner) getCleanerMethod.invoke(buffer); cleaner.clean(); } catch (Throwable e) diff --git a/src/org/apache/cassandra/service/HttpRequestVerbHandler.java b/src/org/apache/cassandra/service/HttpRequestVerbHandler.java index c0b9a14cd6..4023620b21 100644 --- a/src/org/apache/cassandra/service/HttpRequestVerbHandler.java +++ b/src/org/apache/cassandra/service/HttpRequestVerbHandler.java @@ -684,14 +684,7 @@ public class HttpRequestVerbHandler implements IVerbHandler private String handleCompactMe() { Table table = Table.open(DatabaseDescriptor.getTables().get(0)); - try - { - table.forceCompaction(); - } - catch (IOException ex) - { - logger_.debug(LogUtil.throwableToString(ex)); - } + table.forceCompaction(); return "Compacting ..."; } diff --git a/src/org/apache/cassandra/service/StorageService.java b/src/org/apache/cassandra/service/StorageService.java index d14dac52b7..1b35ae0646 100644 --- a/src/org/apache/cassandra/service/StorageService.java +++ b/src/org/apache/cassandra/service/StorageService.java @@ -138,8 +138,8 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto { WEAK, STRONG - }; - + } + private static StorageService instance_; /* Used to lock the factory for creation of StorageService instance */ private static Lock createLock_ = new ReentrantLock(); @@ -181,8 +181,8 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto { HINT, FULL - }; - + } + public static class BootstrapInitiateDoneVerbHandler implements IVerbHandler { private static Logger logger_ = Logger.getLogger( BootstrapInitiateDoneVerbHandler.class ); @@ -302,7 +302,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto } } - public StorageService() throws Throwable + public StorageService() { init(); uptime_ = System.currentTimeMillis(); @@ -627,8 +627,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto Set tokens = tokenToEndPointMap.keySet(); /* All the ranges for the tokens */ Range[] ranges = getAllRanges(tokens); - Map> oldRangeToEndPointMap = constructRangeToEndPointMap(ranges); - return oldRangeToEndPointMap; + return constructRangeToEndPointMap(ranges); } /** @@ -856,7 +855,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto private void doBootstrap(String nodes) { String[] allNodesAndFilter = nodes.split("-"); - String nodesToLoad = null; + String nodesToLoad; String filterSources = null; if ( allNodesAndFilter.length == 2 ) @@ -1032,10 +1031,9 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto List tokens = new ArrayList(tokenToEndPointMap.keySet()); Collections.sort(tokens); int index = Collections.binarySearch(tokens, token); - EndPoint predecessor = (index == 0) ? tokenToEndPointMap.get(tokens + return (index == 0) ? tokenToEndPointMap.get(tokens .get(tokens.size() - 1)) : tokenToEndPointMap.get(tokens .get(--index)); - return predecessor; } /* @@ -1049,10 +1047,9 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto List tokens = new ArrayList(tokenToEndPointMap.keySet()); Collections.sort(tokens); int index = Collections.binarySearch(tokens, token); - EndPoint successor = (index == (tokens.size() - 1)) ? tokenToEndPointMap + return (index == (tokens.size() - 1)) ? tokenToEndPointMap .get(tokens.get(0)) : tokenToEndPointMap.get(tokens.get(++index)); - return successor; } /**