@Override public Map<String, String> getCompressionOptions(String cf) throws BackendException { CFMetaData cfm = Schema.instance.getCFMetaData(keySpaceName, cf); if (cfm == null) return null; return ImmutableMap.copyOf(cfm.compressionParameters().asThriftOptions()); }
@Override public void clearStorage() throws BackendException { openStores.clear(); try { KSMetaData ksMetaData = Schema.instance.getKSMetaData(keySpaceName); // Not a big deal if Keyspace doesn't not exist (dropped manually by user or tests). // This is called on per test setup basis to make sure that previous test cleaned // everything up, so first invocation would always fail as Keyspace doesn't yet exist. if (ksMetaData == null) return; for (String cfName : ksMetaData.cfMetaData().keySet()) StorageService.instance.truncate(keySpaceName, cfName); } catch (Exception e) { throw new PermanentBackendException(e); } }
private void schedule(long timeoutMS) throws TimeoutException { requestScheduler.queue(Thread.currentThread(), "default", DatabaseDescriptor.getRpcTimeout()); }
private void ensureColumnFamilyExists(String keyspaceName, String columnfamilyName, AbstractType<?> comparator) throws BackendException { if (null != Schema.instance.getCFMetaData(keyspaceName, columnfamilyName)) return; CFMetaData cfm = new CFMetaData(keyspaceName, columnfamilyName, ColumnFamilyType.Standard, CellNames.fromAbstractType(comparator, true)); cfm.caching(CachingOptions.KEYS_ONLY); } else if (columnfamilyName.startsWith(Backend.INDEXSTORE_NAME)) { cfm.caching(CachingOptions.ROWS_ONLY); columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION); cfm.compressionParameters(cp); cfm.addDefaultIndexNames(); } catch (ConfigurationException e) { throw new PermanentBackendException("Failed to create column family metadata for " + keyspaceName + ":" + columnfamilyName, e);
private static CFMetaData cqlTestCf(String ksName, String cfName, AbstractType comp) throws ConfigurationException { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null) .keyValidator(UTF8Type.instance).columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>() {{ ByteBuffer cName = ByteBuffer.wrap("birthyear".getBytes(Charsets.UTF_8)); put(cName, new ColumnDefinition(cName, LongType.instance, null, null, null,null, Type.REGULAR)); }}).rebuild(); } }
private static CFMetaData superCFMD(String ksName, String cfName, AbstractType subcc) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Super, BytesType.instance, subcc).rebuild(); }
private static CFMetaData jdbcCFMD(String ksName, String cfName, AbstractType comp) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null) .defaultValidator(comp).rebuild(); }
private static CFMetaData indexCFMD(String ksName, String cfName, final Boolean withIdxType) throws ConfigurationException { return standardCFMD(ksName, cfName) .columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>() {{ ByteBuffer cName = ByteBuffer.wrap("birthyear".getBytes(Charsets.UTF_8)); IndexType keys = withIdxType ? IndexType.KEYS : null; //TODO: that last null is for composites. Need to understand that better, but null is reasonable ColumnDefinition def = new org.apache.cassandra.config.ColumnDefinition(cName,LongType.instance,IndexType.KEYS,null,"birthyear_index",null, Type.REGULAR); put (cName,def); }}).rebuild(); }
public static void mkdirs() { DatabaseDescriptor.createAllDirectories(); }
private void ensureKeyspaceExists(String keyspaceName) throws BackendException { if (null != Schema.instance.getKeyspaceInstance(keyspaceName)) return; // Keyspace not found; create it String strategyName = storageConfig.get(REPLICATION_STRATEGY); KSMetaData ksm; try { ksm = KSMetaData.newKeyspace(keyspaceName, strategyName, strategyOptions, true); } catch (ConfigurationException e) { throw new PermanentBackendException("Failed to instantiate keyspace metadata for " + keyspaceName, e); } try { MigrationManager.announceNewKeyspace(ksm); log.info("Created keyspace {}", keyspaceName); } catch (ConfigurationException e) { throw new PermanentBackendException("Failed to create keyspace " + keyspaceName, e); } }
if(! Schema.instance.getNonSystemTables().contains(CassandraUtils.keySpace) ) throw new IOException("Solandra keyspace is missing, please import then retry"); else DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(), endpoints);
CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily); IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
private InetAddress getIndexLocation(String subIndex) { ByteBuffer indexName = CassandraUtils.hashBytes(subIndex.getBytes()); List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(CassandraUtils.keySpace, indexName); if (endpoints.isEmpty()) throw new RuntimeException("Unable to find a live endpoint for: " + subIndex); DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(), endpoints); if (endpoints.contains(FBUtilities.getLocalAddress())) return FBUtilities.getLocalAddress(); return endpoints.get(0); }
public static void loadSchema() { try { Schema.instance.load(schemaDefinition()); } catch (ConfigurationException e) { throw new RuntimeException(e); } }
public CassandraEmbeddedStoreManager(Configuration config) throws BackendException { super(config); String cassandraConfig = CASSANDRA_YAML_DEFAULT; if (config.has(GraphDatabaseConfiguration.STORAGE_CONF_FILE)) { cassandraConfig = config.get(GraphDatabaseConfiguration.STORAGE_CONF_FILE); } assert cassandraConfig != null && !cassandraConfig.isEmpty(); File ccf = new File(cassandraConfig); if (ccf.exists() && ccf.isAbsolute()) { cassandraConfig = "file://" + cassandraConfig; log.debug("Set cassandra config string \"{}\"", cassandraConfig); } CassandraDaemonWrapper.start(cassandraConfig); this.openStores = new HashMap<String, CassandraEmbeddedKeyColumnValueStore>(8); this.requestScheduler = DatabaseDescriptor.getRequestScheduler(); }
public static synchronized void startupClient() throws IOException { if (cassandraStarted) return; cassandraStarted = true; try { System.setProperty("cassandra-foreground", "1"); StorageService.instance.initClient(); logger.info("Started Solandra in client mode... waiting for gossip information"); Thread.sleep(10000); // createCassandraSchema(); } catch (IOException e2) { e2.printStackTrace(); System.exit(2); } catch (ConfigurationException e2) { e2.printStackTrace(); System.exit(2); } catch (InterruptedException e) { e.printStackTrace(); System.exit(2); } return; }
if (Schema.instance.getNonSystemTables().contains(keySpace)) if (Schema.instance.getNonSystemTables().contains(keySpace))
private static CFMetaData standardCFMD(String ksName, String cfName) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, BytesType.instance, null).rebuild(); }
private void mutate(List<org.apache.cassandra.db.Mutation> cmds, org.apache.cassandra.db.ConsistencyLevel clvl) throws BackendException { try { schedule(DatabaseDescriptor.getRpcTimeout()); try { if (atomicBatch) { StorageProxy.mutateAtomically(cmds, clvl); } else { StorageProxy.mutate(cmds, clvl); } } catch (RequestExecutionException e) { throw new TemporaryBackendException(e); } finally { release(); } } catch (TimeoutException ex) { log.debug("Cassandra TimeoutException", ex); throw new TemporaryBackendException(ex); } }
private static CFMetaData dynamicCompositeCFMD(String ksName, String cfName) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, DynamicCompositeType.getInstance(alias), null).rebuild(); }