Search in sources :

Example 1 with Args

use of org.neo4j.internal.helpers.Args in project neo4j by neo4j.

the class LoggingIndexedIdGeneratorMonitor method main.

/**
 * Used for dumping contents of a log as text
 */
public static void main(String[] args) throws IOException {
    Args arguments = Args.withFlags(ARG_TOFILE).parse(args);
    if (arguments.orphans().isEmpty()) {
        System.err.println("Please supply base name of log file");
        return;
    }
    Path path = Path.of(arguments.orphans().get(0));
    FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
    String filterArg = arguments.get(ARG_FILTER, null);
    LongPredicate filter = filterArg != null ? parseFilter(filterArg) : NO_FILTER;
    PrintStream out = System.out;
    boolean redirectsToFile = arguments.getBoolean(ARG_TOFILE);
    if (redirectsToFile) {
        Path outFile = path.resolveSibling(path.getFileName() + ".txt");
        System.out.println("Redirecting output to " + outFile);
        out = new PrintStream(new BufferedOutputStream(Files.newOutputStream(outFile)));
    }
    dump(fs, path, new Printer(out, filter));
    if (redirectsToFile) {
        out.close();
    }
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) Args(org.neo4j.internal.helpers.Args) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) LongPredicate(java.util.function.LongPredicate) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with Args

use of org.neo4j.internal.helpers.Args in project neo4j by neo4j.

the class TokenScanWriteMonitor method main.

/**
 * Dumps a token scan write log as plain text. Arguments:
 * <ul>
 *     <li>{@value #ARG_TOFILE}: dumps to a .txt file next to the writelog</li>
 *     <li>{@value #ARG_TXFILTER}: filter for which tx ids to include in the dump.
 *     <p>
 *     Consists of one or more groups separated by comma.
 *     <p>
 *     Each group is either a txId, or a txId range, e.g. 123-456
 *     </li>
 * </ul>
 * <p>
 * How to interpret the dump, e.g:
 * <pre>
 * === ..../neostore.labelscanstore.db.writelog ===
 * [1,1]+tx:6,entity:0,token:0
 * [1,1]+tx:3,entity:20,token:0
 * [1,1]+tx:4,entity:40,token:0
 * [1,1]+tx:5,entity:60,token:0
 * [2,1]+tx:8,entity:80,token:1
 * [3,1]+tx:10,entity:41,token:1
 * [4,1]+tx:9,entity:21,token:1
 * [4,1]+tx:11,entity:61,token:1
 * [4,1]+range:0,tokenId:1
 *  [00000000 00000000 00000010 00000000 00000000 00000000 00000000 00000000]
 *  [00100000 00000000 00000000 00000000 00000000 00100000 00000000 00000000]
 * [5,1]+tx:12,entity:81,token:1
 * [5,1]+range:1,tokenId:1
 *  [00000000 00000000 00000000 00000000 00000000 00000001 00000000 00000000]
 *  [00000000 00000000 00000000 00000000 00000000 00000010 00000000 00000000]
 * [6,1]+tx:13,entity:1,token:1
 * [6,1]+range:0,tokenId:1
 *  [00100000 00000000 00000010 00000000 00000000 00100000 00000000 00000000]
 *  [00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000010]
 * [7,1]+tx:14,entity:62,token:1
 * [7,1]+range:0,tokenId:1
 * </pre>
 * How to interpret a message like:
 * <pre>
 * [1,1]+tx:6,entity:0,token:0
 *  ▲ ▲ ▲   ▲        ▲       ▲
 *  │ │ │   │        │       └── token id of the change
 *  │ │ │   │        └────────── entity id of the change
 *  │ │ │   └─────────────────── id of transaction making this particular change
 *  │ │ └─────────────────────── addition, a minus means removal
 *  │ └───────────────────────── flush, local to each write session, incremented when a batch of changes is flushed internally in a writer session
 *  └─────────────────────────── write session, incremented for each token index writer
 * </pre>
 * How to interpret a message like:
 * <pre>
 * [4,1]+range:0,tokenId:1
 *  [00000000 00000000 00000010 00000000 00000000 00000000 00000000 00000000]
 *  [00100000 00000000 00000000 00000000 00000000 00100000 00000000 00000000]
 * </pre>
 * First the first line (parts within bracket same as above):
 * <pre>
 * [4,1]+range:0,tokenId:1
 *             ▲         ▲
 *             │         └── token id of the changed bitset to apply
 *             └──────────── range, i.e. which bitset to apply this change for
 * </pre>
 * Then the bitsets are printed
 * <pre>
 *  [00000000 00000000 00000010 00000000 00000000 00000000 00000000 00000000] : state of the bitset for this token id before the change
 *  [00100000 00000000 00000000 00000000 00000000 00100000 00000000 00000000] : bits that applied to this bitset
 *                                                                              for addition the 1-bits denotes bits to be added
 *                                                                              for removal the 1-bits denotes bits to be removed
 * </pre>
 */
