rename getDefaultToken -> getInitialToken

patch by jbellis; reviewed by Jun Rao for CASSANDRA-65

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@769019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-04-27 15:01:51 +00:00
parent 296e15b63c
commit bfb2e95220
9 changed files with 16 additions and 14 deletions

View File

@ -1113,7 +1113,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
continue; continue;
} }
} }
if (Range.isTokenInRanges(StorageService.getPartitioner().getTokenForKey(lastkey), ranges)) if (Range.isTokenInRanges(StorageService.getPartitioner().getInitialToken(lastkey), ranges))
{ {
if(ssTableRange == null ) if(ssTableRange == null )
{ {
@ -1143,7 +1143,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
continue; continue;
} }
/* keep on looping until we find a key in the range */ /* keep on looping until we find a key in the range */
while (!Range.isTokenInRanges(StorageService.getPartitioner().getTokenForKey(filestruct.getKey()), ranges)) while (!Range.isTokenInRanges(StorageService.getPartitioner().getInitialToken(filestruct.getKey()), ranges))
{ {
filestruct.advance(); filestruct.advance();
if (filestruct.isExhausted()) if (filestruct.isExhausted())

View File

@ -37,7 +37,10 @@ public interface IPartitioner
public Comparator<String> getReverseDecoratedKeyComparator(); public Comparator<String> getReverseDecoratedKeyComparator();
public Token getTokenForKey(String key); /**
* @return the token to use for this node if none was saved
*/
public Token getInitialToken(String key);
public Token getDefaultToken(); public Token getDefaultToken();

View File

@ -110,7 +110,7 @@ public class OrderPreservingPartitioner implements IPartitioner
return tokenFactory; return tokenFactory;
} }
public Token getTokenForKey(String key) public Token getInitialToken(String key)
{ {
return new StringToken(key); return new StringToken(key);
} }

View File

@ -103,7 +103,7 @@ public class RandomPartitioner implements IPartitioner
return tokenFactory; return tokenFactory;
} }
public Token getTokenForKey(String key) public Token getInitialToken(String key)
{ {
return new BigIntegerToken(FBUtilities.hash(key)); return new BigIntegerToken(FBUtilities.hash(key));
} }

View File

@ -110,7 +110,7 @@ public class RackAwareStrategy extends AbstractStrategy
for ( String key : keys ) for ( String key : keys )
{ {
results.put(key, getStorageEndPoints(partitioner_.getTokenForKey(key))); results.put(key, getStorageEndPoints(partitioner_.getInitialToken(key)));
} }
return results; return results;

View File

@ -67,7 +67,7 @@ public class RackUnawareStrategy extends AbstractStrategy
for ( String key : keys ) for ( String key : keys )
{ {
results.put(key, getStorageEndPoints(partitioner_.getTokenForKey(key))); results.put(key, getStorageEndPoints(partitioner_.getInitialToken(key)));
} }
return results; return results;

View File

@ -774,7 +774,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
Token[] tokens = tokenToEndPointMap.keySet().toArray(new Token[tokenToEndPointMap.keySet().size()]); Token[] tokens = tokenToEndPointMap.keySet().toArray(new Token[tokenToEndPointMap.keySet().size()]);
Arrays.sort(tokens); Arrays.sort(tokens);
int index = Arrays.binarySearch(tokens, token) * (keys.length/tokens.length); int index = Arrays.binarySearch(tokens, token) * (keys.length/tokens.length);
Token newToken = partitioner_.getTokenForKey(keys[index]); Token newToken = partitioner_.getInitialToken(keys[index]);
/* update the token */ /* update the token */
updateToken(newToken); updateToken(newToken);
} }
@ -1064,7 +1064,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
public EndPoint getPrimary(String key) public EndPoint getPrimary(String key)
{ {
EndPoint endpoint = StorageService.tcpAddr_; EndPoint endpoint = StorageService.tcpAddr_;
Token token = partitioner_.getTokenForKey(key); Token token = partitioner_.getInitialToken(key);
Map<Token, EndPoint> tokenToEndPointMap = tokenMetadata_.cloneTokenEndPointMap(); Map<Token, EndPoint> tokenToEndPointMap = tokenMetadata_.cloneTokenEndPointMap();
List tokens = new ArrayList<Token>(tokenToEndPointMap.keySet()); List tokens = new ArrayList<Token>(tokenToEndPointMap.keySet());
if (tokens.size() > 0) if (tokens.size() > 0)
@ -1112,7 +1112,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
*/ */
public EndPoint[] getNStorageEndPoint(String key) public EndPoint[] getNStorageEndPoint(String key)
{ {
return nodePicker_.getStorageEndPoints(partitioner_.getTokenForKey(key)); return nodePicker_.getStorageEndPoints(partitioner_.getInitialToken(key));
} }
private Map<String, EndPoint[]> getNStorageEndPoints(String[] keys) private Map<String, EndPoint[]> getNStorageEndPoints(String[] keys)
@ -1151,7 +1151,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
*/ */
public Map<EndPoint, EndPoint> getNStorageEndPointMap(String key) public Map<EndPoint, EndPoint> getNStorageEndPointMap(String key)
{ {
return nodePicker_.getHintedStorageEndPoints(partitioner_.getTokenForKey(key)); return nodePicker_.getHintedStorageEndPoints(partitioner_.getInitialToken(key));
} }
/** /**

View File

@ -2,7 +2,6 @@ package org.apache.cassandra.locator;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.math.BigInteger;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.IPartitioner;
@ -42,7 +41,7 @@ public class RackUnawareStrategyTest
List<Token> keyTokens = new ArrayList<Token>(); List<Token> keyTokens = new ArrayList<Token>();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
endPointTokens.add(new StringToken(String.valueOf((char)('a' + i * 2)))); endPointTokens.add(new StringToken(String.valueOf((char)('a' + i * 2))));
keyTokens.add(partitioner.getTokenForKey(String.valueOf((char)('a' + i * 2 + 1)))); keyTokens.add(partitioner.getInitialToken(String.valueOf((char)('a' + i * 2 + 1))));
} }
testGetStorageEndPoints(tmd, strategy, endPointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0])); testGetStorageEndPoints(tmd, strategy, endPointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0]));
} }

View File

@ -9,6 +9,6 @@ import java.io.IOException;
public class SystemTableTest extends ServerTest { public class SystemTableTest extends ServerTest {
@Test @Test
public void testMain() throws IOException { public void testMain() throws IOException {
SystemTable.openSystemTable(SystemTable.cfName_).updateToken(StorageService.getPartitioner().getTokenForKey("503545744:0")); SystemTable.openSystemTable(SystemTable.cfName_).updateToken(StorageService.getPartitioner().getInitialToken("503545744:0"));
} }
} }