private void invalidateSubscription(String subscription) { _invalidationEventMeter.mark(); _subscriptionCacheHandle.invalidate(InvalidationScope.DATA_CENTER, subscription); // If in legacy mode also invalidate the legacy cache if (_cachingMode == CachingMode.legacy) { _legacyCacheHandle.invalidate(InvalidationScope.DATA_CENTER, SUBSCRIPTIONS); } }
@Override public void invalidateAll() { if(_cacheRegistry != null) { for(String name : _allAvailableCaches.keySet()) { // There is a potential race condition here since the cache is added to _allAvailableCaches // then subsequently added to _cacheRegistry in createCache(), making it possible for a value to // be cached but not invalidated on this call. However, to avoid this issue all caches used by // this manager are pre-created in ApiKeyRealm.onInit(), so in practice this can never happen. CacheHandle cacheHandle = _cacheRegistry.lookup(name, false); cacheHandle.invalidateAll(InvalidationScope.GLOBAL); } } else { for(GuavaCache cache : _allAvailableCaches.values()) { cache.clear(); } } }
@Override public void handleInvalidation(final InvalidationEvent event) { if (!_tableCacheHandle.matches(event) || !isRunningOrStarting()) { return; } // Don't read table metadata from the invalidation thread to avoid holding up other important operations. Use // the scheduled executor thread since there's only one thread, don't have to worry much about race conditions. _executor.submit(new Runnable() { @Override public void run() { if (event.hasKeys()) { for (String name : event.getKeys()) { scheduleTable(name); } } else { scheduleAll(); } } }); }
@Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter out) { String name = checkNotNull(Iterables.getFirst(parameters.get("cache"), null), "cache"); String scopeString = Iterables.getFirst(parameters.get("scope"), "LOCAL"); InvalidationScope scope = InvalidationScope.valueOf(scopeString.toUpperCase()); Collection<String> keys = parameters.get("key"); boolean invalidateAll = keys.isEmpty(); CacheHandle handle = _registry.lookup(name, false); if (handle == null) { out.println("Cache not found: " + name); return; } if (invalidateAll) { handle.invalidateAll(scope); } else { handle.invalidateAll(scope, keys); } out.println("Done!"); } }
@Override public void handleInvalidation(final InvalidationEvent event) { if (!_tableCacheHandle.matches(event) || !isRunningOrStarting()) { return; } // Don't read table metadata from the invalidation thread to avoid holding up other important operations. Use // the scheduled executor thread since there's only one thread, don't have to worry much about race conditions. _executor.submit(new Runnable() { @Override public void run() { if (event.hasKeys()) { for (String name : event.getKeys()) { scheduleTable(name); } } else { scheduleAll(); } } }); }
private void invalidateSubscription(String subscription) { _invalidationEventMeter.mark(); _subscriptionCacheHandle.invalidate(InvalidationScope.DATA_CENTER, subscription); // If in legacy mode also invalidate the legacy cache if (_cachingMode == CachingMode.legacy) { _legacyCacheHandle.invalidate(InvalidationScope.DATA_CENTER, SUBSCRIPTIONS); } }
@Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter out) { String name = checkNotNull(Iterables.getFirst(parameters.get("cache"), null), "cache"); String scopeString = Iterables.getFirst(parameters.get("scope"), "LOCAL"); InvalidationScope scope = InvalidationScope.valueOf(scopeString.toUpperCase()); Collection<String> keys = parameters.get("key"); boolean invalidateAll = keys.isEmpty(); CacheHandle handle = _registry.lookup(name, false); if (handle == null) { out.println("Cache not found: " + name); return; } if (invalidateAll) { handle.invalidateAll(scope); } else { handle.invalidateAll(scope, keys); } out.println("Done!"); } }
/** * Write the delta to the system table and invalidate caches in the specified scope. */ private void updateTableMetadata(String table, Delta delta, Audit audit, @Nullable InvalidationScope scope) { _backingStore.update(_systemTable, table, TimeUUIDs.newUUID(), delta, audit, scope == InvalidationScope.GLOBAL ? WriteConsistency.GLOBAL : WriteConsistency.STRONG); // Synchronously notify other emodb servers of the table change. if (scope != null) { _tableCacheHandle.invalidate(scope, table); } }
/** * Write the delta to the system table and invalidate caches in the specified scope. */ private void updateTableMetadata(String table, Delta delta, Audit audit, @Nullable InvalidationScope scope) { _backingStore.update(_systemTable, table, TimeUUIDs.newUUID(), delta, audit, scope == InvalidationScope.GLOBAL ? WriteConsistency.GLOBAL : WriteConsistency.STRONG); // Synchronously notify other emodb servers of the table change. if (scope != null) { _tableCacheHandle.invalidate(scope, table); } }
private <T> void set(SettingMetadata<T> metadata, T value) { checkNotNull(value, "value"); Delta delta = Deltas.mapBuilder() .put(VALUE_ATTRIBUTE, JsonHelper.asJson(value)) .put(VERSION_ATTRIBUTE, CURRENT_SETTING_VERSION) .build(); // Write the delta to the store _dataStore.get().update(_settingsTable.get(), metadata.getName(), TimeUUIDs.newUUID(), delta, new AuditBuilder().setLocalHost().setComment("Updated setting").build(), WriteConsistency.GLOBAL); // Notify all instances that the setting value has changed _cacheHandle.invalidate(InvalidationScope.GLOBAL, metadata.getName()); }