use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class ParameterSet method paramFromPossibleJSON.
static Object paramFromPossibleJSON(Object value) throws JSONException, IOException {
if (value instanceof JSONObject) {
JSONObject jsonObj = (JSONObject) value;
return VoltTable.fromJSONObject(jsonObj);
}
if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
Object[] retval = new Object[array.length()];
for (int i = 0; i < array.length(); i++) {
Object valueAtIndex = array.get(i);
retval[i] = paramFromPossibleJSON(valueAtIndex);
}
return retval;
}
return value;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class OpsAgent method handleMailboxMessage.
private void handleMailboxMessage(VoltMessage message) {
try {
if (message instanceof BinaryPayloadMessage) {
BinaryPayloadMessage bpm = (BinaryPayloadMessage) message;
byte[] payload = CompressionService.decompressBytes(bpm.m_payload);
if (bpm.m_metadata[0] == JSON_PAYLOAD) {
String jsonString = new String(payload, "UTF-8");
JSONObject obj = new JSONObject(jsonString);
//In early startup generate dummy responses
if (m_dummyMode) {
handleJSONMessageAsDummy(obj);
} else {
handleJSONMessage(obj);
}
} else if (bpm.m_metadata[0] == OPS_PAYLOAD) {
handleOpsResponse(payload, false);
} else if (bpm.m_metadata[0] == OPS_DUMMY) {
handleOpsResponse(payload, true);
}
}
} catch (Exception e) {
hostLog.error("Exception processing message in OpsAgent for " + m_name + ": " + message, e);
} catch (Throwable t) {
//Handle throwable because otherwise the future swallows up other exceptions
VoltDB.crashLocalVoltDB("Exception processing message in OpsAgent for " + m_name + ": " + message, true, t);
}
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class JdbcDatabaseMetaDataGenerator method getTables.
VoltTable getTables() {
VoltTable results = new VoltTable(TABLE_SCHEMA);
for (Table table : m_database.getTables()) {
String type = getTableType(table);
Column partColumn;
if (type.equals("VIEW")) {
partColumn = table.getMaterializer().getPartitioncolumn();
} else {
partColumn = table.getPartitioncolumn();
}
String remark = null;
try {
JSONObject jsObj = new JSONObject();
if (partColumn != null) {
jsObj.put(JSON_PARTITION_COLUMN, partColumn.getName());
if (type.equals("VIEW")) {
jsObj.put(JSON_SOURCE_TABLE, table.getMaterializer().getTypeName());
}
}
String deleteStmt = CatalogUtil.getLimitPartitionRowsDeleteStmt(table);
if (deleteStmt != null) {
jsObj.put(JSON_LIMIT_PARTITION_ROWS_DELETE_STMT, deleteStmt);
}
if (table.getIsdred()) {
jsObj.put(JSON_DRED_TABLE, "true");
}
remark = jsObj.length() > 0 ? jsObj.toString() : null;
} catch (JSONException e) {
hostLog.warn("You have encountered an unexpected error while generating results for the " + "@SystemCatalog procedure call. This error will not affect your database's " + "operation. Please contact VoltDB support with your log files and a " + "description of what you were doing when this error occured.", e);
remark = "{\"" + JSON_ERROR + "\":\"" + e.getMessage() + "\"}";
}
results.addRow(null, // no schema name
null, table.getTypeName(), type, // REMARKS
remark, // unused TYPE_CAT
null, // unused TYPE_SCHEM
null, // unused TYPE_NAME
null, // unused SELF_REFERENCING_COL_NAME
null, // unused REF_GENERATION
null);
}
return results;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class JdbcDatabaseMetaDataGenerator method getProcedures.
VoltTable getProcedures() {
VoltTable results = new VoltTable(PROCEDURES_SCHEMA);
// merge catalog and default procedures
SortedSet<Procedure> procedures = new TreeSet<>();
for (Procedure proc : m_database.getProcedures()) {
procedures.add(proc);
}
if (m_defaultProcs != null) {
for (Procedure proc : m_defaultProcs.m_defaultProcMap.values()) {
procedures.add(proc);
}
}
for (Procedure proc : procedures) {
String remark = null;
try {
JSONObject jsObj = new JSONObject();
jsObj.put(JSON_READ_ONLY, proc.getReadonly());
jsObj.put(JSON_SINGLE_PARTITION, proc.getSinglepartition());
if (proc.getSinglepartition()) {
jsObj.put(JSON_PARTITION_PARAMETER, proc.getPartitionparameter());
jsObj.put(JSON_PARTITION_PARAMETER_TYPE, proc.getPartitioncolumn().getType());
}
remark = jsObj.toString();
} catch (JSONException e) {
hostLog.warn("You have encountered an unexpected error while generating results for the " + "@SystemCatalog procedure call. This error will not affect your database's " + "operation. Please contact VoltDB support with your log files and a " + "description of what you were doing when this error occured.", e);
remark = "{\"" + JSON_ERROR + "\",\"" + e.getMessage() + "\"}";
}
results.addRow(null, // procedure schema
null, // procedure name
proc.getTypeName(), // reserved
null, // reserved
null, // reserved
null, // REMARKS
remark, // procedure time
java.sql.DatabaseMetaData.procedureResultUnknown, // specific name
proc.getTypeName());
}
return results;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class SnapshotSiteProcessor method logSnapshotCompleteToZK.
private static void logSnapshotCompleteToZK(long txnId, boolean snapshotSuccess, ExtensibleSnapshotDigestData extraSnapshotData) {
ZooKeeper zk = VoltDB.instance().getHostMessenger().getZK();
// Timeout after 10 minutes
final long endTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10);
final String snapshotPath = VoltZK.completed_snapshots + "/" + txnId;
boolean success = false;
while (!success) {
if (System.currentTimeMillis() > endTime) {
VoltDB.crashLocalVoltDB("Timed out logging snapshot completion to ZK");
}
Stat stat = new Stat();
byte[] data = null;
try {
data = zk.getData(snapshotPath, false, stat);
} catch (NoNodeException e) {
// if the node doesn't exist yet, retry
continue;
} catch (Exception e) {
VoltDB.crashLocalVoltDB("This ZK get should never fail", true, e);
}
if (data == null) {
VoltDB.crashLocalVoltDB("Data should not be null if the node exists", false, null);
}
try {
JSONObject jsonObj = new JSONObject(new String(data, "UTF-8"));
if (jsonObj.getLong("txnId") != txnId) {
VoltDB.crashLocalVoltDB("TxnId should match", false, null);
}
int remainingHosts = jsonObj.getInt("hostCount") - 1;
jsonObj.put("hostCount", remainingHosts);
jsonObj.put("didSucceed", snapshotSuccess);
if (!snapshotSuccess) {
jsonObj.put("isTruncation", false);
}
extraSnapshotData.mergeToZooKeeper(jsonObj, SNAP_LOG);
byte[] zkData = jsonObj.toString().getBytes("UTF-8");
if (zkData.length > 5000000) {
SNAP_LOG.warn("ZooKeeper node for snapshot digest unexpectedly large: " + zkData.length);
}
zk.setData(snapshotPath, zkData, stat.getVersion());
} catch (KeeperException.BadVersionException e) {
continue;
} catch (Exception e) {
VoltDB.crashLocalVoltDB("This ZK call should never fail", true, e);
}
success = true;
}
/*
* If we are running without command logging there will be no consumer for
* the completed snapshot messages. Consume them here to bound space usage in ZK.
*/
try {
TreeSet<String> snapshots = new TreeSet<String>(zk.getChildren(VoltZK.completed_snapshots, false));
while (snapshots.size() > 30) {
try {
zk.delete(VoltZK.completed_snapshots + "/" + snapshots.first(), -1);
} catch (NoNodeException e) {
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Deleting a snapshot completion record from ZK should only fail with NoNodeException", true, e);
}
snapshots.remove(snapshots.first());
}
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Retrieving list of completed snapshots from ZK should never fail", true, e);
}
}
Aggregations