Example usage for java.util NavigableSet isEmpty

List of usage examples for java.util NavigableSet isEmpty

Introduction

In this page you can find the example usage for java.util NavigableSet isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:org.apache.hadoop.hbase.wal.TestWALSplit.java

/**
 * @throws IOException//from  w  w  w .  j  a  v a  2  s  .c  o m
 * @see https://issues.apache.org/jira/browse/HBASE-4862
 */
@Test(timeout = 300000)
public void testConcurrentSplitLogAndReplayRecoverEdit() throws IOException {
    LOG.info("testConcurrentSplitLogAndReplayRecoverEdit");
    // Generate wals for our destination region
    String regionName = "r0";
    final Path regiondir = new Path(TABLEDIR, regionName);
    REGIONS.clear();
    REGIONS.add(regionName);
    generateWALs(-1);

    wals.getWAL(Bytes.toBytes(regionName));
    FileStatus[] logfiles = fs.listStatus(WALDIR);
    assertTrue("There should be some log file", logfiles != null && logfiles.length > 0);

    WALSplitter logSplitter = new WALSplitter(wals, conf, HBASEDIR, fs, null, null, this.mode) {
        @Override
        protected Writer createWriter(Path logfile) throws IOException {
            Writer writer = wals.createRecoveredEditsWriter(this.fs, logfile);
            // After creating writer, simulate region's
            // replayRecoveredEditsIfAny() which gets SplitEditFiles of this
            // region and delete them, excluding files with '.temp' suffix.
            NavigableSet<Path> files = WALSplitter.getSplitEditFilesSorted(fs, regiondir);
            if (files != null && !files.isEmpty()) {
                for (Path file : files) {
                    if (!this.fs.delete(file, false)) {
                        LOG.error("Failed delete of " + file);
                    } else {
                        LOG.debug("Deleted recovered.edits file=" + file);
                    }
                }
            }
            return writer;
        }
    };
    try {
        logSplitter.splitLogFile(logfiles[0], null);
    } catch (IOException e) {
        LOG.info(e);
        fail("Throws IOException when spliting " + "log, it is most likely because writing file does not "
                + "exist which is caused by concurrent replayRecoveredEditsIfAny()");
    }
    if (fs.exists(CORRUPTDIR)) {
        if (fs.listStatus(CORRUPTDIR).length > 0) {
            fail("There are some corrupt logs, "
                    + "it is most likely caused by concurrent replayRecoveredEditsIfAny()");
        }
    }
}

From source file:org.apache.hadoop.hbase.wal.WALSplitUtil.java

/**
 * Check whether there is recovered.edits in the region dir
 * @param conf conf/*from ww  w. j a  va2  s. c om*/
 * @param regionInfo the region to check
 * @throws IOException IOException
 * @return true if recovered.edits exist in the region dir
 */
public static boolean hasRecoveredEdits(final Configuration conf, final RegionInfo regionInfo)
        throws IOException {
    // No recovered.edits for non default replica regions
    if (regionInfo.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) {
        return false;
    }
    // Only default replica region can reach here, so we can use regioninfo
    // directly without converting it to default replica's regioninfo.
    Path regionDir = FSUtils.getWALRegionDir(conf, regionInfo.getTable(), regionInfo.getEncodedName());
    NavigableSet<Path> files = getSplitEditFilesSorted(FSUtils.getWALFileSystem(conf), regionDir);
    return files != null && !files.isEmpty();
}

From source file:org.apache.kylin.common.persistence.JDBCResourceStore.java

@Override
protected NavigableSet<String> listResourcesImpl(String folderPath, boolean recursive) throws IOException {
    try {/*from w  ww  .j  av  a2s.com*/
        final NavigableSet<String> result = resourceDAO.listAllResource(makeFolderPath(folderPath), recursive);
        return result.isEmpty() ? null : result;
    } catch (SQLException e) {
        throw new IOException(e);
    }
}

From source file:org.apache.kylin.rest.security.MockHTable.java

/**
 * {@inheritDoc}/* w w w.  j  a v a 2s . com*/
 */
