It's the previous value. I've checked.
Groets, Hugo.
On 20 jul 2010, at 00:19, Aaron Morton wrote:
When the test fails what value does the verify array have ? Is it
null or a previous value?
Aaron
On 20 Jul, 2010,at 08:22 AM, Hugo wrote:
See my test case attached below. In my setup it usually fails
around the 800th try...
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import me.prettyprint.cassandra.service.CassandraClient;
import me.prettyprint.cassandra.service.CassandraClientPool;
import me.prettyprint.cassandra.service.CassandraClientPoolFactory;
import me.prettyprint.cassandra.service.Keyspace;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnOrSuperColumn;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.Mutation;
import org.apache.cassandra.thrift.SlicePredicate;
import org.apache.cassandra.thrift.SuperColumn;
import org.junit.Assert;
import org.junit.Test;
public final class ConsistencyTest
{
private static String HOST = "localhost";
private static int PORT = 9160;
private static String KEYSPACE = "Keyspace1";
private static String FAMILY = "Super1";
private static String ROW_KEY = "key";
private static byte[] SUPER_COLUMN = "super".getBytes();
private static byte[] SUB_COLUMN = "sub".getBytes();
private void write(CassandraClientPool aPool, byte[] aValue)
throws Exception
{
CassandraClient client = aPool.borrowClient(HOST, PORT);
final Keyspace keyspace = client.getKeyspace(KEYSPACE);
final List columnList = new ArrayList();
columnList.add(new Column(SUB_COLUMN, aValue,
keyspace.createTimestamp()));
final SuperColumn superColumn = new SuperColumn
(SUPER_COLUMN, columnList);
final ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setSuper_column(superColumn);
final Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cosc);
final List mutations = new ArrayList();
mutations.add(mutation);
final Map> familyBatch =
new HashMap>();
familyBatch.put(FAMILY, mutations);
final Map>> batch =
new HashMap>>();
batch.put(ROW_KEY, familyBatch);
try
{
keyspace.batchMutate(batch);
client = keyspace.getClient();
}
finally
{
aPool.releaseClient(client);
}
}
private byte[] read(CassandraClientPool aPool)
throws Exception
{
CassandraClient client = aPool.borrowClient(HOST, PORT);
final Keyspace keyspace = client.getKeyspace(KEYSPACE);
final List columnNames = new ArrayList();
columnNames.add(SUPER_COLUMN);
final SlicePredicate predicate = new SlicePredicate();
predicate.setColumn_names(columnNames);
final List result;
try
{
result = keyspace.getSuperSlice(ROW_KEY, new
ColumnParent(FAMILY), predicate);
client = keyspace.getClient();
}
finally
{
aPool.releaseClient(client);
}
// never mind the inefficiency
for (SuperColumn superColumn : result)
{
for (Column column : superColumn.getColumns())
{
if (Arrays.equals(superColumn.getName(),
SUPER_COLUMN)
&& Arrays.equals(column.getName(), SUB_COLUMN))
{
return column.getValue();
}
}
}
return null;
}
@Test
public void testConsistency()
throws Exception
{
final CassandraClientPool pool =
CassandraClientPoolFactory.INSTANCE.get();
for (int i = 0; (i < 1000); ++i)
{
final byte[] value = new byte[1];
new Random().nextBytes(value);
write(pool, value);
final byte[] verify = read(pool);
Assert.assertArrayEquals("failed on attempt " + (i +
1), value, verify);
}
}
}
On 7/19/2010 9:26 PM, Ran Tavory wrote:
if your test case is correct then it sounds like a bug to me. With
one node, unless you're writing with CL=0 you should get full
consistency.
On Mon, Jul 19, 2010 at 10:14 PM, Hugo wrote:
Hi,
Being fairly new to Cassandra I have a question on the eventual
consistency. I'm currently performing experiments with a single-
node Cassandra system and a single client. In some of my tests I
perform an update to an existing subcolumn in a row and
subsequently read it back from the same thread. More often than
not I get back the value I've written (and expected), but
sometimes it can occur that I get back the old value of the
subcolumn. Is this a bug or does it fall into the eventual
consistency?
I'm using Hector 0.6.0-14 on Cass