Search in sources :

Example 1 with DatabaseConfig

use of org.cojen.tupl.DatabaseConfig in project Tupl by cojen.

the class Compact method main.

/**
 * @param args a base file path for the database, a compaction target, and an optional
 * cache size
 */
public static void main(String[] args) throws Exception {
    var config = new DatabaseConfig().createFilePath(false).baseFilePath(args[0]).eventListener(EventListener.printTo(System.out).ignore(EventType.Category.CHECKPOINT)).checkpointSizeThreshold(0);
    double target = Double.parseDouble(args[1]);
    if (args.length > 2) {
        config.minCacheSize(Long.parseLong(args[2]));
    }
    Database db = Database.open(config);
    System.out.println("Before: " + db.stats());
    db.compactFile(null, target);
    System.out.println("After: " + db.stats());
}
Also used : Database(org.cojen.tupl.Database) DatabaseConfig(org.cojen.tupl.DatabaseConfig)

Example 2 with DatabaseConfig

use of org.cojen.tupl.DatabaseConfig in project Tupl by cojen.

the class Shutdown method main.

/**
 * @param args a base file path for the database, and an optional cache size
 */
public static void main(String[] args) throws Exception {
    var config = new DatabaseConfig().createFilePath(false).baseFilePath(args[0]).eventListener(EventListener.printTo(System.out));
    if (args.length > 1) {
        config.minCacheSize(Long.parseLong(args[1]));
    }
    Database db = Database.open(config);
    DatabaseStats stats = db.stats();
    db.shutdown();
    System.out.println(stats);
}
Also used : DatabaseStats(org.cojen.tupl.diag.DatabaseStats) Database(org.cojen.tupl.Database) DatabaseConfig(org.cojen.tupl.DatabaseConfig)

Example 3 with DatabaseConfig

use of org.cojen.tupl.DatabaseConfig in project Tupl by cojen.

the class Verify method main.

/**
 * @param args first argument is a base file path for the database, second optional
 * argument is the cache size
 */
public static void main(String[] args) throws Exception {
    var config = new DatabaseConfig().createFilePath(false).baseFilePath(args[0]).eventListener(EventListener.printTo(System.out));
    if (args.length > 1) {
        config.minCacheSize(Long.parseLong(args[1]));
    }
    Database db = Database.open(config);
    System.out.println(db.stats());
    var v = new Verify();
    db.verify(v);
    System.out.println(v);
    System.exit(v.failed);
}
Also used : Database(org.cojen.tupl.Database) DatabaseConfig(org.cojen.tupl.DatabaseConfig)

Example 4 with DatabaseConfig

use of org.cojen.tupl.DatabaseConfig in project Tupl by cojen.

the class CrudJoinedFileTest method createTempDb.

@Before
@Override
public void createTempDb() throws Exception {
    PageArray pa = JoinedPageArray.join(newFilePageArray(), 10, newFilePageArray());
    var config = new DatabaseConfig().dataPageArray(pa).directPageAccess(false);
    decorate(config);
    mDb = newTempDatabase(getClass(), config);
}
Also used : JoinedPageArray(org.cojen.tupl.io.JoinedPageArray) FilePageArray(org.cojen.tupl.io.FilePageArray) PageArray(org.cojen.tupl.io.PageArray) DatabaseConfig(org.cojen.tupl.DatabaseConfig)

Example 5 with DatabaseConfig

use of org.cojen.tupl.DatabaseConfig in project Tupl by cojen.

the class DatabaseReplicatorTest method startGroup.

/**
 * @return first is the leader
 */
private Database[] startGroup(int members, Role replicaRole, Supplier<PrepareHandler> handlerSupplier) throws Exception {
    if (members < 1) {
        throw new IllegalArgumentException();
    }
    mSockets = new ServerSocket[members];
    for (int i = 0; i < members; i++) {
        mSockets[i] = TestUtils.newServerSocket();
    }
    mReplBaseFiles = new File[members];
    mReplConfigs = new ReplicatorConfig[members];
    mReplicators = new StreamReplicator[members];
    mDbConfigs = new DatabaseConfig[members];
    mDatabases = new Database[members];
    for (int i = 0; i < members; i++) {
        mReplBaseFiles[i] = TestUtils.newTempBaseFile(getClass());
        EventListener listener = false ? EventListener.printTo(System.out) : null;
        mReplConfigs[i] = new ReplicatorConfig().groupToken(1).localSocket(mSockets[i]).baseFile(mReplBaseFiles[i]).eventListener(listener);
        if (i > 0) {
            mReplConfigs[i].addSeed(mSockets[0].getLocalSocketAddress());
            mReplConfigs[i].localRole(replicaRole);
        }
        mReplicators[i] = StreamReplicator.open(mReplConfigs[i]);
        ((Controller) mReplicators[i]).keepServerSocket();
        mDbConfigs[i] = new DatabaseConfig().baseFile(mReplBaseFiles[i]).replicate(mReplicators[i]).eventListener(listener).lockTimeout(5, TimeUnit.SECONDS).directPageAccess(false);
        if (handlerSupplier != null) {
            mDbConfigs[i].prepareHandlers(Map.of("TestHandler", handlerSupplier.get()));
        }
        Database db = Database.open(mDbConfigs[i]);
        mDatabases[i] = db;
        readyCheck: {
            for (int trial = 0; trial < 100; trial++) {
                TestUtils.sleep(100);
                if (i == 0) {
                    try {
                        db.openIndex("control");
                        // Ensure that replicas obtain the index in the snapshot.
                        db.checkpoint();
                        break readyCheck;
                    } catch (UnmodifiableReplicaException e) {
                    // Not leader yet.
                    }
                } else {
                    assertNotNull(db.openIndex("control"));
                    break readyCheck;
                }
            }
            throw new AssertionError(i == 0 ? "No leader" : "Not joined");
        }
    }
    return mDatabases;
}
Also used : UnmodifiableReplicaException(org.cojen.tupl.UnmodifiableReplicaException) Database(org.cojen.tupl.Database) EventListener(org.cojen.tupl.diag.EventListener) DatabaseConfig(org.cojen.tupl.DatabaseConfig)

Aggregations

DatabaseConfig (org.cojen.tupl.DatabaseConfig)6 Database (org.cojen.tupl.Database)5 BigDecimal (java.math.BigDecimal)1 UnmodifiableReplicaException (org.cojen.tupl.UnmodifiableReplicaException)1 DatabaseStats (org.cojen.tupl.diag.DatabaseStats)1 EventListener (org.cojen.tupl.diag.EventListener)1 FilePageArray (org.cojen.tupl.io.FilePageArray)1 JoinedPageArray (org.cojen.tupl.io.JoinedPageArray)1 PageArray (org.cojen.tupl.io.PageArray)1