[英]Cassandra: Writes after setting a column to null are lost randomly. Is this a bug, or I am doing something wrong?
@Test
public void testWriteUpdateRead() throws Exception {
Cluster cluster = Cluster.builder()
.addContactPoint("127.0.0.1")
.build();
Session cs = cluster.connect();
cs.execute("DROP KEYSPACE if exists readtest;");
cs.execute("CREATE KEYSPACE readtest WITH replication " +
"= {'class':'SimpleStrategy', 'replication_factor':1};");
cs.execute("create table readtest.sessions(" +
"id text primary key," +
"passwordHash text," +
");");
for (int i = 0; i < 1000; i++) {
String sessionID = UUID.randomUUID().toString();
cs.execute("insert into readtest.sessions (id, passwordHash) values('" + sessionID + "', null)");
cs.execute("update readtest.sessions set passwordHash='" + sessionID + "' where id = '" + sessionID + "' ");
ResultSet rs = cs.execute("select * from readtest.sessions where id = '" + sessionID + "'");
Row row = rs.one();
assertThat("failed ith time=" + i, row.getString("passwordHash"), equalTo(sessionID));
}
cs.close();
cluster.close();
}
上面的测试总是失败,并且总是经过一些随机迭代。 谁能解释为什么有时更新丢失了?
我在本地运行Cassandra,单节点。 在OSX上使用brew安装。
堆栈跟踪:
java.lang.AssertionError: failed ith time=4
Expected: "fd2fb850-b3ad-4bfb-8971-485c4df097dc"
but: was null
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at in.folks.blaze.service.CassandraTest.testWriteUpdateRead(CassandraTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
其他资讯:
Cassandra version: [cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
这似乎是一个问题,在创建行后立即对其进行更新。 如果您要在第二次更新后等待一小段时间,您将获得正确的值,这似乎是个问题,但也许仅在本地运行cassandra时才注意到。
我怀疑这是一个cassandra问题,尽管目前似乎已经在trunk和cassandra-2.1分支上解决了。 我可以针对1.2.19、2.0.11和2.1.2进行复制,但是无法针对trunk或cassandra-2.1进行复制。 我似乎无法根据变更日志查明确切的变更。
EDIT 2014年1月5日:在用户列表上的评论详细说明了可能发生的情况: https : //groups.google.com/a/lists.datastax.com/forum/#!topic / java-driver-用户/ 0IDCz96lAeA 。 显然,当写入的时间戳完全相同时会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.