phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkrish86 <...@git.apache.org>
Subject [GitHub] phoenix pull request: Phoenix-180
Date Wed, 17 Sep 2014 09:26:18 GMT
Github user ramkrish86 commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/12#discussion_r17654384
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/stat/StatisticsCollector.java
---
    @@ -0,0 +1,390 @@
    +/*
    + * 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.
    + */
    +package org.apache.phoenix.schema.stat;
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.TreeMap;
    +import java.util.TreeSet;
    +
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.hadoop.hbase.Cell;
    +import org.apache.hadoop.hbase.Coprocessor;
    +import org.apache.hadoop.hbase.CoprocessorEnvironment;
    +import org.apache.hadoop.hbase.HTableDescriptor;
    +import org.apache.hadoop.hbase.KeyValue;
    +import org.apache.hadoop.hbase.KeyValueUtil;
    +import org.apache.hadoop.hbase.TableName;
    +import org.apache.hadoop.hbase.client.Scan;
    +import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
    +import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
    +import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
    +import org.apache.hadoop.hbase.coprocessor.ObserverContext;
    +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
    +import org.apache.hadoop.hbase.protobuf.ResponseConverter;
    +import org.apache.hadoop.hbase.regionserver.HRegion;
    +import org.apache.hadoop.hbase.regionserver.InternalScanner;
    +import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
    +import org.apache.hadoop.hbase.regionserver.RegionScanner;
    +import org.apache.hadoop.hbase.regionserver.ScanType;
    +import org.apache.hadoop.hbase.regionserver.Store;
    +import org.apache.hadoop.hbase.regionserver.StoreScanner;
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.phoenix.coprocessor.generated.StatCollectorProtos;
    +import org.apache.phoenix.coprocessor.generated.StatCollectorProtos.StatCollectRequest;
    +import org.apache.phoenix.coprocessor.generated.StatCollectorProtos.StatCollectResponse;
    +import org.apache.phoenix.coprocessor.generated.StatCollectorProtos.StatCollectResponse.Builder;
    +import org.apache.phoenix.coprocessor.generated.StatCollectorProtos.StatCollectService;
    +import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
    +import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
    +import org.apache.phoenix.schema.PDataType;
    +import org.apache.phoenix.schema.PhoenixArray;
    +import org.apache.phoenix.util.SchemaUtil;
    +
    +import com.google.protobuf.RpcCallback;
    +import com.google.protobuf.RpcController;
    +import com.google.protobuf.Service;
    +
    +/**
    + * An endpoint implementation that allows to collect the stats for a given region and
groups the stat per family. This is also an
    + * RegionObserver that collects the information on compaction also. The user would be
allowed to invoke this endpoint and thus populate the
    + * Phoenix stats table with the max key, min key and guide posts for the given region.
The stats can be consumed by the stats associated
    + * with every PTable and the same can be used to parallelize the queries
    + */
    +public class StatisticsCollector extends BaseRegionObserver implements CoprocessorService,
Coprocessor,
    +        StatisticsTracker, StatCollectService.Interface {
    +
    +    public static void addToTable(HTableDescriptor desc) throws IOException {
    +        desc.addCoprocessor(StatisticsCollector.class.getName());
    +    }
    +
    +    private Map<String, byte[]> minMap = new TreeMap<String, byte[]>();
    +    private Map<String, byte[]> maxMap = new TreeMap<String, byte[]>();
    +    private long guidepostDepth;
    +    private long byteCount = 0;
    +    private TreeMap<String, List<byte[]>> guidePostsMap = new TreeMap<String,
List<byte[]>>();
    +    private Set<byte[]> familyMap = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
    +    private RegionCoprocessorEnvironment env;
    +    protected StatisticsTable stats;
    +    private static final Log LOG = LogFactory.getLog(StatCollectService.class);
    +
    +    @Override
    +    public void collectStat(RpcController controller, StatCollectRequest request, RpcCallback<StatCollectResponse>
done) {
    +        HRegion region = env.getRegion();
    +        // Clear all old stats
    +        clear();
    +        Scan scan = createScan();
    +        if (request.hasStartRow()) {
    +            scan.setStartRow(request.getStartRow().toByteArray());
    +        }
    +        if (request.hasStopRow()) {
    +            scan.setStopRow(request.getStopRow().toByteArray());
    +        }
    +        RegionScanner scanner = null;
    +        int count = 0;
    +        try {
    +            scanner = region.getScanner(scan);
    +            count = scanRegion(scanner, count);
    +        } catch (IOException e) {
    +            LOG.error(e);
    +            ResponseConverter.setControllerException(controller, e);
    +        } finally {
    +            if (scanner != null) {
    +                try {
    +                    writeStatsToStatsTable(request, region, scanner, false);
    +                } catch (IOException e) {
    +                    LOG.error(e);
    +                    ResponseConverter.setControllerException(controller, e);
    +                }
    +            }
    +        }
    +        Builder newBuilder = StatCollectResponse.newBuilder();
    +        newBuilder.setRowsScanned(count);
    +        StatCollectResponse result = newBuilder.build();
    +        done.run(result);
    +    }
    +
    +    private void writeStatsToStatsTable(final StatCollectRequest request, final HRegion
region,
    --- End diff --
    
    Ok so removed the tableName and cleaned up the usage of URL.  Always will get the table
name from the regionInfo associated with the region.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message