提交 f9935a42 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add constructor for VersionedValue

上级 ad794494
...@@ -372,9 +372,7 @@ public class TransactionStore { ...@@ -372,9 +372,7 @@ public class TransactionStore {
if (value.value == null) { if (value.value == null) {
map.remove(key); map.remove(key);
} else { } else {
VersionedValue v2 = new VersionedValue(); map.put(key, new VersionedValue(0L, value.value));
v2.value = value.value;
map.put(key, v2);
} }
} }
} }
...@@ -1053,8 +1051,7 @@ public class TransactionStore { ...@@ -1053,8 +1051,7 @@ public class TransactionStore {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public V putCommitted(K key, V value) { public V putCommitted(K key, V value) {
DataUtils.checkArgument(value != null, "The value may not be null"); DataUtils.checkArgument(value != null, "The value may not be null");
VersionedValue newValue = new VersionedValue(); VersionedValue newValue = new VersionedValue(0L, value);
newValue.value = value;
VersionedValue oldValue = map.put(key, newValue); VersionedValue oldValue = map.put(key, newValue);
return (V) (oldValue == null ? null : oldValue.value); return (V) (oldValue == null ? null : oldValue.value);
} }
...@@ -1133,10 +1130,9 @@ public class TransactionStore { ...@@ -1133,10 +1130,9 @@ public class TransactionStore {
} }
} }
} }
VersionedValue newValue = new VersionedValue(); VersionedValue newValue = new VersionedValue(
newValue.operationId = getOperationId( getOperationId(transaction.transactionId, transaction.logId),
transaction.transactionId, transaction.logId); value);
newValue.value = value;
if (current == null) { if (current == null) {
// a new value // a new value
transaction.log(mapId, key, current); transaction.log(mapId, key, current);
...@@ -1646,12 +1642,17 @@ public class TransactionStore { ...@@ -1646,12 +1642,17 @@ public class TransactionStore {
/** /**
* The operation id. * The operation id.
*/ */
public long operationId; final long operationId;
/** /**
* The value. * The value.
*/ */
public Object value; final Object value;
VersionedValue(long operationId, Object value) {
this.operationId = operationId;
this.value = value;
}
@Override @Override
public String toString() { public String toString() {
...@@ -1699,9 +1700,7 @@ public class TransactionStore { ...@@ -1699,9 +1700,7 @@ public class TransactionStore {
if (buff.get() == 0) { if (buff.get() == 0) {
// fast path (no op ids or null entries) // fast path (no op ids or null entries)
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
VersionedValue v = new VersionedValue(); obj[i] = new VersionedValue(0L, valueType.read(buff));
v.value = valueType.read(buff);
obj[i] = v;
} }
} else { } else {
// slow path (some entries may be null) // slow path (some entries may be null)
...@@ -1713,12 +1712,14 @@ public class TransactionStore { ...@@ -1713,12 +1712,14 @@ public class TransactionStore {
@Override @Override
public Object read(ByteBuffer buff) { public Object read(ByteBuffer buff) {
VersionedValue v = new VersionedValue(); long operationId = DataUtils.readVarLong(buff);
v.operationId = DataUtils.readVarLong(buff); Object value;
if (buff.get() == 1) { if (buff.get() == 1) {
v.value = valueType.read(buff); value = valueType.read(buff);
} else {
value = null;
} }
return v; return new VersionedValue(operationId, value);
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论