add dump functionality to ConcurrentLockManager
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java
index d102481..2a87511 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java
@@ -23,7 +23,6 @@
BYTE,
SHORT,
INT,
- LOCAL,
GLOBAL
}
@@ -111,11 +110,11 @@
sb.append("if (TRACK_ALLOC) checkSlot(slotNum);\n");
}
sb = indent(sb, indent, level + 1);
- sb.append("final int arenaId = arenaId(slotNum);\n");
+ sb.append("final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("return get(arenaId).")
.append(methodName("get"))
- .append("(localId(slotNum));\n");
+ .append("(RecordManagerTypes.Global.localId(slotNum));\n");
sb = indent(sb, indent, level);
sb.append("}\n");
return sb;
@@ -133,11 +132,11 @@
sb.append("if (TRACK_ALLOC) checkSlot(slotNum);\n");
}
sb = indent(sb, indent, level + 1);
- sb.append("final int arenaId = arenaId(slotNum);\n");
+ sb.append("final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("get(arenaId).")
.append(methodName("set"))
- .append("(localId(slotNum), value);\n");
+ .append("(RecordManagerTypes.Global.localId(slotNum), value);\n");
sb = indent(sb, indent, level);
sb.append("}\n");
return sb;
@@ -233,7 +232,6 @@
case BYTE: return 1;
case SHORT: return 2;
case INT: return 4;
- case LOCAL: return 4;
case GLOBAL: return 8;
default: throw new IllegalArgumentException();
}
@@ -244,7 +242,6 @@
case BYTE: return "byte";
case SHORT: return "short";
case INT: return "int";
- case LOCAL: return "int";
case GLOBAL: return "long";
default: throw new IllegalArgumentException();
}
@@ -255,7 +252,6 @@
case BYTE: return "get";
case SHORT: return "getShort";
case INT: return "getInt";
- case LOCAL: return "getInt";
case GLOBAL: return "getLong";
default: throw new IllegalArgumentException();
}
@@ -266,7 +262,6 @@
case BYTE: return "put";
case SHORT: return "putShort";
case INT: return "putInt";
- case LOCAL: return "putInt";
case GLOBAL: return "putLong";
default: throw new IllegalArgumentException();
}
@@ -277,12 +272,21 @@
case BYTE: return "(byte)0xde";
case SHORT: return "(short)0xdead";
case INT: return "0xdeadbeef";
- case LOCAL: return "0xdeadbeef";
case GLOBAL: return "0xdeadbeefdeadbeefl";
default: throw new IllegalArgumentException();
}
}
+ static String appender(Type t) {
+ switch(t) {
+ case BYTE: return "RecordManagerTypes.Byte.append";
+ case SHORT: return "RecordManagerTypes.Short.append";
+ case INT: return "RecordManagerTypes.Int.append";
+ case GLOBAL: return "RecordManagerTypes.Global.append";
+ default: throw new IllegalArgumentException();
+ }
+ }
+
static String padRight(String s, int n) {
return String.format("%1$-" + n + "s", s);
}
@@ -331,17 +335,9 @@
.append(field.offsetName())
.append(");\n");
sb = indent(sb, indent, level + 1);
- sb.append("sb.append(String.format(\"%1$2x\", ")
- .append(name)
- .append("ArenaManager.arenaId(value)));\n");
- sb = indent(sb, indent, level + 1);
- sb.append("sb.append(\" \");\n");
- sb = indent(sb, indent, level + 1);
- sb.append("sb.append(String.format(\"%1$6x\", ")
- .append(name)
- .append("ArenaManager.localId(value)));\n");
- sb = indent(sb, indent, level + 1);
- sb.append("sb.append(\" | \");\n");
+ sb.append("sb = ")
+ .append(appender(field.type))
+ .append("(sb, value);\n");
sb = indent(sb, indent, level);
sb.append("}\n");
sb = indent(sb, indent, level);
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java
index e7d5590..5d0a2d8 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import edu.uci.ics.asterix.transaction.management.service.locking.AllocInfo;
+import edu.uci.ics.asterix.transaction.management.service.locking.RecordManagerTypes;
public class @E@ArenaManager {
@@ -39,18 +40,6 @@
}
};
}
-
- public static int arenaId(long l) {
- return (int)((l >>> 48) & 0xffff);
- }
-
- public static int allocId(long l) {
- return (int)((l >>> 32) & 0xffff);
- }
-
- public static int localId(long l) {
- return (int) (l & 0xffffffffL);
- }
public long allocate() {
final LocalManager localManager = local.get();
@@ -62,10 +51,10 @@
final long allocId = (++localManager.mgr.allocCounter % 0x7fff);
result |= (allocId << 32);
setAllocId(result, (short) allocId);
- assert allocId(result) == allocId;
+ assert RecordManagerTypes.Global.allocId(result) == allocId;
}
- assert arenaId(result) == localManager.arenaId;
- assert localId(result) == localId;
+ assert RecordManagerTypes.Global.arenaId(result) == localManager.arenaId;
+ assert RecordManagerTypes.Global.localId(result) == localId;
return result;
}
@@ -73,8 +62,8 @@
if (TRACK_ALLOC) {
checkSlot(slotNum);
}
- final int arenaId = arenaId(slotNum);
- get(arenaId).deallocate(localId(slotNum));
+ final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);
+ get(arenaId).deallocate(RecordManagerTypes.Global.localId(slotNum));
}
public synchronized LocalManager getNext() {
@@ -100,13 +89,13 @@
@METHODS@
private void checkSlot(long slotNum) {
- final int refAllocId = allocId(slotNum);
+ final int refAllocId = RecordManagerTypes.Global.allocId(slotNum);
final short curAllocId = getAllocId(slotNum);
if (refAllocId != curAllocId) {
String msg = "reference to slot " + slotNum
- + " of arena " + arenaId(slotNum) + " refers to version "
- + Integer.toHexString(refAllocId) + " current version is "
- + Integer.toHexString(curAllocId);
+ + " of arena " + RecordManagerTypes.Global.arenaId(slotNum)
+ + " refers to version " + Integer.toHexString(refAllocId)
+ + " current version is " + Integer.toHexString(curAllocId);
AllocInfo a = getAllocInfo(slotNum);
if (a != null) {
msg += "\n" + a.toString();
@@ -116,8 +105,8 @@
}
public AllocInfo getAllocInfo(long slotNum) {
- final int arenaId = arenaId(slotNum);
- return get(arenaId).getAllocInfo(localId(slotNum));
+ final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);
+ return get(arenaId).getAllocInfo(RecordManagerTypes.Global.localId(slotNum));
}
static class LocalManager {
@@ -125,7 +114,7 @@
@E@RecordManager mgr;
}
- StringBuffer append(StringBuffer sb) {
+ public StringBuilder append(StringBuilder sb) {
for (int i = 0; i < arenas.size(); ++i) {
sb.append("++++ arena ").append(i).append(" ++++\n");
arenas.get(i).append(sb);
@@ -134,6 +123,6 @@
}
public String toString() {
- return append(new StringBuffer()).toString();
+ return append(new StringBuilder()).toString();
}
}
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java
index 03ac51f..a4e560d 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java
@@ -173,7 +173,7 @@
}
}
- StringBuffer append(StringBuffer sb) {
+ StringBuilder append(StringBuilder sb) {
sb.append("+++ current: ")
.append(current)
.append(" no occupied slots: ")
@@ -187,7 +187,7 @@
}
public String toString() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
append(sb);
return sb.toString();
}
@@ -263,7 +263,7 @@
bb.putInt(slotNum * ITEM_SIZE + NEXT_FREE_SLOT_OFFSET, nextFreeSlot);
}
- StringBuffer append(StringBuffer sb) {
+ StringBuilder append(StringBuilder sb) {
sb.append("++ free slot: ")
.append(freeSlotNum)
.append(" no occupied slots: ")
@@ -274,9 +274,7 @@
}
public String toString() {
- StringBuffer sb = new StringBuffer();
- append(sb);
- return sb.toString();
+ return append(new StringBuilder()).toString();
}
private void checkSlot(int slotNum) {
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
index 359b58e..18997e5 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
@@ -761,6 +761,38 @@
return fromLockMode == LockMode.S && toLockMode == LockMode.X;
}
+ public StringBuilder append(StringBuilder sb) {
+ sb.append(">>dump_begin\t>>----- [resTable] -----\n");
+ table.append(sb);
+ sb.append(">>dump_end\t>>----- [resTable] -----\n");
+
+ sb.append(">>dump_begin\t>>----- [resArenaMgr] -----\n");
+ resArenaMgr.append(sb);
+ sb.append(">>dump_end\t>>----- [resArenaMgr] -----\n");
+
+ sb.append(">>dump_begin\t>>----- [reqArenaMgr] -----\n");
+ reqArenaMgr.append(sb);
+ sb.append(">>dump_end\t>>----- [reqArenaMgr] -----\n");
+
+ sb.append(">>dump_begin\t>>----- [jobIdSlotMap] -----\n");
+ for(Integer i : jobIdSlotMap.keySet()) {
+ sb.append(i).append(" : ");
+ RecordManagerTypes.Global.append(sb, jobIdSlotMap.get(i));
+ sb.append("\n");
+ }
+ sb.append(">>dump_end\t>>----- [jobIdSlotMap] -----\n");
+
+ sb.append(">>dump_begin\t>>----- [jobArenaMgr] -----\n");
+ jobArenaMgr.append(sb);
+ sb.append(">>dump_end\t>>----- [jobArenaMgr] -----\n");
+
+ return sb;
+ }
+
+ public String toString() {
+ return append(new StringBuilder()).toString();
+ }
+
@Override
public String prettyPrint() throws ACIDException {
StringBuilder s = new StringBuilder("\n########### LockManager Status #############\n");
@@ -775,26 +807,8 @@
@Override
public void stop(boolean dumpState, OutputStream os) {
if (dumpState) {
-
- //#. dump Configurable Variables
- dumpConfVars(os);
-
- //#. dump jobHT
- dumpJobInfo(os);
-
- //#. dump datasetResourceHT
- dumpDatasetLockInfo(os);
-
- //#. dump entityLockInfoManager
- dumpEntityLockInfo(os);
-
- //#. dump entityInfoManager
- dumpEntityInfo(os);
-
- //#. dump lockWaiterManager
-
- dumpLockWaiterInfo(os);
try {
+ os.write(toString().getBytes());
os.flush();
} catch (IOException e) {
//ignore
@@ -802,157 +816,6 @@
}
}
- private void dumpConfVars(OutputStream os) {
- try {
- StringBuilder sb = new StringBuilder();
- sb.append("\n>>dump_begin\t>>----- [ConfVars] -----");
- sb.append("\nESCALATE_TRHESHOLD_ENTITY_TO_DATASET: "
- + txnSubsystem.getTransactionProperties().getEntityToDatasetLockEscalationThreshold());
-// sb.append("\nSHRINK_TIMER_THRESHOLD (entityLockInfoManager): "
-// + entityLockInfoManager.getShrinkTimerThreshold());
-// sb.append("\nSHRINK_TIMER_THRESHOLD (entityInfoManager): " + entityInfoManager.getShrinkTimerThreshold());
-// sb.append("\nSHRINK_TIMER_THRESHOLD (lockWaiterManager): " + lockWaiterManager.getShrinkTimerThreshold());
- sb.append("\n>>dump_end\t>>----- [ConfVars] -----\n");
- os.write(sb.toString().getBytes());
- } catch (Exception e) {
- //ignore exception and continue dumping as much as possible.
- if (IS_DEBUG_MODE) {
- e.printStackTrace();
- }
- }
- }
-
- private void dumpJobInfo(OutputStream os) {
- JobId jobId;
- JobInfo jobInfo;
- StringBuilder sb = new StringBuilder();
-/*
- try {
- sb.append("\n>>dump_begin\t>>----- [JobInfo] -----");
- Set<Map.Entry<JobId, JobInfo>> entrySet = jobHT.entrySet();
- if (entrySet != null) {
- for (Map.Entry<JobId, JobInfo> entry : entrySet) {
- if (entry != null) {
- jobId = entry.getKey();
- if (jobId != null) {
- sb.append("\n" + jobId);
- } else {
- sb.append("\nJID:null");
- }
-
- jobInfo = entry.getValue();
- if (jobInfo != null) {
- sb.append(jobInfo.coreDump());
- } else {
- sb.append("\nJobInfo:null");
- }
- }
- }
- }
- sb.append("\n>>dump_end\t>>----- [JobInfo] -----\n");
- os.write(sb.toString().getBytes());
- } catch (Exception e) {
- //ignore exception and continue dumping as much as possible.
- if (IS_DEBUG_MODE) {
- e.printStackTrace();
- }
- }
-*/
- }
-
- private void dumpDatasetLockInfo(OutputStream os) {
-/*
- DatasetId datasetId;
- DatasetLockInfo datasetLockInfo;
- StringBuilder sb = new StringBuilder();
-
- try {
- sb.append("\n>>dump_begin\t>>----- [DatasetLockInfo] -----");
- Set<Map.Entry<DatasetId, DatasetLockInfo>> entrySet = datasetResourceHT.entrySet();
- if (entrySet != null) {
- for (Map.Entry<DatasetId, DatasetLockInfo> entry : entrySet) {
- if (entry != null) {
- datasetId = entry.getKey();
- if (datasetId != null) {
- sb.append("\nDatasetId:" + datasetId.getId());
- } else {
- sb.append("\nDatasetId:null");
- }
-
- datasetLockInfo = entry.getValue();
- if (datasetLockInfo != null) {
- sb.append(datasetLockInfo.coreDump());
- } else {
- sb.append("\nDatasetLockInfo:null");
- }
- }
- sb.append("\n>>dump_end\t>>----- [DatasetLockInfo] -----\n");
- os.write(sb.toString().getBytes());
-
- //create a new sb to avoid possible OOM exception
- sb = new StringBuilder();
- }
- }
- } catch (Exception e) {
- //ignore exception and continue dumping as much as possible.
- if (IS_DEBUG_MODE) {
- e.printStackTrace();
- }
- }
-*/
- }
-
- private void dumpEntityLockInfo(OutputStream os) {
-/*
- StringBuilder sb = new StringBuilder();
- try {
- sb.append("\n>>dump_begin\t>>----- [EntityLockInfo] -----");
- entityLockInfoManager.coreDump(os);
- sb.append("\n>>dump_end\t>>----- [EntityLockInfo] -----\n");
- os.write(sb.toString().getBytes());
- } catch (Exception e) {
- //ignore exception and continue dumping as much as possible.
- if (IS_DEBUG_MODE) {
- e.printStackTrace();
- }
- }
-*/
- }
-
- private void dumpEntityInfo(OutputStream os) {
-/*
- StringBuilder sb = new StringBuilder();
- try {
- sb.append("\n>>dump_begin\t>>----- [EntityInfo] -----");
- entityInfoManager.coreDump(os);
- sb.append("\n>>dump_end\t>>----- [EntityInfo] -----\n");
- os.write(sb.toString().getBytes());
- } catch (Exception e) {
- //ignore exception and continue dumping as much as possible.
- if (IS_DEBUG_MODE) {
- e.printStackTrace();
- }
- }
-*/
- }
-
- private void dumpLockWaiterInfo(OutputStream os) {
-/*
- StringBuilder sb = new StringBuilder();
- try {
- sb.append("\n>>dump_begin\t>>----- [LockWaiterInfo] -----");
- lockWaiterManager.coreDump(os);
- sb.append("\n>>dump_end\t>>----- [LockWaiterInfo] -----\n");
- os.write(sb.toString().getBytes());
- } catch (Exception e) {
- //ignore exception and continue dumping as much as possible.
- if (IS_DEBUG_MODE) {
- e.printStackTrace();
- }
- }
-*/
- }
-
private static class ResourceGroupTable {
public static final int TABLE_SIZE = 10; // TODO increase
@@ -970,6 +833,14 @@
int h = Math.abs(dId.getId() ^ entityHashValue);
return table[h % TABLE_SIZE];
}
+
+ public StringBuilder append(StringBuilder sb) {
+ for (int i = 0; i < table.length; ++i) {
+ sb.append(i).append(" : ");
+ sb.append(table[i].firstResourceIndex).append('\n');
+ }
+ return sb;
+ }
}
private static class ResourceGroup {
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/RecordManagerTypes.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/RecordManagerTypes.java
new file mode 100644
index 0000000..5db4a89
--- /dev/null
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/RecordManagerTypes.java
@@ -0,0 +1,47 @@
+package edu.uci.ics.asterix.transaction.management.service.locking;
+
+public class RecordManagerTypes {
+
+ public static class Byte {
+ public static StringBuilder append(StringBuilder sb, byte b) {
+ return sb.append(String.format("%1$18x", b));
+ }
+ }
+
+ public static class Short {
+ public static StringBuilder append(StringBuilder sb, short s) {
+ return sb.append(String.format("%1$18x", s));
+ }
+ }
+
+ public static class Int {
+ public static StringBuilder append(StringBuilder sb, int i) {
+ return sb.append(String.format("%1$18x", i));
+ }
+ }
+
+ public static class Global {
+
+ public static int arenaId(long l) {
+ return (int)((l >>> 48) & 0xffff);
+ }
+
+ public static int allocId(long l) {
+ return (int)((l >>> 32) & 0xffff);
+ }
+
+ public static int localId(long l) {
+ return (int) (l & 0xffffffffL);
+ }
+
+ public static StringBuilder append(StringBuilder sb, long l) {
+ sb.append(String.format("%1$4x", RecordManagerTypes.Global.arenaId(l)));
+ sb.append(':');
+ sb.append(String.format("%1$4x", RecordManagerTypes.Global.allocId(l)));
+ sb.append(':');
+ sb.append(String.format("%1$8x", RecordManagerTypes.Global.localId(l)));
+ return sb;
+ }
+
+ }
+}