Elffuss BraidHub

kikocis/java-driver public

Merge pull request #463 from datastax/java825b

Make TableOrView public to allow TableOrView.Option to be referenced outside package.
Changeset3c741ee68bee4790d879814446d744ca43d181d7c15e439aa965cd34c3438311
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2015-10-14 22:15 +02:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2015-10-14 22:15 +02:00
Parents8c5bb0f4ce98, 15c1ca636354

Browse the files at this changeset

6 files changed

modified changelog/README.md +1 −0
@@ -9,6 +9,7 @@
99 - [bug] Fix Configuration builder to allow disabled metrics (JAVA-900)
1010 - [new feature] Prepare API for async query trace (JAVA-902)
1111 - [new feature] Add BoundStatement#unset (JAVA-930)
12+- [bug] Make table metadata options class visible (JAVA-946)
1213
1314
1415 ### 3.0.0-alpha3
modified driver-core/src/main/java/com/datastax/driver/core/MaterializedViewMetadata.java +7 −6
@@ -47,7 +47,7 @@
4747 Map<String, ColumnMetadata> columns,
4848 boolean includeAllColumns,
4949 String whereClause,
50- Options options,
50+ TableOptionsMetadata options,
5151 List<Order> clusteringOrder,
5252 VersionNumber cassandraVersion) {
5353 super(keyspace, name, id, partitionKey, clusteringColumns, columns, options, clusteringOrder, cassandraVersion);
@@ -74,16 +74,17 @@
7474
7575 int partitionKeySize = findCollectionSize(rawCols.values(), ColumnMetadata.Raw.Kind.PARTITION_KEY);
7676 int clusteringSize = findCollectionSize(rawCols.values(), ColumnMetadata.Raw.Kind.CLUSTERING_COLUMN);
77- List<ColumnMetadata> partitionKey = nullInitializedList(partitionKeySize);
78- List<ColumnMetadata> clusteringColumns = nullInitializedList(clusteringSize);
79- List<Order> clusteringOrder = nullInitializedList(clusteringSize);
77+
78+ List<ColumnMetadata> partitionKey = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(partitionKeySize, null));
79+ List<ColumnMetadata> clusteringColumns = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(clusteringSize, null));
80+ List<Order> clusteringOrder = new ArrayList<Order>(Collections.<Order>nCopies(clusteringSize, null));
8081
8182 // We use a linked hashmap because we will keep this in the order of a 'SELECT * FROM ...'.
8283 LinkedHashMap<String, ColumnMetadata> columns = new LinkedHashMap<String, ColumnMetadata>();
8384
84- Options options = null;
85+ TableOptionsMetadata options = null;
8586 try {
86- options = new Options(row, false, cassandraVersion);
87+ options = new TableOptionsMetadata(row, false, cassandraVersion);
8788 } catch (RuntimeException e) {
8889 // See ControlConnection#refreshSchema for why we'd rather not probably this further. Since table options is one thing
8990 // that tends to change often in Cassandra, it's worth special casing this.
modified driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java +6 −8
@@ -15,10 +15,8 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-
1918 import java.util.*;
2019
21-import com.google.common.base.*;
2220 import com.google.common.base.Objects;
2321 import org.slf4j.Logger;
2422 import org.slf4j.LoggerFactory;
@@ -63,7 +61,7 @@
6361 List<ColumnMetadata> clusteringColumns,
6462 Map<String, ColumnMetadata> columns,
6563 Map<String, IndexMetadata> indexes,
66- Options options,
64+ TableOptionsMetadata options,
6765 List<Order> clusteringOrder,
6866 VersionNumber cassandraVersion) {
6967 super(keyspace, name, id, partitionKey, clusteringColumns, columns, options, clusteringOrder, cassandraVersion);
@@ -123,17 +121,17 @@
123121 isCompact = isDense || !comparator.isComposite;
124122 }
125123
126- List<ColumnMetadata> partitionKey = nullInitializedList(partitionKeySize);
127- List<ColumnMetadata> clusteringColumns = nullInitializedList(clusteringSize);
128- List<Order> clusteringOrder = nullInitializedList(clusteringSize);
124+ List<ColumnMetadata> partitionKey = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(partitionKeySize, null));
125+ List<ColumnMetadata> clusteringColumns = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(clusteringSize, null));
126+ List<Order> clusteringOrder = new ArrayList<Order>(Collections.<Order>nCopies(clusteringSize, null));
129127
130128 // We use a linked hashmap because we will keep this in the order of a 'SELECT * FROM ...'.
131129 LinkedHashMap<String, ColumnMetadata> columns = new LinkedHashMap<String, ColumnMetadata>();
132130 LinkedHashMap<String, IndexMetadata> indexes = new LinkedHashMap<String, IndexMetadata>();
133131
134- Options options = null;
132+ TableOptionsMetadata options = null;
135133 try {
136- options = new Options(row, isCompact, cassandraVersion);
134+ options = new TableOptionsMetadata(row, isCompact, cassandraVersion);
137135 } catch (RuntimeException e) {
138136 // See ControlConnection#refreshSchema for why we'd rather not probably this further. Since table options is one thing
139137 // that tends to change often in Cassandra, it's worth special casing this.
added driver-core/src/main/java/com/datastax/driver/core/TableOptionsMetadata.java +403 −0
@@ -0,0 +1,403 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core;
17+
18+import java.nio.ByteBuffer;
19+import java.util.Map;
20+
21+import com.google.common.base.Objects;
22+import com.google.common.collect.ImmutableMap;
23+
24+public class TableOptionsMetadata {
25+
26+ private static final String COMMENT = "comment";
27+ private static final String READ_REPAIR = "read_repair_chance";
28+ private static final String DCLOCAL_READ_REPAIR = "dclocal_read_repair_chance";
29+ private static final String LOCAL_READ_REPAIR = "local_read_repair_chance";
30+ private static final String REPLICATE_ON_WRITE = "replicate_on_write";
31+ private static final String GC_GRACE = "gc_grace_seconds";
32+ private static final String BF_FP_CHANCE = "bloom_filter_fp_chance";
33+ private static final String CACHING = "caching";
34+ private static final String COMPACTION = "compaction";
35+ private static final String COMPACTION_CLASS = "compaction_strategy_class";
36+ private static final String COMPACTION_OPTIONS = "compaction_strategy_options";
37+ private static final String POPULATE_CACHE_ON_FLUSH = "populate_io_cache_on_flush";
38+ private static final String COMPRESSION = "compression";
39+ private static final String COMPRESSION_PARAMS = "compression_parameters";
40+ private static final String MEMTABLE_FLUSH_PERIOD_MS = "memtable_flush_period_in_ms";
41+ private static final String DEFAULT_TTL = "default_time_to_live";
42+ private static final String SPECULATIVE_RETRY = "speculative_retry";
43+ private static final String INDEX_INTERVAL = "index_interval";
44+ private static final String MIN_INDEX_INTERVAL = "min_index_interval";
45+ private static final String MAX_INDEX_INTERVAL = "max_index_interval";
46+ private static final String CRC_CHECK_CHANCE = "crc_check_chance";
47+ private static final String EXTENSIONS = "extensions";
48+
49+ private static final boolean DEFAULT_REPLICATE_ON_WRITE = true;
50+ private static final double DEFAULT_BF_FP_CHANCE = 0.01;
51+ private static final boolean DEFAULT_POPULATE_CACHE_ON_FLUSH = false;
52+ private static final int DEFAULT_MEMTABLE_FLUSH_PERIOD = 0;
53+ private static final int DEFAULT_DEFAULT_TTL = 0;
54+ private static final String DEFAULT_SPECULATIVE_RETRY = "NONE";
55+ private static final int DEFAULT_INDEX_INTERVAL = 128;
56+ private static final int DEFAULT_MIN_INDEX_INTERVAL = 128;
57+ private static final int DEFAULT_MAX_INDEX_INTERVAL = 2048;
58+ private static final double DEFAULT_CRC_CHECK_CHANCE = 1.0;
59+
60+ private final boolean isCompactStorage;
61+
62+ private final String comment;
63+ private final double readRepair;
64+ private final double localReadRepair;
65+ private final boolean replicateOnWrite;
66+ private final int gcGrace;
67+ private final double bfFpChance;
68+ private final Map<String, String> caching;
69+ private final boolean populateCacheOnFlush;
70+ private final int memtableFlushPeriodMs;
71+ private final int defaultTTL;
72+ private final String speculativeRetry;
73+ private final Integer indexInterval;
74+ private final Integer minIndexInterval;
75+ private final Integer maxIndexInterval;
76+ private final Map<String, String> compaction;
77+ private final Map<String, String> compression;
78+ private final Double crcCheckChance;
79+ private final Map<String, ByteBuffer> extensions;
80+
81+ TableOptionsMetadata(Row row, boolean isCompactStorage, VersionNumber version) {
82+
83+ boolean is120 = version.getMajor() < 2;
84+ boolean is200 = version.getMajor() == 2 && version.getMinor() == 0;
85+ boolean is210 = version.getMajor() == 2 && version.getMinor() >= 1;
86+ boolean is300OrHigher = version.getMajor() > 2;
87+ boolean is210OrHigher = is210 || is300OrHigher;
88+
89+ this.isCompactStorage = isCompactStorage;
90+ this.comment = isNullOrAbsent(row, COMMENT) ? "" : row.getString(COMMENT);
91+ this.readRepair = row.getDouble(READ_REPAIR);
92+
93+ if (is300OrHigher)
94+ this.localReadRepair = row.getDouble(DCLOCAL_READ_REPAIR);
95+ else
96+ this.localReadRepair = row.getDouble(LOCAL_READ_REPAIR);
97+
98+ this.replicateOnWrite = is210OrHigher || isNullOrAbsent(row, REPLICATE_ON_WRITE) ? DEFAULT_REPLICATE_ON_WRITE : row.getBool(REPLICATE_ON_WRITE);
99+ this.gcGrace = row.getInt(GC_GRACE);
100+ this.bfFpChance = isNullOrAbsent(row, BF_FP_CHANCE) ? DEFAULT_BF_FP_CHANCE : row.getDouble(BF_FP_CHANCE);
101+
102+ this.populateCacheOnFlush = isNullOrAbsent(row, POPULATE_CACHE_ON_FLUSH) ? DEFAULT_POPULATE_CACHE_ON_FLUSH : row.getBool(POPULATE_CACHE_ON_FLUSH);
103+ this.memtableFlushPeriodMs = is120 || isNullOrAbsent(row, MEMTABLE_FLUSH_PERIOD_MS) ? DEFAULT_MEMTABLE_FLUSH_PERIOD : row.getInt(MEMTABLE_FLUSH_PERIOD_MS);
104+ this.defaultTTL = is120 || isNullOrAbsent(row, DEFAULT_TTL) ? DEFAULT_DEFAULT_TTL : row.getInt(DEFAULT_TTL);
105+ this.speculativeRetry = is120 || isNullOrAbsent(row, SPECULATIVE_RETRY) ? DEFAULT_SPECULATIVE_RETRY : row.getString(SPECULATIVE_RETRY);
106+
107+ if (is200)
108+ this.indexInterval = isNullOrAbsent(row, INDEX_INTERVAL) ? DEFAULT_INDEX_INTERVAL : row.getInt(INDEX_INTERVAL);
109+ else
110+ this.indexInterval = null;
111+
112+ if (is210OrHigher) {
113+ this.minIndexInterval = isNullOrAbsent(row, MIN_INDEX_INTERVAL)
114+ ? DEFAULT_MIN_INDEX_INTERVAL
115+ : row.getInt(MIN_INDEX_INTERVAL);
116+ this.maxIndexInterval = isNullOrAbsent(row, MAX_INDEX_INTERVAL)
117+ ? DEFAULT_MAX_INDEX_INTERVAL
118+ : row.getInt(MAX_INDEX_INTERVAL);
119+ } else {
120+ this.minIndexInterval = null;
121+ this.maxIndexInterval = null;
122+ }
123+
124+ if (is300OrHigher) {
125+ this.caching = ImmutableMap.copyOf(row.getMap(CACHING, String.class, String.class));
126+ } else if (is210) {
127+ this.caching = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(CACHING)));
128+ } else {
129+ this.caching = ImmutableMap.of("keys", row.getString(CACHING));
130+ }
131+
132+ if (is300OrHigher)
133+ this.compaction = ImmutableMap.copyOf(row.getMap(COMPACTION, String.class, String.class));
134+ else {
135+ this.compaction = ImmutableMap.<String, String>builder()
136+ .put("class", row.getString(COMPACTION_CLASS))
137+ .putAll(SimpleJSONParser.parseStringMap(row.getString(COMPACTION_OPTIONS)))
138+ .build();
139+ }
140+
141+ if (is300OrHigher)
142+ this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class));
143+ else
144+ this.compression = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(COMPRESSION_PARAMS)));
145+
146+ if (is300OrHigher)
147+ this.crcCheckChance = isNullOrAbsent(row, CRC_CHECK_CHANCE)
148+ ? DEFAULT_CRC_CHECK_CHANCE
149+ : row.getDouble(CRC_CHECK_CHANCE);
150+ else
151+ this.crcCheckChance = null;
152+
153+ if(is300OrHigher)
154+ this.extensions = ImmutableMap.copyOf(row.getMap(EXTENSIONS, String.class, ByteBuffer.class));
155+ else
156+ this.extensions = ImmutableMap.of();
157+ }
158+
159+ private static boolean isNullOrAbsent(Row row, String name) {
160+ return row.getColumnDefinitions().getIndexOf(name) < 0
161+ || row.isNull(name);
162+ }
163+
164+ /**
165+ * Returns whether the table uses the {@code COMPACT STORAGE} option.
166+ *
167+ * @return whether the table uses the {@code COMPACT STORAGE} option.
168+ */
169+ public boolean isCompactStorage() {
170+ return isCompactStorage;
171+ }
172+
173+ /**
174+ * Returns the commentary set for this table.
175+ *
176+ * @return the commentary set for this table, or {@code null} if noe has been set.
177+ */
178+ public String getComment() {
179+ return comment;
180+ }
181+
182+ /**
183+ * Returns the chance with which a read repair is triggered for this table.
184+ *
185+ * @return the read repair chance set for table (in [0.0, 1.0]).
186+ */
187+ public double getReadRepairChance() {
188+ return readRepair;
189+ }
190+
191+ /**
192+ * Returns the cluster local read repair chance set for this table.
193+ *
194+ * @return the local read repair chance set for table (in [0.0, 1.0]).
195+ */
196+ public double getLocalReadRepairChance() {
197+ return localReadRepair;
198+ }
199+
200+ /**
201+ * Returns whether replicateOnWrite is set for this table.
202+ *
203+ * This is only meaningful for tables holding counters.
204+ *
205+ * @return whether replicateOnWrite is set for this table.
206+ */
207+ public boolean getReplicateOnWrite() {
208+ return replicateOnWrite;
209+ }
210+
211+ /**
212+ * Returns the tombstone garbage collection grace time in seconds for this table.
213+ *
214+ * @return the tombstone garbage collection grace time in seconds for this table.
215+ */
216+ public int getGcGraceInSeconds() {
217+ return gcGrace;
218+ }
219+
220+ /**
221+ * Returns the false positive chance for the Bloom filter of this table.
222+ *
223+ * @return the Bloom filter false positive chance for this table (in [0.0, 1.0]).
224+ */
225+ public double getBloomFilterFalsePositiveChance() {
226+ return bfFpChance;
227+ }
228+
229+ /**
230+ * Returns the caching options for this table.
231+ *
232+ * @return an immutable map containing the caching options for this table.
233+ */
234+ public Map<String, String> getCaching() {
235+ return caching;
236+ }
237+
238+ /**
239+ * Whether the populate I/O cache on flush is set on this table.
240+ *
241+ * @return whether the populate I/O cache on flush is set on this table.
242+ */
243+ public boolean getPopulateIOCacheOnFlush() {
244+ return populateCacheOnFlush;
245+ }
246+
247+ /*
248+ * Returns the memtable flush period (in milliseconds) option for this table.
249+ * <p>
250+ * Note: this option is not available in Cassandra 1.2 and will return 0 (no periodic
251+ * flush) when connected to 1.2 nodes.
252+ *
253+ * @return the memtable flush period option for this table or 0 if no
254+ * periodic flush is configured.
255+ */
256+ public int getMemtableFlushPeriodInMs() {
257+ return memtableFlushPeriodMs;
258+ }
259+
260+ /**
261+ * Returns the default TTL for this table.
262+ * <p>
263+ * Note: this option is not available in Cassandra 1.2 and will return 0 (no default
264+ * TTL) when connected to 1.2 nodes.
265+ *
266+ * @return the default TTL for this table or 0 if no default TTL is
267+ * configured.
268+ */
269+ public int getDefaultTimeToLive() {
270+ return defaultTTL;
271+ }
272+
273+ /**
274+ * Returns the speculative retry option for this table.
275+ * <p>
276+ * Note: this option is not available in Cassandra 1.2 and will return "NONE" (no
277+ * speculative retry) when connected to 1.2 nodes.
278+ *
279+ * @return the speculative retry option this table.
280+ */
281+ public String getSpeculativeRetry() {
282+ return speculativeRetry;
283+ }
284+
285+ /**
286+ * Returns the index interval option for this table.
287+ * <p>
288+ * Note: this option is not available in Cassandra 1.2 (more precisely, it is not
289+ * configurable per-table) and will return 128 (the default index interval) when
290+ * connected to 1.2 nodes. It is deprecated in Cassandra 2.1 and above, and will
291+ * therefore return {@code null} for 2.1 nodes.
292+ *
293+ * @return the index interval option for this table.
294+ */
295+ public Integer getIndexInterval() {
296+ return indexInterval;
297+ }
298+
299+ /**
300+ * Returns the minimum index interval option for this table.
301+ * <p>
302+ * Note: this option is available in Cassandra 2.1 and above, and will return
303+ * {@code null} for earlier versions.
304+ *
305+ * @return the minimum index interval option for this table.
306+ */
307+ public Integer getMinIndexInterval() {
308+ return minIndexInterval;
309+ }
310+
311+ /**
312+ * Returns the maximum index interval option for this table.
313+ * <p>
314+ * Note: this option is available in Cassandra 2.1 and above, and will return
315+ * {@code null} for earlier versions.
316+ *
317+ * @return the maximum index interval option for this table.
318+ */
319+ public Integer getMaxIndexInterval() {
320+ return maxIndexInterval;
321+ }
322+
323+ /**
324+ * When compression is enabled, this option defines the probability
325+ * with which checksums for compressed blocks are checked during reads.
326+ * The default value for this options is 1.0 (always check).
327+ * <p>
328+ * Note that this option is available in Cassandra 3.0.0 and above, when it
329+ * became a "top-level" table option, whereas previously it was a suboption
330+ * of the {@link #getCompression() compression} option.
331+ * <p>
332+ * For Cassandra versions prior to 3.0.0, this method always returns {@code null}.
333+ *
334+ * @return the probability with which checksums for compressed blocks are checked during reads
335+ */
336+ public Double getCrcCheckChance() {
337+ return crcCheckChance;
338+ }
339+
340+ /**
341+ * Returns the compaction options for this table.
342+ *
343+ * @return an immutable map containing the compaction options for this table.
344+ */
345+ public Map<String, String> getCompaction() {
346+ return compaction;
347+ }
348+
349+ /**
350+ * Returns the compression options for this table.
351+ *
352+ * @return an immutable map containing the compression options for this table.
353+ */
354+ public Map<String, String> getCompression() {
355+ return compression;
356+ }
357+
358+ /**
359+ * Returns the extension options for this table.
360+ * <p>
361+ * For Cassandra versions prior to 3.0.0, this method always returns an empty map.
362+ *
363+ * @return an immutable map containing the extension options for this table.
364+ */
365+ public Map<String, ByteBuffer> getExtensions() {
366+ return extensions;
367+ }
368+
369+ @Override
370+ public boolean equals(Object other) {
371+ if (other == this)
372+ return true;
373+ if (!(other instanceof TableOptionsMetadata))
374+ return false;
375+
376+ TableOptionsMetadata that = (TableOptionsMetadata)other;
377+ return this.isCompactStorage == that.isCompactStorage &&
378+ Objects.equal(this.comment, that.comment) &&
379+ this.readRepair == that.readRepair &&
380+ this.localReadRepair == that.localReadRepair &&
381+ this.replicateOnWrite == that.replicateOnWrite &&
382+ this.gcGrace == that.gcGrace &&
383+ this.bfFpChance == that.bfFpChance &&
384+ Objects.equal(this.caching, that.caching) &&
385+ this.populateCacheOnFlush == that.populateCacheOnFlush &&
386+ this.memtableFlushPeriodMs == that.memtableFlushPeriodMs &&
387+ this.defaultTTL == that.defaultTTL &&
388+ Objects.equal(this.speculativeRetry, that.speculativeRetry) &&
389+ Objects.equal(this.indexInterval, that.indexInterval) &&
390+ Objects.equal(this.minIndexInterval, that.minIndexInterval) &&
391+ Objects.equal(this.maxIndexInterval, that.maxIndexInterval) &&
392+ Objects.equal(this.compaction, that.compaction) &&
393+ Objects.equal(this.compression, that.compression) &&
394+ Objects.equal(this.extensions, that.extensions);
395+ }
396+
397+ @Override
398+ public int hashCode() {
399+ return Objects.hashCode(isCompactStorage, comment, readRepair, localReadRepair, replicateOnWrite, gcGrace,
400+ bfFpChance, caching, populateCacheOnFlush, memtableFlushPeriodMs, defaultTTL, speculativeRetry,
401+ indexInterval, minIndexInterval, maxIndexInterval, compaction, compression, extensions);
402+ }
403+}
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +22 −412
@@ -16,12 +16,9 @@
1616 package com.datastax.driver.core;
1717
1818
19-import java.nio.ByteBuffer;
2019 import java.util.*;
2120
22-import com.google.common.base.Objects;
2321 import com.google.common.base.Predicate;
24-import com.google.common.collect.ImmutableMap;
2522 import com.google.common.collect.Iterables;
2623
2724 /**
@@ -41,7 +38,7 @@
4138 protected final List<ColumnMetadata> partitionKey;
4239 protected final List<ColumnMetadata> clusteringColumns;
4340 protected final Map<String, ColumnMetadata> columns;
44- protected final Options options;
41+ protected final TableOptionsMetadata options;
4542 protected final List<Order> clusteringOrder;
4643 protected final VersionNumber cassandraVersion;
4744
@@ -67,7 +64,7 @@
6764 List<ColumnMetadata> partitionKey,
6865 List<ColumnMetadata> clusteringColumns,
6966 Map<String, ColumnMetadata> columns,
70- Options options,
67+ TableOptionsMetadata options,
7168 List<Order> clusteringOrder,
7269 VersionNumber cassandraVersion) {
7370 this.keyspace = keyspace;
@@ -81,13 +78,6 @@
8178 this.cassandraVersion = cassandraVersion;
8279 }
8380
84- protected static <T> List<T> nullInitializedList(int size) {
85- List<T> l = new ArrayList<T>(size);
86- for (int i = 0; i < size; ++i)
87- l.add(null);
88- return l;
89- }
90-
9181 /**
9282 * Returns the name of this table.
9383 *
@@ -205,7 +195,7 @@
205195 *
206196 * @return the options for this table.
207197 */
208- public Options getOptions() {
198+ public TableOptionsMetadata getOptions() {
209199 return options;
210200 }
211201
@@ -256,36 +246,36 @@
256246 protected StringBuilder appendOptions(StringBuilder sb, boolean formatted){
257247 // Options
258248 sb.append(" WITH ");
259- if (options.isCompactStorage)
249+ if (options.isCompactStorage())
260250 and(sb.append("COMPACT STORAGE"), formatted);
261251 if (!Iterables.all(clusteringOrder, Order.isAscending))
262252 and(appendClusteringOrder(sb), formatted);
263- sb.append("read_repair_chance = ").append(options.readRepair);
264- and(sb, formatted).append("dclocal_read_repair_chance = ").append(options.localReadRepair);
253+ sb.append("read_repair_chance = ").append(options.getReadRepairChance());
254+ and(sb, formatted).append("dclocal_read_repair_chance = ").append(options.getLocalReadRepairChance());
265255 if (cassandraVersion.getMajor() < 2 || (cassandraVersion.getMajor() == 2 && cassandraVersion.getMinor() == 0))
266- and(sb, formatted).append("replicate_on_write = ").append(options.replicateOnWrite);
267- and(sb, formatted).append("gc_grace_seconds = ").append(options.gcGrace);
268- and(sb, formatted).append("bloom_filter_fp_chance = ").append(options.bfFpChance);
256+ and(sb, formatted).append("replicate_on_write = ").append(options.getReplicateOnWrite());
257+ and(sb, formatted).append("gc_grace_seconds = ").append(options.getGcGraceInSeconds());
258+ and(sb, formatted).append("bloom_filter_fp_chance = ").append(options.getBloomFilterFalsePositiveChance());
269259 if (cassandraVersion.getMajor() < 2 || cassandraVersion.getMajor() == 2 && cassandraVersion.getMinor() < 1)
270- and(sb, formatted).append("caching = '").append(options.caching.get("keys")).append('\'');
260+ and(sb, formatted).append("caching = '").append(options.getCaching().get("keys")).append('\'');
271261 else
272- and(sb, formatted).append("caching = ").append(formatOptionMap(options.caching));
273- if (options.comment != null)
274- and(sb, formatted).append("comment = '").append(options.comment.replace("'","''")).append('\'');
275- and(sb, formatted).append("compaction = ").append(formatOptionMap(options.compaction));
276- and(sb, formatted).append("compression = ").append(formatOptionMap(options.compression));
262+ and(sb, formatted).append("caching = ").append(formatOptionMap(options.getCaching()));
263+ if (options.getComment() != null)
264+ and(sb, formatted).append("comment = '").append(options.getComment().replace("'","''")).append('\'');
265+ and(sb, formatted).append("compaction = ").append(formatOptionMap(options.getCompaction()));
266+ and(sb, formatted).append("compression = ").append(formatOptionMap(options.getCompression()));
277267 if (cassandraVersion.getMajor() >= 2) {
278- and(sb, formatted).append("default_time_to_live = ").append(options.defaultTTL);
279- and(sb, formatted).append("speculative_retry = '").append(options.speculativeRetry).append('\'');
280- if (options.indexInterval != null)
281- and(sb, formatted).append("index_interval = ").append(options.indexInterval);
268+ and(sb, formatted).append("default_time_to_live = ").append(options.getDefaultTimeToLive());
269+ and(sb, formatted).append("speculative_retry = '").append(options.getSpeculativeRetry()).append('\'');
270+ if (options.getIndexInterval() != null)
271+ and(sb, formatted).append("index_interval = ").append(options.getIndexInterval());
282272 }
283273 if (cassandraVersion.getMajor() > 2 || (cassandraVersion.getMajor() == 2 && cassandraVersion.getMinor() >= 1)) {
284- and(sb, formatted).append("min_index_interval = ").append(options.minIndexInterval);
285- and(sb, formatted).append("max_index_interval = ").append(options.maxIndexInterval);
274+ and(sb, formatted).append("min_index_interval = ").append(options.getMinIndexInterval());
275+ and(sb, formatted).append("max_index_interval = ").append(options.getMaxIndexInterval());
286276 }
287277 if (cassandraVersion.getMajor() > 2) {
288- and(sb, formatted).append("crc_check_chance = ").append(options.crcCheckChance);
278+ and(sb, formatted).append("crc_check_chance = ").append(options.getCrcCheckChance());
289279 }
290280 sb.append(';');
291281 return sb;
@@ -349,384 +339,4 @@
349339 return sb;
350340 }
351341
352- public static class Options {
353-
354- private static final String COMMENT = "comment";
355- private static final String READ_REPAIR = "read_repair_chance";
356- private static final String DCLOCAL_READ_REPAIR = "dclocal_read_repair_chance";
357- private static final String LOCAL_READ_REPAIR = "local_read_repair_chance";
358- private static final String REPLICATE_ON_WRITE = "replicate_on_write";
359- private static final String GC_GRACE = "gc_grace_seconds";
360- private static final String BF_FP_CHANCE = "bloom_filter_fp_chance";
361- private static final String CACHING = "caching";
362- private static final String COMPACTION = "compaction";
363- private static final String COMPACTION_CLASS = "compaction_strategy_class";
364- private static final String COMPACTION_OPTIONS = "compaction_strategy_options";
365- private static final String POPULATE_CACHE_ON_FLUSH = "populate_io_cache_on_flush";
366- private static final String COMPRESSION = "compression";
367- private static final String COMPRESSION_PARAMS = "compression_parameters";
368- private static final String MEMTABLE_FLUSH_PERIOD_MS = "memtable_flush_period_in_ms";
369- private static final String DEFAULT_TTL = "default_time_to_live";
370- private static final String SPECULATIVE_RETRY = "speculative_retry";
371- private static final String INDEX_INTERVAL = "index_interval";
372- private static final String MIN_INDEX_INTERVAL = "min_index_interval";
373- private static final String MAX_INDEX_INTERVAL = "max_index_interval";
374- private static final String CRC_CHECK_CHANCE = "crc_check_chance";
375- private static final String EXTENSIONS = "extensions";
376-
377- private static final boolean DEFAULT_REPLICATE_ON_WRITE = true;
378- private static final double DEFAULT_BF_FP_CHANCE = 0.01;
379- private static final boolean DEFAULT_POPULATE_CACHE_ON_FLUSH = false;
380- private static final int DEFAULT_MEMTABLE_FLUSH_PERIOD = 0;
381- private static final int DEFAULT_DEFAULT_TTL = 0;
382- private static final String DEFAULT_SPECULATIVE_RETRY = "NONE";
383- private static final int DEFAULT_INDEX_INTERVAL = 128;
384- private static final int DEFAULT_MIN_INDEX_INTERVAL = 128;
385- private static final int DEFAULT_MAX_INDEX_INTERVAL = 2048;
386- private static final double DEFAULT_CRC_CHECK_CHANCE = 1.0;
387-
388- private final boolean isCompactStorage;
389-
390- private final String comment;
391- private final double readRepair;
392- private final double localReadRepair;
393- private final boolean replicateOnWrite;
394- private final int gcGrace;
395- private final double bfFpChance;
396- private final Map<String, String> caching;
397- private final boolean populateCacheOnFlush;
398- private final int memtableFlushPeriodMs;
399- private final int defaultTTL;
400- private final String speculativeRetry;
401- private final Integer indexInterval;
402- private final Integer minIndexInterval;
403- private final Integer maxIndexInterval;
404- private final Map<String, String> compaction;
405- private final Map<String, String> compression;
406- private final Double crcCheckChance;
407- private final Map<String, ByteBuffer> extensions;
408-
409- Options(Row row, boolean isCompactStorage, VersionNumber version) {
410-
411- boolean is120 = version.getMajor() < 2;
412- boolean is200 = version.getMajor() == 2 && version.getMinor() == 0;
413- boolean is210 = version.getMajor() == 2 && version.getMinor() >= 1;
414- boolean is300OrHigher = version.getMajor() > 2;
415- boolean is210OrHigher = is210 || is300OrHigher;
416-
417- this.isCompactStorage = isCompactStorage;
418- this.comment = isNullOrAbsent(row, COMMENT) ? "" : row.getString(COMMENT);
419- this.readRepair = row.getDouble(READ_REPAIR);
420-
421- if(is300OrHigher)
422- this.localReadRepair = row.getDouble(DCLOCAL_READ_REPAIR);
423- else
424- this.localReadRepair = row.getDouble(LOCAL_READ_REPAIR);
425-
426- this.replicateOnWrite = is210OrHigher || isNullOrAbsent(row, REPLICATE_ON_WRITE) ? DEFAULT_REPLICATE_ON_WRITE : row.getBool(REPLICATE_ON_WRITE);
427- this.gcGrace = row.getInt(GC_GRACE);
428- this.bfFpChance = isNullOrAbsent(row, BF_FP_CHANCE) ? DEFAULT_BF_FP_CHANCE : row.getDouble(BF_FP_CHANCE);
429-
430- this.populateCacheOnFlush = isNullOrAbsent(row, POPULATE_CACHE_ON_FLUSH) ? DEFAULT_POPULATE_CACHE_ON_FLUSH : row.getBool(POPULATE_CACHE_ON_FLUSH);
431- this.memtableFlushPeriodMs = is120 || isNullOrAbsent(row, MEMTABLE_FLUSH_PERIOD_MS) ? DEFAULT_MEMTABLE_FLUSH_PERIOD : row.getInt(MEMTABLE_FLUSH_PERIOD_MS);
432- this.defaultTTL = is120 || isNullOrAbsent(row, DEFAULT_TTL) ? DEFAULT_DEFAULT_TTL : row.getInt(DEFAULT_TTL);
433- this.speculativeRetry = is120 || isNullOrAbsent(row, SPECULATIVE_RETRY) ? DEFAULT_SPECULATIVE_RETRY : row.getString(SPECULATIVE_RETRY);
434-
435- if (is200)
436- this.indexInterval = isNullOrAbsent(row, INDEX_INTERVAL) ? DEFAULT_INDEX_INTERVAL : row.getInt(INDEX_INTERVAL);
437- else
438- this.indexInterval = null;
439-
440- if (is210OrHigher) {
441- this.minIndexInterval = isNullOrAbsent(row, MIN_INDEX_INTERVAL)
442- ? DEFAULT_MIN_INDEX_INTERVAL
443- : row.getInt(MIN_INDEX_INTERVAL);
444- this.maxIndexInterval = isNullOrAbsent(row, MAX_INDEX_INTERVAL)
445- ? DEFAULT_MAX_INDEX_INTERVAL
446- : row.getInt(MAX_INDEX_INTERVAL);
447- } else {
448- this.minIndexInterval = null;
449- this.maxIndexInterval = null;
450- }
451-
452- if (is300OrHigher) {
453- this.caching = ImmutableMap.copyOf(row.getMap(CACHING, String.class, String.class));
454- } else if (is210) {
455- this.caching = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(CACHING)));
456- } else {
457- this.caching = ImmutableMap.of("keys", row.getString(CACHING));
458- }
459-
460- if (is300OrHigher)
461- this.compaction = ImmutableMap.copyOf(row.getMap(COMPACTION, String.class, String.class));
462- else {
463- this.compaction = ImmutableMap.<String, String>builder()
464- .put("class", row.getString(COMPACTION_CLASS))
465- .putAll(SimpleJSONParser.parseStringMap(row.getString(COMPACTION_OPTIONS)))
466- .build();
467- }
468-
469- if(is300OrHigher)
470- this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class));
471- else
472- this.compression = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(COMPRESSION_PARAMS)));
473-
474- if(is300OrHigher)
475- this.crcCheckChance = isNullOrAbsent(row, CRC_CHECK_CHANCE)
476- ? DEFAULT_CRC_CHECK_CHANCE
477- : row.getDouble(CRC_CHECK_CHANCE);
478- else
479- this.crcCheckChance = null;
480-
481- if(is300OrHigher)
482- this.extensions = ImmutableMap.copyOf(row.getMap(EXTENSIONS, String.class, ByteBuffer.class));
483- else
484- this.extensions = ImmutableMap.of();
485- }
486-
487- private static boolean isNullOrAbsent(Row row, String name) {
488- return row.getColumnDefinitions().getIndexOf(name) < 0
489- || row.isNull(name);
490- }
491-
492- /**
493- * Returns whether the table uses the {@code COMPACT STORAGE} option.
494- *
495- * @return whether the table uses the {@code COMPACT STORAGE} option.
496- */
497- public boolean isCompactStorage() {
498- return isCompactStorage;
499- }
500-
501- /**
502- * Returns the commentary set for this table.
503- *
504- * @return the commentary set for this table, or {@code null} if noe has been set.
505- */
506- public String getComment() {
507- return comment;
508- }
509-
510- /**
511- * Returns the chance with which a read repair is triggered for this table.
512- *
513- * @return the read repair chance set for table (in [0.0, 1.0]).
514- */
515- public double getReadRepairChance() {
516- return readRepair;
517- }
518-
519- /**
520- * Returns the cluster local read repair chance set for this table.
521- *
522- * @return the local read repair chance set for table (in [0.0, 1.0]).
523- */
524- public double getLocalReadRepairChance() {
525- return localReadRepair;
526- }
527-
528- /**
529- * Returns whether replicateOnWrite is set for this table.
530- *
531- * This is only meaningful for tables holding counters.
532- *
533- * @return whether replicateOnWrite is set for this table.
534- */
535- public boolean getReplicateOnWrite() {
536- return replicateOnWrite;
537- }
538-
539- /**
540- * Returns the tombstone garbage collection grace time in seconds for this table.
541- *
542- * @return the tombstone garbage collection grace time in seconds for this table.
543- */
544- public int getGcGraceInSeconds() {
545- return gcGrace;
546- }
547-
548- /**
549- * Returns the false positive chance for the Bloom filter of this table.
550- *
551- * @return the Bloom filter false positive chance for this table (in [0.0, 1.0]).
552- */
553- public double getBloomFilterFalsePositiveChance() {
554- return bfFpChance;
555- }
556-
557- /**
558- * Returns the caching options for this table.
559- *
560- * @return an immutable map containing the caching options for this table.
561- */
562- public Map<String, String> getCaching() {
563- return caching;
564- }
565-
566- /**
567- * Whether the populate I/O cache on flush is set on this table.
568- *
569- * @return whether the populate I/O cache on flush is set on this table.
570- */
571- public boolean getPopulateIOCacheOnFlush() {
572- return populateCacheOnFlush;
573- }
574-
575- /*
576- * Returns the memtable flush period (in milliseconds) option for this table.
577- * <p>
578- * Note: this option is not available in Cassandra 1.2 and will return 0 (no periodic
579- * flush) when connected to 1.2 nodes.
580- *
581- * @return the memtable flush period option for this table or 0 if no
582- * periodic flush is configured.
583- */
584- public int getMemtableFlushPeriodInMs() {
585- return memtableFlushPeriodMs;
586- }
587-
588- /**
589- * Returns the default TTL for this table.
590- * <p>
591- * Note: this option is not available in Cassandra 1.2 and will return 0 (no default
592- * TTL) when connected to 1.2 nodes.
593- *
594- * @return the default TTL for this table or 0 if no default TTL is
595- * configured.
596- */
597- public int getDefaultTimeToLive() {
598- return defaultTTL;
599- }
600-
601- /**
602- * Returns the speculative retry option for this table.
603- * <p>
604- * Note: this option is not available in Cassandra 1.2 and will return "NONE" (no
605- * speculative retry) when connected to 1.2 nodes.
606- *
607- * @return the speculative retry option this table.
608- */
609- public String getSpeculativeRetry() {
610- return speculativeRetry;
611- }
612-
613- /**
614- * Returns the index interval option for this table.
615- * <p>
616- * Note: this option is not available in Cassandra 1.2 (more precisely, it is not
617- * configurable per-table) and will return 128 (the default index interval) when
618- * connected to 1.2 nodes. It is deprecated in Cassandra 2.1 and above, and will
619- * therefore return {@code null} for 2.1 nodes.
620- *
621- * @return the index interval option for this table.
622- */
623- public Integer getIndexInterval() {
624- return indexInterval;
625- }
626-
627- /**
628- * Returns the minimum index interval option for this table.
629- * <p>
630- * Note: this option is available in Cassandra 2.1 and above, and will return
631- * {@code null} for earlier versions.
632- *
633- * @return the minimum index interval option for this table.
634- */
635- public Integer getMinIndexInterval() {
636- return minIndexInterval;
637- }
638-
639- /**
640- * Returns the maximum index interval option for this table.
641- * <p>
642- * Note: this option is available in Cassandra 2.1 and above, and will return
643- * {@code null} for earlier versions.
644- *
645- * @return the maximum index interval option for this table.
646- */
647- public Integer getMaxIndexInterval() {
648- return maxIndexInterval;
649- }
650-
651- /**
652- * When compression is enabled, this option defines the probability
653- * with which checksums for compressed blocks are checked during reads.
654- * The default value for this options is 1.0 (always check).
655- * <p>
656- * Note that this option is available in Cassandra 3.0.0 and above, when it
657- * became a "top-level" table option, whereas previously it was a suboption
658- * of the {@link #getCompression() compression} option.
659- * <p>
660- * For Cassandra versions prior to 3.0.0, this method always returns {@code null}.
661- *
662- * @return the probability with which checksums for compressed blocks are checked during reads
663- */
664- public Double getCrcCheckChance() {
665- return crcCheckChance;
666- }
667-
668- /**
669- * Returns the compaction options for this table.
670- *
671- * @return an immutable map containing the compaction options for this table.
672- */
673- public Map<String, String> getCompaction() {
674- return compaction;
675- }
676-
677- /**
678- * Returns the compression options for this table.
679- *
680- * @return an immutable map containing the compression options for this table.
681- */
682- public Map<String, String> getCompression() {
683- return compression;
684- }
685-
686- /**
687- * Returns the extension options for this table.
688- * <p>
689- * For Cassandra versions prior to 3.0.0, this method always returns an empty map.
690- *
691- * @return an immutable map containing the extension options for this table.
692- */
693- public Map<String, ByteBuffer> getExtensions() {
694- return extensions;
695- }
696-
697- @Override
698- public boolean equals(Object other) {
699- if (other == this)
700- return true;
701- if (!(other instanceof Options))
702- return false;
703-
704- Options that = (Options)other;
705- return this.isCompactStorage == that.isCompactStorage &&
706- Objects.equal(this.comment, that.comment) &&
707- this.readRepair == that.readRepair &&
708- this.localReadRepair == that.localReadRepair &&
709- this.replicateOnWrite == that.replicateOnWrite &&
710- this.gcGrace == that.gcGrace &&
711- this.bfFpChance == that.bfFpChance &&
712- Objects.equal(this.caching, that.caching) &&
713- this.populateCacheOnFlush == that.populateCacheOnFlush &&
714- this.memtableFlushPeriodMs == that.memtableFlushPeriodMs &&
715- this.defaultTTL == that.defaultTTL &&
716- Objects.equal(this.speculativeRetry, that.speculativeRetry) &&
717- Objects.equal(this.indexInterval, that.indexInterval) &&
718- Objects.equal(this.minIndexInterval, that.minIndexInterval) &&
719- Objects.equal(this.maxIndexInterval, that.maxIndexInterval) &&
720- Objects.equal(this.compaction, that.compaction) &&
721- Objects.equal(this.compression, that.compression) &&
722- Objects.equal(this.extensions, that.extensions);
723- }
724-
725- @Override
726- public int hashCode() {
727- return Objects.hashCode(isCompactStorage, comment, readRepair, localReadRepair, replicateOnWrite, gcGrace,
728- bfFpChance, caching, populateCacheOnFlush, memtableFlushPeriodMs, defaultTTL, speculativeRetry,
729- indexInterval, minIndexInterval, maxIndexInterval, compaction, compression, extensions);
730- }
731- }
732342 }
modified upgrade_guide/README.md +3 −0
@@ -202,6 +202,9 @@
202202 `Session` interface (the only purpose of the extra interface was to preserve
203203 binary compatibility on the 2.1 branch).
204204
205+20. `TableMetadata.Options` has been made a top-level class and renamed to
206+ `TableOptionsMetadata`. It is now also used by `MaterializedViewMetadata`.
207+
205208
206209 ### 2.1.8
207210