Search in sources :

Example 1 with FDB

use of com.apple.foundationdb.FDB in project fdb-record-layer by FoundationDB.

the class ClientLogEventCounterTest method main.

@SuppressWarnings("PMD.SystemPrintln")
public static void main(String[] args) {
    String cluster = null;
    Instant start = null;
    Instant end = null;
    boolean countReads = true;
    boolean countWrites = false;
    final boolean countSingleKeys = true;
    final boolean countRanges = true;
    if (args.length > 0) {
        cluster = args[0];
    }
    if (args.length > 1) {
        start = ZonedDateTime.parse(args[1]).toInstant();
    }
    if (args.length > 2) {
        end = ZonedDateTime.parse(args[2]).toInstant();
    }
    if (args.length > 3) {
        String arg = args[3];
        countReads = "READ".equals(arg) || "BOTH".equals(arg);
        countWrites = "WRITE".equals(arg) || "BOTH".equals(arg);
    }
    FDB fdb = FDB.selectAPIVersion(630);
    Database database = fdb.open(cluster);
    Executor executor = database.getExecutor();
    TupleKeyCountTree root = new TupleKeyCountTree();
    DatabaseClientLogEventCounter counter = new DatabaseClientLogEventCounter(root, countReads, countWrites, countSingleKeys, countRanges, true);
    TupleKeyCountTree.Printer printer = (depth, path) -> {
        for (int i = 0; i < depth; i++) {
            System.out.print("  ");
        }
        System.out.print(path.stream().map(Object::toString).collect(Collectors.joining("/")));
        int percent = (path.get(0).getCount() * 100) / path.get(0).getParent().getCount();
        System.out.println(" " + percent + "%");
    };
    int eventLimit = 10_000;
    long timeLimit = 15_000;
    DatabaseClientLogEvents events = DatabaseClientLogEvents.forEachEventBetweenTimestamps(database, executor, counter, start, end, eventLimit, timeLimit).join();
    while (true) {
        System.out.println(events.getEarliestTimestamp() + " - " + events.getLatestTimestamp());
        root.hideLessThanFraction(0.10);
        root.printTree(printer, "/");
        if (!events.hasMore()) {
            break;
        }
        events.forEachEventContinued(database, executor, counter, eventLimit, timeLimit).join();
    }
}
Also used : FDB(com.apple.foundationdb.FDB) Executor(java.util.concurrent.Executor) ZonedDateTime(java.time.ZonedDateTime) Database(com.apple.foundationdb.Database) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FDB(com.apple.foundationdb.FDB) Instant(java.time.Instant) Executor(java.util.concurrent.Executor) Database(com.apple.foundationdb.Database)

Example 2 with FDB

use of com.apple.foundationdb.FDB in project fdb-record-layer by FoundationDB.

the class DatabaseClientLogEventsTest method main.

@SuppressWarnings("PMD.SystemPrintln")
public static void main(String[] args) {
    String cluster = null;
    Instant start = null;
    Instant end = null;
    if (args.length > 0) {
        cluster = args[0];
    }
    if (args.length > 1) {
        start = ZonedDateTime.parse(args[1]).toInstant();
    }
    if (args.length > 2) {
        end = ZonedDateTime.parse(args[2]).toInstant();
    }
    FDB fdb = FDB.selectAPIVersion(630);
    Database database = fdb.open(cluster);
    Executor executor = database.getExecutor();
    DatabaseClientLogEvents.EventConsumer consumer = (tr, event) -> {
        System.out.println(event);
        return AsyncUtil.DONE;
    };
    DatabaseClientLogEvents.forEachEventBetweenTimestamps(database, executor, consumer, start, end, Integer.MAX_VALUE, Long.MAX_VALUE).join();
}
Also used : FDB(com.apple.foundationdb.FDB) Executor(java.util.concurrent.Executor) ZonedDateTime(java.time.ZonedDateTime) Database(com.apple.foundationdb.Database) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) Instant(java.time.Instant) Executor(java.util.concurrent.Executor) FDB(com.apple.foundationdb.FDB) Instant(java.time.Instant) Database(com.apple.foundationdb.Database)

Example 3 with FDB

use of com.apple.foundationdb.FDB in project fdb-record-layer by FoundationDB.

the class RankedSetTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    FDB fdb = FDB.instance();
    if (TRACE) {
        NetworkOptions options = fdb.options();
        options.setTraceEnable("/tmp");
        options.setTraceLogGroup("RankedSetTest");
    }
    this.db = fdb.open();
    this.rsSubspace = DirectoryLayer.getDefault().createOrOpen(db, PathUtil.from(getClass().getSimpleName())).get();
    db.run(tr -> {
        tr.clear(rsSubspace.range());
        return null;
    });
}
Also used : NetworkOptions(com.apple.foundationdb.NetworkOptions) FDB(com.apple.foundationdb.FDB) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

FDB (com.apple.foundationdb.FDB)3 Database (com.apple.foundationdb.Database)2 Instant (java.time.Instant)2 ZonedDateTime (java.time.ZonedDateTime)2 Executor (java.util.concurrent.Executor)2 NetworkOptions (com.apple.foundationdb.NetworkOptions)1 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)1 Collectors (java.util.stream.Collectors)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1