use of org.apache.cassandra.config.CFMetaData in project titan by thinkaurelius.
the class CassandraEmbeddedStoreManager method ensureColumnFamilyExists.
private void ensureColumnFamilyExists(String keyspaceName, String columnfamilyName, AbstractType<?> comparator) throws BackendException {
if (null != Schema.instance.getCFMetaData(keyspaceName, columnfamilyName))
return;
// Column Family not found; create it
CFMetaData cfm = new CFMetaData(keyspaceName, columnfamilyName, ColumnFamilyType.Standard, CellNames.fromAbstractType(comparator, true));
// Hard-coded caching settings
if (columnfamilyName.startsWith(Backend.EDGESTORE_NAME)) {
cfm.caching(CachingOptions.KEYS_ONLY);
} else if (columnfamilyName.startsWith(Backend.INDEXSTORE_NAME)) {
cfm.caching(CachingOptions.ROWS_ONLY);
}
// Configure sstable compression
final CompressionParameters cp;
if (compressionEnabled) {
try {
cp = new CompressionParameters(compressionClass, compressionChunkSizeKB * 1024, Collections.<String, String>emptyMap());
// CompressionParameters doesn't override toString(), so be explicit
log.debug("Creating CF {}: setting {}={} and {}={} on {}", new Object[] { columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION, compressionClass, CompressionParameters.CHUNK_LENGTH_KB, compressionChunkSizeKB, cp });
} catch (ConfigurationException ce) {
throw new PermanentBackendException(ce);
}
} else {
cp = new CompressionParameters(null);
log.debug("Creating CF {}: setting {} to null to disable compression", columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION);
}
cfm.compressionParameters(cp);
try {
cfm.addDefaultIndexNames();
} catch (ConfigurationException e) {
throw new PermanentBackendException("Failed to create column family metadata for " + keyspaceName + ":" + columnfamilyName, e);
}
try {
MigrationManager.announceNewColumnFamily(cfm);
log.info("Created CF {} in KS {}", columnfamilyName, keyspaceName);
} catch (ConfigurationException e) {
throw new PermanentBackendException("Failed to create column family " + keyspaceName + ":" + columnfamilyName, e);
}
/*
* I'm chasing a nondetermistic exception that appears only rarely on my
* machine when executing the embedded cassandra tests. If these dummy
* reads ever actually fail and dump a log message, it could help debug
* the root cause.
*
* java.lang.RuntimeException: java.lang.IllegalArgumentException: Unknown table/cf pair (InternalCassandraEmbeddedKeyColumnValueTest.testStore1)
* at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1582)
* at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
* at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
* at java.lang.Thread.run(Thread.java:744)
* Caused by: java.lang.IllegalArgumentException: Unknown table/cf pair (InternalCassandraEmbeddedKeyColumnValueTest.testStore1)
* at org.apache.cassandra.db.Table.getColumnFamilyStore(Table.java:166)
* at org.apache.cassandra.db.Table.getRow(Table.java:354)
* at org.apache.cassandra.db.SliceFromReadCommand.getRow(SliceFromReadCommand.java:70)
* at org.apache.cassandra.service.StorageProxy$LocalReadRunnable.runMayThrow(StorageProxy.java:1052)
* at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1578)
* ... 3 more
*/
retryDummyRead(keyspaceName, columnfamilyName);
}
use of org.apache.cassandra.config.CFMetaData in project janusgraph by JanusGraph.
the class CassandraEmbeddedKeyColumnValueStore method getKeySlice.
/**
* Create a RangeSliceCommand and run it against the StorageProxy.
* <p>
* To match the behavior of the standard Cassandra thrift API endpoint, the
* {@code nowMillis} argument should be the number of milliseconds since the
* UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained
* through a {@link TimestampProvider}). This is per
* {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)},
* which passes the server's System.currentTimeMillis() to the
* {@code RangeSliceCommand} constructor.
*/
private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize, long nowMillis) throws BackendException {
IPartitioner partitioner = StorageService.getPartitioner();
SliceRange columnSlice = new SliceRange();
if (sliceQuery == null) {
columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
} else {
columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
}
/* Note: we need to fetch columns for each row as well to remove "range ghosts" */
SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
RowPosition startPosition = start.minKeyBound(partitioner);
RowPosition endPosition = end.minKeyBound(partitioner);
List<Row> rows;
try {
CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily);
IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
final RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<>(startPosition, endPosition), pageSize);
rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM);
} catch (Exception e) {
throw new PermanentBackendException(e);
}
return rows;
}
use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.
the class AbstractCassandraDaemon method setup.
/**
* This is a hook for concrete daemons to initialize themselves suitably.
*
* Subclasses should override this to finish the job (listening on ports, etc.)
*
* @throws IOException
*/
protected void setup() throws IOException {
logger.info("JVM vendor/version: {}/{}", System.getProperty("java.vm.name"), System.getProperty("java.version"));
logger.info("Heap size: {}/{}", Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory());
logger.info("Classpath: {}", System.getProperty("java.class.path"));
CLibrary.tryMlockall();
listenPort = DatabaseDescriptor.getRpcPort();
listenAddr = DatabaseDescriptor.getRpcAddress();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
exceptions.incrementAndGet();
logger.error("Fatal exception in thread " + t, e);
for (Throwable e2 = e; e2 != null; e2 = e2.getCause()) {
// some code, like FileChannel.map, will wrap an OutOfMemoryError in another exception
if (e2 instanceof OutOfMemoryError)
System.exit(100);
}
}
});
// check all directories(data, commitlog, saved cache) for existence and permission
Iterable<String> dirs = Iterables.concat(Arrays.asList(DatabaseDescriptor.getAllDataFileLocations()), Arrays.asList(new String[] { DatabaseDescriptor.getCommitLogLocation(), DatabaseDescriptor.getSavedCachesLocation() }));
for (String dataDir : dirs) {
logger.debug("Checking directory {}", dataDir);
File dir = new File(dataDir);
if (dir.exists())
assert dir.isDirectory() && dir.canRead() && dir.canWrite() && dir.canExecute() : String.format("Directory %s is not accessible.", dataDir);
}
// Migrate sstables from pre-#2749 to the correct location
if (Directories.sstablesNeedsMigration())
Directories.migrateSSTables();
if (// should never happen
CacheService.instance == null)
throw new RuntimeException("Failed to initialize Cache Service.");
// until system table is opened.
for (CFMetaData cfm : Schema.instance.getTableMetaData(Table.SYSTEM_TABLE).values()) ColumnFamilyStore.scrubDataDirectories(Table.SYSTEM_TABLE, cfm.cfName);
try {
SystemTable.checkHealth();
} catch (ConfigurationException e) {
logger.error("Fatal exception during initialization", e);
System.exit(100);
}
// load keyspace descriptions.
try {
DatabaseDescriptor.loadSchemas();
} catch (IOException e) {
logger.error("Fatal exception during initialization", e);
System.exit(100);
}
// clean up debris in the rest of the tables
for (String table : Schema.instance.getTables()) {
for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values()) {
ColumnFamilyStore.scrubDataDirectories(table, cfm.cfName);
}
}
// initialize keyspaces
for (String table : Schema.instance.getTables()) {
if (logger.isDebugEnabled())
logger.debug("opening keyspace " + table);
Table.open(table);
}
if (CacheService.instance.keyCache.size() > 0)
logger.info("completed pre-loading ({} keys) key cache.", CacheService.instance.keyCache.size());
if (CacheService.instance.rowCache.size() > 0)
logger.info("completed pre-loading ({} keys) row cache.", CacheService.instance.rowCache.size());
try {
GCInspector.instance.start();
} catch (Throwable t) {
logger.warn("Unable to start GCInspector (currently only supported on the Sun JVM)");
}
// replay the log if necessary
CommitLog.instance.recover();
// check to see if CL.recovery modified the lastMigrationId. if it did, we need to re apply migrations. this isn't
// the same as merely reloading the schema (which wouldn't perform file deletion after a DROP). The solution
// is to read those migrations from disk and apply them.
UUID currentMigration = Schema.instance.getVersion();
UUID lastMigration = Migration.getLastMigrationId();
if ((lastMigration != null) && (lastMigration.timestamp() > currentMigration.timestamp())) {
Gossiper.instance.maybeInitializeLocalState(SystemTable.incrementAndGetGeneration());
MigrationManager.applyMigrations(currentMigration, lastMigration);
}
SystemTable.finishStartup();
// start server internals
StorageService.instance.registerDaemon(this);
try {
StorageService.instance.initServer();
} catch (ConfigurationException e) {
logger.error("Fatal configuration error", e);
System.err.println(e.getMessage() + "\nFatal configuration error; unable to start server. See log for stacktrace.");
System.exit(1);
}
Mx4jTool.maybeLoad();
}
use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.
the class CreateColumnFamilyStatement method getCFMetaData.
/**
* Returns a CFMetaData instance based on the parameters parsed from this
* <code>CREATE</code> statement, or defaults where applicable.
*
* @param keyspace keyspace to apply this column family to
* @return a CFMetaData instance corresponding to the values parsed from this statement
* @throws InvalidRequestException on failure to validate parsed parameters
*/
public CFMetaData getCFMetaData(String keyspace, List<String> variables) throws InvalidRequestException {
validate(variables);
CFMetaData newCFMD;
try {
AbstractType<?> comparator = cfProps.getComparator();
newCFMD = new CFMetaData(keyspace, name, ColumnFamilyType.Standard, comparator, null);
newCFMD.comment(cfProps.getProperty(CFPropDefs.KW_COMMENT)).readRepairChance(getPropertyDouble(CFPropDefs.KW_READREPAIRCHANCE, CFMetaData.DEFAULT_READ_REPAIR_CHANCE)).replicateOnWrite(getPropertyBoolean(CFPropDefs.KW_REPLICATEONWRITE, CFMetaData.DEFAULT_REPLICATE_ON_WRITE)).gcGraceSeconds(getPropertyInt(CFPropDefs.KW_GCGRACESECONDS, CFMetaData.DEFAULT_GC_GRACE_SECONDS)).defaultValidator(cfProps.getValidator()).minCompactionThreshold(getPropertyInt(CFPropDefs.KW_MINCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD)).maxCompactionThreshold(getPropertyInt(CFPropDefs.KW_MAXCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD)).mergeShardsChance(0.0).columnMetadata(getColumns(comparator)).keyValidator(TypeParser.parse(CFPropDefs.comparators.get(getKeyType()))).keyAlias(keyAlias).compactionStrategyOptions(cfProps.compactionStrategyOptions).compressionParameters(CompressionParameters.create(cfProps.compressionParameters)).validate();
} catch (ConfigurationException e) {
throw new InvalidRequestException(e.toString());
}
return newCFMD;
}
use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.
the class UpdateStatement method prepareRowMutations.
/**
* {@inheritDoc}
*/
@Override
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<String> variables) throws InvalidRequestException {
List<String> cfamsSeen = new ArrayList<String>();
boolean hasCommutativeOperation = false;
for (Map.Entry<Term, Operation> column : getColumns().entrySet()) {
if (!column.getValue().isUnary())
hasCommutativeOperation = true;
if (hasCommutativeOperation && column.getValue().isUnary())
throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");
}
CFMetaData metadata = validateColumnFamily(keyspace, columnFamily, hasCommutativeOperation);
if (hasCommutativeOperation)
validateCommutativeForWrite(metadata, cLevel);
QueryProcessor.validateKeyAlias(metadata, keyName);
// Avoid unnecessary authorizations.
if (!(cfamsSeen.contains(columnFamily))) {
clientState.hasColumnFamilyAccess(columnFamily, Permission.WRITE);
cfamsSeen.add(columnFamily);
}
List<IMutation> rowMutations = new LinkedList<IMutation>();
for (Term key : keys) {
if (timestamp != 0) {
logger.warn("Supplied timestamp: " + timestamp + " ignored, server generating timestamp");
}
long opTimestamp = LamportClock.getVersion();
rowMutations.add(mutationForKey(keyspace, key.getByteBuffer(getKeyType(keyspace), variables), metadata, opTimestamp, clientState, variables));
}
return rowMutations;
}
Aggregations