[
https://issues.apache.org/jira/browse/CASSANDRA-6152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13793025#comment-13793025
]
Donald Smith commented on CASSANDRA-6152:
-----------------------------------------
I found a *simple* example of the bug.
If I insert an empty string ("") into the table it causes the AssertionError.
If I insert a non-empty string there's no AssertionError!
{noformat}
create keyspace if not exists bug with replication = {'class':'SimpleStrategy',
'replication_factor':1};
create table if not exists bug.bug_table ( -- compact; column values are
ordered by item_name
report_id uuid,
item_name text,
item_value text,
primary key (report_id, item_name)) with compact storage;
}
{noformat}
BugMain.java:
{noformat}
package bug;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class BugMain {
private static String CASSANDRA_HOST =
System.getProperty("cassandraServer","172.17.1.169");
//"donalds01lx.uscorp.audsci.com";
private static BugInterface dao = new BugImpl(CASSANDRA_HOST);
public static void bug() throws IOException {
List<BugItem> items = new ArrayList<BugItem>();
items.add(new BugItem("",1,2,3)); // if you change the empty string
"" to a non-empty string, the AssertionError goes away!
items.add(new BugItem("twp",2,2,3));
items.add(new BugItem("three",3,2,3));
items.add(new BugItem("four",4,2,3));
dao.saveReport(items);
}
public static void main(String [] args) throws IOException {
try {
for(int i=0;i<1000;i++) {
System.out.println("\ndas: iteration " + i + "\n");
bug();
}
} finally {
dao.shutdown();
}
}
}
{noformat}
BugItem.java:
{noformat}
package bug;
public class BugItem {
public String name;
public long long1;
public long long2;
public long long3;
public BugItem(String string, long i, long j, long k) {
name=string;
long1 = i;
long2= j;
long3 = k;
}
public String toString() {return "Item with name = " + name + ", long1 = "
+ long1 + ", long2 = " + long2 + ", long3 = " + long3;}
}
{noformat}
BugInterface.java:
{noformat}
package bug;
import java.util.List;
public interface BugInterface {
public static final String VALUE_DELIMITER = ":";
public static final String HIERARCHY_DELIMITER = " > ";
void saveReport(List<BugItem> item);
void connect();
void shutdown();
}
{noformat}
BugImpl.java:
{noformat}
package bug;
import java.text.NumberFormat;
import java.util.List;
import java.util.UUID;
import org.apache.log4j.Logger;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.Insert;
import com.datastax.driver.core.querybuilder.QueryBuilder;
public class BugImpl implements BugInterface {
private static final String CASSANDRA_NODE_PROPERTY="CASSANDRA_NODE";
private static final Logger L = Logger.getLogger(new Throwable()
.getStackTrace()[0].getClassName());
private static final String KEYSPACE_NAME = "bug";
private static final String REPORT_DATA_TABLE_NAME = "bug_table";
private static NumberFormat numberFormat = NumberFormat.getInstance();
private Cluster m_cluster;
private Session m_session;
private int m_writeBatchSize = 64;
private String m_cassandraNode = "<your cassandra hostname here>";
static {
numberFormat.setMaximumFractionDigits(1);
}
public BugImpl() {
m_cassandraNode=System.getProperty(CASSANDRA_NODE_PROPERTY,
m_cassandraNode); // Get from command line
}
public BugImpl(String cassandraNode) {
m_cassandraNode=cassandraNode;
}
@Override
public void shutdown() {
if (m_session!=null) {m_session.shutdown();}
if (m_cluster!=null) {m_cluster.shutdown();}
}
@Override
public void connect() {
m_cluster =
Cluster.builder().addContactPoint(m_cassandraNode).build();
m_session = m_cluster.connect();
}
//
---------------------------------------------------------------------------------
@Override
public void saveReport(List<BugItem> items) {
final long time1 = System.currentTimeMillis();
if (m_session==null) {
connect();
}
UUID reportId = UUID.randomUUID();
saveReportAux(items,reportId);
final long time2 = System.currentTimeMillis();
L.info("saveReport: t=" +
numberFormat.format((double)(time2-time1) * 0.001) + " seconds");
}
public void saveReportAux(List<BugItem> items, UUID reportId) {
int index = 0;
int reportSize = items.size();
int maxBatchedIndex = (int) (reportSize / m_writeBatchSize) *
m_writeBatchSize;
// prepare the batch statement
final StringBuilder sb = new StringBuilder();
sb.append("BEGIN UNLOGGED BATCH ");
for (int i = 0; i < m_writeBatchSize; i++) {
sb.append("insert into " + KEYSPACE_NAME + "."
+ REPORT_DATA_TABLE_NAME
+ " (report_id, item_name, item_value)
values (" + reportId
+ ",?,?);");
}
sb.append("APPLY BATCH;");
PreparedStatement insertBatchPrep =
m_session.prepare(sb.toString());
// prepare the single-insert statement for "the rest" that does
not fit
// in a whole batch
final Insert writeReportData = QueryBuilder
.insertInto(KEYSPACE_NAME,
REPORT_DATA_TABLE_NAME)
.value("report_id", reportId)
.value("item_name", QueryBuilder.bindMarker())
.value("item_value", QueryBuilder.bindMarker());
final PreparedStatement writeReportDataPrep = m_session
.prepare(writeReportData);
// write the rows
Object[] args = new Object[2 * m_writeBatchSize];
int batchIndex = 0;
int argsIndex = 0;
for (final BugItem item : items) {
if (index < maxBatchedIndex) {
args[argsIndex++] = item.name;
args[argsIndex++] = item.long1 + VALUE_DELIMITER
+ item.long2 + VALUE_DELIMITER
+ item.long3;
batchIndex++;
if (batchIndex == m_writeBatchSize) {
argsIndex = 0;
batchIndex = 0;
m_session.execute(insertBatchPrep.bind(args));
}
} else {
m_session.execute(writeReportDataPrep.bind(item.name,
item.long1 + VALUE_DELIMITER +
item.long2 + VALUE_DELIMITER + item.long3));
}
index++;
}
}
public void setWriteBatchSize(int size) {m_writeBatchSize=size;}
public void setCassandraNode(String node) {m_cassandraNode=node;}
}
{noformat}
> Assertion error in 2.0.1 at
> db.ColumnSerializer.serialize(ColumnSerializer.java:56)
> -----------------------------------------------------------------------------------
>
> Key: CASSANDRA-6152
> URL: https://issues.apache.org/jira/browse/CASSANDRA-6152
> Project: Cassandra
> Issue Type: Bug
> Components: Core
> Environment: CentOS release 6.2 (Final)
> With default set up on single node.
> I also saw this exception in 2.0.0 on a three node cluster.
> Reporter: Donald Smith
>
> {noformat}
> ERROR [COMMIT-LOG-WRITER] 2013-10-06 12:12:36,845 CassandraDaemon.java (line
> 185) Exception in thread Thread[COMMIT-LOG-WRITER,5,main]
> java.lang.AssertionError
> at
> org.apache.cassandra.db.ColumnSerializer.serialize(ColumnSerializer.java:56)
> at
> org.apache.cassandra.db.ColumnFamilySerializer.serialize(ColumnFamilySerializer.java:77)
> at
> org.apache.cassandra.db.RowMutation$RowMutationSerializer.serialize(RowMutation.java:268)
> at
> org.apache.cassandra.db.commitlog.CommitLogSegment.write(CommitLogSegment.java:229)
> at
> org.apache.cassandra.db.commitlog.CommitLog$LogRecordAdder.run(CommitLog.java:352)
> at
> org.apache.cassandra.db.commitlog.PeriodicCommitLogExecutorService$1.runMayThrow(PeriodicCommitLogExecutorService.java:48)
> at
> org.apache.cassandra.utils.WrappedRunnable.run(WrappedRunnable.java:28)
> at java.lang.Thread.run(Thread.java:722)
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.1#6144)