Example usage for java.util NavigableMap equals

List of usage examples for java.util NavigableMap equals

Introduction

In this page you can find the example usage for java.util NavigableMap equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this map for equality.

Usage

From source file:org.apache.impala.datagenerator.HBaseTestDataRegionAssigment.java

/**
 * Split the table regions according to splitPoints and pair up adjacent regions to the
 * same server. Each region pair in ([unbound:1,1:3], [3:5,5:7], [7:9,9:unbound])
 * will be on the same server./* w w w  .  jav  a  2  s.c o  m*/
 * The table must have data loaded and only a single region.
 */
public void performAssigment(String tableName)
        throws IOException, InterruptedException, TableNotFoundException {
    HTableDescriptor[] desc = hbaseAdmin.listTables(tableName);
    if (desc == null || desc.length == 0) {
        throw new TableNotFoundException("Table " + tableName + " not found.");
    }

    if (hbaseAdmin.getTableRegions(tableName.getBytes()).size() == 1) {
        // Split into regions
        // The table has one region only to begin with. The logic of
        // blockUntilRegionSplit requires that the input regionName has performed a split. 
        // If the table has already been split (i.e. regions count > 1), the same split
        // call will be a no-op and this will cause blockUntilRegionSplit to break.
        for (int i = 0; i < splitPoints.length; ++i) {
            hbaseAdmin.majorCompact(tableName);
            List<HRegionInfo> regions = hbaseAdmin.getTableRegions(tableName.getBytes());
            HRegionInfo splitRegion = regions.get(regions.size() - 1);
            int attempt = 1;
            boolean done = false;
            while (!done && attempt < MAX_SPLIT_ATTEMPTS) {
                // HBase seems to not always properly receive/process this split RPC,
                // so we need to retry the split/block several times.
                hbaseAdmin.split(splitRegion.getRegionNameAsString(), splitPoints[i]);
                done = blockUntilRegionSplit(conf, WAIT_FOR_SPLIT_TIMEOUT, splitRegion.getRegionName(), true);
                Thread.sleep(100);
                ++attempt;
            }
            if (!done) {
                throw new IllegalStateException(String.format("Failed to split region '%s' after %s attempts.",
                        splitRegion.getRegionNameAsString(), WAIT_FOR_SPLIT_TIMEOUT));
            }
            LOG.info(String.format("Split region '%s' after %s attempts.", splitRegion.getRegionNameAsString(),
                    attempt));
        }
    }

    // Sort the region by start key
    List<HRegionInfo> regions = hbaseAdmin.getTableRegions(tableName.getBytes());
    Preconditions.checkArgument(regions.size() == splitPoints.length + 1);
    Collections.sort(regions);

    // Pair up two adjacent regions to the same region server. That is, 
    // region server 1 <- regions (unbound:1), (1:3)
    // region server 2 <- regions (3:5), (5:7)
    // region server 3 <- regions (7:9), (9:unbound)
    NavigableMap<HRegionInfo, ServerName> expectedLocs = Maps.newTreeMap();
    for (int i = 0; i < regions.size(); ++i) {
        HRegionInfo regionInfo = regions.get(i);
        int rsIdx = (i / 2) % sortedRS.size();
        ServerName regionServerName = sortedRS.get(rsIdx);
        hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), regionServerName.getServerName().getBytes());
        expectedLocs.put(regionInfo, regionServerName);
    }

    // hbaseAdmin.move() is an asynchronous operation. HBase tests use sleep to wait for
    // the move to complete. It should be done in 10sec.
    int sleepCnt = 0;
    HTable hbaseTable = new HTable(conf, tableName);
    try {
        while (!expectedLocs.equals(hbaseTable.getRegionLocations()) && sleepCnt < 100) {
            Thread.sleep(100);
            ++sleepCnt;
        }
        NavigableMap<HRegionInfo, ServerName> actualLocs = hbaseTable.getRegionLocations();
        Preconditions.checkArgument(expectedLocs.equals(actualLocs));

        // Log the actual region location map
        for (Map.Entry<HRegionInfo, ServerName> entry : actualLocs.entrySet()) {
            LOG.info(printKey(entry.getKey().getStartKey()) + " -> " + entry.getValue().getHostAndPort());
        }

        // Force a major compaction such that the HBase table is backed by deterministic
        // physical artifacts (files, WAL, etc.). Our #rows estimate relies on the sizes of
        // these physical artifacts.
        LOG.info("Major compacting HBase table: " + tableName);
        hbaseAdmin.majorCompact(tableName);
    } finally {
        IOUtils.closeQuietly(hbaseTable);
    }
}