当前用户访问同一行时,Cassandra行级锁定支持
考虑到Cassandra作为库存数据库,我们处于推车应用的设计阶段.现在的要求是,如果多个用户同时访问Inventory DB中的相同产品行.例如: - 产品表:productID productQuantitiy 1000 1如果第一个用户选择产品"1000"并在购物车中添加产品数量为"1",访问同一产品的其他用户在获得免费之前不应该选择此产品第一个用户(更新的产品数量为0).cassandra也为这种场景提供了行级锁定支持
我需要从文件名中提取扩展名.
我知道这可以用于单个扩展,例如,.gz或者.tar通过使用filePath.lastIndexOf('.')或使用FilenameUtils.getExtension(filePath)来自Apache commons-io的实用程序方法.
但是,如果我有一个扩展名的文件.tar.gz怎么办?如何管理包含.字符的扩展名的文件?
我在我的笔记本电脑上运行了Cassandra 1.2.11.我可以使用nodetool和连接它,cqlsh但当我尝试使用DataStax 1.0.4 Java API使用CQL 3.0进行连接时,我收到以下错误:
com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1 ([localhost/127.0.0.1] Unexpected error during transport initialization (com.datastax.driver.core.TransportException: [localhost/127.0.0.1] Channel has been closed)))
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:186)
Run Code Online (Sandbox Code Playgroud)
我使用以下代码进行连接,取自DataStax文档.我已经尝试了几个端口号,包括离开withPort()呼叫,但似乎没有任何工作.
Cluster cluster = new Cluster.Builder()
.addContactPoints("localhost")
.withPort(9160)
.build();
Run Code Online (Sandbox Code Playgroud)
使用telnet我可以验证Cassandra服务器肯定在我指定的每个端口上监听.我还验证了所有必需的库jar文件都在我的类路径中,如文档中所述.
我一直在查看CQL 3.0 数据建模文档,该文档描述了带有标签的列系列歌曲,如下所示:
CREATE TABLE songs (
id uuid PRIMARY KEY,
title text,
tags set<text>
);
Run Code Online (Sandbox Code Playgroud)
我想获得所有具有特定标签的歌曲的列表,因此我需要添加适当的索引.
我可以title很容易地在列上创建索引,但是如果我尝试索引tags作为集合的列,如下所示:
CREATE INDEX ON songs ( tags );
Run Code Online (Sandbox Code Playgroud)
我从DataStax Java驱动程序1.0.4收到以下错误:
Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Indexes on collections are no yet supported
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:269)
Run Code Online (Sandbox Code Playgroud)
根据JIRA问题CASSANDRA-4511,看起来这可以在更高版本的Cassandra(2.1)中修复.我目前正在使用Apache Cassandra 1.2.11,但不想升级.根据发行CASSANDRA-5615虽然在卡桑德拉1.2.6存在是支持自定义索引的集合.
问题是,唯一可用的文档说明:
Cassandra支持创建自定义索引,该索引供内部使用且超出本文档的范围.
但是,它确实暗示的语法如下:
CREATE CUSTOM INDEX ON songs ( tags ) USING 'class_name';
Run Code Online (Sandbox Code Playgroud)
什么是class_name …