Java Code Examples for com.netflix.astyanax.model.ConsistencyLevel#CL_LOCAL_ONE
The following examples show how to use
com.netflix.astyanax.model.ConsistencyLevel#CL_LOCAL_ONE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsistencyTopologyAdapter.java From emodb with Apache License 2.0 | 6 votes |
/** * Reduce the desired consistency level to be compatible with the deployed ring topology. */ public ConsistencyLevel clamp(ConsistencyLevel consistencyLevel) { // Cassandra only allows the use of LOCAL_QUORUM and EACH_QUORUM if the keyspace // placement strategy is NetworkTopologyStrategy if ((consistencyLevel == ConsistencyLevel.CL_LOCAL_QUORUM || consistencyLevel == ConsistencyLevel.CL_EACH_QUORUM) && !_networkTopology) { consistencyLevel = ConsistencyLevel.CL_QUORUM; } if (consistencyLevel == ConsistencyLevel.CL_LOCAL_ONE && !_networkTopology) { consistencyLevel = ConsistencyLevel.CL_ONE; } // we may want to write to at two or three servers to ensure the write survives the // permanent failure of any single server. but if the ring has fewer servers to // begin with (ie. it's a test ring) we must reduce the consistency level. if (consistencyLevel == ConsistencyLevel.CL_THREE && _replicationFactor < 3) { consistencyLevel = ConsistencyLevel.CL_TWO; } if (consistencyLevel == ConsistencyLevel.CL_TWO && _replicationFactor < 2) { consistencyLevel = ConsistencyLevel.CL_ONE; } return consistencyLevel; }
Example 2
Source File: AstyanaxEventReaderDAO.java From emodb with Apache License 2.0 | 5 votes |
/** * Reads the ordered manifest for a channel. The read can either be weak or strong. A weak read will use CL1 * and may use the cached oldest slab from a previous strong call to improve performance. A strong read will use * CL local_quorum and will always read the entire manifest row. This makes a weak read significantly faster than a * strong read but also means the call is not guaranteed to return the entire manifest. Because of this at least * every 10 seconds a weak read for a channel is automatically promoted to a strong read. * * The vast majority of calls to this method are performed during a "peek" or "poll" operation. Since these are * typically called repeatedly a weak call provides improved performance while guaranteeing that at least every * 10 seconds the manifest is strongly read so no slabs are missed over time. Calls which must guarantee * the full manifest should explicitly request strong consistency. */ private Iterator<Column<ByteBuffer>> readManifestForChannel(final String channel, final boolean weak) { final ByteBuffer oldestSlab = weak ? _oldestSlab.getIfPresent(channel) : null; final ConsistencyLevel consistency; RangeBuilder range = new RangeBuilder().setLimit(50); if (oldestSlab != null) { range.setStart(oldestSlab); consistency = ConsistencyLevel.CL_LOCAL_ONE; } else { consistency = ConsistencyLevel.CL_LOCAL_QUORUM; } final Iterator<Column<ByteBuffer>> manifestColumns = executePaginated( _keyspace.prepareQuery(ColumnFamilies.MANIFEST, consistency) .getKey(channel) .withColumnRange(range.build()) .autoPaginate(true)); if (oldestSlab != null) { // Query was executed weakly using the cached oldest slab, so don't update the cache with an unreliable oldest value return manifestColumns; } else { PeekingIterator<Column<ByteBuffer>> peekingManifestColumns = Iterators.peekingIterator(manifestColumns); if (peekingManifestColumns.hasNext()) { // Cache the first slab returned from querying the full manifest column family since it is the oldest. cacheOldestSlabForChannel(channel, TimeUUIDSerializer.get().fromByteBuffer(peekingManifestColumns.peek().getName())); return peekingManifestColumns; } else { // Channel was completely empty. Cache a TimeUUID for the current time. This will cause future calls // to read at most 1 minute of tombstones until the cache expires 10 seconds later. cacheOldestSlabForChannel(channel, TimeUUIDs.newUUID()); return Iterators.emptyIterator(); } } }
Example 3
Source File: SorConsistencies.java From emodb with Apache License 2.0 | 5 votes |
public static ConsistencyLevel toAstyanax(ReadConsistency consistency) { switch (consistency) { case WEAK: return ConsistencyLevel.CL_LOCAL_ONE; // first node to respond case STRONG: return ConsistencyLevel.CL_LOCAL_QUORUM; // single data center quorum default: throw new UnsupportedOperationException(String.valueOf(consistency)); } }