Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-19747

Invalid schema.cql created by snapshot after dropping more than one field

    XMLWordPrintableJSON

Details

    Description

      After dropping at least 2 fields the schema.cql produced by nodetool snapshot is invalid (it is missing a comma)

      CREATE TABLE IF NOT EXISTS test.testtable (
          field1 text PRIMARY KEY,
          field2 text
          field3 text
      ) WITH ID ...

      expected outcome

      CREATE TABLE IF NOT EXISTS test.testtable (
          field1 text PRIMARY KEY,
          field2 text,
          field3 text
      ) WITH ID ...

      reproducing the isue is simple by running the following commands

      docker run -d --name cassandra cassandra:4.1.5
      
      echo "Wait for the container to start"
      until docker exec -ti cassandra nodetool status | grep UN;do sleep 1;done;sleep 10
      
      echo "Create keyspace and table for test"
      docker exec -ti cassandra cqlsh -e "CREATE KEYSPACE IF NOT EXISTS test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}; CREATE TABLE IF NOT EXISTS test.testtable (field1 text PRIMARY KEY,field2 text,field3 text);"
      
      echo "Drop 2 fields"
      docker exec -ti cassandra cqlsh -e "ALTER TABLE test.testtable DROP (field2, field3);"
      
      echo "Create snapshot and view schema.cql"
      docker exec -ti cassandra /opt/cassandra/bin/nodetool snapshot -t my_snapshot
      docker exec -ti cassandra find /var/lib/cassandra/data -name schema.cql  -exec cat {} +   

      the full output of the sql generated by the reproduce is below

      CREATE TABLE IF NOT EXISTS test.testtable (
          field1 text PRIMARY KEY,
          field2 text
          field3 text
      ) WITH ID = 0e9aa540-391f-11ef-945e-0be1221ff441
          AND additional_write_policy = '99p'
          AND bloom_filter_fp_chance = 0.01
          AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
          AND cdc = false
          AND comment = ''
          AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
          AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
          AND memtable = 'default'
          AND crc_check_chance = 1.0
          AND default_time_to_live = 0
          AND extensions = {}
          AND gc_grace_seconds = 864000
          AND max_index_interval = 2048
          AND memtable_flush_period_in_ms = 0
          AND min_index_interval = 128
          AND read_repair = 'BLOCKING'
          AND speculative_retry = '99p';
      ALTER TABLE test.testtable DROP field2 USING TIMESTAMP 1719999102807000;
      ALTER TABLE test.testtable DROP field3 USING TIMESTAMP 1719999102807001;
      

      Found this bug while trying to restore the schema from a backup created by copying a snapshot from a running node.

      Attachments

        Activity

          People

            smiklosovic Stefan Miklosovic
            fvissing Frank vissing
            Stefan Miklosovic
            Benjamin Lerer, Francisco Guerrero
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m