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());
}
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);
}
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);
}
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);
}
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;
}
Aggregations