Search in sources :

Example 31 with JSONArray

use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.

the class AbstractSubqueryExpression method loadFromJSONObject.

@Override
protected void loadFromJSONObject(JSONObject obj) throws JSONException {
    m_subqueryId = obj.getInt(Members.SUBQUERY_ID.name());
    m_subqueryNodeId = obj.getInt(Members.SUBQUERY_ROOT_NODE_ID.name());
    if (obj.has(AbstractExpression.Members.VALUE_TYPE)) {
        m_valueType = VoltType.get((byte) obj.getInt(AbstractExpression.Members.VALUE_TYPE));
        m_valueSize = m_valueType.getLengthInBytesForFixedTypes();
    }
    if (obj.has(Members.PARAM_IDX.name())) {
        JSONArray paramIdxArray = obj.getJSONArray(Members.PARAM_IDX.name());
        int paramSize = paramIdxArray.length();
        assert (m_args != null);
        for (int i = 0; i < paramSize; ++i) {
            m_parameterIdxList.add(paramIdxArray.getInt(i));
        }
    }
}
Also used : JSONArray(org.json_voltpatches.JSONArray)

Example 32 with JSONArray

use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.

the class SelectSubqueryExpression method loadFromJSONObject.

@Override
protected void loadFromJSONObject(JSONObject obj) throws JSONException {
    super.loadFromJSONObject(obj);
    if (obj.has(Members.OTHER_PARAM_IDX.name())) {
        JSONArray otherParamIdxArray = obj.getJSONArray(Members.OTHER_PARAM_IDX.name());
        int paramSize = otherParamIdxArray.length();
        for (int i = 0; i < paramSize; ++i) {
            m_allParameterIdxList.add(otherParamIdxArray.getInt(i));
        }
        m_allParameterIdxList.addAll(getParameterIdxList());
    }
}
Also used : JSONArray(org.json_voltpatches.JSONArray)

Example 33 with JSONArray

use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.

the class HashRangeExpression method loadFromJSONObject.

@Override
protected void loadFromJSONObject(JSONObject obj) throws JSONException {
    m_hashColumn = obj.getInt(Members.HASH_COLUMN.name());
    JSONArray array = obj.getJSONArray(Members.RANGES.name());
    ImmutableSortedMap.Builder<Integer, Integer> b = ImmutableSortedMap.naturalOrder();
    for (int ii = 0; ii < array.length(); ii++) {
        JSONObject range = array.getJSONObject(ii);
        b.put(range.getInt(Members.RANGE_START.name()), range.getInt(Members.RANGE_END.name()));
    }
    m_ranges = b.build();
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray) ImmutableSortedMap(com.google_voltpatches.common.collect.ImmutableSortedMap)

Example 34 with JSONArray

use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.

the class RestoreAgent method checkSnapshotIsComplete.

private SnapshotInfo checkSnapshotIsComplete(Long key, Snapshot s) {
    int partitionCount = -1;
    for (TableFiles tf : s.m_tableFiles.values()) {
        // Check if the snapshot is complete
        if (tf.m_completed.stream().anyMatch(b -> !b)) {
            m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because it was not completed.");
            return null;
        }
        // Replicated table doesn't check partition count
        if (tf.m_isReplicated) {
            continue;
        }
        // Everyone has to agree on the total partition count
        for (int count : tf.m_totalPartitionCounts) {
            if (partitionCount == -1) {
                partitionCount = count;
            } else if (count != partitionCount) {
                m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because it had the wrong partition count ").append(count).append(", expecting ").append(partitionCount);
                return null;
            }
        }
    }
    if (s.m_digests.isEmpty()) {
        m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because it had no valid digest file.");
        return null;
    }
    File digest = s.m_digests.get(0);
    Long catalog_crc = null;
    Map<Integer, Long> pidToTxnMap = new TreeMap<Integer, Long>();
    Set<String> digestTableNames = new HashSet<String>();
    // Create a valid but meaningless InstanceId to support pre-instanceId checking versions
    InstanceId instanceId = new InstanceId(0, 0);
    int newParitionCount = -1;
    try {
        JSONObject digest_detail = SnapshotUtil.CRCCheck(digest, LOG);
        if (digest_detail == null)
            throw new IOException();
        catalog_crc = digest_detail.getLong("catalogCRC");
        if (digest_detail.has("partitionTransactionIds")) {
            JSONObject pidToTxnId = digest_detail.getJSONObject("partitionTransactionIds");
            Iterator<String> it = pidToTxnId.keys();
            while (it.hasNext()) {
                String pidkey = it.next();
                Long txnidval = pidToTxnId.getLong(pidkey);
                pidToTxnMap.put(Integer.valueOf(pidkey), txnidval);
            }
        }
        if (digest_detail.has("instanceId")) {
            instanceId = new InstanceId(digest_detail.getJSONObject("instanceId"));
        }
        if (digest_detail.has("newPartitionCount")) {
            newParitionCount = digest_detail.getInt("newPartitionCount");
        }
        if (digest_detail.has("tables")) {
            JSONArray tableObj = digest_detail.getJSONArray("tables");
            for (int i = 0; i < tableObj.length(); i++) {
                digestTableNames.add(tableObj.getString(i));
            }
        }
    } catch (IOException ioe) {
        m_snapshotErrLogStr.append("\nUnable to read digest file: ").append(digest.getAbsolutePath()).append(" due to: ").append(ioe.getMessage());
        return null;
    } catch (JSONException je) {
        m_snapshotErrLogStr.append("\nUnable to extract catalog CRC from digest: ").append(digest.getAbsolutePath()).append(" due to: ").append(je.getMessage());
        return null;
    }
    if (s.m_catalogFile == null) {
        m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because it had no catalog.");
        return null;
    }
    try {
        byte[] bytes = MiscUtils.fileToBytes(s.m_catalogFile);
        InMemoryJarfile jarfile = CatalogUtil.loadInMemoryJarFile(bytes);
        if (jarfile.getCRC() != catalog_crc) {
            m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because catalog CRC did not match digest.");
            return null;
        }
        // Make sure this is not a partial snapshot.
        // Compare digestTableNames with all normal table names in catalog file.
        // A normal table is one that's NOT a materialized view, nor an export table.
        Set<String> catalogNormalTableNames = CatalogUtil.getNormalTableNamesFromInMemoryJar(jarfile);
        if (!catalogNormalTableNames.equals(digestTableNames)) {
            m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because this is a partial snapshot.");
            return null;
        }
    } catch (IOException ioe) {
        m_snapshotErrLogStr.append("\nRejected snapshot ").append(s.getNonce()).append(" because catalog file could not be validated");
        return null;
    }
    SnapshotInfo info = new SnapshotInfo(key, digest.getParent(), SnapshotUtil.parseNonceFromDigestFilename(digest.getName()), partitionCount, newParitionCount, catalog_crc, m_hostId, instanceId, digestTableNames, s.m_stype);
    // populate table to partition map.
    for (Entry<String, TableFiles> te : s.m_tableFiles.entrySet()) {
        TableFiles tableFile = te.getValue();
        HashSet<Integer> ids = new HashSet<Integer>();
        for (Set<Integer> idSet : tableFile.m_validPartitionIds) {
            ids.addAll(idSet);
        }
        if (!tableFile.m_isReplicated) {
            info.partitions.put(te.getKey(), ids);
        }
        // keep track of tables for which we've seen files while we're here
        info.fileTables.add(te.getKey());
    }
    info.setPidToTxnIdMap(pidToTxnMap);
    return info;
}
Also used : InstanceId(org.voltcore.utils.InstanceId) JSONArray(org.json_voltpatches.JSONArray) TableFiles(org.voltdb.sysprocs.saverestore.SnapshotUtil.TableFiles) JSONException(org.json_voltpatches.JSONException) IOException(java.io.IOException) TreeMap(java.util.TreeMap) JSONObject(org.json_voltpatches.JSONObject) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) File(java.io.File) HashSet(java.util.HashSet)

