Skip to content

Commit a49d8e0

Browse files
To-omporunov
authored andcommitted
Replace deprecated compression options in cql
Signed-off-by: toom <thomas@strangebee.com>
1 parent c92b10e commit a49d8e0

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

docs/configs/janusgraph-cfg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ CQL storage backend options
473473
| storage.cql.compaction-strategy-options | Compaction strategy options. This list is interpreted as a map. It must have an even number of elements in [key,val,key,val,...] form. | String[] | (no default value) | FIXED |
474474
| storage.cql.compression | Whether the storage backend should use compression when storing the data | Boolean | true | FIXED |
475475
| storage.cql.compression-block-size | The size of the compression blocks in kilobytes | Integer | 64 | FIXED |
476-
| storage.cql.compression-type | The sstable_compression value JanusGraph uses when creating column families. This accepts any value allowed by Cassandra's sstable_compression option. Leave this unset to disable sstable_compression on JanusGraph-created CFs. | String | LZ4Compressor | MASKABLE |
476+
| storage.cql.compression-type | The compression class value JanusGraph uses when creating column families. This accepts any value allowed by Cassandra's compression class option. Leave this unset to disable compression on JanusGraph-created CFs. | String | LZ4Compressor | MASKABLE |
477477
| storage.cql.gc-grace-seconds | The number of seconds before tombstones (deletion markers) are eligible for garbage-collection. | Integer | (no default value) | FIXED |
478478
| storage.cql.heartbeat-interval | The connection heartbeat interval in milliseconds. | Long | (no default value) | MASKABLE |
479479
| storage.cql.heartbeat-timeout | How long the driver waits for the response (in milliseconds) to a heartbeat. | Long | (no default value) | MASKABLE |

janusgraph-cql/src/main/java/org/janusgraph/diskstorage/cql/CQLConfigOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ public interface CQLConfigOptions {
178178
ConfigOption<String> CF_COMPRESSION_TYPE = new ConfigOption<>(
179179
CQL_NS,
180180
"compression-type",
181-
"The sstable_compression value JanusGraph uses when creating column families. " +
182-
"This accepts any value allowed by Cassandra's sstable_compression option. " +
183-
"Leave this unset to disable sstable_compression on JanusGraph-created CFs.",
181+
"The compression class value JanusGraph uses when creating column families. " +
182+
"This accepts any value allowed by Cassandra's compression class option. " +
183+
"Leave this unset to disable compression on JanusGraph-created CFs.",
184184
ConfigOption.Type.MASKABLE,
185185
"LZ4Compressor");
186186

janusgraph-cql/src/main/java/org/janusgraph/diskstorage/cql/CQLKeyColumnValueStore.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.datastax.oss.driver.api.core.cql.BoundStatement;
2222
import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder;
2323
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
24+
import com.datastax.oss.driver.api.core.cql.ResultSet;
2425
import com.datastax.oss.driver.api.core.cql.Row;
2526
import com.datastax.oss.driver.api.core.metadata.TokenMap;
2627
import com.datastax.oss.driver.api.core.servererrors.QueryValidationException;
@@ -305,33 +306,51 @@ private boolean shouldInitializeTable() {
305306
.orElse(true);
306307
}
307308

309+
private static int getCassandraMajorVersion(final CqlSession session) {
310+
try {
311+
ResultSet rs = session.execute("SELECT release_version FROM system.local");
312+
Row row = rs.one();
313+
String version = row.getString("release_version");
314+
return Integer.parseInt(version.split("\\.")[0]);
315+
} catch (final Exception e) {
316+
return 0;
317+
}
318+
}
319+
308320
private static void initializeTable(final CqlSession session, final String keyspaceName, final String tableName, final Configuration configuration) {
321+
int cassandraMajorVersion = getCassandraMajorVersion(session);
309322
CreateTableWithOptions createTable = createTable(keyspaceName, tableName)
310323
.ifNotExists()
311324
.withPartitionKey(KEY_COLUMN_NAME, DataTypes.BLOB)
312325
.withClusteringColumn(COLUMN_COLUMN_NAME, DataTypes.BLOB)
313326
.withColumn(VALUE_COLUMN_NAME, DataTypes.BLOB);
314327

315328
createTable = compactionOptions(createTable, configuration);
316-
createTable = compressionOptions(createTable, configuration);
329+
createTable = compressionOptions(createTable, configuration, cassandraMajorVersion);
317330
createTable = gcGraceSeconds(createTable, configuration);
318331
createTable = speculativeRetryOptions(createTable, configuration);
319332

320333
session.execute(createTable.build());
321334
}
322335

323336
private static CreateTableWithOptions compressionOptions(final CreateTableWithOptions createTable,
324-
final Configuration configuration) {
337+
final Configuration configuration,
338+
final int cassandraMajorVersion) {
325339
if (!configuration.get(CF_COMPRESSION)) {
326340
// No compression
327341
return createTable.withNoCompression();
328342
}
329343

330344
String compressionType = configuration.get(CF_COMPRESSION_TYPE);
331345
int chunkLengthInKb = configuration.get(CF_COMPRESSION_BLOCK_SIZE);
346+
Map<String, Object> options;
347+
348+
if (cassandraMajorVersion >= 5)
349+
options = ImmutableMap.of("class", compressionType, "chunk_length_in_kb", chunkLengthInKb);
350+
else
351+
options = ImmutableMap.of("sstable_compression", compressionType, "chunk_length_kb", chunkLengthInKb);
332352

333-
return createTable.withOption("compression",
334-
ImmutableMap.of("sstable_compression", compressionType, "chunk_length_kb", chunkLengthInKb));
353+
return createTable.withOption("compression", options);
335354
}
336355

337356
static CreateTableWithOptions compactionOptions(final CreateTableWithOptions createTable,

0 commit comments

Comments
 (0)