Search in sources :

Example 1 with ClearCacheResponse

use of org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse in project phoenix by apache.

the class MetaDataEndpointImpl method clearCache.

@Override
public void clearCache(RpcController controller, ClearCacheRequest request, RpcCallback<ClearCacheResponse> done) {
    GlobalCache cache = GlobalCache.getInstance(this.env);
    Cache<ImmutableBytesPtr, PMetaDataEntity> metaDataCache = GlobalCache.getInstance(this.env).getMetaDataCache();
    metaDataCache.invalidateAll();
    long unfreedBytes = cache.clearTenantCache();
    ClearCacheResponse.Builder builder = ClearCacheResponse.newBuilder();
    builder.setUnfreedBytes(unfreedBytes);
    done.run(builder.build());
}
Also used : GlobalCache(org.apache.phoenix.cache.GlobalCache) PMetaDataEntity(org.apache.phoenix.schema.PMetaDataEntity) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) ClearCacheResponse(org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse)

Example 2 with ClearCacheResponse

use of org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse in project phoenix by apache.

the class TestUtil method clearMetaDataCache.

public static void clearMetaDataCache(Connection conn) throws Throwable {
    PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
    HTableInterface htable = pconn.getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
    htable.coprocessorService(MetaDataService.class, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, new Batch.Call<MetaDataService, ClearCacheResponse>() {

        @Override
        public ClearCacheResponse call(MetaDataService instance) throws IOException {
            ServerRpcController controller = new ServerRpcController();
            BlockingRpcCallback<ClearCacheResponse> rpcCallback = new BlockingRpcCallback<ClearCacheResponse>();
            ClearCacheRequest.Builder builder = ClearCacheRequest.newBuilder();
            instance.clearCache(controller, builder.build(), rpcCallback);
            if (controller.getFailedOn() != null) {
                throw controller.getFailedOn();
            }
            return rpcCallback.get();
        }
    });
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) MetaDataService(org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch) ClearCacheResponse(org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse) BlockingRpcCallback(org.apache.hadoop.hbase.ipc.BlockingRpcCallback) IOException(java.io.IOException) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController)

Example 3 with ClearCacheResponse

use of org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse in project phoenix by apache.

the class ConnectionQueryServicesImpl method clearCache.

/**
 * Clears the Phoenix meta data cache on each region server
 * @throws SQLException
 */
@Override
public long clearCache() throws SQLException {
    synchronized (latestMetaDataLock) {
        latestMetaData = newEmptyMetaData();
    }
    tableStatsCache.invalidateAll();
    try (HTableInterface htable = this.getTable(SchemaUtil.getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, this.getProps()).getName())) {
        final Map<byte[], Long> results = htable.coprocessorService(MetaDataService.class, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, new Batch.Call<MetaDataService, Long>() {

            @Override
            public Long call(MetaDataService instance) throws IOException {
                ServerRpcController controller = new ServerRpcController();
                BlockingRpcCallback<ClearCacheResponse> rpcCallback = new BlockingRpcCallback<ClearCacheResponse>();
                ClearCacheRequest.Builder builder = ClearCacheRequest.newBuilder();
                builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
                instance.clearCache(controller, builder.build(), rpcCallback);
                if (controller.getFailedOn() != null) {
                    throw controller.getFailedOn();
                }
                return rpcCallback.get().getUnfreedBytes();
            }
        });
        long unfreedBytes = 0;
        for (Map.Entry<byte[], Long> result : results.entrySet()) {
            if (result.getValue() != null) {
                unfreedBytes += result.getValue();
            }
        }
        return unfreedBytes;
    } catch (IOException e) {
        throw ServerUtil.parseServerException(e);
    } catch (Throwable e) {
        // wrap all other exceptions in a SQLException
        throw new SQLException(e);
    }
}
Also used : SQLException(java.sql.SQLException) KeyValueBuilder(org.apache.phoenix.hbase.index.util.KeyValueBuilder) NonTxIndexBuilder(org.apache.phoenix.hbase.index.covered.NonTxIndexBuilder) PhoenixIndexBuilder(org.apache.phoenix.index.PhoenixIndexBuilder) ClearCacheResponse(org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse) IOException(java.io.IOException) PhoenixIOException(org.apache.phoenix.exception.PhoenixIOException) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) MetaDataService(org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch) PLong(org.apache.phoenix.schema.types.PLong) BlockingRpcCallback(org.apache.hadoop.hbase.ipc.BlockingRpcCallback) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

ClearCacheResponse (org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse)3 IOException (java.io.IOException)2 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)2 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)2 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)2 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)2 MetaDataService (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GlobalCache (org.apache.phoenix.cache.GlobalCache)1 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)1 NonTxIndexBuilder (org.apache.phoenix.hbase.index.covered.NonTxIndexBuilder)1 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)1 KeyValueBuilder (org.apache.phoenix.hbase.index.util.KeyValueBuilder)1 PhoenixIndexBuilder (org.apache.phoenix.index.PhoenixIndexBuilder)1