public static void main(String[] args) throws IOException {
    Args arguments = Args.withFlags(ARG_TOFILE).parse(args);
    if (arguments.orphans().size() == 0) {
        System.err.println("Please supply database directory");
        return;
    }
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(Path.of(arguments.orphans().get(0)));
    FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
    TxFilter txFilter = parseTxFilter(arguments.get(ARG_TXFILTER, null));
    PrintStream out = System.out;
    boolean redirectsToFile = arguments.getBoolean(ARG_TOFILE);
    for (EntityType entityType : EntityType.values()) {
        if (redirectsToFile) {
            Path outFile = Path.of(writeLogBaseFile(databaseLayout, entityType).toAbsolutePath() + ".txt");
            System.out.println("Redirecting output to " + outFile);
            out = new PrintStream(new BufferedOutputStream(Files.newOutputStream(outFile)));
        }
        Dumper dumper = new PrintStreamDumper(out);
        dump(fs, databaseLayout, dumper, txFilter, entityType);
        if (redirectsToFile) {
            out.close();
        }
    }
}
Also used : EntityType(org.neo4j.common.EntityType) Path(java.nio.file.Path) PrintStream(java.io.PrintStream) Args(org.neo4j.internal.helpers.Args) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with Args

use of org.neo4j.internal.helpers.Args in project neo4j-documentation by neo4j.

the class GenerateProcedureReference method main.

