Skip to content

Commit

Permalink
Use different compression options for cql and scylladb
Browse files Browse the repository at this point in the history
Signed-off-by: toom <[email protected]>
  • Loading branch information
To-om committed Oct 9, 2024
1 parent 4b7cc43 commit 885456f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private boolean shouldInitializeTable() {
.orElse(true);
}

private static void initializeTable(final CqlSession session, final String keyspaceName, final String tableName, final Configuration configuration) {
protected void initializeTable(final CqlSession session, final String keyspaceName, final String tableName, final Configuration configuration) {
CreateTableWithOptions createTable = createTable(keyspaceName, tableName)
.ifNotExists()
.withPartitionKey(KEY_COLUMN_NAME, DataTypes.BLOB)
Expand All @@ -320,7 +320,7 @@ private static void initializeTable(final CqlSession session, final String keysp
session.execute(createTable.build());
}

private static CreateTableWithOptions compressionOptions(final CreateTableWithOptions createTable,
protected CreateTableWithOptions compressionOptions(final CreateTableWithOptions createTable,
final Configuration configuration) {
if (!configuration.get(CF_COMPRESSION)) {
// No compression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,13 @@ public StoreFeatures getFeatures() {
return this.storeFeatures;
}

protected CQLKeyColumnValueStore createKeyColumnValueStore(final CQLStoreManager storeManager, final String tableName, final Configuration configuration, final Runnable closer) {
return new CQLKeyColumnValueStore(storeManager, tableName, configuration, closer);

Check warning on line 317 in janusgraph-cql/src/main/java/org/janusgraph/diskstorage/cql/CQLStoreManager.java

View check run for this annotation

Codecov / codecov/patch

janusgraph-cql/src/main/java/org/janusgraph/diskstorage/cql/CQLStoreManager.java#L317

Added line #L317 was not covered by tests
}

@Override
public KeyColumnValueStore openDatabase(final String name, final Container metaData) throws BackendException {
return this.openStores.computeIfAbsent(name, n -> new CQLKeyColumnValueStore(this, n, getStorageConfig(), () -> this.openStores.remove(n)));
return this.openStores.computeIfAbsent(name, n -> createKeyColumnValueStore(this, n, getStorageConfig(), () -> this.openStores.remove(n)));

Check warning on line 322 in janusgraph-cql/src/main/java/org/janusgraph/diskstorage/cql/CQLStoreManager.java

View check run for this annotation

Codecov / codecov/patch

janusgraph-cql/src/main/java/org/janusgraph/diskstorage/cql/CQLStoreManager.java#L322

Added line #L322 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 JanusGraph Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.janusgraph.diskstorage.cql;

import com.datastax.oss.driver.api.querybuilder.schema.CreateTableWithOptions;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
import org.janusgraph.diskstorage.configuration.Configuration;

import static org.janusgraph.diskstorage.cql.CQLConfigOptions.CF_COMPRESSION;
import static org.janusgraph.diskstorage.cql.CQLConfigOptions.CF_COMPRESSION_BLOCK_SIZE;
import static org.janusgraph.diskstorage.cql.CQLConfigOptions.CF_COMPRESSION_TYPE;

public class ScyllaKeyColumnValueStore extends CQLKeyColumnValueStore {
/**
* Creates an instance of the {@link ScyllaKeyColumnValueStore} that stores the data in a CQL backed table.
*
* @param storeManager the {@link CQLStoreManager} that maintains the list of {@link CQLKeyColumnValueStore}s
* @param tableName the name of the database table for storing the key/column/values
* @param configuration data used in creating this store
* @param closer callback used to clean up references to this store in the store manager
*/
public ScyllaKeyColumnValueStore(CQLStoreManager storeManager, String tableName, Configuration configuration, Runnable closer) {
super(storeManager, tableName, configuration, closer);
}

@Override
protected CreateTableWithOptions compressionOptions(final CreateTableWithOptions createTable,
final Configuration configuration) {
if (!configuration.get(CF_COMPRESSION)) {
// No compression
return createTable.withNoCompression();
}

String compressionType = configuration.get(CF_COMPRESSION_TYPE);
int chunkLengthInKb = configuration.get(CF_COMPRESSION_BLOCK_SIZE);

return createTable.withOption("compression",
ImmutableMap.of("sstable_compression", compressionType, "chunk_length_kb", chunkLengthInKb));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public ScyllaStoreManager(Configuration configuration) throws BackendException {
public ScyllaStoreManager(Configuration configuration, CQLMutateManyFunctionBuilder mutateManyFunctionBuilder, CQLStoreFeaturesBuilder storeFeaturesBuilder, CQLSessionBuilder sessionBuilder, CQLProgrammaticConfigurationLoaderBuilder baseConfigurationLoaderBuilder) throws BackendException {
super(configuration, mutateManyFunctionBuilder, storeFeaturesBuilder, sessionBuilder, baseConfigurationLoaderBuilder);
}

@Override
protected CQLKeyColumnValueStore createKeyColumnValueStore(final CQLStoreManager storeManager, final String tableName, final Configuration configuration, final Runnable closer) {
return new ScyllaKeyColumnValueStore(storeManager, tableName, configuration, closer);
}
}

0 comments on commit 885456f

Please sign in to comment.