Example 35 with JSONArray

use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.

the class RestoreAgent method deserializeRestoreInformation.

/**
     * This function, like all good functions, does three things.
     * It produces the command log start transaction Id.
     * It produces a map of SnapshotInfo objects.
     * And, it errors if the remote start action does not match the local action.
     */
private Long deserializeRestoreInformation(List<String> children, Map<String, Set<SnapshotInfo>> snapshotFragments) throws Exception {
    try {
        int recover = m_action.ordinal();
        Long clStartTxnId = null;
        for (String node : children) {
            //This might be created before we are done fetching the restore info
            if (node.equals("snapshot_id"))
                continue;
            byte[] data = null;
            data = m_zk.getData(VoltZK.restore + "/" + node, false, null);
            String jsonData = new String(data, "UTF8");
            JSONObject json = new JSONObject(jsonData);
            long maxTxnId = json.optLong("max", Long.MIN_VALUE);
            if (maxTxnId != Long.MIN_VALUE) {
                if (clStartTxnId == null || maxTxnId > clStartTxnId) {
                    clStartTxnId = maxTxnId;
                }
            }
            int remoteRecover = json.getInt("action");
            if (remoteRecover != recover) {
                String msg = "Database actions are not consistent. Remote node action is not 'recover'. " + "Please enter the same database action on the command-line.";
                VoltDB.crashLocalVoltDB(msg, false, null);
            }
            JSONArray snapInfos = json.getJSONArray("snapInfos");
            int snapInfoCnt = snapInfos.length();
            for (int i = 0; i < snapInfoCnt; i++) {
                JSONObject jsonInfo = snapInfos.getJSONObject(i);
                SnapshotInfo info = new SnapshotInfo(jsonInfo);
                Set<SnapshotInfo> fragments = snapshotFragments.get(info.nonce);
                if (fragments == null) {
                    fragments = new HashSet<SnapshotInfo>();
                    snapshotFragments.put(info.nonce, fragments);
                }
                fragments.add(info);
            }
        }
        return clStartTxnId;
    } catch (JSONException je) {
        VoltDB.crashLocalVoltDB("Error exchanging snapshot information", true, je);
    }
    throw new RuntimeException("impossible");
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException)

Aggregations

JSONArray (org.json_voltpatches.JSONArray)44 JSONObject (org.json_voltpatches.JSONObject)29 JSONException (org.json_voltpatches.JSONException)13 File (java.io.File)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)4 JSONString (org.json_voltpatches.JSONString)4 ByteBuffer (java.nio.ByteBuffer)3 HashSet (java.util.HashSet)3 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)2 InetSocketAddress (java.net.InetSocketAddress)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 ExecutionException (java.util.concurrent.ExecutionException)2 ZipFile (java.util.zip.ZipFile)2 HttpResponse (org.apache.http.HttpResponse)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 InstanceId (org.voltcore.utils.InstanceId)2 Configuration (org.voltdb.VoltDB.Configuration)2 ClientResponse (org.voltdb.client.ClientResponse)2