Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

arnulf.hanauer_193730 avatar image
arnulf.hanauer_193730 asked ·

Cannot re-add previously dropped column

After running an ALTER TABLE DROP <column_name>, I am unable to re-add the same column_name at a later date.

Are column_names not reusable ever?

Can you please confirm the process/conditions required to re-use a column name with or without a TYPE change as well.

I have run nodetool upgradesstables <ks> as well as nodetool compact <ks> <tbl> which is supposed to remove the tombstone information which I was under the impression is holding up the re-usability or do I need to force gc_grace_seconds before the compaction.

Full error message from CQL is

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot re-add previously dropped column ...
cql
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

It is not possible add a column with the same name as a column that was previously dropped from a table. There is no condition where this is possible, even when no data has been inserted into the table yet.

Background

The Cassandra storage engine was completely refactored in 3.0 (CASSANDRA-8099).

As part of the refactoring, the SerializationHeader class only retrieves the column names from the metadata (see SerializationHeader.toHeader() method in C* 3.0.21) and ignores the kinds of columns they are, i.e. regular or static. If a column's kind is changed via ALTER TABLE ... DROP then eventually ADD, the header could be interpreted incorrectly and may lead to CorruptSSTableException or data corruption (CASSANDRA-14843).

Prevention

The proposed solution to the problem described above is to store additional metadata about the dropped columns but it is only planned to be implemented in a future major version.

The workaround in C* 3.x is to simply prevent columns from being added back to a table after it has been dropped (CASSANDRA-14948). This improvement completely prevents DBAs from re-using column names in a table.

Suggestion

If you really must use the same name, I would recommend adding a suffix like "v2" so the new column name is of the form columnname_v2. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.