public static KeyCache fromString(String keyCache) { return new KeyCache(Type.valueOf(keyCache.toUpperCase())); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CachingOptions o2 = (CachingOptions) o; if (!keyCache.equals(o2.keyCache)) return false; if (!rowCache.equals(o2.rowCache)) return false; return true; }
public static CachingOptions fromMap(Map<String, String> cacheConfig) throws ConfigurationException { validateCacheConfig(cacheConfig); if (!cacheConfig.containsKey("keys") && !cacheConfig.containsKey("rows_per_partition")) return CachingOptions.NONE; if (!cacheConfig.containsKey("keys")) return new CachingOptions(new KeyCache(KeyCache.Type.NONE), RowCache.fromString(cacheConfig.get("rows_per_partition"))); if (!cacheConfig.containsKey("rows_per_partition")) return CachingOptions.KEYS_ONLY; return new CachingOptions(KeyCache.fromString(cacheConfig.get("keys")), RowCache.fromString(cacheConfig.get("rows_per_partition"))); }
/** * Creates CFMetaData for secondary index CF. * Secondary index CF has the same CF ID as parent's. * * @param parent Parent CF where secondary index is created * @param info Column definition containing secondary index definition * @param indexComparator Comparator for secondary index * @return CFMetaData for secondary index */ public static CFMetaData newIndexMetadata(CFMetaData parent, ColumnDefinition info, CellNameType indexComparator) { // Depends on parent's cache setting, turn on its index CF's cache. // Row caching is never enabled; see CASSANDRA-5732 CachingOptions indexCaching = parent.getCaching().keyCache.isEnabled() ? CachingOptions.KEYS_ONLY : CachingOptions.NONE; return new CFMetaData(parent.ksName, parent.indexColumnFamilyName(info), ColumnFamilyType.Standard, indexComparator, parent.cfId) .keyValidator(info.type) .readRepairChance(0.0) .dcLocalReadRepairChance(0.0) .gcGraceSeconds(0) .caching(indexCaching) .speculativeRetry(parent.speculativeRetry) .compactionStrategyClass(parent.compactionStrategyClass) .compactionStrategyOptions(parent.compactionStrategyOptions) .reloadSecondaryIndexMetadata(parent) .rebuild(); }
private RowIndexEntry getCachedPosition(KeyCacheKey unifiedKey, boolean updateStats) { if (keyCache != null && keyCache.getCapacity() > 0 && metadata.getCaching().keyCache.isEnabled()) { if (updateStats) { RowIndexEntry cachedEntry = keyCache.get(unifiedKey); keyCacheRequest.incrementAndGet(); if (cachedEntry != null) { keyCacheHit.incrementAndGet(); bloomFilterTracker.addTruePositive(); } return cachedEntry; } else { return keyCache.getInternal(unifiedKey); } } return null; }
public static CachingOptions fromThrift(String caching, String cellsPerRow) throws ConfigurationException { RowCache rc = new RowCache(RowCache.Type.NONE); KeyCache kc = new KeyCache(KeyCache.Type.ALL); // if we get a caching string from thrift it is legacy, "ALL", "KEYS_ONLY" etc, fromString handles those if (caching != null) { CachingOptions givenOptions = CachingOptions.fromString(caching); rc = givenOptions.rowCache; kc = givenOptions.keyCache; } // if we get cells_per_row from thrift, it is either "ALL" or "<number of cells to cache>". if (cellsPerRow != null && rc.isEnabled()) rc = RowCache.fromString(cellsPerRow); return new CachingOptions(kc, rc); }
public void cacheKey(DecoratedKey key, RowIndexEntry info) { CachingOptions caching = metadata.getCaching(); if (!caching.keyCache.isEnabled() || keyCache == null || keyCache.getCapacity() == 0) { return; } KeyCacheKey cacheKey = new KeyCacheKey(metadata.ksAndCFName, descriptor, key.getKey()); logger.trace("Adding cache entry for {} -> {}", cacheKey, info); keyCache.put(cacheKey, info); }
public boolean isKeyCacheEnabled() { return metadata.getCaching().keyCache.isEnabled() && CacheService.instance.keyCache.getCapacity() > 0; }
@Override public int hashCode() { int result = keyCache.hashCode(); result = 31 * result + rowCache.hashCode(); return result; }
@Override public String toString() { return String.format("{\"keys\":\"%s\", \"rows_per_partition\":\"%s\"}", keyCache.toString(), rowCache.toString()); }