@Override
public Result get(Get get) throws IOException {
    if (!data.containsKey(get.getRow()))
        return new Result();
    byte[] row = get.getRow();
    List<KeyValue> kvs = new ArrayList<KeyValue>();
    if (!get.hasFamilies()) {
        kvs = toKeyValue(row, data.get(row), get.getMaxVersions());
    } else {
        for (byte[] family : get.getFamilyMap().keySet()) {
            if (data.get(row).get(family) == null)
                continue;
            NavigableSet<byte[]> qualifiers = get.getFamilyMap().get(family);
            if (qualifiers == null || qualifiers.isEmpty())
                qualifiers = data.get(row).get(family).navigableKeySet();
            for (byte[] qualifier : qualifiers) {
                if (qualifier == null)
                    qualifier = "".getBytes();
                if (!data.get(row).containsKey(family) || !data.get(row).get(family).containsKey(qualifier)
                        || data.get(row).get(family).get(qualifier).isEmpty())
                    continue;
                Map.Entry<Long, byte[]> timestampAndValue = data.get(row).get(family).get(qualifier)
                        .lastEntry();
                kvs.add(new KeyValue(row, family, qualifier, timestampAndValue.getKey(),
                        timestampAndValue.getValue()));
            }
        }
    }
    Filter filter = get.getFilter();
    if (filter != null) {
        kvs = filter(filter, kvs);
    }

    return new Result(kvs);
}

From source file:org.apache.kylin.rest.security.MockHTable.java

/**
 * {@inheritDoc}/*from   ww  w  .  j  a  va2 s  . c  om*/
 */
@Override
public ResultScanner getScanner(Scan scan) throws IOException {
    final List<Result> ret = new ArrayList<Result>();
    byte[] st = scan.getStartRow();
    byte[] sp = scan.getStopRow();
    Filter filter = scan.getFilter();

    for (byte[] row : data.keySet()) {
        // if row is equal to startRow emit it. When startRow (inclusive) and
        // stopRow (exclusive) is the same, it should not be excluded which would
        // happen w/o this control.
        if (st != null && st.length > 0 && Bytes.BYTES_COMPARATOR.compare(st, row) != 0) {
            // if row is before startRow do not emit, pass to next row
            if (st != null && st.length > 0 && Bytes.BYTES_COMPARATOR.compare(st, row) > 0)
                continue;
            // if row is equal to stopRow or after it do not emit, stop iteration
            if (sp != null && sp.length > 0 && Bytes.BYTES_COMPARATOR.compare(sp, row) <= 0)
                break;
        }

        List<KeyValue> kvs = null;
        if (!scan.hasFamilies()) {
            kvs = toKeyValue(row, data.get(row), scan.getTimeRange().getMin(), scan.getTimeRange().getMax(),
                    scan.getMaxVersions());
        } else {
            kvs = new ArrayList<KeyValue>();
            for (byte[] family : scan.getFamilyMap().keySet()) {
                if (data.get(row).get(family) == null)
                    continue;
                NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(family);
                if (qualifiers == null || qualifiers.isEmpty())
                    qualifiers = data.get(row).get(family).navigableKeySet();
                for (byte[] qualifier : qualifiers) {
                    if (data.get(row).get(family).get(qualifier) == null)
                        continue;
                    for (Long timestamp : data.get(row).get(family).get(qualifier).descendingKeySet()) {
                        if (timestamp < scan.getTimeRange().getMin())
                            continue;
                        if (timestamp > scan.getTimeRange().getMax())
                            continue;
                        byte[] value = data.get(row).get(family).get(qualifier).get(timestamp);
                        kvs.add(new KeyValue(row, family, qualifier, timestamp, value));
                        if (kvs.size() == scan.getMaxVersions()) {
                            break;
                        }
                    }
                }
            }
        }
        if (filter != null) {
            kvs = filter(filter, kvs);
            // Check for early out optimization
            if (filter.filterAllRemaining()) {
                break;
            }
        }
        if (!kvs.isEmpty()) {
            ret.add(new Result(kvs));
        }
    }

    return new ResultScanner() {
        private final Iterator<Result> iterator = ret.iterator();

        public Iterator<Result> iterator() {
            return iterator;
        }

        public Result[] next(int nbRows) throws IOException {
            ArrayList<Result> resultSets = new ArrayList<Result>(nbRows);
            for (int i = 0; i < nbRows; i++) {
                Result next = next();
                if (next != null) {
                    resultSets.add(next);
                } else {
                    break;
                }
            }
            return resultSets.toArray(new Result[resultSets.size()]);
        }

        public Result next() throws IOException {
            try {
                return iterator().next();
            } catch (NoSuchElementException e) {
                return null;
            }
        }

        public void close() {
        }
    };
}

From source file:org.openstreetmap.osmosis.hbase.utility.MockHTable.java

/**
 * {@inheritDoc}/*from  w w  w .j a v  a 2 s  . c om*/
 */
