Search in sources :

Example 96 with JSONObject

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray) JSONObject(org.json_voltpatches.JSONObject)

Example 97 with JSONObject

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);
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) BinaryPayloadMessage(org.voltcore.messaging.BinaryPayloadMessage)

Example 98 with JSONObject

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;
}
Also used : Table(org.voltdb.catalog.Table) JSONObject(org.json_voltpatches.JSONObject) Column(org.voltdb.catalog.Column) JSONException(org.json_voltpatches.JSONException)

Example 99 with JSONObject

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) TreeSet(java.util.TreeSet) Procedure(org.voltdb.catalog.Procedure) JSONException(org.json_voltpatches.JSONException)

Example 100 with JSONObject

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);
    }
}
Also used : NoNodeException(org.apache.zookeeper_voltpatches.KeeperException.NoNodeException) StreamSnapshotTimeoutException(org.voltdb.rejoin.StreamSnapshotDataTarget.StreamSnapshotTimeoutException) NoNodeException(org.apache.zookeeper_voltpatches.KeeperException.NoNodeException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) JSONObject(org.json_voltpatches.JSONObject) TreeSet(java.util.TreeSet) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Aggregations

JSONObject (org.json_voltpatches.JSONObject)123 JSONException (org.json_voltpatches.JSONException)45 JSONArray (org.json_voltpatches.JSONArray)30 IOException (java.io.IOException)20 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)18 HashMap (java.util.HashMap)17 File (java.io.File)14 Map (java.util.Map)14 ByteBuffer (java.nio.ByteBuffer)13 ExecutionException (java.util.concurrent.ExecutionException)12 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 TreeSet (java.util.TreeSet)6 JSONStringer (org.json_voltpatches.JSONStringer)6 HashSet (java.util.HashSet)5 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)5 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)4 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)4 InetAddress (java.net.InetAddress)4