@Override
    public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException {
        Snapshot snapshot = db.getSnapshot();
        DBIterator iterator = null;
        try {
            List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size);
            ReadOptions options = new ReadOptions();
            options.snapshot(snapshot);
            iterator = db.iterator(options);
            for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
                Map.Entry<byte[], byte[]> entry = iterator.peekNext();
                String key = new String(entry.getKey(), "UTF-8");
                T value = JSON.parse(new String(entry.getValue(), "UTF-8"), type);
                Pair<String, T> pair = new Pair<String, T>(key, value);
                list.add(pair);
                if (list.size() >= size) {
                    break;
                }
            }
            return list;
        } catch (Exception e) {
            throw new FailStoreException(e);
        } finally {
            if (iterator != null) {
                try {
                    iterator.close();
                } catch (IOException ignored) {
                }
            }
            try {
                snapshot.close();
            } catch (IOException ignored) {
            }
        }
    }
Only a single process (possibly multi-threaded) can access a particular database at a time
Robert HG (254963746@qq.com) on 5/21/15.
lts-core/src/main/java/com/github/ltsopensource/core/failstore/leveldb/LeveldbFailStore.java