提交 5eeccf53 authored 作者: Thomas Mueller's avatar Thomas Mueller

Slightly improved storage format.

上级 8807a867
...@@ -32,12 +32,6 @@ public class TransactionStore { ...@@ -32,12 +32,6 @@ public class TransactionStore {
* Whether the concurrent maps should be used. * Whether the concurrent maps should be used.
*/ */
private static final boolean CONCURRENT = false; private static final boolean CONCURRENT = false;
private static final boolean PACK_DATA = true;
; // TODO find out why TestTransactionStore.testStopWhileCommitting
// fails when the following is enabled:
private static final boolean PACK_DATA2 = false;
/** /**
* The store. * The store.
...@@ -108,6 +102,11 @@ public class TransactionStore { ...@@ -108,6 +102,11 @@ public class TransactionStore {
valueType(undoLogValueType); valueType(undoLogValueType);
undoLog = store.openMap("undoLog", builder); undoLog = store.openMap("undoLog", builder);
// remove all temporary maps // remove all temporary maps
if (undoLog.getValueType() != undoLogValueType) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_CORRUPT,
"Undo map open with a different value type");
}
for (String mapName : store.getMapNames()) { for (String mapName : store.getMapNames()) {
if (mapName.startsWith("temp.")) { if (mapName.startsWith("temp.")) {
MVMap<Object, Integer> temp = openTempMap(mapName); MVMap<Object, Integer> temp = openTempMap(mapName);
...@@ -1537,29 +1536,16 @@ public class TransactionStore { ...@@ -1537,29 +1536,16 @@ public class TransactionStore {
} }
@Override @Override
public void read(ByteBuffer buff, Object[] obj, public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
int len, boolean key) { if (buff.get() == 0) {
if (PACK_DATA) { // fast path (no op ids or null entries)
// Read the operationIds
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
VersionedValue v = new VersionedValue(); VersionedValue v = new VersionedValue();
v.operationId = DataUtils.readVarLong(buff); v.value = valueType.read(buff);
obj[i] = v; obj[i] = v;
} }
// Read the null/not-null indicators.
final byte[] notNullIndicators = new byte[(len + 7) / 8];
buff.get(notNullIndicators, 0, notNullIndicators.length);
// Read the child values.
for (int i = 0; i < len; i++) {
VersionedValue v = (VersionedValue) obj[i];
int x = notNullIndicators[i / 8] & 0xff;
x = x >> (i % 8);
x = x & 1;
if (x == 1) {
v.value = valueType.read(buff);
}
}
} else { } else {
// slow path (some entries may be null)
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
obj[i] = read(buff); obj[i] = read(buff);
} }
...@@ -1577,41 +1563,24 @@ public class TransactionStore { ...@@ -1577,41 +1563,24 @@ public class TransactionStore {
} }
@Override @Override
public void write(WriteBuffer buff, Object[] obj, public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
int len, boolean key) { boolean fastPath = true;
if (PACK_DATA) { for (int i = 0; i < len; i++) {
// Write the operationIds VersionedValue v = (VersionedValue) obj[i];
for (int i = 0; i < len; i++) { if (v.operationId != 0 || v.value == null) {
VersionedValue v = (VersionedValue) obj[i]; fastPath = false;
buff.putVarLong(v.operationId);
}
// Write the not-null-indicators as a bit-packed array
int x = 0;
int byteIdx = 0;
for (int i = 0; i < len; i++) {
VersionedValue v = (VersionedValue) obj[i];
if (v.value != null) {
x |= 1 << byteIdx;
}
byteIdx++;
if (byteIdx == 8) {
buff.put((byte) x);
byteIdx = 0;
x = 0;
}
}
if (byteIdx != 0) {
buff.put((byte) x);
} }
// Write the child values. }
if (fastPath) {
buff.put((byte) 0);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
VersionedValue v = (VersionedValue) obj[i]; VersionedValue v = (VersionedValue) obj[i];
if (v.value != null) { valueType.write(buff, v.value);
valueType.write(buff, v.value);
}
} }
} else { } else {
// slow path:
// store op ids, and some entries may be null
buff.put((byte) 1);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
write(buff, obj[i]); write(buff, obj[i]);
} }
...@@ -1723,4 +1692,3 @@ public class TransactionStore { ...@@ -1723,4 +1692,3 @@ public class TransactionStore {
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论