@Override
public Result get(Get get) throws IOException {
    this.sleeper();
    if (!data.containsKey(get.getRow()))
        return new Result();
    byte[] row = get.getRow();
    List<KeyValue> kvs = new ArrayList<KeyValue>();
    if (!get.hasFamilies()) {
        kvs = toKeyValue(row, data.get(row), get.getMaxVersions());
    } else {
        for (byte[] family : get.getFamilyMap().keySet()) {
            if (data.get(row).get(family) == null)
                continue;
            NavigableSet<byte[]> qualifiers = get.getFamilyMap().get(family);
            if (qualifiers == null || qualifiers.isEmpty())
                qualifiers = data.get(row).get(family).navigableKeySet();
            for (byte[] qualifier : qualifiers) {
                if (qualifier == null)
                    qualifier = "".getBytes();
                if (!data.get(row).containsKey(family) || !data.get(row).get(family).containsKey(qualifier)
                        || data.get(row).get(family).get(qualifier).isEmpty())
                    continue;
                Map.Entry<Long, byte[]> timestampAndValue = data.get(row).get(family).get(qualifier)
                        .lastEntry();
                kvs.add(new KeyValue(row, family, qualifier, timestampAndValue.getKey(),
                        timestampAndValue.getValue()));
            }
        }
    }
    Filter filter = get.getFilter();
    if (filter != null) {
        kvs = filter(filter, kvs);
    }

    return new Result(kvs);
}

From source file:org.openstreetmap.osmosis.hbase.utility.MockHTable.java

/**
 * {@inheritDoc}/*  w  ww  . ja v a2s.com*/
 */
@Override
public ResultScanner getScanner(Scan scan) throws IOException {
    final List<Result> ret = new ArrayList<Result>();
    byte[] st = scan.getStartRow();
    byte[] sp = scan.getStopRow();
    Filter filter = scan.getFilter();

    for (byte[] row : data.keySet()) {
        // if row is equal to startRow emit it. When startRow (inclusive) and
        // stopRow (exclusive) is the same, it should not be excluded which would
        // happen w/o this control.
        if (st != null && st.length > 0 && Bytes.BYTES_COMPARATOR.compare(st, row) != 0) {
            // if row is before startRow do not emit, pass to next row
            if (st.length > 0 && Bytes.BYTES_COMPARATOR.compare(st, row) > 0)
                continue;
            // if row is equal to stopRow or after it do not emit, stop iteration
            if (sp != null && sp.length > 0 && Bytes.BYTES_COMPARATOR.compare(sp, row) <= 0)
                break;
        }

        List<KeyValue> kvs;
        if (!scan.hasFamilies()) {
            kvs = toKeyValue(row, data.get(row), scan.getTimeRange().getMin(), scan.getTimeRange().getMax(),
                    scan.getMaxVersions());
        } else {
            kvs = new ArrayList<KeyValue>();
            for (byte[] family : scan.getFamilyMap().keySet()) {
                if (data.get(row).get(family) == null)
                    continue;
                NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(family);
                if (qualifiers == null || qualifiers.isEmpty())
                    qualifiers = data.get(row).get(family).navigableKeySet();
                for (byte[] qualifier : qualifiers) {
                    if (data.get(row).get(family).get(qualifier) == null)
                        continue;
                    for (Long timestamp : data.get(row).get(family).get(qualifier).descendingKeySet()) {
                        if (timestamp < scan.getTimeRange().getMin())
                            continue;
                        if (timestamp > scan.getTimeRange().getMax())
                            continue;
                        byte[] value = data.get(row).get(family).get(qualifier).get(timestamp);
                        kvs.add(new KeyValue(row, family, qualifier, timestamp, value));
                        if (kvs.size() == scan.getMaxVersions()) {
                            break;
                        }
                    }
                }
            }
        }
        if (filter != null) {
            kvs = filter(filter, kvs);
            // Check for early out optimization
            if (filter.filterAllRemaining()) {
                break;
            }
        }
        if (!kvs.isEmpty()) {
            ret.add(new Result(kvs));
        }
    }

    return new ResultScanner() {
        private final Iterator<Result> iterator = ret.iterator();

        public Iterator<Result> iterator() {
            return iterator;
        }

        public Result[] next(int nbRows) throws IOException {
            ArrayList<Result> resultSets = new ArrayList<Result>(nbRows);
            for (int i = 0; i < nbRows; i++) {
                Result next = next();
                if (next != null) {
                    resultSets.add(next);
                } else {
                    break;
                }
            }
            return resultSets.toArray(new Result[resultSets.size()]);
        }

        public Result next() throws IOException {
            try {
                return iterator().next();
            } catch (NoSuchElementException e) {
                return null;
            }
        }

        public void close() {
        }
    };
}