http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/db/SystemKeyspace.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java index def21bf..c204e0a 100644 --- a/src/java/org/apache/cassandra/db/SystemKeyspace.java +++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java @@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.cql3.functions.*; @@ -84,8 +85,6 @@ public final class SystemKeyspace // Cassandra was not previously installed and we're in the process of starting a fresh node. public static final CassandraVersion NULL_VERSION = new CassandraVersion("0.0.0-absent"); - public static final String NAME = "system"; - public static final String BATCHES = "batches"; public static final String PAXOS = "paxos"; public static final String BUILT_INDEXES = "IndexInfo"; @@ -432,13 +431,13 @@ public final class SystemKeyspace private static CFMetaData compile(String name, String description, String schema) { - return CFMetaData.compile(String.format(schema, name), NAME) + return CFMetaData.compile(String.format(schema, name), SchemaConstants.SYSTEM_KEYSPACE_NAME) .comment(description); } public static KeyspaceMetadata metadata() { - return KeyspaceMetadata.create(NAME, KeyspaceParams.local(), tables(), Views.none(), Types.none(), functions()); + return KeyspaceMetadata.create(SchemaConstants.SYSTEM_KEYSPACE_NAME, KeyspaceParams.local(), tables(), Views.none(), Types.none(), functions()); } private static Tables tables() @@ -557,14 +556,14 @@ public final class SystemKeyspace public static boolean isViewBuilt(String keyspaceName, String viewName) { String req = "SELECT view_name FROM %s.\"%s\" WHERE keyspace_name=? AND view_name=?"; - UntypedResultSet result = executeInternal(String.format(req, NAME, BUILT_VIEWS), keyspaceName, viewName); + UntypedResultSet result = executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName); return !result.isEmpty(); } public static boolean isViewStatusReplicated(String keyspaceName, String viewName) { String req = "SELECT status_replicated FROM %s.\"%s\" WHERE keyspace_name=? AND view_name=?"; - UntypedResultSet result = executeInternal(String.format(req, NAME, BUILT_VIEWS), keyspaceName, viewName); + UntypedResultSet result = executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName); if (result.isEmpty()) return false; @@ -575,18 +574,18 @@ public final class SystemKeyspace public static void setViewBuilt(String keyspaceName, String viewName, boolean replicated) { String req = "INSERT INTO %s.\"%s\" (keyspace_name, view_name, status_replicated) VALUES (?, ?, ?)"; - executeInternal(String.format(req, NAME, BUILT_VIEWS), keyspaceName, viewName, replicated); + executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName, replicated); forceBlockingFlush(BUILT_VIEWS); } public static void setViewRemoved(String keyspaceName, String viewName) { String buildReq = "DELETE FROM %S.%s WHERE keyspace_name = ? AND view_name = ?"; - executeInternal(String.format(buildReq, NAME, VIEWS_BUILDS_IN_PROGRESS), keyspaceName, viewName); + executeInternal(String.format(buildReq, SchemaConstants.SYSTEM_KEYSPACE_NAME, VIEWS_BUILDS_IN_PROGRESS), keyspaceName, viewName); forceBlockingFlush(VIEWS_BUILDS_IN_PROGRESS); String builtReq = "DELETE FROM %s.\"%s\" WHERE keyspace_name = ? AND view_name = ?"; - executeInternal(String.format(builtReq, NAME, BUILT_VIEWS), keyspaceName, viewName); + executeInternal(String.format(builtReq, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName); forceBlockingFlush(BUILT_VIEWS); } @@ -814,7 +813,7 @@ public final class SystemKeyspace public static void forceBlockingFlush(String cfname) { if (!Boolean.getBoolean("cassandra.unsafesystem")) - FBUtilities.waitOnFuture(Keyspace.open(NAME).getColumnFamilyStore(cfname).forceFlush()); + FBUtilities.waitOnFuture(Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(cfname).forceFlush()); } /** @@ -930,7 +929,7 @@ public final class SystemKeyspace Keyspace keyspace; try { - keyspace = Keyspace.open(NAME); + keyspace = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME); } catch (AssertionError err) { @@ -1041,21 +1040,21 @@ public final class SystemKeyspace public static boolean isIndexBuilt(String keyspaceName, String indexName) { String req = "SELECT index_name FROM %s.\"%s\" WHERE table_name=? AND index_name=?"; - UntypedResultSet result = executeInternal(String.format(req, NAME, BUILT_INDEXES), keyspaceName, indexName); + UntypedResultSet result = executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, indexName); return !result.isEmpty(); } public static void setIndexBuilt(String keyspaceName, String indexName) { String req = "INSERT INTO %s.\"%s\" (table_name, index_name) VALUES (?, ?)"; - executeInternal(String.format(req, NAME, BUILT_INDEXES), keyspaceName, indexName); + executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, indexName); forceBlockingFlush(BUILT_INDEXES); } public static void setIndexRemoved(String keyspaceName, String indexName) { String req = "DELETE FROM %s.\"%s\" WHERE table_name = ? AND index_name = ?"; - executeInternal(String.format(req, NAME, BUILT_INDEXES), keyspaceName, indexName); + executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, indexName); forceBlockingFlush(BUILT_INDEXES); } @@ -1063,7 +1062,7 @@ public final class SystemKeyspace { List<String> names = new ArrayList<>(indexNames); String req = "SELECT index_name from %s.\"%s\" WHERE table_name=? AND index_name IN ?"; - UntypedResultSet results = executeInternal(String.format(req, NAME, BUILT_INDEXES), keyspaceName, names); + UntypedResultSet results = executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, names); return StreamSupport.stream(results.spliterator(), false) .map(r -> r.getString("index_name")) .collect(Collectors.toList()); @@ -1273,7 +1272,7 @@ public final class SystemKeyspace */ public static void clearSizeEstimates(String keyspace, String table) { - String cql = String.format("DELETE FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", NAME, SIZE_ESTIMATES); + String cql = String.format("DELETE FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", SchemaConstants.SYSTEM_KEYSPACE_NAME, SIZE_ESTIMATES); executeInternal(cql, keyspace, table); } @@ -1306,7 +1305,7 @@ public final class SystemKeyspace public static void resetAvailableRanges() { - ColumnFamilyStore availableRanges = Keyspace.open(NAME).getColumnFamilyStore(AVAILABLE_RANGES); + ColumnFamilyStore availableRanges = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(AVAILABLE_RANGES); availableRanges.truncateBlocking(); } @@ -1363,7 +1362,7 @@ public final class SystemKeyspace String snapshotName = Keyspace.getTimestampedSnapshotName(String.format("upgrade-%s-%s", previous, next)); - Keyspace systemKs = Keyspace.open(SystemKeyspace.NAME); + Keyspace systemKs = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME); systemKs.snapshot(snapshotName, null); return true; } @@ -1392,7 +1391,7 @@ public final class SystemKeyspace // the current version is. If we couldn't read a previous version from system.local we check for // the existence of the legacy system.Versions table. We don't actually attempt to read a version // from there, but it informs us that this isn't a completely new node. - for (File dataDirectory : Directories.getKSChildDirectories(SystemKeyspace.NAME)) + for (File dataDirectory : Directories.getKSChildDirectories(SchemaConstants.SYSTEM_KEYSPACE_NAME)) { if (dataDirectory.getName().equals("Versions") && dataDirectory.listFiles().length > 0) { @@ -1474,7 +1473,7 @@ public final class SystemKeyspace { executeInternal(String.format("INSERT INTO %s.%s" + " (logged_keyspace, prepared_id, query_string) VALUES (?, ?, ?)", - NAME, PREPARED_STATEMENTS), + SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS), loggedKeyspace, key.byteBuffer(), cql); logger.debug("stored prepared statement for logged keyspace '{}': '{}'", loggedKeyspace, cql); } @@ -1483,13 +1482,13 @@ public final class SystemKeyspace { executeInternal(String.format("DELETE FROM %s.%s" + " WHERE prepared_id = ?", - NAME, PREPARED_STATEMENTS), + SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS), key.byteBuffer()); } public static List<Pair<String, String>> loadPreparedStatements() { - String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", NAME, PREPARED_STATEMENTS); + String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS); UntypedResultSet resultSet = executeOnceInternal(query); List<Pair<String, String>> r = new ArrayList<>(); for (UntypedResultSet.Row row : resultSet)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java index 92364c8..32ea0e9 100644 --- a/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java +++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java @@ -39,7 +39,11 @@ import org.apache.cassandra.concurrent.Stage; import org.apache.cassandra.concurrent.StageManager; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.Schema; -import org.apache.cassandra.db.*; +import org.apache.cassandra.config.SchemaConstants; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.Keyspace; +import org.apache.cassandra.db.Mutation; +import org.apache.cassandra.db.SystemKeyspace; import org.apache.cassandra.db.partitions.PartitionUpdate; import org.apache.cassandra.io.sstable.format.SSTableReader; import org.apache.cassandra.utils.FBUtilities; @@ -155,7 +159,7 @@ public class CommitLogReplayer implements CommitLogReadHandler List<Future<?>> futures = new ArrayList<Future<?>>(); for (Keyspace keyspace : keyspacesReplayed) { - if (keyspace.getName().equals(SystemKeyspace.NAME)) + if (keyspace.getName().equals(SchemaConstants.SYSTEM_KEYSPACE_NAME)) flushingSystem = true; futures.addAll(keyspace.flush()); @@ -163,7 +167,7 @@ public class CommitLogReplayer implements CommitLogReadHandler // also flush batchlog incase of any MV updates if (!flushingSystem) - futures.add(Keyspace.open(SystemKeyspace.NAME).getColumnFamilyStore(SystemKeyspace.BATCHES).forceFlush()); + futures.add(Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(SystemKeyspace.BATCHES).forceFlush()); FBUtilities.waitOnFutures(futures); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/hadoop/cql3/CqlInputFormat.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hadoop/cql3/CqlInputFormat.java b/src/java/org/apache/cassandra/hadoop/cql3/CqlInputFormat.java index 5dba3e2..5e47ed5 100644 --- a/src/java/org/apache/cassandra/hadoop/cql3/CqlInputFormat.java +++ b/src/java/org/apache/cassandra/hadoop/cql3/CqlInputFormat.java @@ -29,6 +29,7 @@ import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.datastax.driver.core.TokenRange; +import org.apache.cassandra.config.SchemaConstants; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.mapred.InputSplit; import org.apache.hadoop.mapred.JobConf; @@ -239,7 +240,7 @@ public class CqlInputFormat extends org.apache.hadoop.mapreduce.InputFormat<Long String query = String.format("SELECT mean_partition_size, partitions_count " + "FROM %s.%s " + "WHERE keyspace_name = ? AND table_name = ? AND range_start = ? AND range_end = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.SIZE_ESTIMATES); ResultSet resultSet = session.execute(query, keyspace, table, tokenRange.getStart().toString(), tokenRange.getEnd().toString()); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/hints/HintsDispatcher.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hints/HintsDispatcher.java b/src/java/org/apache/cassandra/hints/HintsDispatcher.java index 00ef52b..478a76b 100644 --- a/src/java/org/apache/cassandra/hints/HintsDispatcher.java +++ b/src/java/org/apache/cassandra/hints/HintsDispatcher.java @@ -27,7 +27,6 @@ import java.util.function.Function; import com.google.common.util.concurrent.RateLimiter; -import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.net.IAsyncCallbackWithFailure; import org.apache.cassandra.net.MessageIn; import org.apache.cassandra.net.MessagingService; @@ -178,7 +177,7 @@ final class HintsDispatcher implements AutoCloseable Outcome await() { - long timeout = TimeUnit.MILLISECONDS.toNanos(DatabaseDescriptor.getTimeout(MessagingService.Verb.HINT)) - (System.nanoTime() - start); + long timeout = TimeUnit.MILLISECONDS.toNanos(MessagingService.Verb.HINT.getTimeout()) - (System.nanoTime() - start); boolean timedOut; try http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/hints/LegacyHintsMigrator.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hints/LegacyHintsMigrator.java b/src/java/org/apache/cassandra/hints/LegacyHintsMigrator.java index 93c1193..50d8b6e 100644 --- a/src/java/org/apache/cassandra/hints/LegacyHintsMigrator.java +++ b/src/java/org/apache/cassandra/hints/LegacyHintsMigrator.java @@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.db.*; @@ -59,7 +60,7 @@ public final class LegacyHintsMigrator this.hintsDirectory = hintsDirectory; this.maxHintsFileSize = maxHintsFileSize; - legacyHintsTable = Keyspace.open(SystemKeyspace.NAME).getColumnFamilyStore(SystemKeyspace.LEGACY_HINTS); + legacyHintsTable = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(SystemKeyspace.LEGACY_HINTS); pageSize = calculatePageSize(legacyHintsTable); } @@ -88,7 +89,7 @@ public final class LegacyHintsMigrator logger.info("Migrating legacy hints to new storage"); // major-compact all of the existing sstables to get rid of the tombstones + expired hints - logger.info("Forcing a major compaction of {}.{} table", SystemKeyspace.NAME, SystemKeyspace.LEGACY_HINTS); + logger.info("Forcing a major compaction of {}.{} table", SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_HINTS); compactLegacyHints(); // paginate over legacy hints and write them to the new storage @@ -96,7 +97,7 @@ public final class LegacyHintsMigrator migrateLegacyHints(); // truncate the legacy hints table - logger.info("Truncating {}.{} table", SystemKeyspace.NAME, SystemKeyspace.LEGACY_HINTS); + logger.info("Truncating {}.{} table", SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_HINTS); legacyHintsTable.truncateBlocking(); } @@ -123,7 +124,7 @@ public final class LegacyHintsMigrator private void migrateLegacyHints() { ByteBuffer buffer = ByteBuffer.allocateDirect(256 * 1024); - String query = String.format("SELECT DISTINCT target_id FROM %s.%s", SystemKeyspace.NAME, SystemKeyspace.LEGACY_HINTS); + String query = String.format("SELECT DISTINCT target_id FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_HINTS); //noinspection ConstantConditions QueryProcessor.executeInternal(query).forEach(row -> migrateLegacyHints(row.getUUID("target_id"), buffer)); FileUtils.clean(buffer); @@ -134,7 +135,7 @@ public final class LegacyHintsMigrator String query = String.format("SELECT target_id, hint_id, message_version, mutation, ttl(mutation) AS ttl, writeTime(mutation) AS write_time " + "FROM %s.%s " + "WHERE target_id = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_HINTS); // read all the old hints (paged iterator), write them in the new format @@ -215,7 +216,7 @@ public final class LegacyHintsMigrator { logger.error("Failed to migrate a hint for {} from legacy {}.{} table", row.getUUID("target_id"), - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_HINTS, e); return null; @@ -224,7 +225,7 @@ public final class LegacyHintsMigrator { logger.warn("Failed to validate a hint for {} from legacy {}.{} table - skipping", row.getUUID("target_id"), - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_HINTS, e); return null; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java b/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java index f2ccd64..a2ed65c 100644 --- a/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java +++ b/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java @@ -17,7 +17,7 @@ */ package org.apache.cassandra.io.compress; -import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.schema.CompressionParams; import java.io.IOException; import java.nio.ByteBuffer; @@ -32,6 +32,20 @@ public class DeflateCompressor implements ICompressor { public static final DeflateCompressor instance = new DeflateCompressor(); + private static final ThreadLocal<byte[]> threadLocalScratchBuffer = new ThreadLocal<byte[]>() + { + @Override + protected byte[] initialValue() + { + return new byte[CompressionParams.DEFAULT_CHUNK_LENGTH]; + } + }; + + public static byte[] getThreadLocalScratchBuffer() + { + return threadLocalScratchBuffer.get(); + } + private final ThreadLocal<Deflater> deflater; private final ThreadLocal<Inflater> inflater; @@ -104,7 +118,7 @@ public class DeflateCompressor implements ICompressor Deflater def = deflater.get(); def.reset(); - byte[] buffer = FBUtilities.getThreadLocalScratchBuffer(); + byte[] buffer = getThreadLocalScratchBuffer(); // Use half the buffer for input, half for output. int chunkLen = buffer.length / 2; while (input.remaining() > chunkLen) @@ -149,7 +163,7 @@ public class DeflateCompressor implements ICompressor Inflater inf = inflater.get(); inf.reset(); - byte[] buffer = FBUtilities.getThreadLocalScratchBuffer(); + byte[] buffer = getThreadLocalScratchBuffer(); // Use half the buffer for input, half for output. int chunkLen = buffer.length / 2; while (input.remaining() > chunkLen) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java b/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java index 10b4caa..f989878 100644 --- a/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java +++ b/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java @@ -25,14 +25,10 @@ import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.compaction.OperationType; -import org.apache.cassandra.db.lifecycle.LifecycleTransaction; import org.apache.cassandra.db.rows.EncodingStats; import org.apache.cassandra.db.partitions.PartitionUpdate; import org.apache.cassandra.dht.IPartitioner; -import org.apache.cassandra.io.sstable.format.RangeAwareSSTableWriter; import org.apache.cassandra.io.sstable.format.SSTableFormat; import org.apache.cassandra.service.ActiveRepairService; import org.apache.cassandra.utils.Pair; @@ -45,7 +41,7 @@ abstract class AbstractSSTableSimpleWriter implements Closeable protected final ColumnFamilyStore cfs; protected final IPartitioner partitioner; protected final PartitionColumns columns; - protected SSTableFormat.Type formatType = DatabaseDescriptor.getSSTableFormat(); + protected SSTableFormat.Type formatType = SSTableFormat.Type.current(); protected static AtomicInteger generation = new AtomicInteger(0); protected boolean makeRangeAware = false; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/io/sstable/Descriptor.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/sstable/Descriptor.java b/src/java/org/apache/cassandra/io/sstable/Descriptor.java index 13611a6..3848771 100644 --- a/src/java/org/apache/cassandra/io/sstable/Descriptor.java +++ b/src/java/org/apache/cassandra/io/sstable/Descriptor.java @@ -61,6 +61,15 @@ public class Descriptor private final int hashCode; /** + * A descriptor that assumes CURRENT_VERSION. + */ + @VisibleForTesting + public Descriptor(File directory, String ksname, String cfname, int generation) + { + this(SSTableFormat.Type.current().info.getLatestVersion(), directory, ksname, cfname, generation, SSTableFormat.Type.current(), null); + } + + /** * Constructor for sstable writers only. */ public Descriptor(File directory, String ksname, String cfname, int generation, SSTableFormat.Type formatType) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/io/sstable/format/SSTableFormat.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/sstable/format/SSTableFormat.java b/src/java/org/apache/cassandra/io/sstable/format/SSTableFormat.java index a3f7520..4391946 100644 --- a/src/java/org/apache/cassandra/io/sstable/format/SSTableFormat.java +++ b/src/java/org/apache/cassandra/io/sstable/format/SSTableFormat.java @@ -51,6 +51,11 @@ public interface SSTableFormat public final SSTableFormat info; public final String name; + public static Type current() + { + return BIG; + } + private Type(String name, SSTableFormat info) { //Since format comes right after generation http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java index 32d3156..6c2243b 100644 --- a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java @@ -47,6 +47,7 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.Config; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.ColumnFilter; import org.apache.cassandra.db.rows.EncodingStats; @@ -136,11 +137,18 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS { private static final Logger logger = LoggerFactory.getLogger(SSTableReader.class); - private static final ScheduledThreadPoolExecutor syncExecutor = new ScheduledThreadPoolExecutor(1); - static + private static final ScheduledThreadPoolExecutor syncExecutor = initSyncExecutor(); + private static ScheduledThreadPoolExecutor initSyncExecutor() { + if (Config.isClientOrToolsMode()) + return null; + + // Do NOT start this thread pool in client mode + + ScheduledThreadPoolExecutor syncExecutor = new ScheduledThreadPoolExecutor(1); // Immediately remove readMeter sync task when cancelled. syncExecutor.setRemoveOnCancelPolicy(true); + return syncExecutor; } private static final RateLimiter meterSyncThrottle = RateLimiter.create(100.0); @@ -2205,7 +2213,8 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS // Don't track read rates for tables in the system keyspace and don't bother trying to load or persist // the read meter when in client mode. - if (Schema.isSystemKeyspace(desc.ksname)) + // Also, do not track read rates when running in client or tools mode (syncExecuter isn't available in these modes) + if (SchemaConstants.isSystemKeyspace(desc.ksname) || Config.isClientOrToolsMode()) { readMeter = null; readMeterSyncFuture = NULL; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java b/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java index de0cdde..ba587f3 100644 --- a/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java +++ b/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java @@ -31,6 +31,7 @@ import javax.management.MBeanServer; import javax.management.ObjectName; import org.apache.cassandra.concurrent.ScheduledExecutors; +import org.apache.cassandra.config.Config; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.gms.ApplicationState; import org.apache.cassandra.gms.EndpointState; @@ -100,9 +101,13 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa reset(); } }; - updateSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(update, dynamicUpdateInterval, dynamicUpdateInterval, TimeUnit.MILLISECONDS); - resetSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(reset, dynamicResetInterval, dynamicResetInterval, TimeUnit.MILLISECONDS); - registerMBean(); + + if (!Config.isClientOrToolsMode()) + { + updateSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(update, dynamicUpdateInterval, dynamicUpdateInterval, TimeUnit.MILLISECONDS); + resetSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(reset, dynamicResetInterval, dynamicResetInterval, TimeUnit.MILLISECONDS); + registerMBean(); + } } /** @@ -114,15 +119,21 @@ public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements ILa if (dynamicUpdateInterval != DatabaseDescriptor.getDynamicUpdateInterval()) { dynamicUpdateInterval = DatabaseDescriptor.getDynamicUpdateInterval(); - updateSchedular.cancel(false); - updateSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(update, dynamicUpdateInterval, dynamicUpdateInterval, TimeUnit.MILLISECONDS); + if (!Config.isClientOrToolsMode()) + { + updateSchedular.cancel(false); + updateSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(update, dynamicUpdateInterval, dynamicUpdateInterval, TimeUnit.MILLISECONDS); + } } if (dynamicResetInterval != DatabaseDescriptor.getDynamicResetInterval()) { dynamicResetInterval = DatabaseDescriptor.getDynamicResetInterval(); - resetSchedular.cancel(false); - resetSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(reset, dynamicResetInterval, dynamicResetInterval, TimeUnit.MILLISECONDS); + if (!Config.isClientOrToolsMode()) + { + resetSchedular.cancel(false); + resetSchedular = ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(reset, dynamicResetInterval, dynamicResetInterval, TimeUnit.MILLISECONDS); + } } dynamicBadnessThreshold = DatabaseDescriptor.getDynamicBadnessThreshold(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/metrics/TableMetrics.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/metrics/TableMetrics.java b/src/java/org/apache/cassandra/metrics/TableMetrics.java index d1d4a3d..f811873 100644 --- a/src/java/org/apache/cassandra/metrics/TableMetrics.java +++ b/src/java/org/apache/cassandra/metrics/TableMetrics.java @@ -29,6 +29,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.db.Memtable; @@ -37,7 +38,6 @@ import org.apache.cassandra.index.SecondaryIndexManager; import org.apache.cassandra.io.compress.CompressionMetadata; import org.apache.cassandra.io.sstable.format.SSTableReader; import org.apache.cassandra.io.sstable.metadata.MetadataCollector; -import org.apache.cassandra.repair.SystemDistributedKeyspace; import org.apache.cassandra.utils.EstimatedHistogram; import org.apache.cassandra.utils.TopKSampler; @@ -178,7 +178,7 @@ public class TableMetrics for (String keyspace : Schema.instance.getNonSystemKeyspaces()) { Keyspace k = Schema.instance.getKeyspaceInstance(keyspace); - if (SystemDistributedKeyspace.NAME.equals(k.getName())) + if (SchemaConstants.DISTRIBUTED_KEYSPACE_NAME.equals(k.getName())) continue; if (k.getReplicationStrategy().getReplicationFactor() < 2) continue; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/net/MessageIn.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/net/MessageIn.java b/src/java/org/apache/cassandra/net/MessageIn.java index 23b2995..a122b61 100644 --- a/src/java/org/apache/cassandra/net/MessageIn.java +++ b/src/java/org/apache/cassandra/net/MessageIn.java @@ -154,7 +154,7 @@ public class MessageIn<T> public long getTimeout() { - return DatabaseDescriptor.getTimeout(verb); + return verb.getTimeout(); } public long getSlowQueryTimeout() http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/net/MessageOut.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/net/MessageOut.java b/src/java/org/apache/cassandra/net/MessageOut.java index 77f0d55..a088335 100644 --- a/src/java/org/apache/cassandra/net/MessageOut.java +++ b/src/java/org/apache/cassandra/net/MessageOut.java @@ -27,7 +27,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import org.apache.cassandra.concurrent.Stage; -import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.TypeSizes; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.io.util.DataOutputBuffer; @@ -91,7 +90,7 @@ public class MessageOut<T> public long getTimeout() { - return DatabaseDescriptor.getTimeout(verb); + return verb.getTimeout(); } public String toString() http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/net/MessagingService.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/net/MessagingService.java b/src/java/org/apache/cassandra/net/MessagingService.java index 243bf0c..459c7e6 100644 --- a/src/java/org/apache/cassandra/net/MessagingService.java +++ b/src/java/org/apache/cassandra/net/MessagingService.java @@ -107,16 +107,58 @@ public final class MessagingService implements MessagingServiceMBean /* All verb handler identifiers */ public enum Verb { - MUTATION, - HINT, - READ_REPAIR, - READ, + MUTATION + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, + HINT + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, + READ_REPAIR + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, + READ + { + public long getTimeout() + { + return DatabaseDescriptor.getReadRpcTimeout(); + } + }, REQUEST_RESPONSE, // client-initiated reads and writes - BATCH_STORE, // was @Deprecated STREAM_INITIATE, - BATCH_REMOVE, // was @Deprecated STREAM_INITIATE_DONE, + BATCH_STORE + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, // was @Deprecated STREAM_INITIATE, + BATCH_REMOVE + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, // was @Deprecated STREAM_INITIATE_DONE, @Deprecated STREAM_REPLY, @Deprecated STREAM_REQUEST, - RANGE_SLICE, + RANGE_SLICE + { + public long getTimeout() + { + return DatabaseDescriptor.getRangeRpcTimeout(); + } + }, @Deprecated BOOTSTRAP_TOKEN, @Deprecated TREE_REQUEST, @Deprecated TREE_RESPONSE, @@ -126,12 +168,24 @@ public final class MessagingService implements MessagingServiceMBean GOSSIP_DIGEST_ACK2, @Deprecated DEFINITIONS_ANNOUNCE, DEFINITIONS_UPDATE, - TRUNCATE, + TRUNCATE + { + public long getTimeout() + { + return DatabaseDescriptor.getTruncateRpcTimeout(); + } + }, SCHEMA_CHECK, @Deprecated INDEX_SCAN, REPLICATION_FINISHED, INTERNAL_RESPONSE, // responses to internal calls - COUNTER_MUTATION, + COUNTER_MUTATION + { + public long getTimeout() + { + return DatabaseDescriptor.getCounterWriteRpcTimeout(); + } + }, @Deprecated STREAMING_REPAIR_REQUEST, @Deprecated STREAMING_REPAIR_RESPONSE, SNAPSHOT, // Similar to nt snapshot @@ -140,10 +194,34 @@ public final class MessagingService implements MessagingServiceMBean _TRACE, // dummy verb so we can use MS.droppedMessagesMap ECHO, REPAIR_MESSAGE, - PAXOS_PREPARE, - PAXOS_PROPOSE, - PAXOS_COMMIT, - @Deprecated PAGED_RANGE, + PAXOS_PREPARE + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, + PAXOS_PROPOSE + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, + PAXOS_COMMIT + { + public long getTimeout() + { + return DatabaseDescriptor.getWriteRpcTimeout(); + } + }, + @Deprecated PAGED_RANGE + { + public long getTimeout() + { + return DatabaseDescriptor.getRangeRpcTimeout(); + } + }, // remember to add new verbs at the end, since we serialize by ordinal UNUSED_1, UNUSED_2, @@ -161,6 +239,11 @@ public final class MessagingService implements MessagingServiceMBean return verb; } + + public long getTimeout() + { + return DatabaseDescriptor.getRpcTimeout(); + } } public static final Verb[] verbValues = Verb.values(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/repair/RepairRunnable.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/repair/RepairRunnable.java b/src/java/org/apache/cassandra/repair/RepairRunnable.java index a34401a..9c00025 100644 --- a/src/java/org/apache/cassandra/repair/RepairRunnable.java +++ b/src/java/org/apache/cassandra/repair/RepairRunnable.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.concurrent.JMXConfigurableThreadPoolExecutor; import org.apache.cassandra.concurrent.NamedThreadFactory; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.QueryOptions; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; @@ -375,7 +376,7 @@ public class RepairRunnable extends WrappedRunnable implements ProgressEventNoti throw new Exception("no tracestate"); String format = "select event_id, source, activity from %s.%s where session_id = ? and event_id > ? and event_id < ?;"; - String query = String.format(format, TraceKeyspace.NAME, TraceKeyspace.EVENTS); + String query = String.format(format, SchemaConstants.TRACE_KEYSPACE_NAME, TraceKeyspace.EVENTS); SelectStatement statement = (SelectStatement) QueryProcessor.parseStatement(query).prepare().statement; ByteBuffer sessionIdBytes = ByteBufferUtil.bytes(sessionId); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/repair/SystemDistributedKeyspace.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/repair/SystemDistributedKeyspace.java b/src/java/org/apache/cassandra/repair/SystemDistributedKeyspace.java index fbbc125..43fc586 100644 --- a/src/java/org/apache/cassandra/repair/SystemDistributedKeyspace.java +++ b/src/java/org/apache/cassandra/repair/SystemDistributedKeyspace.java @@ -38,6 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.db.ConsistencyLevel; @@ -60,8 +61,6 @@ public final class SystemDistributedKeyspace private static final Logger logger = LoggerFactory.getLogger(SystemDistributedKeyspace.class); - public static final String NAME = "system_distributed"; - public static final String REPAIR_HISTORY = "repair_history"; public static final String PARENT_REPAIR_HISTORY = "parent_repair_history"; @@ -115,13 +114,13 @@ public final class SystemDistributedKeyspace private static CFMetaData compile(String name, String description, String schema) { - return CFMetaData.compile(String.format(schema, name), NAME) + return CFMetaData.compile(String.format(schema, name), SchemaConstants.DISTRIBUTED_KEYSPACE_NAME) .comment(description); } public static KeyspaceMetadata metadata() { - return KeyspaceMetadata.create(NAME, KeyspaceParams.simple(3), Tables.of(RepairHistory, ParentRepairHistory, ViewBuildStatus)); + return KeyspaceMetadata.create(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, KeyspaceParams.simple(3), Tables.of(RepairHistory, ParentRepairHistory, ViewBuildStatus)); } public static void startParentRepair(UUID parent_id, String keyspaceName, String[] cfnames, RepairOption options) @@ -130,7 +129,7 @@ public final class SystemDistributedKeyspace String query = "INSERT INTO %s.%s (parent_id, keyspace_name, columnfamily_names, requested_ranges, started_at, options)"+ " VALUES (%s, '%s', { '%s' }, { '%s' }, toTimestamp(now()), { %s })"; String fmtQry = String.format(query, - NAME, + SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, PARENT_REPAIR_HISTORY, parent_id.toString(), keyspaceName, @@ -165,14 +164,14 @@ public final class SystemDistributedKeyspace StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); - String fmtQuery = String.format(query, NAME, PARENT_REPAIR_HISTORY, parent_id.toString()); + String fmtQuery = String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, PARENT_REPAIR_HISTORY, parent_id.toString()); processSilent(fmtQuery, t.getMessage(), sw.toString()); } public static void successfulParentRepair(UUID parent_id, Collection<Range<Token>> successfulRanges) { String query = "UPDATE %s.%s SET finished_at = toTimestamp(now()), successful_ranges = {'%s'} WHERE parent_id=%s"; - String fmtQuery = String.format(query, NAME, PARENT_REPAIR_HISTORY, Joiner.on("','").join(successfulRanges), parent_id.toString()); + String fmtQuery = String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, PARENT_REPAIR_HISTORY, Joiner.on("','").join(successfulRanges), parent_id.toString()); processSilent(fmtQuery); } @@ -192,7 +191,7 @@ public final class SystemDistributedKeyspace { for (Range<Token> range : ranges) { - String fmtQry = String.format(query, NAME, REPAIR_HISTORY, + String fmtQry = String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, REPAIR_HISTORY, keyspaceName, cfname, id.toString(), @@ -216,7 +215,7 @@ public final class SystemDistributedKeyspace public static void successfulRepairJob(UUID id, String keyspaceName, String cfname) { String query = "UPDATE %s.%s SET status = '%s', finished_at = toTimestamp(now()) WHERE keyspace_name = '%s' AND columnfamily_name = '%s' AND id = %s"; - String fmtQuery = String.format(query, NAME, REPAIR_HISTORY, + String fmtQuery = String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, REPAIR_HISTORY, RepairState.SUCCESS.toString(), keyspaceName, cfname, @@ -230,18 +229,18 @@ public final class SystemDistributedKeyspace StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); - String fmtQry = String.format(query, NAME, REPAIR_HISTORY, - RepairState.FAILED.toString(), - keyspaceName, - cfname, - id.toString()); + String fmtQry = String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, REPAIR_HISTORY, + RepairState.FAILED.toString(), + keyspaceName, + cfname, + id.toString()); processSilent(fmtQry, t.getMessage(), sw.toString()); } public static void startViewBuild(String keyspace, String view, UUID hostId) { String query = "INSERT INTO %s.%s (keyspace_name, view_name, host_id, status) VALUES (?, ?, ?, ?)"; - QueryProcessor.process(String.format(query, NAME, VIEW_BUILD_STATUS), + QueryProcessor.process(String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, VIEW_BUILD_STATUS), ConsistencyLevel.ONE, Lists.newArrayList(bytes(keyspace), bytes(view), @@ -252,7 +251,7 @@ public final class SystemDistributedKeyspace public static void successfulViewBuild(String keyspace, String view, UUID hostId) { String query = "UPDATE %s.%s SET status = ? WHERE keyspace_name = ? AND view_name = ? AND host_id = ?"; - QueryProcessor.process(String.format(query, NAME, VIEW_BUILD_STATUS), + QueryProcessor.process(String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, VIEW_BUILD_STATUS), ConsistencyLevel.ONE, Lists.newArrayList(bytes(BuildStatus.SUCCESS.toString()), bytes(keyspace), @@ -266,7 +265,7 @@ public final class SystemDistributedKeyspace UntypedResultSet results; try { - results = QueryProcessor.execute(String.format(query, NAME, VIEW_BUILD_STATUS), + results = QueryProcessor.execute(String.format(query, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, VIEW_BUILD_STATUS), ConsistencyLevel.ONE, keyspace, view); @@ -286,7 +285,7 @@ public final class SystemDistributedKeyspace public static void setViewRemoved(String keyspaceName, String viewName) { String buildReq = "DELETE FROM %s.%s WHERE keyspace_name = ? AND view_name = ?"; - QueryProcessor.executeInternal(String.format(buildReq, NAME, VIEW_BUILD_STATUS), keyspaceName, viewName); + QueryProcessor.executeInternal(String.format(buildReq, SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, VIEW_BUILD_STATUS), keyspaceName, viewName); forceBlockingFlush(VIEW_BUILD_STATUS); } @@ -310,7 +309,7 @@ public final class SystemDistributedKeyspace public static void forceBlockingFlush(String table) { if (!Boolean.getBoolean("cassandra.unsafesystem")) - FBUtilities.waitOnFuture(Keyspace.open(NAME).getColumnFamilyStore(table).forceFlush()); + FBUtilities.waitOnFuture(Keyspace.open(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME).getColumnFamilyStore(table).forceFlush()); } private enum RepairState http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/schema/KeyspaceMetadata.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/schema/KeyspaceMetadata.java b/src/java/org/apache/cassandra/schema/KeyspaceMetadata.java index e6f7754..4fefd44 100644 --- a/src/java/org/apache/cassandra/schema/KeyspaceMetadata.java +++ b/src/java/org/apache/cassandra/schema/KeyspaceMetadata.java @@ -28,7 +28,7 @@ import com.google.common.base.Objects; import com.google.common.collect.Iterables; import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.config.ViewDefinition; import org.apache.cassandra.exceptions.ConfigurationException; @@ -170,7 +170,7 @@ public final class KeyspaceMetadata if (!CFMetaData.isNameValid(name)) throw new ConfigurationException(String.format("Keyspace name must not be empty, more than %s characters long, " + "or contain non-alphanumeric-underscore characters (got \"%s\")", - Schema.NAME_LENGTH, + SchemaConstants.NAME_LENGTH, name)); params.validate(name); tablesAndViews().forEach(CFMetaData::validate); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java index ec50a39..05233bd 100644 --- a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java +++ b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java @@ -85,7 +85,7 @@ public final class LegacySchemaMigrator // write metadata to the new schema tables logger.info("Moving {} keyspaces from legacy schema tables to the new schema keyspace ({})", keyspaces.size(), - SchemaKeyspace.NAME); + SchemaConstants.SCHEMA_KEYSPACE_NAME); keyspaces.forEach(LegacySchemaMigrator::storeKeyspaceInNewSchemaTables); keyspaces.forEach(LegacySchemaMigrator::migrateBuiltIndexesForKeyspace); @@ -125,7 +125,7 @@ public final class LegacySchemaMigrator static void unloadLegacySchemaTables() { - KeyspaceMetadata systemKeyspace = Schema.instance.getKSMetaData(SystemKeyspace.NAME); + KeyspaceMetadata systemKeyspace = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME); Tables systemTables = systemKeyspace.tables; for (CFMetaData table : LegacySchemaTables) @@ -167,10 +167,10 @@ public final class LegacySchemaMigrator */ private static Collection<Keyspace> readSchema() { - String query = format("SELECT keyspace_name FROM %s.%s", SystemKeyspace.NAME, SystemKeyspace.LEGACY_KEYSPACES); + String query = format("SELECT keyspace_name FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_KEYSPACES); Collection<String> keyspaceNames = new ArrayList<>(); query(query).forEach(row -> keyspaceNames.add(row.getString("keyspace_name"))); - keyspaceNames.removeAll(Schema.SYSTEM_KEYSPACE_NAMES); + keyspaceNames.removeAll(SchemaConstants.SYSTEM_KEYSPACE_NAMES); Collection<Keyspace> keyspaces = new ArrayList<>(); keyspaceNames.forEach(name -> keyspaces.add(readKeyspace(name))); @@ -199,7 +199,7 @@ public final class LegacySchemaMigrator private static long readKeyspaceTimestamp(String keyspaceName) { String query = format("SELECT writeTime(durable_writes) AS timestamp FROM %s.%s WHERE keyspace_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_KEYSPACES); return query(query, keyspaceName).one().getLong("timestamp"); } @@ -207,7 +207,7 @@ public final class LegacySchemaMigrator private static KeyspaceParams readKeyspaceParams(String keyspaceName) { String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_KEYSPACES); UntypedResultSet.Row row = query(query, keyspaceName).one(); @@ -227,7 +227,7 @@ public final class LegacySchemaMigrator private static Collection<Table> readTables(String keyspaceName) { String query = format("SELECT columnfamily_name FROM %s.%s WHERE keyspace_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_COLUMNFAMILIES); Collection<String> tableNames = new ArrayList<>(); query(query, keyspaceName).forEach(row -> tableNames.add(row.getString("columnfamily_name"))); @@ -247,7 +247,7 @@ public final class LegacySchemaMigrator private static long readTableTimestamp(String keyspaceName, String tableName) { String query = format("SELECT writeTime(type) AS timestamp FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_COLUMNFAMILIES); return query(query, keyspaceName, tableName).one().getLong("timestamp"); } @@ -255,17 +255,17 @@ public final class LegacySchemaMigrator private static CFMetaData readTableMetadata(String keyspaceName, String tableName) { String tableQuery = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_COLUMNFAMILIES); UntypedResultSet.Row tableRow = query(tableQuery, keyspaceName, tableName).one(); String columnsQuery = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_COLUMNS); UntypedResultSet columnRows = query(columnsQuery, keyspaceName, tableName); String triggersQuery = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_TRIGGERS); UntypedResultSet triggerRows = query(triggersQuery, keyspaceName, tableName); @@ -811,7 +811,7 @@ public final class LegacySchemaMigrator private static Collection<Type> readTypes(String keyspaceName) { String query = format("SELECT type_name FROM %s.%s WHERE keyspace_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_USERTYPES); Collection<String> typeNames = new ArrayList<>(); query(query, keyspaceName).forEach(row -> typeNames.add(row.getString("type_name"))); @@ -834,7 +834,7 @@ public final class LegacySchemaMigrator */ private static long readTypeTimestamp(String keyspaceName, String typeName) { - ColumnFamilyStore store = org.apache.cassandra.db.Keyspace.open(SystemKeyspace.NAME) + ColumnFamilyStore store = org.apache.cassandra.db.Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME) .getColumnFamilyStore(SystemKeyspace.LEGACY_USERTYPES); ClusteringComparator comparator = store.metadata.comparator; @@ -853,7 +853,7 @@ public final class LegacySchemaMigrator private static UserType readTypeMetadata(String keyspaceName, String typeName) { String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND type_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_USERTYPES); UntypedResultSet.Row row = query(query, keyspaceName, typeName).one(); @@ -879,7 +879,7 @@ public final class LegacySchemaMigrator private static Collection<Function> readFunctions(String keyspaceName) { String query = format("SELECT function_name, signature FROM %s.%s WHERE keyspace_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_FUNCTIONS); HashMultimap<String, List<String>> functionSignatures = HashMultimap.create(); query(query, keyspaceName).forEach(row -> functionSignatures.put(row.getString("function_name"), row.getList("signature", UTF8Type.instance))); @@ -901,7 +901,7 @@ public final class LegacySchemaMigrator String query = format("SELECT writeTime(return_type) AS timestamp " + "FROM %s.%s " + "WHERE keyspace_name = ? AND function_name = ? AND signature = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_FUNCTIONS); return query(query, keyspaceName, functionName, signature).one().getLong("timestamp"); } @@ -909,7 +909,7 @@ public final class LegacySchemaMigrator private static UDFunction readFunctionMetadata(String keyspaceName, String functionName, List<String> signature) { String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND function_name = ? AND signature = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_FUNCTIONS); UntypedResultSet.Row row = query(query, keyspaceName, functionName, signature).one(); @@ -948,7 +948,7 @@ public final class LegacySchemaMigrator private static Collection<Aggregate> readAggregates(Functions functions, String keyspaceName) { String query = format("SELECT aggregate_name, signature FROM %s.%s WHERE keyspace_name = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_AGGREGATES); HashMultimap<String, List<String>> aggregateSignatures = HashMultimap.create(); query(query, keyspaceName).forEach(row -> aggregateSignatures.put(row.getString("aggregate_name"), row.getList("signature", UTF8Type.instance))); @@ -970,7 +970,7 @@ public final class LegacySchemaMigrator String query = format("SELECT writeTime(return_type) AS timestamp " + "FROM %s.%s " + "WHERE keyspace_name = ? AND aggregate_name = ? AND signature = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_AGGREGATES); return query(query, keyspaceName, aggregateName, signature).one().getLong("timestamp"); } @@ -978,7 +978,7 @@ public final class LegacySchemaMigrator private static UDAggregate readAggregateMetadata(Functions functions, String keyspaceName, String functionName, List<String> signature) { String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND aggregate_name = ? AND signature = ?", - SystemKeyspace.NAME, + SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.LEGACY_AGGREGATES); UntypedResultSet.Row row = query(query, keyspaceName, functionName, signature).one(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/schema/SchemaKeyspace.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java index 992ddfe..51812fb 100644 --- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java +++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java @@ -68,8 +68,6 @@ public final class SchemaKeyspace private static final boolean FLUSH_SCHEMA_TABLES = Boolean.parseBoolean(System.getProperty("cassandra.test.flush_local_schema_changes", "true")); - public static final String NAME = "system_schema"; - public static final String KEYSPACES = "keyspaces"; public static final String TABLES = "tables"; public static final String COLUMNS = "columns"; @@ -237,14 +235,14 @@ public final class SchemaKeyspace private static CFMetaData compile(String name, String description, String schema) { - return CFMetaData.compile(String.format(schema, name), NAME) + return CFMetaData.compile(String.format(schema, name), SchemaConstants.SCHEMA_KEYSPACE_NAME) .comment(description) .gcGraceSeconds((int) TimeUnit.DAYS.toSeconds(7)); } public static KeyspaceMetadata metadata() { - return KeyspaceMetadata.create(NAME, KeyspaceParams.local(), org.apache.cassandra.schema.Tables.of(ALL_TABLE_METADATA)); + return KeyspaceMetadata.create(SchemaConstants.SCHEMA_KEYSPACE_NAME, KeyspaceParams.local(), org.apache.cassandra.schema.Tables.of(ALL_TABLE_METADATA)); } /** @@ -252,16 +250,16 @@ public final class SchemaKeyspace */ public static void saveSystemKeyspacesSchema() { - KeyspaceMetadata system = Schema.instance.getKSMetaData(SystemKeyspace.NAME); - KeyspaceMetadata schema = Schema.instance.getKSMetaData(NAME); + KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME); + KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME); long timestamp = FBUtilities.timestampMicros(); // delete old, possibly obsolete entries in schema tables for (String schemaTable : ALL) { - String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", NAME, schemaTable); - for (String systemKeyspace : Schema.SYSTEM_KEYSPACE_NAMES) + String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable); + for (String systemKeyspace : SchemaConstants.SYSTEM_KEYSPACE_NAMES) executeOnceInternal(query, timestamp, systemKeyspace); } @@ -327,7 +325,7 @@ public final class SchemaKeyspace */ private static ColumnFamilyStore getSchemaCFS(String schemaTableName) { - return Keyspace.open(NAME).getColumnFamilyStore(schemaTableName); + return Keyspace.open(SchemaConstants.SCHEMA_KEYSPACE_NAME).getColumnFamilyStore(schemaTableName); } /** @@ -367,7 +365,7 @@ public final class SchemaKeyspace Mutation mutation = mutationMap.get(key); if (mutation == null) { - mutation = new Mutation(NAME, key); + mutation = new Mutation(SchemaConstants.SCHEMA_KEYSPACE_NAME, key); mutationMap.put(key, mutation); } @@ -379,7 +377,7 @@ public final class SchemaKeyspace private static boolean isSystemKeyspaceSchemaPartition(DecoratedKey partitionKey) { - return Schema.isSystemKeyspace(UTF8Type.instance.compose(partitionKey.getKey())); + return SchemaConstants.isSystemKeyspace(UTF8Type.instance.compose(partitionKey.getKey())); } /* @@ -419,7 +417,7 @@ public final class SchemaKeyspace public static Mutation.SimpleBuilder makeDropKeyspaceMutation(KeyspaceMetadata keyspace, long timestamp) { - Mutation.SimpleBuilder builder = Mutation.simpleBuilder(NAME, decorate(Keyspaces, keyspace.name)) + Mutation.SimpleBuilder builder = Mutation.simpleBuilder(SchemaConstants.SCHEMA_KEYSPACE_NAME, decorate(Keyspaces, keyspace.name)) .timestamp(timestamp); for (CFMetaData schemaTable : ALL_TABLE_METADATA) @@ -850,12 +848,12 @@ public final class SchemaKeyspace public static Keyspaces fetchNonSystemKeyspaces() { - return fetchKeyspacesWithout(Schema.SYSTEM_KEYSPACE_NAMES); + return fetchKeyspacesWithout(SchemaConstants.SYSTEM_KEYSPACE_NAMES); } private static Keyspaces fetchKeyspacesWithout(Set<String> excludedKeyspaceNames) { - String query = format("SELECT keyspace_name FROM %s.%s", NAME, KEYSPACES); + String query = format("SELECT keyspace_name FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, KEYSPACES); Keyspaces.Builder keyspaces = org.apache.cassandra.schema.Keyspaces.builder(); for (UntypedResultSet.Row row : query(query)) @@ -873,7 +871,7 @@ public final class SchemaKeyspace * We know the keyspace names we are going to query, but we still want to run the SELECT IN * query, to filter out the keyspaces that had been dropped by the applied mutation set. */ - String query = format("SELECT keyspace_name FROM %s.%s WHERE keyspace_name IN ?", NAME, KEYSPACES); + String query = format("SELECT keyspace_name FROM %s.%s WHERE keyspace_name IN ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, KEYSPACES); Keyspaces.Builder keyspaces = org.apache.cassandra.schema.Keyspaces.builder(); for (UntypedResultSet.Row row : query(query, new ArrayList<>(includedKeyspaceNames))) @@ -893,7 +891,7 @@ public final class SchemaKeyspace private static KeyspaceParams fetchKeyspaceParams(String keyspaceName) { - String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", NAME, KEYSPACES); + String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, KEYSPACES); UntypedResultSet.Row row = query(query, keyspaceName).one(); boolean durableWrites = row.getBoolean(KeyspaceParams.Option.DURABLE_WRITES.toString()); @@ -903,7 +901,7 @@ public final class SchemaKeyspace private static Types fetchTypes(String keyspaceName) { - String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", NAME, TYPES); + String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, TYPES); Types.RawBuilder types = org.apache.cassandra.schema.Types.rawBuilder(keyspaceName); for (UntypedResultSet.Row row : query(query, keyspaceName)) @@ -918,7 +916,7 @@ public final class SchemaKeyspace private static Tables fetchTables(String keyspaceName, Types types) { - String query = format("SELECT table_name FROM %s.%s WHERE keyspace_name = ?", NAME, TABLES); + String query = format("SELECT table_name FROM %s.%s WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, TABLES); Tables.Builder tables = org.apache.cassandra.schema.Tables.builder(); for (UntypedResultSet.Row row : query(query, keyspaceName)) @@ -928,7 +926,7 @@ public final class SchemaKeyspace private static CFMetaData fetchTable(String keyspaceName, String tableName, Types types) { - String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", NAME, TABLES); + String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, TABLES); UntypedResultSet rows = query(query, keyspaceName, tableName); if (rows.isEmpty()) throw new RuntimeException(String.format("%s:%s not found in the schema definitions keyspace.", keyspaceName, tableName)); @@ -994,7 +992,7 @@ public final class SchemaKeyspace private static List<ColumnDefinition> fetchColumns(String keyspace, String table, Types types) { - String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", NAME, COLUMNS); + String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, COLUMNS); List<ColumnDefinition> columns = new ArrayList<>(); query(query, keyspace, table).forEach(row -> columns.add(createColumnFromRow(row, types))); return columns; @@ -1021,7 +1019,7 @@ public final class SchemaKeyspace private static Map<ByteBuffer, CFMetaData.DroppedColumn> fetchDroppedColumns(String keyspace, String table) { - String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", NAME, DROPPED_COLUMNS); + String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, DROPPED_COLUMNS); Map<ByteBuffer, CFMetaData.DroppedColumn> columns = new HashMap<>(); for (UntypedResultSet.Row row : query(query, keyspace, table)) { @@ -1047,7 +1045,7 @@ public final class SchemaKeyspace private static Indexes fetchIndexes(String keyspace, String table) { - String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", NAME, INDEXES); + String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, INDEXES); Indexes.Builder indexes = org.apache.cassandra.schema.Indexes.builder(); query(query, keyspace, table).forEach(row -> indexes.add(createIndexMetadataFromRow(row))); return indexes.build(); @@ -1063,7 +1061,7 @@ public final class SchemaKeyspace private static Triggers fetchTriggers(String keyspace, String table) { - String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", NAME, TRIGGERS); + String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND table_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, TRIGGERS); Triggers.Builder triggers = org.apache.cassandra.schema.Triggers.builder(); query(query, keyspace, table).forEach(row -> triggers.add(createTriggerFromRow(row))); return triggers.build(); @@ -1078,7 +1076,7 @@ public final class SchemaKeyspace private static Views fetchViews(String keyspaceName, Types types) { - String query = format("SELECT view_name FROM %s.%s WHERE keyspace_name = ?", NAME, VIEWS); + String query = format("SELECT view_name FROM %s.%s WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, VIEWS); Views.Builder views = org.apache.cassandra.schema.Views.builder(); for (UntypedResultSet.Row row : query(query, keyspaceName)) @@ -1088,7 +1086,7 @@ public final class SchemaKeyspace private static ViewDefinition fetchView(String keyspaceName, String viewName, Types types) { - String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND view_name = ?", NAME, VIEWS); + String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND view_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, VIEWS); UntypedResultSet rows = query(query, keyspaceName, viewName); if (rows.isEmpty()) throw new RuntimeException(String.format("%s:%s not found in the schema definitions keyspace.", keyspaceName, viewName)); @@ -1136,7 +1134,7 @@ public final class SchemaKeyspace private static Functions fetchUDFs(String keyspaceName, Types types) { - String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", NAME, FUNCTIONS); + String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, FUNCTIONS); Functions.Builder functions = org.apache.cassandra.schema.Functions.builder(); for (UntypedResultSet.Row row : query(query, keyspaceName)) @@ -1197,7 +1195,7 @@ public final class SchemaKeyspace private static Functions fetchUDAs(String keyspaceName, Functions udfs, Types types) { - String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", NAME, AGGREGATES); + String query = format("SELECT * FROM %s.%s WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, AGGREGATES); Functions.Builder aggregates = org.apache.cassandra.schema.Functions.builder(); for (UntypedResultSet.Row row : query(query, keyspaceName)) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/service/CassandraDaemon.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java b/src/java/org/apache/cassandra/service/CassandraDaemon.java index eaf35ac..d18fc82 100644 --- a/src/java/org/apache/cassandra/service/CassandraDaemon.java +++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java @@ -50,11 +50,13 @@ import com.addthis.metrics3.reporter.config.ReporterConfig; import com.codahale.metrics.Meter; import com.codahale.metrics.MetricRegistryListener; import com.codahale.metrics.SharedMetricRegistries; +import org.apache.cassandra.auth.AuthConfig; import org.apache.cassandra.batchlog.LegacyBatchlogMigrator; import org.apache.cassandra.concurrent.ScheduledExecutors; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.functions.ThreadAwareSecurityManager; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.db.*; @@ -153,7 +155,7 @@ public class CassandraDaemon } } - private static final CassandraDaemon instance = new CassandraDaemon(); + static final CassandraDaemon instance = new CassandraDaemon(); public Server thriftServer; private NativeTransportService nativeTransportService; @@ -264,7 +266,7 @@ public class CassandraDaemon for (String keyspaceName : Schema.instance.getKeyspaces()) { // Skip system as we've already cleaned it - if (keyspaceName.equals(SystemKeyspace.NAME)) + if (keyspaceName.equals(SchemaConstants.SYSTEM_KEYSPACE_NAME)) continue; for (CFMetaData cfm : Schema.instance.getTablesAndViews(keyspaceName)) @@ -575,14 +577,7 @@ public class CassandraDaemon // Do not put any references to DatabaseDescriptor above the forceStaticInitialization call. try { - try - { - DatabaseDescriptor.forceStaticInitialization(); - } - catch (ExceptionInInitializerError e) - { - throw e.getCause(); - } + applyConfig(); try { @@ -645,6 +640,12 @@ public class CassandraDaemon } } + public void applyConfig() + { + DatabaseDescriptor.daemonInitialization(); + AuthConfig.applyAuthz(); + } + public void startNativeTransport() { if (nativeTransportService == null) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/service/ClientState.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/ClientState.java b/src/java/org/apache/cassandra/service/ClientState.java index b131701..b109b67 100644 --- a/src/java/org/apache/cassandra/service/ClientState.java +++ b/src/java/org/apache/cassandra/service/ClientState.java @@ -32,6 +32,7 @@ import org.apache.cassandra.config.Config; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.QueryHandler; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.functions.Function; @@ -41,7 +42,6 @@ import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.UnauthorizedException; import org.apache.cassandra.schema.SchemaKeyspace; import org.apache.cassandra.thrift.ThriftValidation; -import org.apache.cassandra.tracing.TraceKeyspace; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.JVMStabilityInspector; import org.apache.cassandra.utils.CassandraVersion; @@ -63,11 +63,12 @@ public class ClientState // We want these system cfs to be always readable to authenticated users since many tools rely on them // (nodetool, cqlsh, bulkloader, etc.) for (String cf : Arrays.asList(SystemKeyspace.LOCAL, SystemKeyspace.PEERS)) - READABLE_SYSTEM_RESOURCES.add(DataResource.table(SystemKeyspace.NAME, cf)); + READABLE_SYSTEM_RESOURCES.add(DataResource.table(SchemaConstants.SYSTEM_KEYSPACE_NAME, cf)); - SchemaKeyspace.ALL.forEach(table -> READABLE_SYSTEM_RESOURCES.add(DataResource.table(SchemaKeyspace.NAME, table))); + SchemaKeyspace.ALL.forEach(table -> READABLE_SYSTEM_RESOURCES.add(DataResource.table(SchemaConstants.SCHEMA_KEYSPACE_NAME, table))); - if (!Config.isClientMode()) + // neither clients nor tools need authentication/authorization + if (!Config.isClientOrToolsMode()) { PROTECTED_AUTH_RESOURCES.addAll(DatabaseDescriptor.getAuthenticator().protectedResources()); PROTECTED_AUTH_RESOURCES.addAll(DatabaseDescriptor.getAuthorizer().protectedResources()); @@ -77,11 +78,11 @@ public class ClientState // allow users with sufficient privileges to alter KS level options on AUTH_KS and // TRACING_KS, and also to drop legacy tables (users, credentials, permissions) from // AUTH_KS - ALTERABLE_SYSTEM_KEYSPACES.add(AuthKeyspace.NAME); - ALTERABLE_SYSTEM_KEYSPACES.add(TraceKeyspace.NAME); - DROPPABLE_SYSTEM_TABLES.add(DataResource.table(AuthKeyspace.NAME, PasswordAuthenticator.LEGACY_CREDENTIALS_TABLE)); - DROPPABLE_SYSTEM_TABLES.add(DataResource.table(AuthKeyspace.NAME, CassandraRoleManager.LEGACY_USERS_TABLE)); - DROPPABLE_SYSTEM_TABLES.add(DataResource.table(AuthKeyspace.NAME, CassandraAuthorizer.USER_PERMISSIONS)); + ALTERABLE_SYSTEM_KEYSPACES.add(SchemaConstants.AUTH_KEYSPACE_NAME); + ALTERABLE_SYSTEM_KEYSPACES.add(SchemaConstants.TRACE_KEYSPACE_NAME); + DROPPABLE_SYSTEM_TABLES.add(DataResource.table(SchemaConstants.AUTH_KEYSPACE_NAME, PasswordAuthenticator.LEGACY_CREDENTIALS_TABLE)); + DROPPABLE_SYSTEM_TABLES.add(DataResource.table(SchemaConstants.AUTH_KEYSPACE_NAME, CassandraRoleManager.LEGACY_USERS_TABLE)); + DROPPABLE_SYSTEM_TABLES.add(DataResource.table(SchemaConstants.AUTH_KEYSPACE_NAME, CassandraAuthorizer.USER_PERMISSIONS)); } // Current user for the session @@ -323,7 +324,7 @@ public class ClientState // Access to built in functions is unrestricted if(resource instanceof FunctionResource && resource.hasParent()) - if (((FunctionResource)resource).getKeyspace().equals(SystemKeyspace.NAME)) + if (((FunctionResource)resource).getKeyspace().equals(SchemaConstants.SYSTEM_KEYSPACE_NAME)) return; checkPermissionOnResourceChain(perm, resource); @@ -365,7 +366,7 @@ public class ClientState return; // prevent system keyspace modification - if (Schema.isSystemKeyspace(keyspace)) + if (SchemaConstants.isSystemKeyspace(keyspace)) throw new UnauthorizedException(keyspace + " keyspace is not user-modifiable."); // allow users with sufficient privileges to alter KS level options on AUTH_KS and http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/service/EmbeddedCassandraService.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/EmbeddedCassandraService.java b/src/java/org/apache/cassandra/service/EmbeddedCassandraService.java index 659d851..2515259 100644 --- a/src/java/org/apache/cassandra/service/EmbeddedCassandraService.java +++ b/src/java/org/apache/cassandra/service/EmbeddedCassandraService.java @@ -19,8 +19,6 @@ package org.apache.cassandra.service; import java.io.IOException; -import org.apache.cassandra.service.CassandraDaemon; - /** * An embedded, in-memory cassandra storage service that listens * on the thrift interface as configured in cassandra.yaml @@ -48,7 +46,8 @@ public class EmbeddedCassandraService public void start() throws IOException { - cassandraDaemon = new CassandraDaemon(); + cassandraDaemon = CassandraDaemon.instance; + cassandraDaemon.applyConfig(); cassandraDaemon.init(null); cassandraDaemon.start(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/service/MigrationManager.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/MigrationManager.java b/src/java/org/apache/cassandra/service/MigrationManager.java index 7eac678..89933a3 100644 --- a/src/java/org/apache/cassandra/service/MigrationManager.java +++ b/src/java/org/apache/cassandra/service/MigrationManager.java @@ -31,6 +31,7 @@ import org.apache.cassandra.concurrent.Stage; import org.apache.cassandra.concurrent.StageManager; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.config.ViewDefinition; import org.apache.cassandra.cql3.functions.UDAggregate; import org.apache.cassandra.cql3.functions.UDFunction; @@ -95,7 +96,7 @@ public class MigrationManager return; } - if (Schema.emptyVersion.equals(Schema.instance.getVersion()) || runtimeMXBean.getUptime() < MIGRATION_DELAY_IN_MS) + if (SchemaConstants.emptyVersion.equals(Schema.instance.getVersion()) || runtimeMXBean.getUptime() < MIGRATION_DELAY_IN_MS) { // If we think we may be bootstrapping or have recently started, submit MigrationTask immediately logger.debug("Submitting migration task for {}", endpoint); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/src/java/org/apache/cassandra/service/StartupChecks.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/StartupChecks.java b/src/java/org/apache/cassandra/service/StartupChecks.java index edb63ce..83971dd 100644 --- a/src/java/org/apache/cassandra/service/StartupChecks.java +++ b/src/java/org/apache/cassandra/service/StartupChecks.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Directories; import org.apache.cassandra.db.SystemKeyspace; @@ -317,7 +318,7 @@ public class StartupChecks // we do a one-off scrub of the system keyspace first; we can't load the list of the rest of the keyspaces, // until system keyspace is opened. - for (CFMetaData cfm : Schema.instance.getTablesAndViews(SystemKeyspace.NAME)) + for (CFMetaData cfm : Schema.instance.getTablesAndViews(SchemaConstants.SYSTEM_KEYSPACE_NAME)) ColumnFamilyStore.scrubDataDirectories(cfm); try