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);
@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 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); } }
public void validate(ClientState state) throws RequestValidationException { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(name.getKeyspace()); if (ksm == null) throw new InvalidRequestException(String.format("Cannot add type in unknown keyspace %s", name.getKeyspace())); if (ksm.types.get(name.getUserTypeName()).isPresent() && !ifNotExists) throw new InvalidRequestException(String.format("A user type of name %s already exists", name)); for (CQL3Type.Raw type : columnTypes) { if (type.isCounter()) throw new InvalidRequestException("A user type cannot contain counters"); if (type.isUDT() && !type.isFrozen()) throw new InvalidRequestException("A user type cannot contain non-frozen UDTs"); } }
public void updateView(ViewDefinition view) { ViewDefinition current = getKSMetaData(view.ksName).views.get(view.viewName).get(); boolean changeAffectsStatements = current.metadata.apply(view.metadata); Keyspace keyspace = Keyspace.open(current.ksName); keyspace.getColumnFamilyStore(current.viewName).reload(); Keyspace.open(current.ksName).viewManager.update(current.viewName); MigrationManager.instance.notifyUpdateView(current, changeAffectsStatements); }
/** * Find the function with the specified name * * @param name fully qualified function name * @param argTypes function argument types * @return an empty {@link Optional} if the keyspace or the function name are not found; * a non-empty optional of {@link Function} otherwise */ public Optional<Function> findFunction(FunctionName name, List<AbstractType<?>> argTypes) { if (!name.hasKeyspace()) throw new IllegalArgumentException(String.format("Function name must be fully quallified: got %s", name)); KeyspaceMetadata ksm = getKSMetaData(name.keyspace); return ksm == null ? Optional.empty() : ksm.functions.find(name, argTypes); }
if (!DatabaseDescriptor.hasLargeAddressSpace()) logger.info("32bit JVM detected. It is recommended to run Cassandra on a 64bit JVM for better performance."); String javaVersion = System.getProperty("java.version"); for (CFMetaData cfm : Schema.instance.getKeyspaceMetaData(Keyspace.SYSTEM_KS).values()) ColumnFamilyStore.scrubDataDirectories(cfm); try for (Pair<String, String> kscf : unfinishedCompactions.keySet()) CFMetaData cfm = Schema.instance.getCFMetaData(kscf.left, kscf.right); for (String keyspaceName : Schema.instance.getKeyspaces()) continue; for (CFMetaData cfm : Schema.instance.getKeyspaceMetaData(keyspaceName).values()) ColumnFamilyStore.scrubDataDirectories(cfm); for (String keyspaceName : Schema.instance.getKeyspaces()) StorageService.instance.registerDaemon(this); try StorageService.instance.initServer(); if (!FBUtilities.getBroadcastAddress().equals(InetAddress.getLoopbackAddress())) waitForGossipToSettle();
DatabaseDescriptor.isAutoBootstrap(), SystemKeyspace.bootstrapInProgress(), SystemKeyspace.bootstrapComplete(), DatabaseDescriptor.getSeeds().contains(FBUtilities.getBroadcastAddress())); if (DatabaseDescriptor.isAutoBootstrap() && !SystemKeyspace.bootstrapComplete() && DatabaseDescriptor.getSeeds().contains(FBUtilities.getBroadcastAddress())) logger.info("This node will not auto bootstrap because it is configured to be a seed node."); if (shouldBootstrap()) else SystemKeyspace.setBootstrapState(SystemKeyspace.BootstrapState.IN_PROGRESS); setMode(Mode.JOINING, "waiting for ring information", true); if (!Schema.instance.getVersion().equals(Schema.emptyVersion)) logger.debug("got schema: {}", Schema.instance.getVersion()); break; setMode(Mode.JOINING, "waiting for schema information to complete", true); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); if (!DatabaseDescriptor.isReplacing()) if (tokenMetadata.isMember(FBUtilities.getBroadcastAddress())) if (Schema.instance.getKSMetaData(Tracing.TRACE_KS) == null)
if (Schema.instance.getCFMetaData(desc) == null) if (!StorageService.instance.isJoined()) Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(keyspace.getName()); boolean hasIndexes = cfs.indexManager.hasIndexes(); SSTableReader sstable = lookupSSTable(cfs, entry.getValue()); CleanupStrategy cleanupStrategy = CleanupStrategy.get(cfs, ranges, FBUtilities.nowInSeconds()); try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstable, OperationType.CLEANUP))
public static void announceTypeDrop(UserType droppedType, boolean announceLocally) { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(droppedType.keyspace); announce(SchemaKeyspace.dropTypeFromSchemaMutation(ksm, droppedType, FBUtilities.timestampMicros()), announceLocally); }
/** * Clear all locally stored schema information and reset schema to initial state. * Called by user (via JMX) who wants to get rid of schema disagreement. */ public static void resetLocalSchema() { logger.info("Starting local schema reset..."); logger.debug("Truncating schema tables..."); SchemaKeyspace.truncate(); logger.debug("Clearing local schema keyspace definitions..."); Schema.instance.clear(); Set<InetAddress> liveEndpoints = Gossiper.instance.getLiveMembers(); liveEndpoints.remove(FBUtilities.getBroadcastAddress()); // force migration if there are nodes around for (InetAddress node : liveEndpoints) { if (shouldPullSchemaFrom(node)) { logger.debug("Requesting schema from {}", node); FBUtilities.waitOnFuture(submitMigrationTask(node)); break; } } logger.info("Local schema reset is complete."); }
/** * Get ColumnFamily metadata by its identifier * * @param cfId The ColumnFamily identifier * * @return metadata about ColumnFamily */ public CFMetaData getCFMetaData(UUID cfId) { Pair<String,String> cf = getCF(cfId); return (cf == null) ? null : getCFMetaData(cf.left, cf.right); }
/** * Initialize empty schema object and load the hardcoded system tables */ public Schema() { if (DatabaseDescriptor.isDaemonInitialized() || DatabaseDescriptor.isToolInitialized()) { load(SchemaKeyspace.metadata()); load(SystemKeyspace.metadata()); } }
public static void announceNewView(ViewDefinition view, boolean announceLocally) throws ConfigurationException { view.metadata.validate(); KeyspaceMetadata ksm = Schema.instance.getKSMetaData(view.ksName); if (ksm == null) throw new ConfigurationException(String.format("Cannot add table '%s' to non existing keyspace '%s'.", view.viewName, view.ksName)); else if (ksm.getTableOrViewNullable(view.viewName) != null) throw new AlreadyExistsException(view.ksName, view.viewName); logger.info("Create new view: {}", view); announce(SchemaKeyspace.makeCreateViewMutation(ksm, view, FBUtilities.timestampMicros()), announceLocally); }
public static void announceColumnFamilyDrop(String ksName, String cfName, boolean announceLocally) throws ConfigurationException { CFMetaData oldCfm = Schema.instance.getCFMetaData(ksName, cfName); if (oldCfm == null) throw new ConfigurationException(String.format("Cannot drop non existing table '%s' in keyspace '%s'.", cfName, ksName)); KeyspaceMetadata ksm = Schema.instance.getKSMetaData(ksName); logger.info("Drop table '{}/{}'", oldCfm.ksName, oldCfm.cfName); announce(SchemaKeyspace.makeDropTableMutation(ksm, oldCfm, FBUtilities.timestampMicros()), announceLocally); }
/** * Like updateVersion, but also announces via gossip * * 3.11 note: we announce the "current" schema version, which can be either the 3.0 * compatible one, if at least one node is still running 3.0, or the "real" schema version. */ public void updateVersionAndAnnounce() { updateVersion(); UUID current = getVersion(); MigrationManager.passiveAnnounce(current, current == getAltVersion()); }
/** * All MVs have been created during bootstrap, so mark them as built */ private void markViewsAsBuilt() { for (String keyspace : Schema.instance.getUserKeyspaces()) { for (ViewDefinition view: Schema.instance.getKSMetaData(keyspace).views) SystemKeyspace.finishViewBuildStatus(view.ksName, view.viewName); } }
public void addKeyspace(KeyspaceMetadata ksm) { assert getKSMetaData(ksm.name) == null; load(ksm); Keyspace.open(ksm.name); MigrationManager.instance.notifyCreateKeyspace(ksm); }
if (!schemaVersion.equals(Schema.instance.getVersion())) throw new RuntimeException("Cache schema version " + schemaVersion.toString() + " does not match current schema version " + Schema.instance.getVersion()); String cfname = in.readUTF(); ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreIncludingIndexes(Pair.create(ksname, cfname));
int pageSize, long nowMillis) throws BackendException { IPartitioner partitioner = StorageService.getPartitioner(); CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily); IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);