本文整理汇总了Java中org.apache.cassandra.config.Schema类的典型用法代码示例。如果您正苦于以下问题:Java Schema类的具体用法?Java Schema怎么用?Java Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Schema类属于org.apache.cassandra.config包,在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStore
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
private ColumnFamilyStore getStore(String ksName, String cfName) {
// Start by validating keyspace name
if (Schema.instance.getKSMetaData(ksName) == null) {
System.err.println(String.format("Reference to nonexistent keyspace: %s!", ksName));
System.exit(1);
}
Keyspace keyspace = Keyspace.open(ksName);
// Make it works for indexes too - find parent cf if necessary
String baseName = cfName;
if (cfName.contains(".")) {
String[] parts = cfName.split("\\.", 2);
baseName = parts[0];
}
// IllegalArgumentException will be thrown here if ks/cf pair does not exist
try {
return keyspace.getColumnFamilyStore(baseName);
} catch (Throwable t) {
System.err.println(String.format(
"The provided column family is not part of this cassandra keyspace: keyspace = %s, column family = %s",
ksName, cfName));
System.exit(1);
}
return null;
}
示例2: getColumnFamily
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public ColumnFamilyProxy getColumnFamily(String ksName, String cfName, String snapshotName, Collection<String> filter) {
ColumnFamilyStore cfStore = getStore(ksName, cfName);
try {
CFMetaData metaData = Schema.instance.getCFMetaData(ksName, cfName);
return new ColumnFamilyBackend(
metaData.getKeyValidator(),
metaData.params.compaction.klass().equals(org.apache.cassandra.db.compaction.DateTieredCompactionStrategy.class),
cfStore,
snapshotName,
filter);
} catch (Throwable t) {
System.err.println(String.format("Error retrieving snapshot for %s.%s", ksName, cfName));
System.exit(1);
}
return null;
}
示例3: getColumnFamily
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public ColumnFamilyProxy getColumnFamily(String ksName, String cfName, String snapshotName, Collection<String> filter) {
ColumnFamilyStore cfStore = getStore(ksName, cfName);
try {
CFMetaData metaData = Schema.instance.getCFMetaData(ksName, cfName);
return new ColumnFamilyBackend(
metaData.getKeyValidator(),
cfStore.getCompactionStrategyClass().equals("org.apache.cassandra.db.compaction.DateTieredCompactionStrategy"),
cfStore,
snapshotName,
filter);
} catch (Throwable t) {
System.err.println(String.format("Error retrieving snapshot for %s.%s", ksName, cfName));
System.exit(1);
}
return null;
}
示例4: getColumnFamily
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public ColumnFamilyProxy getColumnFamily(String ksName, String cfName, String snapshotName, Collection<String> filter) {
ColumnFamilyStore cfStore = getStore(ksName, cfName);
try {
CFMetaData metaData = Schema.instance.getCFMetaData(ksName, cfName);
return new ColumnFamilyBackend(
metaData.getKeyValidator(),
cfStore.getCompactionStrategyClass().equals("org.apache.cassandra.db.compaction.DateTieredCompactionStrategy"),
cfStore,
snapshotName,
filter);
} catch (Throwable t) {
System.err.println(String.format("Error retrieving snapshot for %s.%s", ksName, cfName));
System.exit(1);
}
return null;
}
示例5: clearStorage
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
@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);
}
}
示例6: create
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public static ReplayFilter create()
{
// If no replaylist is supplied an empty array of strings is used to replay everything.
if (System.getProperty("cassandra.replayList") == null)
return new AlwaysReplayFilter();
Multimap<String, String> toReplay = HashMultimap.create();
for (String rawPair : System.getProperty("cassandra.replayList").split(","))
{
String[] pair = rawPair.trim().split("\\.");
if (pair.length != 2)
throw new IllegalArgumentException("Each table to be replayed must be fully qualified with keyspace name, e.g., 'system.peers'");
Keyspace ks = Schema.instance.getKeyspaceInstance(pair[0]);
if (ks == null)
throw new IllegalArgumentException("Unknown keyspace " + pair[0]);
ColumnFamilyStore cfs = ks.getColumnFamilyStore(pair[1]);
if (cfs == null)
throw new IllegalArgumentException(String.format("Unknown table %s.%s", pair[0], pair[1]));
toReplay.put(pair[0], pair[1]);
}
return new CustomReplayFilter(toReplay);
}
示例7: findIndexedCF
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
private CFMetaData findIndexedCF() throws InvalidRequestException
{
KSMetaData ksm = Schema.instance.getKSMetaData(keyspace());
if (ksm == null)
throw new KeyspaceNotDefinedException("Keyspace " + keyspace() + " does not exist");
for (CFMetaData cfm : ksm.cfMetaData().values())
{
if (findIndexedColumn(cfm) != null)
return cfm;
}
if (ifExists)
return null;
else
throw new InvalidRequestException("Index '" + indexName + "' could not be found in any of the tables of keyspace '" + keyspace() + '\'');
}
示例8: validate
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
/**
* The <code>CqlParser</code> only goes as far as extracting the keyword arguments
* from these statements, so this method is responsible for processing and
* validating.
*
* @throws InvalidRequestException if arguments are missing or unacceptable
*/
public void validate(ClientState state) throws RequestValidationException
{
ThriftValidation.validateKeyspaceNotSystem(name);
// keyspace name
if (!name.matches("\\w+"))
throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
if (name.length() > Schema.NAME_LENGTH)
throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));
attrs.validate();
if (attrs.getReplicationStrategyClass() == null)
throw new ConfigurationException("Missing mandatory replication strategy class");
// The strategy is validated through KSMetaData.validate() in announceNewKeyspace below.
// However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
// so doing proper validation here.
AbstractReplicationStrategy.validateReplicationStrategy(name,
AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
StorageService.instance.getTokenMetadata(),
DatabaseDescriptor.getEndpointSnitch(),
attrs.getReplicationOptions());
}
示例9: toString
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public String toString(boolean shallow)
{
StringBuilder buff = new StringBuilder("Mutation(");
buff.append("keyspace='").append(keyspaceName).append('\'');
buff.append(", key='").append(ByteBufferUtil.bytesToHex(key.getKey())).append('\'');
buff.append(", modifications=[");
if (shallow)
{
List<String> cfnames = new ArrayList<String>(modifications.size());
for (UUID cfid : modifications.keySet())
{
CFMetaData cfm = Schema.instance.getCFMetaData(cfid);
cfnames.add(cfm == null ? "-dropped-" : cfm.cfName);
}
buff.append(StringUtils.join(cfnames, ", "));
}
else
{
buff.append("\n ").append(StringUtils.join(modifications.values(), "\n ")).append("\n");
}
return buff.append("])").toString();
}
示例10: addNewKS
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
@Test
public void addNewKS() throws ConfigurationException
{
CFMetaData cfm = addTestTable("newkeyspace1", "newstandard1", "A new cf for a new ks");
KeyspaceMetadata newKs = KeyspaceMetadata.create(cfm.ksName, KeyspaceParams.simple(5), Tables.of(cfm));
MigrationManager.announceNewKeyspace(newKs);
assertNotNull(Schema.instance.getKSMetaData(cfm.ksName));
assertEquals(Schema.instance.getKSMetaData(cfm.ksName), newKs);
// test reads and writes.
QueryProcessor.executeInternal("INSERT INTO newkeyspace1.newstandard1 (key, col, val) VALUES (?, ?, ?)",
"key0", "col0", "val0");
ColumnFamilyStore store = Keyspace.open(cfm.ksName).getColumnFamilyStore(cfm.cfName);
assertNotNull(store);
store.forceBlockingFlush();
UntypedResultSet rows = QueryProcessor.executeInternal("SELECT * FROM newkeyspace1.newstandard1");
assertRows(rows, row("key0", "col0", "val0"));
}
示例11: announceMigration
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public Event.SchemaChange announceMigration(boolean isLocalOnly) throws ConfigurationException, InvalidRequestException
{
CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily()).copy();
Triggers triggers = cfm.getTriggers();
if (!triggers.get(triggerName).isPresent())
{
if (ifExists)
return null;
else
throw new InvalidRequestException(String.format("Trigger %s was not found", triggerName));
}
logger.info("Dropping trigger with name {}", triggerName);
cfm.triggers(triggers.without(triggerName));
MigrationManager.announceColumnFamilyUpdate(cfm, isLocalOnly);
return new Event.SchemaChange(Event.SchemaChange.Change.UPDATED, Event.SchemaChange.Target.TABLE, keyspace(), columnFamily());
}
示例12: run
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public void run()
{
RateLimiter rl = rateLimit != 0 ? RateLimiter.create(rateLimit) : null;
final Random rand = random != null ? random : ThreadLocalRandom.current();
while (!stop)
{
if (rl != null)
rl.acquire();
ByteBuffer key = randomBytes(16, rand);
UpdateBuilder builder = UpdateBuilder.create(Schema.instance.getCFMetaData("Keyspace1", "Standard1"), Util.dk(key));
for (int ii = 0; ii < numCells; ii++)
{
int sz = randomSize ? rand.nextInt(cellSize) : cellSize;
ByteBuffer bytes = randomBytes(sz, rand);
builder.newRow("name" + ii).add("val", bytes);
hash = hash(hash, bytes);
++cells;
dataSize += sz;
}
rp = commitLog.add(new Mutation(builder.build()));
counter.incrementAndGet();
}
}
示例13: removeTriggerFromCf
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
@Test
public void removeTriggerFromCf() throws Exception
{
TriggerMetadata td = TriggerMetadata.create(triggerName, triggerClass);
CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
cfm1.triggers(cfm1.getTriggers().with(td));
KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1), Tables.of(cfm1));
MigrationManager.announceNewKeyspace(ksm);
CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName).copy();
cfm2.triggers(cfm2.getTriggers().without(triggerName));
MigrationManager.announceColumnFamilyUpdate(cfm2);
CFMetaData cfm3 = Schema.instance.getCFMetaData(ksName, cfName).copy();
assertTrue(cfm3.getTriggers().isEmpty());
}
示例14: toString
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public String toString(boolean shallow)
{
StringBuilder buff = new StringBuilder("Mutation(");
buff.append("keyspace='").append(keyspaceName).append('\'');
buff.append(", key='").append(ByteBufferUtil.bytesToHex(key)).append('\'');
buff.append(", modifications=[");
if (shallow)
{
List<String> cfnames = new ArrayList<String>(modifications.size());
for (UUID cfid : modifications.keySet())
{
CFMetaData cfm = Schema.instance.getCFMetaData(cfid);
cfnames.add(cfm == null ? "-dropped-" : cfm.cfName);
}
buff.append(StringUtils.join(cfnames, ", "));
}
else
buff.append(StringUtils.join(modifications.values(), ", "));
return buff.append("])").toString();
}
示例15: describe_splits_ex
import org.apache.cassandra.config.Schema; //导入依赖的package包/类
public List<CfSplit> describe_splits_ex(String cfName, String start_token, String end_token, int keys_per_split)
throws InvalidRequestException, TException
{
try
{
Token.TokenFactory tf = StorageService.getPartitioner().getTokenFactory();
Range<Token> tr = new Range<Token>(tf.fromString(start_token), tf.fromString(end_token));
List<Pair<Range<Token>, Long>> splits =
StorageService.instance.getSplits(state().getKeyspace(), cfName, tr, keys_per_split, Schema.instance.getCFMetaData(state().getKeyspace(), cfName));
List<CfSplit> result = new ArrayList<CfSplit>(splits.size());
for (Pair<Range<Token>, Long> split : splits)
result.add(new CfSplit(split.left.left.toString(), split.left.right.toString(), split.right));
return result;
}
catch (RequestValidationException e)
{
throw ThriftConversion.toThrift(e);
}
}