use of org.h2.mvstore.db.MVTableEngine.Store in project jackrabbit-oak by apache.
the class BlobCache method addGeneration.
@Override
public void addGeneration(int generation, boolean readOnly) {
CacheMap<Long, byte[]> d = cache.openMap(generation, "data", new MVMap.Builder<Long, byte[]>());
data.addReadMap(generation, d);
CacheMap<String, byte[]> m = cache.openMap(generation, "meta", new MVMap.Builder<String, byte[]>());
meta.addReadMap(generation, m);
if (!readOnly) {
// the order is important:
// if we switch the data first,
// we could end up with the data in store 1
// but the metadata in store 2 - which could
// result in a data block not found if store 1
// is removed later on
meta.setWriteMap(m);
data.setWriteMap(d);
}
if (streamStore == null) {
streamStore = new StreamStore(data);
}
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class ScriptBase method openInput.
/**
* Open the input stream.
*/
void openInput() {
String file = getFileName();
if (file == null) {
return;
}
if (isEncrypted()) {
initStore();
in = new FileStoreInputStream(store, this, compressionAlgorithm != null, false);
} else {
InputStream inStream;
try {
inStream = FileUtils.newInputStream(file);
} catch (IOException e) {
throw DbException.convertIOException(e, file);
}
in = new BufferedInputStream(inStream, Constants.IO_BUFFER_SIZE);
in = CompressTool.wrapInputStream(in, compressionAlgorithm, SCRIPT_SQL);
if (in == null) {
throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, SCRIPT_SQL + " in " + file);
}
}
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class BackupCommand method backupTo.
private void backupTo(String fileName) {
Database db = session.getDatabase();
if (!db.isPersistent()) {
throw DbException.get(ErrorCode.DATABASE_IS_NOT_PERSISTENT);
}
try {
Store mvStore = db.getMvStore();
if (mvStore != null) {
mvStore.flush();
}
String name = db.getName();
name = FileUtils.getName(name);
try (OutputStream zip = FileUtils.newOutputStream(fileName, false)) {
ZipOutputStream out = new ZipOutputStream(zip);
db.flush();
if (db.getPageStore() != null) {
String fn = db.getName() + Constants.SUFFIX_PAGE_FILE;
backupPageStore(out, fn, db.getPageStore());
}
// synchronize on the database, to avoid concurrent temp file
// creation / deletion / backup
String base = FileUtils.getParent(db.getName());
synchronized (db.getLobSyncObject()) {
String prefix = db.getDatabasePath();
String dir = FileUtils.getParent(prefix);
dir = FileLister.getDir(dir);
ArrayList<String> fileList = FileLister.getDatabaseFiles(dir, name, true);
for (String n : fileList) {
if (n.endsWith(Constants.SUFFIX_LOB_FILE)) {
backupFile(out, base, n);
}
if (n.endsWith(Constants.SUFFIX_MV_FILE) && mvStore != null) {
MVStore s = mvStore.getStore();
boolean before = s.getReuseSpace();
s.setReuseSpace(false);
try {
InputStream in = mvStore.getInputStream();
backupFile(out, base, n, in);
} finally {
s.setReuseSpace(before);
}
}
}
}
out.close();
}
} catch (IOException e) {
throw DbException.convertIOException(e, fileName);
}
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class BackupCommand method backupPageStore.
private void backupPageStore(ZipOutputStream out, String fileName, PageStore store) throws IOException {
Database db = session.getDatabase();
fileName = FileUtils.getName(fileName);
out.putNextEntry(new ZipEntry(fileName));
int pos = 0;
try {
store.setBackup(true);
while (true) {
pos = store.copyDirect(pos, out);
if (pos < 0) {
break;
}
int max = store.getPageCount();
db.setProgress(DatabaseEventListener.STATE_BACKUP_FILE, fileName, pos, max);
}
} finally {
store.setBackup(false);
}
out.closeEntry();
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class Explain method query.
@Override
public ResultInterface query(int maxrows) {
Column column = new Column("PLAN", Value.STRING);
Database db = session.getDatabase();
ExpressionColumn expr = new ExpressionColumn(db, column);
Expression[] expressions = { expr };
result = new LocalResult(session, expressions, 1);
if (maxrows >= 0) {
String plan;
if (executeCommand) {
PageStore store = null;
Store mvStore = null;
if (db.isPersistent()) {
store = db.getPageStore();
if (store != null) {
store.statisticsStart();
}
mvStore = db.getMvStore();
if (mvStore != null) {
mvStore.statisticsStart();
}
}
if (command.isQuery()) {
command.query(maxrows);
} else {
command.update();
}
plan = command.getPlanSQL();
Map<String, Integer> statistics = null;
if (store != null) {
statistics = store.statisticsEnd();
} else if (mvStore != null) {
statistics = mvStore.statisticsEnd();
}
if (statistics != null) {
int total = 0;
for (Entry<String, Integer> e : statistics.entrySet()) {
total += e.getValue();
}
if (total > 0) {
statistics = new TreeMap<>(statistics);
StringBuilder buff = new StringBuilder();
if (statistics.size() > 1) {
buff.append("total: ").append(total).append('\n');
}
for (Entry<String, Integer> e : statistics.entrySet()) {
int value = e.getValue();
int percent = (int) (100L * value / total);
buff.append(e.getKey()).append(": ").append(value);
if (statistics.size() > 1) {
buff.append(" (").append(percent).append("%)");
}
buff.append('\n');
}
plan += "\n/*\n" + buff.toString() + "*/";
}
}
} else {
plan = command.getPlanSQL();
}
add(plan);
}
result.done();
return result;
}
Aggregations