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

remove mapId from TransactionMap, since it duplicates id from MVMap

remove maps registry from TransactionStore, because it duplicates MVStore's one
上级 8b4bfee5
...@@ -345,8 +345,7 @@ public class Transaction { ...@@ -345,8 +345,7 @@ public class Transaction {
*/ */
public <K, V> TransactionMap<K, V> openMap(MVMap<K, VersionedValue> map) { public <K, V> TransactionMap<K, V> openMap(MVMap<K, VersionedValue> map) {
checkNotClosed(); checkNotClosed();
int mapId = map.getId(); return new TransactionMap<>(this, map);
return new TransactionMap<>(this, map, mapId);
} }
/** /**
......
...@@ -24,11 +24,6 @@ import java.util.Map; ...@@ -24,11 +24,6 @@ import java.util.Map;
*/ */
public class TransactionMap<K, V> { public class TransactionMap<K, V> {
/**
* The map id.
*/
final int mapId;
/** /**
* If a record was read that was updated by this transaction, and the * If a record was read that was updated by this transaction, and the
* update occurred before this log id, the older version is read. This * update occurred before this log id, the older version is read. This
...@@ -50,11 +45,9 @@ public class TransactionMap<K, V> { ...@@ -50,11 +45,9 @@ public class TransactionMap<K, V> {
*/ */
final Transaction transaction; final Transaction transaction;
TransactionMap(Transaction transaction, MVMap<K, VersionedValue> map, TransactionMap(Transaction transaction, MVMap<K, VersionedValue> map) {
int mapId) {
this.transaction = transaction; this.transaction = transaction;
this.map = map; this.map = map;
this.mapId = mapId;
} }
/** /**
...@@ -77,7 +70,7 @@ public class TransactionMap<K, V> { ...@@ -77,7 +70,7 @@ public class TransactionMap<K, V> {
public TransactionMap<K, V> getInstance(Transaction transaction, public TransactionMap<K, V> getInstance(Transaction transaction,
long savepoint) { long savepoint) {
TransactionMap<K, V> m = TransactionMap<K, V> m =
new TransactionMap<>(transaction, map, mapId); new TransactionMap<>(transaction, map);
m.setSavepoint(savepoint); m.setSavepoint(savepoint);
return m; return m;
} }
...@@ -141,7 +134,7 @@ public class TransactionMap<K, V> { ...@@ -141,7 +134,7 @@ public class TransactionMap<K, V> {
cursor.next(); cursor.next();
Object[] op = cursor.getValue(); Object[] op = cursor.getValue();
int m = (int) op[0]; int m = (int) op[0];
if (m != mapId) { if (m != map.getId()) {
// a different map - ignore // a different map - ignore
continue; continue;
} }
......
...@@ -8,7 +8,6 @@ package org.h2.mvstore.tx; ...@@ -8,7 +8,6 @@ package org.h2.mvstore.tx;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
...@@ -53,12 +52,6 @@ public class TransactionStore { ...@@ -53,12 +52,6 @@ public class TransactionStore {
*/ */
final MVMap<Long, Object[]> undoLog; final MVMap<Long, Object[]> undoLog;
/**
* The map of maps.
*/
private final HashMap<Integer, MVMap<Object, VersionedValue>> maps =
new HashMap<>();
private final DataType dataType; private final DataType dataType;
/** /**
...@@ -408,7 +401,6 @@ public class TransactionStore { ...@@ -408,7 +401,6 @@ public class TransactionStore {
* @param map the map * @param map the map
*/ */
synchronized <K, V> void removeMap(TransactionMap<K, V> map) { synchronized <K, V> void removeMap(TransactionMap<K, V> map) {
maps.remove(map.mapId);
store.removeMap(map.map); store.removeMap(map.map);
} }
...@@ -476,7 +468,7 @@ public class TransactionStore { ...@@ -476,7 +468,7 @@ public class TransactionStore {
* @param valueType the value type * @param valueType the value type
* @return the map * @return the map
*/ */
synchronized <K> MVMap<K, VersionedValue> openMap(String name, <K> MVMap<K, VersionedValue> openMap(String name,
DataType keyType, DataType valueType) { DataType keyType, DataType valueType) {
if (keyType == null) { if (keyType == null) {
keyType = new ObjectDataType(); keyType = new ObjectDataType();
...@@ -490,9 +482,6 @@ public class TransactionStore { ...@@ -490,9 +482,6 @@ public class TransactionStore {
new MVMap.Builder<K, VersionedValue>(). new MVMap.Builder<K, VersionedValue>().
keyType(keyType).valueType(vt); keyType(keyType).valueType(vt);
map = store.openMap(name, builder); map = store.openMap(name, builder);
@SuppressWarnings("unchecked")
MVMap<Object, VersionedValue> m = (MVMap<Object, VersionedValue>) map;
maps.put(map.getId(), m);
return map; return map;
} }
...@@ -502,22 +491,20 @@ public class TransactionStore { ...@@ -502,22 +491,20 @@ public class TransactionStore {
* @param mapId the id * @param mapId the id
* @return the map * @return the map
*/ */
synchronized MVMap<Object, VersionedValue> openMap(int mapId) { MVMap<Object, VersionedValue> openMap(int mapId) {
MVMap<Object, VersionedValue> map = maps.get(mapId); MVMap<Object, VersionedValue> map = store.getMap(mapId);
if (map != null) { if (map == null) {
return map; String mapName = store.getMapName(mapId);
} if (mapName == null) {
String mapName = store.getMapName(mapId); // the map was removed later on
if (mapName == null) { return null;
// the map was removed later on }
return null; DataType vt = new VersionedValue.Type(dataType);
MVMap.Builder<Object, VersionedValue> mapBuilder =
new MVMap.Builder<Object, VersionedValue>().
keyType(dataType).valueType(vt);
map = store.openMap(mapName, mapBuilder);
} }
DataType vt = new VersionedValue.Type(dataType);
MVMap.Builder<Object, VersionedValue> mapBuilder =
new MVMap.Builder<Object, VersionedValue>().
keyType(dataType).valueType(vt);
map = store.openMap(mapName, mapBuilder);
maps.put(mapId, map);
return map; return map;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论