我最近开始使用Cassandra数据库.现在我正在评估Cassandra client我们应该推进哪些方面.
我已经在stackoverflow上看到关于哪个客户端用于Cassandra的各种帖子,但没有一个有非常确定的答案.
我的团队已经让我对此进行一些研究,并pros and cons为Cassandra Client API’sJava中的每一个做出一定的研究.
正如我所提到的,我最近参与其中,Cassandra所以没有那么多想法为什么某些人选择Pelops client以及为什么某些人和Astyanax其他客户一起去.
我知道每个Cassandra客户的简短介绍,我的意思是我能够完成这项工作并开始阅读和写入Cassandra数据库.
以下是我到目前为止的信息.
CASSANDRA APIS
Hector(Production-Ready)
最稳定的Java API,为黄金时段做好准备.
Astyanax(The Up and Comer)
来自Netflix的干净Java API.它没有Hector广泛使用,但它是坚实的.
符合JPA标准的Kundera(NoSQL ORM),当您想通过对象与Cassandra进行交互时,这很方便.
这在一定程度上限制了您将无法拥有动态数量的列/名称等.但它确实允许您移植到ORM,或将存储集中到Cassandra以获得更多传统用途.
Pelops
我只是简单地使用了Pelops.这是一个直接的API,但似乎没有它背后的动力.
PlayORM(没有约束的ORM?)
我刚才听说过这个.看起来它试图通过引入JQL来解决传统的基于JPA的ORM和NoSQL之间的阻抗不匹配问题.看起来很有希望.
节俭(避免我!)
这是"低级"API.
以下是我们决定的优先事项Cassandra Client-
任何人都可以对此提出一些想法吗?此外,每个Cassandra Client客户都可以满足我的要求的任何利弊也将有很大的帮助.
我相信,主要是我将围绕着Astyanax client or New Datastax client that uses Binary protocol我的研究基础到目前为止.但是没有某些信息可以支持我的研究并将其呈现给我的团队.
Astyanax客户端和New Datastax客户端(使用新的二进制协议)之间的任何比较都将有很大帮助.
这对我的研究有很大的帮助,并且会从过去使用不同客户的不同人那里获得很多相关知识.
我最近在php和play框架上实现了非常小的cassandra web应用程序来比较这些技术.我在一台有ubuntu-server的虚拟机上运行这些测试.在php和play框架应用程序中,只有一个url可以插入cassandra键空间.
在php中,我运行了以下apache基准测试;
ab -n 100000 -c 100 http://mydomain.com/insert
测试结果显示服务器可以服务120#/ sec(每秒请求数)
我使用netflix的astyanax cassandra库在play框架中创建了几乎相同的应用程序.然而,即使在开始时服务器似乎也很糟糕ab.
我正在生产中通过play start终端命令进行游戏框架测试.
所以,我知道play框架已经准备就绪了.那么,我在这里做错了什么?
我是astyanax的新手并尝试了一些示例程序并收到此错误.这是一个简单的写法,看起来像是在做一些基本错误的事情.不使用复合键.
Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:20833)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:964)
at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:950)
at com.netflix.astyanax.thrift.ThriftKeyspaceImpl$1$1.internalExecute(ThriftKeyspaceImpl.java:120)
at com.netflix.astyanax.thrift.ThriftKeyspaceImpl$1$1.internalExecute(ThriftKeyspaceImpl.java:117)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:56)
Run Code Online (Sandbox Code Playgroud)
这是代码:
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster(CLUSTER_NAME)
.forKeyspace(keySpaceName)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2")
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(50825)
.setMaxConnsPerHost(10)
.setSeeds("nodename:50825")
.setConnectTimeout(20000)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
System.out.println("getting context.. done ");
Keyspace keyspace = context.getEntity();
MutationBatch m = keyspace.prepareMutationBatch();
ColumnFamily<String, String> colFam = new ColumnFamily<String, String>("test",
StringSerializer.get(), StringSerializer.get());
m.withRow(colFam, "abc")
.putColumn("col2", "test1", null);
m.execute();
Run Code Online (Sandbox Code Playgroud)
这是表格描述的:
CREATE …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用astyanax连接到本地cassandra,但不断获取PoolTimeoutException.我可以使用cli或hector客户端连接到cassandra.知道我做错了什么吗?
谢谢.
我的代码:
val context = new AstyanaxContext.Builder()
.forCluster("cluster")
.forKeyspace(keyspace)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.NONE)
)
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("ConnPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setMaxBlockedThreadsPerHost(1)
.setSeeds("127.0.0.1:9160")
.setConnectTimeout(10000)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance())
context.start()
return context.getEntity()
Run Code Online (Sandbox Code Playgroud)
例外:
Exception in thread "main" java.lang.RuntimeException: com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=127.0.0.1(127.0.0.1):9160, latency=10004(10004), attempts=1] Timed out waiting for connection
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$7.getNextBlock(ThriftColumnFamilyQueryImpl.java:652)
at com.netflix.astyanax.thrift.ThriftAllRowsImpl$1.hasNext(ThriftAllRowsImpl.java:61)
at scala.collection.JavaConversions$JIteratorWrapper.hasNext(JavaConversions.scala:574)
at scala.collection.Iterator$class.foreach(Iterator.scala:772)
at scala.collection.JavaConversions$JIteratorWrapper.foreach(JavaConversions.scala:573)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:73)
at scala.collection.JavaConversions$JIterableWrapper.foreach(JavaConversions.scala:587)
at at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at Caused by: …Run Code Online (Sandbox Code Playgroud) Astyanax是否通过CQL3准备好的声明支持"插入"?我使用最新的Astyanax库1.56.24和Cassandra 1.2.1.当我尝试使用CQL3执行预准备语句时:
keyspace.prepareQuery(conn.CF_CONTACTS)
.withCql("INSERT INTO contacts (a, b) VALUES (?, ?);")
.asPreparedStatement()
.withStringValue("123")
.withStringValue("456")
.execute();;
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
Caused by: InvalidRequestException(why:Cannot execute/prepare CQL2 statement since the CQL has been set to CQL3(This might mean your client hasn't been upgraded correctly to use the new CQL3 methods introduced in Cassandra 1.2+).)
at org.apache.cassandra.thrift.Cassandra$prepare_cql_query_result.read(Cassandra.java:38738)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_prepare_cql_query(Cassandra.java:1598)
at org.apache.cassandra.thrift.Cassandra$Client.prepare_cql_query(Cassandra.java:1584)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$6$3$1.internalExecute(ThriftColumnFamilyQueryImpl.java:747)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$6$3$1.internalExecute(ThriftColumnFamilyQueryImpl.java:742)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:56)
Run Code Online (Sandbox Code Playgroud) 背景
Astyanax的Entity Persister将实体地图保存在多个列中.格式为mapVariable.key
问题:
当实体中的地图更新时,astyanax的Entity Persister不会从cassandra中删除已删除的键/值对
我正在使用的解决方案(糟糕的方法)
我正在删除整行,然后重新插入它
更多信息
我使用astyanax的Entity Persister(com.netflix.astyanax.entitystore)将我的java对象保存在cassandra中.
我注意到的是,当一个实体的地图被持久化时,例如,2个值:testkey:testvalue&testkey2:testvalue2,并且下一次相同的实体地图被持有一个值(一个键/值对被删除) :testkey:testvalue,testkey2:testvalue2未从列系列中删除.
因此,作为解决方法,我需要删除整行然后重新插入它.
我的插入代码:
final EntityManager<T, String> entityManager = new DefaultEntityManager.Builder<T, String>()
.withEntityType(clazz)
.withKeyspace(getKeyspace())
.withColumnFamily(columnFamily)
.build();
entityManager.put(entity);
Run Code Online (Sandbox Code Playgroud)
我错过了什么?这是非常低效的,我认为astyanax的实体persister应该自己解决这个问题.
有什么想法吗?
我正在尝试从具有双类型列的Cassandra表中获取Double值.我用CQL3语法创建了表:
CREATE TABLE data_double (
datetime timestamp,
value double,
primary key (datetime)
);
Run Code Online (Sandbox Code Playgroud)
我插了一行:
INSERT INTO data_double (datetime, value) VALUES ('111111111', 123.456);
Run Code Online (Sandbox Code Playgroud)
当我做:
SELECT * from data_double;
Run Code Online (Sandbox Code Playgroud)
我知道这个值是123.46
为什么价值四舍五入?
谢谢
我有一个奇怪的问题.我的java应用程序通过astyanax将列放入cassandra.这似乎是暂时的,但是几个小时之后,如果我通过[row] [复合列],那么该列似乎就会消失.如果我获取整行,或者获取应该包含该列的一系列列,则返回该列.此行为发生在多个客户端,包括cassandra-cli和pycassa.例如:
get msg_metadata['someKey'];
=> (column=185779:completed, value={"timestamp":"1407777081","id":"167727"}, timestamp=1407777083241001)
Returned 1 results.
Elapsed time: 58 msec(s)
get msg_metadata['someKey']['185779:completed'];
=> (column=185779:completed, value={"timestamp":"1407777081","id":"167727"}, timestamp=1407777083241001)
Returned 1 results.
Elapsed time: 42 msec(s)
-- several hours later
get msg_metadata['someKey']['185779:completed'];
Value was not found
Elapsed time: 72 msec(s).
get msg_metadata['someKey'];
=> (column=185779:completed, value={"timestamp":"1407777081","id":"167727"}, timestamp=1407777083241001)
Returned 1 results.
Elapsed time: 107 msec(s)
Run Code Online (Sandbox Code Playgroud)
我在Cassandra 1.1.12集群中创建了以下列族:
create column family msg_metadata
with column_type = 'Standard'
and comparator = 'CompositeType(org.apache.cassandra.db.marshal.IntegerType,org.apache.cassandra.db.marshal.AsciiType)'
and default_validation_class = 'UTF8Type'
and key_validation_class = …Run Code Online (Sandbox Code Playgroud)