CASSANDRA-965 remove deprecated methods, update dependent code

* removed method defs and regenerated thrift code
 * removed CassandraServer implementations
 * updated cassandra-cli to call new (describe_*) methods
 * updated RingCache to use describe_ring()
 * removed "show config file" from cli (no thrift access for this anymore).
 * updated release notes.

Patch by eevans for CASSANDRA-965

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@932072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eric Evans 2010-04-08 19:27:25 +00:00
parent 50f8b0f2da
commit fe34d59766
12 changed files with 87 additions and 1444 deletions

View File

@ -9,6 +9,8 @@ Configuraton
Thrift API
----------
- The return type for login() is now AccessLevel.
- The get_string_property() method has been removed.
- The get_string_list_property() method has been removed.
0.6.0

View File

@ -456,12 +456,6 @@ service Cassandra {
// Meta-APIs -- APIs to get information about the node or cluster,
// rather than user data. The nodeprobe program provides usage examples.
/** get property whose value is of type string. @Deprecated */
string get_string_property(1:required string property),
/** get property whose value is list of strings. @Deprecated */
list<string> get_string_list_property(1:required string property),
/** list the defined keyspaces in this cluster */
set<string> describe_keyspaces(),

View File

@ -24,6 +24,8 @@ package org.apache.cassandra.thrift;
* under the License.
*
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

View File

@ -24,6 +24,8 @@ package org.apache.cassandra.thrift;
* under the License.
*
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

View File

@ -40,7 +40,6 @@ tokens {
NODE_HELP;
NODE_NO_OP;
NODE_SHOW_CLUSTER_NAME;
NODE_SHOW_CONFIG_FILE;
NODE_SHOW_VERSION;
NODE_SHOW_TABLES;
NODE_THRIFT_GET;
@ -115,7 +114,6 @@ delStmt
showStmt
: showClusterName
| showVersion
| showConfigFile
| showTables
;
@ -123,10 +121,6 @@ showClusterName
: K_SHOW K_CLUSTER K_NAME -> ^(NODE_SHOW_CLUSTER_NAME)
;
showConfigFile
: K_SHOW K_CONFIG K_FILE -> ^(NODE_SHOW_CONFIG_FILE)
;
showVersion
: K_SHOW K_VERSION -> ^(NODE_SHOW_VERSION)
;

View File

@ -71,13 +71,10 @@ public class CliClient
executeCount(ast);
break;
case CliParser.NODE_SHOW_CLUSTER_NAME:
executeShowProperty(ast, "cluster name");
break;
case CliParser.NODE_SHOW_CONFIG_FILE:
executeShowProperty(ast, "config file");
executeShowClusterName();
break;
case CliParser.NODE_SHOW_VERSION:
executeShowProperty(ast, "version");
executeShowVersion();
break;
case CliParser.NODE_SHOW_TABLES:
executeShowTables(ast);
@ -111,7 +108,6 @@ public class CliClient
css_.out.println("describe keyspace <keyspacename> Describe keyspace.");
css_.out.println("exit Exit CLI.");
css_.out.println("quit Exit CLI.");
css_.out.println("show config file Display contents of config file.");
css_.out.println("show cluster name Display cluster name.");
css_.out.println("show keyspaces Show list of keyspaces.");
css_.out.println("show api version Show server API version.");
@ -420,14 +416,19 @@ public class CliClient
css_.out.println("Value inserted.");
}
private void executeShowProperty(CommonTree ast, String propertyName) throws TException
private void executeShowClusterName() throws TException
{
if (!CliMain.isConnected())
return;
String propertyValue = thriftClient_.get_string_property(propertyName);
css_.out.println(propertyValue);
css_.out.println(thriftClient_.describe_cluster_name());
}
private void executeShowVersion() throws TException
{
if (!CliMain.isConnected())
return;
css_.out.println(thriftClient_.describe_version());
}
// process "show tables" statement
@ -436,7 +437,7 @@ public class CliClient
if (!CliMain.isConnected())
return;
List<String> tables = thriftClient_.get_string_list_property("keyspaces");
Set<String> tables = thriftClient_.describe_keyspaces();
for (String table : tables)
{
css_.out.println(table);

View File

@ -27,7 +27,6 @@ public class CliCompleter extends SimpleCompletor
"exit",
"help",
"quit",
"show config file",
"show cluster name",
"show keyspaces",
"show api version",

View File

@ -134,7 +134,7 @@ public class CliMain
try
{
clusterName = thriftClient_.get_string_property("cluster name");
clusterName = thriftClient_.describe_cluster_name();
}
catch (Exception e)
{
@ -150,7 +150,7 @@ public class CliMain
// Extend the completer with keyspace and column family data.
try
{
for (String keyspace : thriftClient_.get_string_list_property("keyspaces"))
for (String keyspace : thriftClient_.describe_keyspaces())
{
// Ignore system column family
if (keyspace.equals(SYSTEM_TABLE))

View File

@ -29,13 +29,12 @@ import java.net.UnknownHostException;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.CassandraServer;
import org.apache.cassandra.thrift.TokenRange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;
import org.json.simple.JSONValue;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
@ -51,14 +50,16 @@ public class RingCache
private Set<String> seeds_ = new HashSet<String>();
final private int port_= DatabaseDescriptor.getRpcPort();
final private static IPartitioner partitioner_ = DatabaseDescriptor.getPartitioner();
private final String keyspace;
private TokenMetadata tokenMetadata;
public RingCache()
public RingCache(String keyspace)
{
for (InetAddress seed : DatabaseDescriptor.getSeeds())
{
seeds_.add(seed.getHostAddress());
}
this.keyspace = keyspace;
refreshEndPointMap();
}
@ -73,13 +74,14 @@ public class RingCache
Cassandra.Client client = new Cassandra.Client(binaryProtocol);
socket.open();
Map<String,String> tokenToHostMap = (Map<String,String>) JSONValue.parse(client.get_string_property(CassandraServer.TOKEN_MAP));
List<TokenRange> ring = client.describe_ring(keyspace);
BiMap<Token, InetAddress> tokenEndpointMap = HashBiMap.create();
for (Map.Entry<String,String> entry : tokenToHostMap.entrySet())
for (TokenRange range : ring)
{
Token token = StorageService.getPartitioner().getTokenFactory().fromString(entry.getKey());
String host = entry.getValue();
Token<?> token = StorageService.getPartitioner().getTokenFactory().fromString(range.start_token);
String host = range.endpoints.get(0);
try
{
tokenEndpointMap.put(token, InetAddress.getByName(host));
@ -102,11 +104,11 @@ public class RingCache
}
}
public List<InetAddress> getEndPoint(String table, String key)
public List<InetAddress> getEndPoint(String key)
{
if (tokenMetadata == null)
throw new RuntimeException("Must refresh endpoints before looking up a key.");
AbstractReplicationStrategy strat = StorageService.getReplicationStrategy(tokenMetadata, table);
return strat.getNaturalEndpoints(partitioner_.getToken(key), table);
AbstractReplicationStrategy strat = StorageService.getReplicationStrategy(tokenMetadata, keyspace);
return strat.getNaturalEndpoints(partitioner_.getToken(key), keyspace);
}
}

View File

@ -18,8 +18,6 @@
package org.apache.cassandra.thrift;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Future;
@ -55,7 +53,6 @@ import org.apache.cassandra.dht.Token;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.service.StorageService;
import org.apache.thrift.TException;
import org.json.simple.JSONValue;
public class CassandraServer implements Cassandra.Iface
{
@ -488,57 +485,6 @@ public class CassandraServer implements Cassandra.Iface
}
}
public String get_string_property(String propertyName)
{
if (propertyName.equals("cluster name"))
{
return DatabaseDescriptor.getClusterName();
}
else if (propertyName.equals("config file"))
{
String filename = DatabaseDescriptor.getConfigFileName();
try
{
StringBuilder fileData = new StringBuilder(8192);
BufferedInputStream stream = new BufferedInputStream(new FileInputStream(filename));
byte[] buf = new byte[1024];
int numRead;
while( (numRead = stream.read(buf)) != -1)
{
String str = new String(buf, 0, numRead);
fileData.append(str);
}
stream.close();
return fileData.toString();
}
catch (IOException e)
{
return "file not found!";
}
}
else if (propertyName.equals(TOKEN_MAP))
{
return JSONValue.toJSONString(storageService.getStringEndpointMap());
}
else if (propertyName.equals("version"))
{
return Constants.VERSION;
}
else
{
return "?";
}
}
public List<String> get_string_list_property(String propertyName)
{
if (propertyName.equals("keyspaces"))
{
return new ArrayList<String>(DatabaseDescriptor.getTables());
}
return Collections.emptyList();
}
public Map<String, Map<String, String>> describe_keyspace(String table) throws NotFoundException
{
Map<String, Map<String, String>> columnFamiliesMap = new HashMap<String, Map<String, String>>();

View File

@ -36,11 +36,12 @@ import org.apache.thrift.transport.TTransport;
public class TestRingCache
{
private static RingCache ringCache;
private static String keyspace = "Keyspace1";
private static Cassandra.Client thriftClient;
static
{
ringCache = new RingCache();
ringCache = new RingCache(keyspace);
}
private static void setup(String server, int port) throws Exception
@ -65,20 +66,18 @@ public class TestRingCache
*/
public static void main(String[] args) throws Throwable
{
String table;
int minRow;
int maxRow;
String rowPrefix;
if (args.length > 0)
{
table = args[0];
keyspace = args[0];
rowPrefix = args[1];
minRow = Integer.parseInt(args[2]);
maxRow = minRow + 1;
}
else
{
table = "Keyspace1";
minRow = 1;
maxRow = 10;
rowPrefix = "row";
@ -89,7 +88,7 @@ public class TestRingCache
String row = rowPrefix + nRows;
ColumnPath col = new ColumnPath("Standard1").setSuper_column(null).setColumn("col1".getBytes());
List<InetAddress> endPoints = ringCache.getEndPoint(table, row);
List<InetAddress> endPoints = ringCache.getEndPoint(row);
String hosts="";
for (int i = 0; i < endPoints.size(); i++)
hosts = hosts + ((i > 0) ? "," : "") + endPoints.get(i);
@ -97,8 +96,8 @@ public class TestRingCache
// now, read the row back directly from the host owning the row locally
setup(endPoints.get(0).getHostAddress(), DatabaseDescriptor.getRpcPort());
thriftClient.insert(table, row, col, "val1".getBytes(), 1, ConsistencyLevel.ONE);
Column column=thriftClient.get(table, row, col, ConsistencyLevel.ONE).column;
thriftClient.insert(keyspace, row, col, "val1".getBytes(), 1, ConsistencyLevel.ONE);
Column column=thriftClient.get(keyspace, row, col, ConsistencyLevel.ONE).column;
System.out.println("read row " + row + " " + new String(column.name) + ":" + new String(column.value) + ":" + column.timestamp);
}