2015-06-24 15:48:56 +02:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Cloudius Systems
|
|
|
|
*
|
|
|
|
* Modified by Cloudius Systems
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.apache.cassandra.service;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
2016-10-11 14:07:03 +02:00
|
|
|
import java.util.logging.Logger;
|
2015-07-01 09:11:21 +02:00
|
|
|
|
2015-10-28 10:25:37 +01:00
|
|
|
import javax.ws.rs.core.MultivaluedHashMap;
|
2015-06-24 15:48:56 +02:00
|
|
|
import javax.ws.rs.core.MultivaluedMap;
|
|
|
|
|
2015-07-01 09:11:21 +02:00
|
|
|
import org.apache.cassandra.metrics.CacheMetrics;
|
|
|
|
|
2015-12-17 08:26:19 +01:00
|
|
|
import com.scylladb.jmx.api.APIClient;
|
2016-10-11 14:07:03 +02:00
|
|
|
import com.scylladb.jmx.metrics.MetricsMBean;
|
2015-06-24 15:48:56 +02:00
|
|
|
|
2016-10-11 14:07:03 +02:00
|
|
|
public class CacheService extends MetricsMBean implements CacheServiceMBean {
|
|
|
|
private static final Logger logger = Logger.getLogger(CacheService.class.getName());
|
2015-06-24 15:48:56 +02:00
|
|
|
|
|
|
|
public void log(String str) {
|
2015-12-30 07:47:32 +01:00
|
|
|
logger.finest(str);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static final String MBEAN_NAME = "org.apache.cassandra.db:type=Caches";
|
|
|
|
|
2016-10-11 14:07:03 +02:00
|
|
|
public CacheService(APIClient client) {
|
|
|
|
super(MBEAN_NAME, client, new CacheMetrics("KeyCache", "key"), new CacheMetrics("RowCache", "row"),
|
|
|
|
new CacheMetrics("CounterCache", "counter"));
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public int getRowCacheSavePeriodInSeconds() {
|
|
|
|
log(" getRowCacheSavePeriodInSeconds()");
|
2016-10-11 14:07:03 +02:00
|
|
|
return client.getIntValue("cache_service/row_cache_save_period");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setRowCacheSavePeriodInSeconds(int rcspis) {
|
|
|
|
log(" setRowCacheSavePeriodInSeconds(int rcspis)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("period", Integer.toString(rcspis));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/row_cache_save_period", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public int getKeyCacheSavePeriodInSeconds() {
|
|
|
|
log(" getKeyCacheSavePeriodInSeconds()");
|
2016-10-11 14:07:03 +02:00
|
|
|
return client.getIntValue("cache_service/key_cache_save_period");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setKeyCacheSavePeriodInSeconds(int kcspis) {
|
|
|
|
log(" setKeyCacheSavePeriodInSeconds(int kcspis)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("period", Integer.toString(kcspis));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/key_cache_save_period", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public int getCounterCacheSavePeriodInSeconds() {
|
|
|
|
log(" getCounterCacheSavePeriodInSeconds()");
|
2016-10-11 14:07:03 +02:00
|
|
|
return client.getIntValue("cache_service/counter_cache_save_period");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setCounterCacheSavePeriodInSeconds(int ccspis) {
|
|
|
|
log(" setCounterCacheSavePeriodInSeconds(int ccspis)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("ccspis", Integer.toString(ccspis));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/counter_cache_save_period", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public int getRowCacheKeysToSave() {
|
|
|
|
log(" getRowCacheKeysToSave()");
|
2016-10-11 14:07:03 +02:00
|
|
|
return client.getIntValue("cache_service/row_cache_keys_to_save");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setRowCacheKeysToSave(int rckts) {
|
|
|
|
log(" setRowCacheKeysToSave(int rckts)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("rckts", Integer.toString(rckts));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/row_cache_keys_to_save", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public int getKeyCacheKeysToSave() {
|
|
|
|
log(" getKeyCacheKeysToSave()");
|
2016-10-11 14:07:03 +02:00
|
|
|
return client.getIntValue("cache_service/key_cache_keys_to_save");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setKeyCacheKeysToSave(int kckts) {
|
|
|
|
log(" setKeyCacheKeysToSave(int kckts)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("kckts", Integer.toString(kckts));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/key_cache_keys_to_save", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public int getCounterCacheKeysToSave() {
|
|
|
|
log(" getCounterCacheKeysToSave()");
|
2016-10-11 14:07:03 +02:00
|
|
|
return client.getIntValue("cache_service/counter_cache_keys_to_save");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setCounterCacheKeysToSave(int cckts) {
|
|
|
|
log(" setCounterCacheKeysToSave(int cckts)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("cckts", Integer.toString(cckts));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/counter_cache_keys_to_save", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* invalidate the key cache; for use after invalidating row cache
|
|
|
|
*/
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void invalidateKeyCache() {
|
|
|
|
log(" invalidateKeyCache()");
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/invalidate_key_cache");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* invalidate the row cache; for use after bulk loading via BinaryMemtable
|
|
|
|
*/
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void invalidateRowCache() {
|
|
|
|
log(" invalidateRowCache()");
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/invalidate_row_cache");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void invalidateCounterCache() {
|
|
|
|
log(" invalidateCounterCache()");
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/invalidate_counter_cache");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setRowCacheCapacityInMB(long capacity) {
|
|
|
|
log(" setRowCacheCapacityInMB(long capacity)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("capacity", Long.toString(capacity));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/row_cache_capacity", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setKeyCacheCapacityInMB(long capacity) {
|
|
|
|
log(" setKeyCacheCapacityInMB(long capacity)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("capacity", Long.toString(capacity));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/key_cache_capacity", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void setCounterCacheCapacityInMB(long capacity) {
|
|
|
|
log(" setCounterCacheCapacityInMB(long capacity)");
|
2015-10-28 10:25:37 +01:00
|
|
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
2015-06-24 15:48:56 +02:00
|
|
|
queryParams.add("capacity", Long.toString(capacity));
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/counter_cache_capacity_in_mb", queryParams);
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* save row and key caches
|
|
|
|
*
|
|
|
|
* @throws ExecutionException
|
|
|
|
* when attempting to retrieve the result of a task that aborted
|
|
|
|
* by throwing an exception
|
|
|
|
* @throws InterruptedException
|
|
|
|
* when a thread is waiting, sleeping, or otherwise occupied,
|
|
|
|
* and the thread is interrupted, either before or during the
|
|
|
|
* activity.
|
|
|
|
*/
|
2016-08-17 10:38:55 +02:00
|
|
|
@Override
|
2015-06-24 15:48:56 +02:00
|
|
|
public void saveCaches() throws ExecutionException, InterruptedException {
|
|
|
|
log(" saveCaches() throws ExecutionException, InterruptedException");
|
2016-10-11 14:07:03 +02:00
|
|
|
client.post("cache_service/save_caches");
|
2015-06-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
}
|