@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); } }
/** * Get metadata about keyspace inner ColumnFamilies * * @param keyspaceName The name of the keyspace * * @return metadata about ColumnFamilies the belong to the given keyspace */ public Map<String, CFMetaData> getKeyspaceMetaData(String keyspaceName) { assert keyspaceName != null; KSMetaData ksm = keyspaces.get(keyspaceName); assert ksm != null; return ksm.cfMetaData(); }
/** * Given a keyspace name & column family name, get the column family * meta data. If the keyspace name or column family name is not valid * this function returns null. * * @param keyspaceName The keyspace name * @param cfName The ColumnFamily name * * @return ColumnFamily Metadata object or null if it wasn't found */ public CFMetaData getCFMetaData(String keyspaceName, String cfName) { assert keyspaceName != null; KSMetaData ksm = keyspaces.get(keyspaceName); return (ksm == null) ? null : ksm.cfMetaData().get(cfName); }
private static KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm, CFMetaData toExclude) { // clone ksm but do not include the new def List<CFMetaData> newCfs = new ArrayList<>(ksm.cfMetaData().values()); newCfs.remove(toExclude); assert newCfs.size() == ksm.cfMetaData().size() - 1; return KSMetaData.cloneWith(ksm, newCfs); }
/** * Load specific keyspace into Schema * * @param keyspaceDef The keyspace to load up * * @return self to support chaining calls */ public Schema load(KSMetaData keyspaceDef) { for (CFMetaData cfm : keyspaceDef.cfMetaData().values()) load(cfm); setKeyspaceDefinition(keyspaceDef); return this; }
public KsDef toThrift() { List<CfDef> cfDefs = new ArrayList<>(cfMetaData.size()); for (CFMetaData cfm : cfMetaData().values()) { // Don't expose CF that cannot be correctly handle by thrift; see CASSANDRA-4377 for further details if (cfm.isThriftCompatible()) cfDefs.add(cfm.toThrift()); } KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs); ksdef.setStrategy_options(strategyOptions); ksdef.setDurable_writes(durableWrites); return ksdef; }
/** * Adds the specified column family to the specified keyspace. * * @param ksm the keyspace meta data * @param cfm the column family meta data */ private static void addTableToKeyspace(KSMetaData ksm, CFMetaData cfm) { ksm = KSMetaData.cloneWith(ksm, Iterables.concat(ksm.cfMetaData().values(), Collections.singleton(cfm))); Schema.instance.load(cfm); Schema.instance.setKeyspaceDefinition(ksm); }
private CFMetaData findIndexedCF() throws InvalidRequestException { KSMetaData ksm = Schema.instance.getKSMetaData(keyspace); for (CFMetaData cfm : ksm.cfMetaData().values()) { if (findIndexedColumn(cfm) != null) return cfm; } throw new InvalidRequestException("Index '" + indexName + "' could not be found in any of the column families of keyspace '" + keyspace + "'"); }
for (CFMetaData cfmd : Schema.instance.getKSMetaData(ks).cfMetaData().values())
@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); } }
@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 Keyspace(String keyspaceName, boolean loadSSTables) { metadata = Schema.instance.getKSMetaData(keyspaceName); assert metadata != null : "Unknown keyspace " + keyspaceName; createReplicationStrategy(metadata); this.metric = new KeyspaceMetrics(this); for (CFMetaData cfm : new ArrayList<CFMetaData>(metadata.cfMetaData().values())) { logger.debug("Initializing {}.{}", getName(), cfm.cfName); initCf(cfm.cfId, cfm.cfName, loadSSTables); } }
public static void announceNewColumnFamily(CFMetaData cfm, boolean announceLocally) throws ConfigurationException { cfm.validate(); KSMetaData ksm = Schema.instance.getKSMetaData(cfm.ksName); if (ksm == null) throw new ConfigurationException(String.format("Cannot add column family '%s' to non existing keyspace '%s'.", cfm.cfName, cfm.ksName)); else if (ksm.cfMetaData().containsKey(cfm.cfName)) throw new AlreadyExistsException(cfm.ksName, cfm.cfName); logger.info(String.format("Create new ColumnFamily: %s", cfm)); announce(addSerializedKeyspace(cfm.toSchema(FBUtilities.timestampMicros()), cfm.ksName), announceLocally); }
/** * Clear all KS/CF metadata and reset version. */ public synchronized void clear() { for (String keyspaceName : getNonSystemKeyspaces()) { KSMetaData ksm = getKSMetaData(keyspaceName); for (CFMetaData cfm : ksm.cfMetaData().values()) purge(cfm); clearKeyspaceDefinition(ksm); } updateVersionAndAnnounce(); }
/** * This method returns the N endpoints that are responsible for storing the * specified key i.e for replication. * * @param keyspaceName keyspace name also known as keyspace * @param cf Column family name * @param key key for which we need to find the endpoint * @return the endpoint responsible for this key */ public List<InetAddress> getNaturalEndpoints(String keyspaceName, String cf, String key) { KSMetaData ksMetaData = Schema.instance.getKSMetaData(keyspaceName); if (ksMetaData == null) throw new IllegalArgumentException("Unknown keyspace '" + keyspaceName + "'"); CFMetaData cfMetaData = ksMetaData.cfMetaData().get(cf); if (cfMetaData == null) throw new IllegalArgumentException("Unknown table '" + cf + "' in keyspace '" + keyspaceName + "'"); return getNaturalEndpoints(keyspaceName, getPartitioner().getToken(cfMetaData.getKeyValidator().fromString(key))); }
private static void updateKeyspace(String ksName) { KSMetaData oldKsm = Schema.instance.getKSMetaData(ksName); assert oldKsm != null; KSMetaData newKsm = KSMetaData.cloneWith(oldKsm.reloadAttributes(), oldKsm.cfMetaData().values()); Schema.instance.setKeyspaceDefinition(newKsm); if (!StorageService.instance.isClientMode()) { Keyspace.open(ksName).setMetadata(newKsm); MigrationManager.instance.notifyUpdateKeyspace(newKsm); } }
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() + '\''); }
private static void addColumnFamily(CFMetaData cfm) { assert Schema.instance.getCFMetaData(cfm.ksName, cfm.cfName) == null; KSMetaData ksm = Schema.instance.getKSMetaData(cfm.ksName); ksm = KSMetaData.cloneWith(ksm, Iterables.concat(ksm.cfMetaData().values(), Collections.singleton(cfm))); logger.info("Loading {}", cfm); Schema.instance.load(cfm); // make sure it's init-ed w/ the old definitions first, // since we're going to call initCf on the new one manually Keyspace.open(cfm.ksName); Schema.instance.setKeyspaceDefinition(ksm); if (!StorageService.instance.isClientMode()) { Keyspace.open(ksm.name).initCf(cfm.cfId, cfm.cfName, true); MigrationManager.instance.notifyCreateColumnFamily(cfm); } }
String snapshotName = Keyspace.getTimestampedSnapshotName(ksName); CompactionManager.instance.interruptCompactionFor(ksm.cfMetaData().values(), true); for (CFMetaData cfm : ksm.cfMetaData().values())
private static void dropColumnFamily(String ksName, String cfName) { KSMetaData ksm = Schema.instance.getKSMetaData(ksName); assert ksm != null; ColumnFamilyStore cfs = Keyspace.open(ksName).getColumnFamilyStore(cfName); assert cfs != null; // reinitialize the keyspace. CFMetaData cfm = ksm.cfMetaData().get(cfName); Schema.instance.purge(cfm); Schema.instance.setKeyspaceDefinition(makeNewKeyspaceDefinition(ksm, cfm)); CompactionManager.instance.interruptCompactionFor(Arrays.asList(cfm), true); if (!StorageService.instance.isClientMode()) { if (DatabaseDescriptor.isAutoSnapshot()) cfs.snapshot(Keyspace.getTimestampedSnapshotName(cfs.name)); Keyspace.open(ksm.name).dropCf(cfm.cfId); MigrationManager.instance.notifyDropColumnFamily(cfm); CommitLog.instance.forceRecycleAllSegments(Collections.singleton(cfm.cfId)); } }