提交 daa433f0 authored 作者: Andrei Tokar's avatar Andrei Tokar

Exception handling improvements

Assorted minor changes
上级 f796e624
...@@ -511,16 +511,18 @@ public class MVStore { ...@@ -511,16 +511,18 @@ public class MVStore {
M map = (M) getMap(id); M map = (M) getMap(id);
if (map == null) { if (map == null) {
String configAsString = meta.get(MVMap.getMapKey(id)); String configAsString = meta.get(MVMap.getMapKey(id));
if(configAsString != null) { HashMap<String, Object> config;
HashMap<String, Object> config = if (configAsString != null) {
new HashMap<String, Object>(DataUtils.parseMap(configAsString)); config = new HashMap<String, Object>(DataUtils.parseMap(configAsString));
config.put("id", id); } else {
map = builder.create(this, config); config = new HashMap<>();
map.init();
long root = getRootPos(meta, id);
map.setRootPos(root, lastStoredVersion);
maps.put(id, map);
} }
config.put("id", id);
map = builder.create(this, config);
map.init();
long root = getRootPos(meta, id);
map.setRootPos(root, lastStoredVersion);
maps.put(id, map);
} }
return map; return map;
} finally { } finally {
......
...@@ -246,21 +246,6 @@ public class MVTableEngine implements TableEngine { ...@@ -246,21 +246,6 @@ public class MVTableEngine implements TableEngine {
store.closeImmediately(); store.closeImmediately();
} }
/**
* Commit all transactions that are in the committing state, and
* rollback all open transactions.
*/
public void initTransactions() {
List<Transaction> list = transactionStore.getOpenTransactions();
for (Transaction t : list) {
if (t.getStatus() == Transaction.STATUS_COMMITTED) {
t.commit();
} else if (t.getStatus() != Transaction.STATUS_PREPARED) {
t.rollback();
}
}
}
/** /**
* Remove all temporary maps. * Remove all temporary maps.
* *
......
...@@ -147,14 +147,6 @@ public class TransactionStore { ...@@ -147,14 +147,6 @@ public class TransactionStore {
*/ */
public void init() { public void init() {
if (!init) { if (!init) {
// remove all temporary maps
for (String mapName : store.getMapNames()) {
if (mapName.startsWith("temp.")) {
MVMap<Object, Integer> temp = openTempMap(mapName);
store.removeMap(temp);
}
}
for (String mapName : store.getMapNames()) { for (String mapName : store.getMapNames()) {
if (mapName.startsWith(UNDO_LOG_NAME_PEFIX)) { if (mapName.startsWith(UNDO_LOG_NAME_PEFIX)) {
if (store.hasData(mapName)) { if (store.hasData(mapName)) {
...@@ -165,13 +157,15 @@ public class TransactionStore { ...@@ -165,13 +157,15 @@ public class TransactionStore {
int status; int status;
String name; String name;
if (data == null) { if (data == null) {
status = mapName.charAt(UNDO_LOG_NAME_PEFIX.length()) == UNDO_LOG_OPEN ? status = Transaction.STATUS_OPEN;
Transaction.STATUS_OPEN : Transaction.STATUS_COMMITTED;
name = null; name = null;
} else { } else {
status = (Integer) data[0]; status = (Integer) data[0];
name = (String) data[1]; name = (String) data[1];
} }
if (mapName.charAt(UNDO_LOG_NAME_PEFIX.length()) == UNDO_LOG_COMMITTED) {
status = Transaction.STATUS_COMMITTED;
}
MVMap<Long, Object[]> undoLog = store.openMap(mapName, undoLogBuilder); MVMap<Long, Object[]> undoLog = store.openMap(mapName, undoLogBuilder);
undoLogs[transactionId] = undoLog; undoLogs[transactionId] = undoLog;
Long lastUndoKey = undoLog.lastKey(); Long lastUndoKey = undoLog.lastKey();
...@@ -187,6 +181,21 @@ public class TransactionStore { ...@@ -187,6 +181,21 @@ public class TransactionStore {
} }
} }
/**
* Commit all transactions that are in the committed state, and
* rollback all open transactions.
*/
public void endLeftoverTransactions() {
List<Transaction> list = getOpenTransactions();
for (Transaction t : list) {
if (t.getStatus() == Transaction.STATUS_COMMITTED) {
t.commit();
} else if (t.getStatus() != Transaction.STATUS_PREPARED) {
t.rollback();
}
}
}
/** /**
* Set the maximum transaction id, after which ids are re-used. If the old * Set the maximum transaction id, after which ids are re-used. If the old
* transaction is still in use when re-using an old id, the new transaction * transaction is still in use when re-using an old id, the new transaction
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论