我正在尝试使用Astyanax驱动程序列出Cassandra中的列族。它列出的键空间还可以,但是输出中缺少许多列族。
为此,我有一个简单的程序
import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Cluster;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
import com.netflix.astyanax.ddl.KeyspaceDefinition;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;
public class App {
public static void main(String[] args) throws Exception {
ConnectionPoolConfigurationImpl cpool = new ConnectionPoolConfigurationImpl("ConnectionPool")
.setPort(9160)
.setSeeds("localhost");
AstyanaxConfigurationImpl astyanaxConfiguration = new AstyanaxConfigurationImpl();
AstyanaxContext.Builder ctxBuilder = new AstyanaxContext.Builder();
ctxBuilder.forCluster("Cluster")
.withAstyanaxConfiguration(astyanaxConfiguration)
.withConnectionPoolConfiguration(cpool)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
AstyanaxContext<Cluster> clusterContext = ctxBuilder.buildCluster(ThriftFamilyFactory.getInstance());
clusterContext.start();
Cluster cluster = clusterContext.getClient();
for (KeyspaceDefinition ksDef : cluster.describeKeyspaces()) {
List<ColumnFamilyDefinition> cfDefList = ksDef.getColumnFamilyList();
System.out.println("there are " + cfDefList.size() + " column families in keyspace " + ksDef.getName());
for (ColumnFamilyDefinition cfDef : cfDefList) System.out.println(" - " + cfDef.getName());
}
它可以列出键空间,但是缺少许多列族。这是输出。可以看到有许多默认键空间,但是缺少许多列族。
there are 0 column families in keyspace system_distributed
there are 3 column families in keyspace system
- hints
- schema_keyspaces
- IndexInfo
there are 2 column families in keyspace system_auth
- role_members
- resource_role_permissons_index
there are 0 column families in keyspace system_traces
我可以使用cqlsh确认列族确实存在
cqlsh> DESCRIBE COLUMNFAMILIES
Keyspace system_traces
----------------------
events sessions
Keyspace system_auth
--------------------
resource_role_permissons_index role_permissions role_members roles
Keyspace system
---------------
available_ranges size_estimates schema_usertypes compactions_in_progress
range_xfers peers paxos schema_aggregates
schema_keyspaces schema_triggers batchlog schema_columnfamilies
schema_columns sstable_activity schema_functions local
"IndexInfo" peer_events compaction_history hints
Keyspace system_distributed
---------------------------
repair_history parent_repair_history
上面的输出使用的是cassandra 2.2,但我已经确认了其他版本的cassandra和scylla的行为。
答案 0 :(得分:5)
节俭已被弃用,默认情况下,Cassandra不再启用节俭。您需要启用它才能使用它。请记住,在下一个版本的Cassandra中甚至不存在。即使启用并使用它,也很可能无法正常工作。不再真正使用它了,没有太多使用它的测试。不同版本之间表的存储和检索方式有所不同,因此驱动程序必须意识到这一点。由于未维护Astyanax,因此可能无法正确处理。
Astyanax已退休,仅适用于较旧的应用程序。您应该真正使用java driver(与Astyanax页面上的建议相同)。
答案 1 :(得分:4)
我记得将Astyanax与Cassandra 0.8.8-1.1和1.2一起使用。曾经有一段时间,我们会将所有数据(列)作为Blob推送到一个分区中(启用更快的写入),然后我们将数据从节俭的胖客户端解析出来(据说Cassandra此时读取速度很慢)。我们必须跟踪模式,然后在对节俭客户端的输出进行反序列化时,我们将根据所有单独列的数据类型进行解析。在引入CQL之后,所有这些都改变了,正如Chris所指出的那样,这是使用c *的推荐方法。
答案 2 :(得分:0)
您尝试了哪个版本的Scylla? Scylla仍支持Thrift(尽管Cassandra不推荐使用)。