Search code examples
javacassandraastyanax

How can I set GCGraceSeconds in Cassandra using astyanax?


I need to set GCGraceSeconds to 0, because I have only one node, but I cannot find where I can set value to this. Is it possible to set from astyanax or is it in some settings file?


Solution

  • In more recent versions of cassandra, you actually set gc_grace_seconds on a per column family basis as part of the schema. From what I can tell, Astyanax currently doesn't support setting that property. There is no corresponding method in the ColumnFamilyDefinition class.

    https://github.com/Netflix/astyanax/blob/master/src/main/java/com/netflix/astyanax/ddl/ColumnFamilyDefinition.java

    You can use the cassandra-cli tool to set the property on any existing column families if you wish.

    Additionally, it doesn't look like it would be too hard to add support to Astyanax. I'm sure they would accept a pull request.

    Update

    Astyanax (for a while) now supports this setting. See ColumnFamilyDefinition. This can be set in the astyanax column family creation like so:

    OperationResult<SchemaChangeResult> opres = keyspace.createColumnFamily(cf, ImmutableMap.<String, Object> builder()
        .put("comparator", "UTF8Type")
        .put("key_validation_class", "UTF8Type")
        .put("gc_grace_seconds", 60*60*24) // gc grace seconds of one day
        .build()
    );