generate methods to print a record as JSON
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java
index 14d8a7e..f1eb9c6 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java
@@ -139,6 +139,9 @@
sb.append('\n');
}
}
+ } else if (line.contains("@PRINT_RECORD@")) {
+ resource.appendRecordPrinter(sb, indent, 1);
+ sb.append('\n');
} else {
sb.append(line).append('\n');
}
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 f45f509..a3d065c 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
@@ -29,18 +29,19 @@
public class RecordType {
enum Type {
- BYTE (1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append"),
- SHORT (2, "short", "getShort", "putShort", "(short)0xdead", "TypeUtil.Short.append"),
- INT (4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append"),
- GLOBAL(8, "long", "getLong", "putLong", "0xdeadbeefdeadbeefl", "TypeUtil.Global.append");
+ BYTE (1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append", "TypeUtil.Byte.appendFixed"),
+ SHORT (2, "short", "getShort", "putShort", "(short)0xdead", "TypeUtil.Short.append", "TypeUtil.Short.appendFixed"),
+ INT (4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append", "TypeUtil.Int.appendFixed"),
+ GLOBAL(8, "long", "getLong", "putLong", "0xdeadbeefdeadbeefl", "TypeUtil.Global.append", "TypeUtil.Global.appendFixed");
- Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender) {
+ Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender, String tabAppender) {
this.size = size;
this.javaType = javaType;
this.bbGetter = bbGetter;
this.bbSetter = bbSetter;
this.deadMemInitializer = deadMemInitializer;
this.appender = appender;
+ this.tabAppender = tabAppender;
}
int size;
@@ -49,6 +50,7 @@
String bbSetter;
String deadMemInitializer;
String appender;
+ String tabAppender;
}
static class Field {
@@ -374,7 +376,7 @@
.append(");\n");
sb = indent(sb, indent, level + 1);
sb.append("sb = ")
- .append(field.type.appender)
+ .append(field.type.tabAppender)
.append("(sb, value);\n");
sb = indent(sb, indent, level + 1);
sb.append("sb.append(\" | \");\n");
@@ -385,4 +387,37 @@
}
return sb;
}
+
+ StringBuilder appendRecordPrinter(StringBuilder sb, String indent, int level) {
+ sb = indent(sb, indent, level);
+ sb.append("public StringBuilder appendRecord(StringBuilder sb, long slotNum) {\n");
+
+ sb = indent(sb, indent, level + 1);
+ sb.append("sb.append(\"{ \");\n\n");
+
+ for (int i = 0; i < fields.size(); ++i) {
+ Field field = fields.get(i);
+ if (field.accessible) {
+ if (i > 0) {
+ sb = indent(sb, indent, level + 1);
+ sb.append("sb.append(\", \");\n\n");
+ }
+ sb = indent(sb, indent, level + 1);
+ sb.append("sb.append(\"\\\"").append(field.name).append("\\\" : \\\"\");\n");
+ sb = indent(sb, indent, level + 1);
+ sb.append("sb = ").append(field.type.appender).append("(sb, ");
+ sb.append(field.methodName("get")).append("(slotNum)");
+ sb.append(");\n");
+ sb = indent(sb, indent, level + 1);
+ sb.append("sb.append(\"\\\"\");\n\n");
+ }
+ }
+ sb = indent(sb, indent, level + 1);
+ sb.append("return sb.append(\" }\");\n");
+
+ sb = indent(sb, indent, level);
+ sb.append("}");
+
+ return sb;
+ }
}
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 3ac410c..a950d30 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
@@ -102,6 +102,8 @@
return get(arenaId).getAllocInfo(TypeUtil.Global.localId(slotNum));
}
+ @PRINT_RECORD@
+
public StringBuilder append(StringBuilder sb) {
for (int i = 0; i < noArenas; ++i) {
sb.append("++++ arena ").append(i).append(" ++++\n");
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java
index c1423a1..f5d9734 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java
@@ -4,18 +4,30 @@
public static class Byte {
public static StringBuilder append(StringBuilder sb, byte b) {
+ return sb.append(String.format("%1$x", b));
+ }
+
+ public static StringBuilder appendFixed(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$x", s));
+ }
+
+ public static StringBuilder appendFixed(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$x", i));
+ }
+
+ public static StringBuilder appendFixed(StringBuilder sb, int i) {
return sb.append(String.format("%1$18x", i));
}
}
@@ -43,6 +55,15 @@
}
public static StringBuilder append(StringBuilder sb, long l) {
+ sb.append(String.format("%1$x", TypeUtil.Global.arenaId(l)));
+ sb.append(':');
+ sb.append(String.format("%1$x", TypeUtil.Global.allocId(l)));
+ sb.append(':');
+ sb.append(String.format("%1$x", TypeUtil.Global.localId(l)));
+ return sb;
+ }
+
+ public static StringBuilder appendFixed(StringBuilder sb, long l) {
sb.append(String.format("%1$4x", TypeUtil.Global.arenaId(l)));
sb.append(':');
sb.append(String.format("%1$4x", TypeUtil.Global.allocId(l)));
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 d955ab2..d4fa95b 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
@@ -681,7 +681,7 @@
if (holder < 0) {
throw new IllegalStateException("no holder for resource " + resource);
}
-
+ LOGGER.warning(resQueueToString(resource));
// remove from the list of holders for a resource
if (requestMatches(holder, jobSlot, lockMode)) {
// if the head of the queue matches, we need to update the resource
@@ -854,12 +854,12 @@
return holder;
}
- private String resQueueToString(long head) {
- return appendResQueue(new StringBuilder(), head).toString();
+ private String resQueueToString(long resSlot) {
+ return appendResQueue(new StringBuilder(), resSlot).toString();
}
private StringBuilder appendResQueue(StringBuilder sb, long resSlot) {
- appendResource(sb, resSlot);
+ resArenaMgr.appendRecord(sb, resSlot);
sb.append("\n");
appendReqQueue(sb, resArenaMgr.getLastHolder(resSlot));
return sb;
@@ -867,93 +867,13 @@
private StringBuilder appendReqQueue(StringBuilder sb, long head) {
while (head != -1) {
- appendRequest(sb, head);
+ reqArenaMgr.appendRecord(sb, head);
sb.append("\n");
head = reqArenaMgr.getNextRequest(head);
}
return sb;
}
- private void appendResource(StringBuilder sb, long resSlot) {
- sb.append("{ ");
-
- sb.append(" \"dataset id\"");
- sb.append(" : \"");
- sb.append(resArenaMgr.getDatasetId(resSlot));
-
- sb.append("\", ");
-
- sb.append(" \"pk hash val\"");
- sb.append(" : \"");
- sb.append(resArenaMgr.getPkHashVal(resSlot));
-
- sb.append("\", ");
-
- sb.append(" \"max mode\"");
- sb.append(" : \"");
- sb.append(LockMode.toString((byte)resArenaMgr.getMaxMode(resSlot)));
-
- sb.append("\", ");
-
- sb.append(" \"last holder\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, resArenaMgr.getLastHolder(resSlot));
-
- sb.append("\", ");
-
- sb.append(" \"first waiter\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, resArenaMgr.getFirstWaiter(resSlot));
-
- sb.append("\", ");
-
- sb.append(" \"first upgrader\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, resArenaMgr.getFirstUpgrader(resSlot));
-
- sb.append("\", ");
-
- sb.append(" \"next\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, resArenaMgr.getNext(resSlot));
-
- sb.append("\" }");
- }
-
- private void appendRequest(StringBuilder sb, long reqSlot) {
- sb.append("{ ");
-
- sb.append(" \"resource id\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, reqArenaMgr.getResourceId(reqSlot));
-
- sb.append("\", ");
-
- sb.append(" \"lock mode\"");
- sb.append(" : \"");
- sb.append(LockMode.toString((byte)reqArenaMgr.getLockMode(reqSlot)));
-
- sb.append("\", ");
-
- sb.append(" \"job slot\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, reqArenaMgr.getJobSlot(reqSlot));
-
- sb.append("\", ");
-
- sb.append(" \"prev job request\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, reqArenaMgr.getPrevJobRequest(reqSlot));
-
- sb.append("\", ");
-
- sb.append(" \"next job request\"");
- sb.append(" : \"");
- TypeUtil.Global.append(sb, reqArenaMgr.getNextJobRequest(reqSlot));
-
- sb.append("\" }");
- }
-
private int determineNewMaxMode(long resource, int oldMaxMode) {
int newMaxMode = LockMode.NL;
long holder = resArenaMgr.getLastHolder(resource);