/** * @param args a base file path for the database and a compaction target */ public static void main(String[] args) throws Exception { Database db = Database.open(new DatabaseConfig() .baseFilePath(args[0]) .checkpointSizeThreshold(0)); double target = Double.parseDouble(args[1]); System.out.println("Before: " + db.stats()); db.compactFile(null, target); System.out.println("After: " + db.stats()); }
/** * @param config base file is set as a side-effect */ static Tree openTemp(TempFileManager tfm, DatabaseConfig config) throws IOException { File file = tfm.createTempFile(); config.baseFile(file); config.dataFile(file); config.createFilePath(false); config.durabilityMode(DurabilityMode.NO_FLUSH); LocalDatabase db = new LocalDatabase(config, OPEN_TEMP); tfm.register(file, db); db.mCheckpointer.start(false); return db.mRegistry; }
public DatabaseConfig() { createFilePath(true); durabilityMode(null); lockTimeout(1, TimeUnit.SECONDS); checkpointRate(1, TimeUnit.SECONDS); checkpointSizeThreshold(1024 * 1024); checkpointDelayThreshold(1, TimeUnit.MINUTES); }
stores = new HashMap<String, TuplKeyValueStore>(); config = new DatabaseConfig().baseFilePath(persistent ? prefixFile.getAbsolutePath() : null) .mapDataFiles(mapDataFiles) .minCacheSize(minCacheSize) .secondaryCacheSize(secondaryCacheSize) .durabilityMode(durabilityMode) .lockUpgradeRule(lockUpgradeRule) .lockTimeout(lockTimeout, TimeUnit.MILLISECONDS) .syncWrites(syncWrites) .pageSize(pageSize) .directPageAccess(directPageAccess) .checkpointRate(checkpointRate, TimeUnit.MILLISECONDS) .checkpointDelayThreshold(checkpointDelayThreshold, TimeUnit.MILLISECONDS) .checkpointSizeThreshold(checkpointSizeThreshold);
/** * @param nodeCache optional */ SnapshotImpl(TempFileManager tfm, long pageCount, long redoPos, LocalDatabase nodeCache, PageArray rawPageArray) throws IOException { mNodeCache = nodeCache; mRawPageArray = rawPageArray; mTempFileManager = tfm; mSnapshotPageCount = pageCount; mSnapshotRedoPosition = redoPos; int pageSize = pageSize(); DatabaseConfig config = new DatabaseConfig() .pageSize(pageSize).minCacheSize(pageSize * 100); mPageCopyIndex = LocalDatabase.openTemp(tfm, config); mTempFile = config.mBaseFile; mSnapshotLock = new Object(); mCaptureLatch = new Latch(); mCaptureBufferArray = new byte[pageSize]; // Allocates if page is not an array. The copy is not actually required. mCaptureBuffer = p_transfer(mCaptureBufferArray); // -2: Not yet started. -1: Started, but nothing written yet. mProgress = -2; mWriteInProgress = -2; mCaptureInProgress = -1; }
/** * @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 { DatabaseConfig config = new DatabaseConfig() .baseFilePath(args[0]) .eventListener(new EventPrinter().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()); }
/** * Opens a new {@link Database} on the given {@link File} with the given maximum cache size (in bytes). * * @param file * The file to use for the database instance. Must not be <code>null</code>. * @param cacheMaxSizeBytes * The maximum number of bytes to allocate for the cache. Must be greater than zero. * @return The newly created database instance. Never <code>null</code>. * * @throws IllegalStateException * Thrown if an error occurs while opening the database. */ public static Database openDatabase(final File file, final long cacheMaxSizeBytes) { checkNotNull(file, "Precondition violation - argument 'file' must not be NULL!"); checkArgument(cacheMaxSizeBytes > 0, "Precondition violation - argument 'cacheMaxSizeBytes' must be positive!"); try { DatabaseConfig config = new DatabaseConfig(); config.baseFile(file); config.maxCacheSize(cacheMaxSizeBytes); Database database = Database.open(config); return database; } catch (IOException e) { throw new IllegalStateException( "Failed to open database on file '" + file.getAbsolutePath() + "'! See root cause for details.", e); } }
/** * @param args only argument is a base file path for the database */ public static void main(String[] args) throws Exception { Database db = Database.open(new DatabaseConfig().baseFilePath(args[0])); System.out.println(db.stats()); Verify v = new Verify(); db.verify(v); System.out.println(v); System.exit(v.failed); }
/** * @param nodeCache optional */ SnapshotImpl(TempFileManager tfm, long pageCount, long redoPos, _LocalDatabase nodeCache, PageArray rawPageArray) throws IOException { mNodeCache = nodeCache; mRawPageArray = rawPageArray; mTempFileManager = tfm; mSnapshotPageCount = pageCount; mSnapshotRedoPosition = redoPos; int pageSize = pageSize(); DatabaseConfig config = new DatabaseConfig() .pageSize(pageSize).minCacheSize(pageSize * 100); mPageCopyIndex = _LocalDatabase.openTemp(tfm, config); mTempFile = config.mBaseFile; mSnapshotLock = new Object(); mCaptureLatch = new Latch(); mCaptureBufferArray = new byte[pageSize]; // Allocates if page is not an array. The copy is not actually required. mCaptureBuffer = p_transfer(mCaptureBufferArray); // -2: Not yet started. -1: Started, but nothing written yet. mProgress = -2; mWriteInProgress = -2; mCaptureInProgress = -1; }
/** * @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 { DatabaseConfig config = new DatabaseConfig() .baseFilePath(args[0]) .eventListener(new EventPrinter()); if (args.length > 1) { config.minCacheSize(Long.parseLong(args[1])); } Database db = Database.open(config); System.out.println(db.stats()); Verify v = new Verify(); db.verify(v); System.out.println(v); System.exit(v.failed); }
/** * @param args only argument is a base file path for the database */ public static void main(String[] args) throws Exception { Database db = Database.open(new DatabaseConfig().baseFilePath(args[0])); System.out.println(db.stats()); Verify v = new Verify(); db.verify(v); System.out.println(v); System.exit(v.failed); }
public DatabaseConfig() { createFilePath(true); durabilityMode(null); lockTimeout(1, TimeUnit.SECONDS); checkpointRate(1, TimeUnit.SECONDS); checkpointSizeThreshold(1024 * 1024); checkpointDelayThreshold(1, TimeUnit.MINUTES); }
/** * @param config base file is set as a side-effect */ static _Tree openTemp(TempFileManager tfm, DatabaseConfig config) throws IOException { File file = tfm.createTempFile(); config.baseFile(file); config.dataFile(file); config.createFilePath(false); config.durabilityMode(DurabilityMode.NO_FLUSH); _LocalDatabase db = new _LocalDatabase(config, OPEN_TEMP); tfm.register(file, db); db.mCheckpointer.start(false); return db.mRegistry; }
DatabaseConfig config = new DatabaseConfig() .pageSize(pageSize).minCacheSize(pageSize * Math.max(100, slots * 16)); mPageCopyIndex = LocalDatabase.openTemp(tfm, config); mTempFile = config.mBaseFile;
/** * @param args a base file path for the database and a compaction target */ public static void main(String[] args) throws Exception { Database db = Database.open(new DatabaseConfig() .baseFilePath(args[0]) .checkpointSizeThreshold(0)); double target = Double.parseDouble(args[1]); System.out.println("Before: " + db.stats()); db.compactFile(null, target); System.out.println("After: " + db.stats()); }
public DatabaseConfig() { createFilePath(true); durabilityMode(null); lockTimeout(1, TimeUnit.SECONDS); checkpointRate(1, TimeUnit.SECONDS); checkpointSizeThreshold(1024 * 1024); checkpointDelayThreshold(1, TimeUnit.MINUTES); }
/** * @param config base file is set as a side-effect */ static Tree openTemp(TempFileManager tfm, DatabaseConfig config) throws IOException { File file = tfm.createTempFile(); config.baseFile(file); config.dataFile(file); config.createFilePath(false); config.durabilityMode(DurabilityMode.NO_FLUSH); LocalDatabase db = new LocalDatabase(config, OPEN_TEMP); tfm.register(file, db); db.mCheckpointer = new Checkpointer(db, config); db.mCheckpointer.start(false); return db.mRegistry; }
DatabaseConfig config = new DatabaseConfig() .pageSize(pageSize).minCacheSize(pageSize * Math.max(100, slots * 16)); mPageCopyIndex = _LocalDatabase.openTemp(tfm, config); mTempFile = config.mBaseFile;
/** * @param config base file is set as a side-effect */ static _Tree openTemp(TempFileManager tfm, DatabaseConfig config) throws IOException { File file = tfm.createTempFile(); config.baseFile(file); config.dataFile(file); config.createFilePath(false); config.durabilityMode(DurabilityMode.NO_FLUSH); _LocalDatabase db = new _LocalDatabase(config, OPEN_TEMP); tfm.register(file, db); db.mCheckpointer = new Checkpointer(db, config); db.mCheckpointer.start(false); return db.mRegistry; }
DatabaseConfig config = new DatabaseConfig() .pageSize(pageSize).minCacheSize(pageSize * Math.max(100, slots * 16)); mPageCopyIndex = _LocalDatabase.openTemp(tfm, config); mTempFile = config.mBaseFile;