Example usage for org.apache.lucene.index IndexFileNames parseSegmentName

List of usage examples for org.apache.lucene.index IndexFileNames parseSegmentName

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexFileNames parseSegmentName.

Prototype

public static String parseSegmentName(String filename) 

Source Link

Document

Parses the segment name out of the given file name.

Usage

From source file:org.elasticsearch.index.store.CorruptedFileIT.java

License:Apache License

/**
 * prunes the list of index files such that only the latest del generation files are contained.
 *//*ww  w . jav a  2 s.co  m*/
private void pruneOldDeleteGenerations(Set<Path> files) {
    final TreeSet<Path> delFiles = new TreeSet<>();
    for (Path file : files) {
        if (file.getFileName().toString().endsWith(".liv")) {
            delFiles.add(file);
        }
    }
    Path last = null;
    for (Path current : delFiles) {
        if (last != null) {
            final String newSegmentName = IndexFileNames.parseSegmentName(current.getFileName().toString());
            final String oldSegmentName = IndexFileNames.parseSegmentName(last.getFileName().toString());
            if (newSegmentName.equals(oldSegmentName)) {
                int oldGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(last.getFileName().toString()))
                        .replace("_", ""), Character.MAX_RADIX);
                int newGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(current.getFileName().toString()))
                        .replace("_", ""), Character.MAX_RADIX);
                if (newGen > oldGen) {
                    files.remove(last);
                } else {
                    files.remove(current);
                    continue;
                }
            }
        }
        last = current;
    }
}

From source file:org.elasticsearch.index.store.CorruptedFileTest.java

License:Apache License

/**
 * prunes the list of index files such that only the latest del generation files are contained.
 *//*  w ww .  j ava2s  .  c  om*/
private void pruneOldDeleteGenerations(Set<File> files) {
    final TreeSet<File> delFiles = new TreeSet<>();
    for (File file : files) {
        if (file.getName().endsWith(".del")) {
            delFiles.add(file);
        }
    }
    File last = null;
    for (File current : delFiles) {
        if (last != null) {
            final String newSegmentName = IndexFileNames.parseSegmentName(current.getName());
            final String oldSegmentName = IndexFileNames.parseSegmentName(last.getName());
            if (newSegmentName.equals(oldSegmentName)) {
                int oldGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(last.getName())).replace("_", ""),
                        Character.MAX_RADIX);
                int newGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(current.getName())).replace("_", ""),
                        Character.MAX_RADIX);
                if (newGen > oldGen) {
                    files.remove(last);
                } else {
                    files.remove(current);
                    continue;
                }
            }
        }
        last = current;
    }
}