use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class TestOutOfMemory method testMVStoreUsingInMemoryFileSystem.
private void testMVStoreUsingInMemoryFileSystem() {
FilePath.register(new FilePathMem());
String fileName = "memFS:" + getTestName();
final AtomicReference<Throwable> exRef = new AtomicReference<>();
MVStore store = new MVStore.Builder().fileName(fileName).backgroundExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
exRef.compareAndSet(null, e);
}
}).open();
try {
Map<Integer, byte[]> map = store.openMap("test");
Random r = new Random(1);
try {
for (int i = 0; i < 100; i++) {
byte[] data = new byte[10 * 1024 * 1024];
r.nextBytes(data);
map.put(i, data);
}
Throwable throwable = exRef.get();
if (throwable instanceof OutOfMemoryError)
throw (OutOfMemoryError) throwable;
if (throwable instanceof IllegalStateException)
throw (IllegalStateException) throwable;
fail();
} catch (OutOfMemoryError | IllegalStateException e) {
// expected
}
try {
store.close();
} catch (IllegalStateException e) {
// expected
}
store.closeImmediately();
store = MVStore.open(fileName);
store.openMap("test");
store.close();
} finally {
// just in case, otherwise if this test suffers a spurious failure,
// succeeding tests will too, because they will OOM
store.closeImmediately();
FileUtils.delete(fileName);
}
}
use of org.h2.mvstore.db.MVTableEngine.Store in project georocket by georocket.
the class H2Store method close.
/**
* Release all resources and close this store
*/
public void close() {
MVStore s = mvstore.getAndSet(null);
if (s != null) {
s.close();
}
map = null;
}
use of org.h2.mvstore.db.MVTableEngine.Store in project elastic-core-maven by OrdinaryDude.
the class DbShellServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, private");
resp.setHeader("Pragma", "no-cache");
resp.setDateHeader("Expires", 0);
if (!API.isAllowed(req.getRemoteHost())) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
String body = null;
if (!API.disableAdminPassword) {
if (API.adminPassword.isEmpty()) {
body = errorNoPasswordIsConfigured;
} else {
try {
API.verifyPassword(req);
if ("true".equals(req.getParameter("showShell"))) {
body = form.replace("{adminPassword}", URLEncoder.encode(req.getParameter("adminPassword"), "UTF-8"));
}
} catch (ParameterException exc) {
String desc = (String) ((JSONObject) JSONValue.parse(JSON.toString(exc.getErrorResponse()))).get("errorDescription");
body = String.format(passwordFormTemplate, "<p style=\"color:red\">" + desc + "</p>");
}
}
}
if (body != null) {
try (PrintStream out = new PrintStream(resp.getOutputStream())) {
out.print(header);
out.print(body);
out.print(barter);
}
return;
}
String line = Convert.nullToEmpty(req.getParameter("line"));
try (PrintStream out = new PrintStream(resp.getOutputStream())) {
out.println("\n> " + line);
try {
Shell shell = new Shell();
shell.setErr(out);
shell.setOut(out);
shell.runTool(Db.db.getConnection(), "-sql", line);
} catch (SQLException e) {
out.println(e.toString());
}
}
}
use of org.h2.mvstore.db.MVTableEngine.Store in project ignite by apache.
the class GridSqlQueryParser method collectOptimizedTableFiltersOrder.
/**
* @param qry Query.
*/
private void collectOptimizedTableFiltersOrder(Query qry) {
if (qry instanceof SelectUnion) {
collectOptimizedTableFiltersOrder(((SelectUnion) qry).getLeft());
collectOptimizedTableFiltersOrder(((SelectUnion) qry).getRight());
} else {
Select select = (Select) qry;
TableFilter filter = select.getTopTableFilter();
int i = 0;
do {
assert0(filter != null, select);
assert0(filter.getNestedJoin() == null, select);
// Here all the table filters must have generated unique aliases,
// thus we can store them in the same map for all the subqueries.
optimizedTableFilterOrder.put(filter.getTableAlias(), i++);
Table tbl = filter.getTable();
// Go down and collect inside of optimized subqueries.
if (tbl instanceof TableView) {
ViewIndex viewIdx = (ViewIndex) filter.getIndex();
collectOptimizedTableFiltersOrder(viewIdx.getQuery());
}
filter = filter.getJoin();
} while (filter != null);
}
}
use of org.h2.mvstore.db.MVTableEngine.Store in project jackrabbit-oak by apache.
the class PersistentCache method createMapFactory.
private MapFactory createMapFactory(final int generation, final boolean readOnly) {
MapFactory f = new MapFactory() {
final String fileName = getFileName(generation);
MVStore store;
@Override
void openStore() {
if (store != null) {
return;
}
MVStore.Builder builder = new MVStore.Builder();
try {
if (compress) {
builder.compress();
}
if (manualCommit) {
builder.autoCommitDisabled();
}
if (fileName != null) {
builder.fileName(fileName);
}
if (memCache >= 0) {
builder.cacheSize(memCache);
}
if (readOnly) {
builder.readOnly();
}
if (maxSizeMB < 10) {
builder.cacheSize(maxSizeMB);
}
if (autoCompact >= 0) {
builder.autoCompactFillRate(autoCompact);
}
builder.backgroundExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
exceptionCount++;
LOG.debug("Error in the background thread of the persistent cache", e);
LOG.warn("Error in the background thread of the persistent cache: " + e);
}
});
store = builder.open();
if (appendOnly) {
store.setReuseSpace(false);
}
} catch (Exception e) {
exceptionCount++;
LOG.warn("Could not open the store " + fileName, e);
}
}
@Override
synchronized void closeStore() {
if (store == null) {
return;
}
boolean compact = compactOnClose;
try {
if (store.getFileStore().isReadOnly()) {
compact = false;
}
// clear the interrupted flag, if set
Thread.interrupted();
store.close();
} catch (Exception e) {
exceptionCount++;
LOG.debug("Could not close the store", e);
LOG.warn("Could not close the store: " + e);
store.closeImmediately();
}
if (compact) {
try {
MVStoreTool.compact(fileName, true);
} catch (Exception e) {
exceptionCount++;
LOG.debug("Could not compact the store", e);
LOG.warn("Could not compact the store: " + e);
}
}
store = null;
}
@Override
<K, V> Map<K, V> openMap(String name, Builder<K, V> builder) {
try {
if (builder == null) {
return store.openMap(name);
}
return store.openMap(name, builder);
} catch (Exception e) {
exceptionCount++;
LOG.warn("Could not open the map", e);
return null;
}
}
@Override
long getFileSize() {
try {
if (store == null) {
return 0;
}
FileStore fs = store.getFileStore();
if (fs == null) {
return 0;
}
return fs.size();
} catch (Exception e) {
exceptionCount++;
LOG.warn("Could not retrieve the map size", e);
return 0;
}
}
};
f.openStore();
return f;
}
Aggregations