public static void main(String[] args) throws IOException {
    Args arguments = Args.parse(args);
    printUsage();
    List<String> orphans = arguments.orphans();
    Path outFile = orphans.size() == 1 ? Paths.get(orphans.get(0)) : null;
    String id = arguments.has("id") || warnMissingOption("ID", "--id=my-id", DEFAULT_ID) ? arguments.get("id") : DEFAULT_ID;
    String title = arguments.has("title") || warnMissingOption("title", "--title=my-title", DEFAULT_TITLE) ? arguments.get("title") : DEFAULT_TITLE;
    String edition = arguments.has("edition") || warnMissingOption("edition", "--edition=community", DEFAULT_EDITION) ? arguments.get("edition") : DEFAULT_EDITION;
    Predicate<ProcedureReferenceGenerator.Procedure> filter = filter(arguments);
    System.out.printf("[+++] id=%s  title=%s%n", id, title);
    try {
        String doc = new ProcedureReferenceGenerator().document(id, title, edition, filter);
        if (null != outFile) {
            Path parentDir = outFile.getParent();
            if (!Files.exists(parentDir)) {
                Files.createDirectories(parentDir);
            }
            System.out.println("Saving docs in '" + outFile.toFile().getAbsolutePath() + "'.");
            Files.write(outFile, doc.getBytes());
        } else {
            System.out.println(doc);
        }
    } catch (NoSuchElementException | NoSuchFileException e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Path(java.nio.file.Path) Args(org.neo4j.internal.helpers.Args) NoSuchFileException(java.nio.file.NoSuchFileException) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with Args

use of org.neo4j.internal.helpers.Args in project neo4j-documentation by neo4j.

the class GenerateFunctionDescriptions method main.

public static void main(String[] args) throws IOException {
    Args arguments = Args.parse(args);
    printUsage();
    List<String> orphans = arguments.orphans();
    Path outFile = orphans.size() == 1 ? Paths.get(orphans.get(0)) : null;
    try {
        String doc = new FunctionDescriptionsGenerator().document();
        if (null != outFile) {
            Path parentDir = outFile.getParent();
            if (!Files.exists(parentDir)) {
                Files.createDirectories(parentDir);
            }
            System.out.println("Saving docs in '" + outFile.toFile().getAbsolutePath() + "'.");
            Files.write(outFile, doc.getBytes());
        } else {
            System.out.println(doc);
        }
    } catch (NoSuchElementException | NoSuchFileException e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Path(java.nio.file.Path) Args(org.neo4j.internal.helpers.Args) NoSuchFileException(java.nio.file.NoSuchFileException) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with Args

use of org.neo4j.internal.helpers.Args in project neo4j-documentation by neo4j.

the class ConfigDocsTool method main.

public static void main(String[] args) throws IOException {
    Args arguments = Args.parse(args);
    printUsage();
    List<String> orphans = arguments.orphans();
    Path outFile = orphans.size() == 1 ? Paths.get(orphans.get(0)) : null;
    String id = arguments.has("id") || warnMissingOption("ID", "--id=my-id", DEFAULT_ID) ? arguments.get("id") : DEFAULT_ID;
    String title = arguments.has("title") || warnMissingOption("title", "--title=my-title", DEFAULT_TITLE) ? arguments.get("title") : DEFAULT_TITLE;
    String idPrefix = arguments.has("id-prefix") || warnMissingOption("ID prefix", "--id-prefix=my-id-prefix", DEFAULT_ID_PREFIX) ? arguments.get("id-prefix") : DEFAULT_ID_PREFIX;
    Predicate<SettingImpl<Object>> filter = filters(arguments);
    System.out.printf("[+++] id=%s  title=%s  idPrefix=%s%n", id, title, idPrefix);
    try {
        String doc = new ConfigDocsGenerator().document(filter, id, title, idPrefix);
        if (null != outFile) {
            Path parentDir = outFile.getParent();
            if (!Files.exists(parentDir)) {
                Files.createDirectories(parentDir);
            }
            System.out.println("Saving docs in '" + outFile.toFile().getAbsolutePath() + "'.");
            Files.write(outFile, doc.getBytes());
        } else {
            System.out.println(doc);
        }
    } catch (NoSuchElementException | NoSuchFileException e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Path(java.nio.file.Path) Args(org.neo4j.internal.helpers.Args) NoSuchFileException(java.nio.file.NoSuchFileException) SettingImpl(org.neo4j.configuration.SettingImpl) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Path (java.nio.file.Path)8 Args (org.neo4j.internal.helpers.Args)8 NoSuchFileException (java.nio.file.NoSuchFileException)3 NoSuchElementException (java.util.NoSuchElementException)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 BufferedOutputStream (java.io.BufferedOutputStream)2 PrintStream (java.io.PrintStream)2 MetricGroup (com.neo4j.metrics.source.MetricGroup)1 Metrics (com.neo4j.metrics.source.Metrics)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 LongPredicate (java.util.function.LongPredicate)1 EntityType (org.neo4j.common.EntityType)1 Config (org.neo4j.configuration.Config)1 SettingImpl (org.neo4j.configuration.SettingImpl)1 Configuration (org.neo4j.csv.reader.Configuration)1 Extractors (org.neo4j.csv.reader.Extractors)1