cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benyi Wang (JIRA)" <>
Subject [jira] [Commented] (CASSANDRA-7768) Error when creating multiple CQLSSTableWriters for more than one column family in the same keyspace
Date Sat, 27 Dec 2014 22:49:14 GMT


Benyi Wang commented on CASSANDRA-7768:

I encounter this problem in cassandra-all.2.1.2 if you write two column families of the same
keyspace in one JVM. The following code can reproduce the error. 

package org.apache.cassandra.hadoop.cql3;

import java.lang.reflect.Field;
import java.util.concurrent.ScheduledExecutorService;

import org.apache.cassandra.config.Config;
import org.apache.cassandra.cql3.QueryProcessor;

public class TWriter2 {

	public static void main(String[] args) {
		String schema = "create table mgindex.test (x int primary key, y int)";
		String insert = "insert into mgindex.test (x,y) values(?,?)";

		String schema1 = "create table mgindex.test1 (x int primary key, y int)";
		String insert1 = "insert into mgindex.test1 (x,y) values(?,?)";


		try {
			CQLSSTableWriter w = CQLSSTableWriter.builder()
			w.addRow(1, 1);

			CQLSSTableWriter w1 = CQLSSTableWriter.builder()
			w1.addRow(4, 4);
		} catch (Exception e) {


You will see this exception when the second {{forTable}} is called.

Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.apache.cassandra.hadoop.cql3.TWriter2.main(
Caused by: java.lang.NullPointerException
	at org.apache.cassandra.config.DatabaseDescriptor.createAllDirectories(
	at org.apache.cassandra.db.Keyspace.<clinit>(
	... 2 more

Here is how the code fails for the second column family:
# For the first column family: ksm is null, and it will work correctly
# For the second column family: ksm is not null, it goes into the second branch to check if
the table exists. If not, load the this.schema into Schema.instance. 

                    // We need to register the keyspace/table metadata through Schema, otherwise
we won't be able to properly
                    // build the insert statement in using().
                    KSMetaData ksm = Schema.instance.getKSMetaData(this.schema.ksName);
                    if (ksm == null)
                        ksm = KSMetaData.newKeyspace(this.schema.ksName,
                                ImmutableMap.of("replication_factor", "1"),
                    else if (Schema.instance.getCFMetaData(this.schema.ksName, this.schema.cfName)
== null)
                        ksm = KSMetaData.cloneWith(ksm, Iterables.concat(ksm.cfMetaData().values(),
              , this.schema.cfName,
                    return this;

The problem happens when Keyspace class is initialized at {{}}, 

        if (!StorageService.instance.isClientMode())

At this time, StorageService is not in client mode, and createAllDirectories will fail because
conf.data_file_directories is null.

I'm not quite sure why {{}} is needed. When I comment out this line, everything
seems working.

Could you reopen this jira and fix it?

> Error when creating multiple CQLSSTableWriters for more than one column family in the
same keyspace
> ---------------------------------------------------------------------------------------------------
>                 Key: CASSANDRA-7768
>                 URL:
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Hadoop
>            Reporter: Paul Pak
>            Assignee: Paul Pak
>            Priority: Minor
>              Labels: cql3, hadoop
>         Attachments: trunk-7768-v1.txt
> The reason why this occurs is if the keyspace has already been loaded (due to another
column family being previously loaded in the same keyspace), CQLSSTableWriter builder only
loads the column family via Schema.load(CFMetaData). However, Schema.load(CFMetaData) only
adds to the Schema.cfIdMap without making the proper addition to the CFMetaData map belonging
to the KSMetaData map.

This message was sent by Atlassian JIRA

View raw message