Search in sources :

Example 26 with JSONObject

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

the class SnapshotScanAgent method getSnapshotDigestScanResults.

private VoltTable getSnapshotDigestScanResults(String path) {
    VoltTable results = constructDigestResultsTable();
    List<File> relevantFiles = retrieveRelevantFiles(path);
    if (relevantFiles == null) {
        results.addRow(m_messenger.getHostId(), "", "", "", "FAILURE", m_errorString);
    } else {
        for (final File f : relevantFiles) {
            if (f.getName().endsWith(".vpt")) {
                continue;
            }
            if (f.canRead()) {
                try {
                    Set<String> tableNames = new HashSet<String>();
                    JSONObject digest = SnapshotUtil.CRCCheck(f, SNAP_LOG);
                    if (digest == null)
                        continue;
                    JSONArray tables = digest.getJSONArray("tables");
                    for (int ii = 0; ii < tables.length(); ii++) {
                        tableNames.add(tables.getString(ii));
                    }
                    final StringWriter sw = new StringWriter();
                    int ii = 0;
                    for (String name : tableNames) {
                        sw.append(name);
                        if (ii != tableNames.size() - 1) {
                            sw.append(',');
                        }
                        ii++;
                    }
                    results.addRow(m_messenger.getHostId(), path, f.getName(), sw.toString(), "SUCCESS", "");
                } catch (Exception e) {
                    SNAP_LOG.warn(e);
                }
            }
        }
    }
    return results;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) StringWriter(java.io.StringWriter) JSONArray(org.json_voltpatches.JSONArray) VoltFile(org.voltdb.utils.VoltFile) TableSaveFile(org.voltdb.sysprocs.saverestore.TableSaveFile) File(java.io.File) IOException(java.io.IOException) JSONException(org.json_voltpatches.JSONException) HashSet(java.util.HashSet)

Example 27 with JSONObject

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

the class RealVoltDB method collectLocalNetworkMetadata.

void collectLocalNetworkMetadata() {
    boolean threw = false;
    JSONStringer stringer = new JSONStringer();
    try {
        stringer.object();
        stringer.key("interfaces").array();
        if (m_config.m_externalInterface.equals("")) {
            LinkedList<NetworkInterface> interfaces = new LinkedList<>();
            try {
                Enumeration<NetworkInterface> intfEnum = NetworkInterface.getNetworkInterfaces();
                while (intfEnum.hasMoreElements()) {
                    NetworkInterface intf = intfEnum.nextElement();
                    if (intf.isLoopback() || !intf.isUp()) {
                        continue;
                    }
                    interfaces.offer(intf);
                }
            } catch (SocketException e) {
                throw new RuntimeException(e);
            }
            if (interfaces.isEmpty()) {
                stringer.value("localhost");
            } else {
                boolean addedIp = false;
                while (!interfaces.isEmpty()) {
                    NetworkInterface intf = interfaces.poll();
                    Enumeration<InetAddress> inetAddrs = intf.getInetAddresses();
                    Inet6Address inet6addr = null;
                    Inet4Address inet4addr = null;
                    while (inetAddrs.hasMoreElements()) {
                        InetAddress addr = inetAddrs.nextElement();
                        if (addr instanceof Inet6Address) {
                            inet6addr = (Inet6Address) addr;
                            if (inet6addr.isLinkLocalAddress()) {
                                inet6addr = null;
                            }
                        } else if (addr instanceof Inet4Address) {
                            inet4addr = (Inet4Address) addr;
                        }
                    }
                    if (inet4addr != null) {
                        stringer.value(inet4addr.getHostAddress());
                        addedIp = true;
                    }
                    if (inet6addr != null) {
                        stringer.value(inet6addr.getHostAddress());
                        addedIp = true;
                    }
                }
                if (!addedIp) {
                    stringer.value("localhost");
                }
            }
        } else {
            stringer.value(m_config.m_externalInterface);
        }
    } catch (Exception e) {
        threw = true;
        hostLog.warn("Error while collecting data about local network interfaces", e);
    }
    try {
        if (threw) {
            stringer = new JSONStringer();
            stringer.object();
            stringer.key("interfaces").array();
            stringer.value("localhost");
            stringer.endArray();
        } else {
            stringer.endArray();
        }
        stringer.keySymbolValuePair("clientPort", m_config.m_port);
        stringer.keySymbolValuePair("clientInterface", m_config.m_clientInterface);
        stringer.keySymbolValuePair("adminPort", m_config.m_adminPort);
        stringer.keySymbolValuePair("adminInterface", m_config.m_adminInterface);
        stringer.keySymbolValuePair("httpPort", m_config.m_httpPort);
        stringer.keySymbolValuePair("httpInterface", m_config.m_httpPortInterface);
        stringer.keySymbolValuePair("internalPort", m_config.m_internalPort);
        stringer.keySymbolValuePair("internalInterface", m_config.m_internalInterface);
        String[] zkInterface = m_config.m_zkInterface.split(":");
        stringer.keySymbolValuePair("zkPort", zkInterface[1]);
        stringer.keySymbolValuePair("zkInterface", zkInterface[0]);
        stringer.keySymbolValuePair("drPort", VoltDB.getReplicationPort(m_catalogContext.cluster.getDrproducerport()));
        stringer.keySymbolValuePair("drInterface", VoltDB.getDefaultReplicationInterface());
        stringer.keySymbolValuePair("publicInterface", m_config.m_publicInterface);
        stringer.endObject();
        JSONObject obj = new JSONObject(stringer.toString());
        // possibly atomic swap from null to realz
        m_localMetadata = obj.toString(4);
        hostLog.debug("System Metadata is: " + m_localMetadata);
    } catch (Exception e) {
        hostLog.warn("Failed to collect data about lcoal network interfaces", e);
    }
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) LinkedList(java.util.LinkedList) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException) JSONObject(org.json_voltpatches.JSONObject) JSONStringer(org.json_voltpatches.JSONStringer) InetAddress(java.net.InetAddress)

Example 28 with JSONObject

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

the class Distributer method updateProcedurePartitioning.

private void updateProcedurePartitioning(VoltTable vt) {
    Map<String, Procedure> procs = Maps.newHashMap();
    while (vt.advanceRow()) {
        try {
            //Data embedded in JSON object in remarks column
            String jsString = vt.getString(6);
            String procedureName = vt.getString(2);
            JSONObject jsObj = new JSONObject(jsString);
            boolean readOnly = jsObj.getBoolean(Constants.JSON_READ_ONLY);
            if (jsObj.getBoolean(Constants.JSON_SINGLE_PARTITION)) {
                int partitionParameter = jsObj.getInt(Constants.JSON_PARTITION_PARAMETER);
                int partitionParameterType = jsObj.getInt(Constants.JSON_PARTITION_PARAMETER_TYPE);
                procs.put(procedureName, new Procedure(false, readOnly, partitionParameter, partitionParameterType));
            } else {
                // Multi Part procedure JSON descriptors omit the partitionParameter
                procs.put(procedureName, new Procedure(true, readOnly, Procedure.PARAMETER_NONE, Procedure.PARAMETER_NONE));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    ImmutableSortedMap<String, Procedure> oldProcs = m_procedureInfo.get();
    m_procedureInfo.compareAndSet(oldProcs, ImmutableSortedMap.copyOf(procs));
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException)

Example 29 with JSONObject

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

the class LeaderAppointer method assignLeader.

private long assignLeader(int partitionId, List<Long> children) {
    // We used masterHostId = -1 as a way to force the leader choice to be
    // the first replica in the list, if we don't have some other mechanism
    // which has successfully overridden it.
    int masterHostId = -1;
    if (m_state.get() == AppointerState.CLUSTER_START) {
        try {
            // find master in topo
            JSONArray parts = m_topo.getJSONArray(AbstractTopology.TOPO_PARTITIONS);
            for (int p = 0; p < parts.length(); p++) {
                JSONObject aPartition = parts.getJSONObject(p);
                int pid = aPartition.getInt(AbstractTopology.TOPO_PARTITION_ID);
                if (pid == partitionId) {
                    masterHostId = aPartition.getInt(AbstractTopology.TOPO_MASTER);
                    break;
                }
            }
        } catch (JSONException jse) {
            tmLog.error("Failed to find master for partition " + partitionId + ", defaulting to 0");
            jse.printStackTrace();
            // stupid default
            masterHostId = -1;
        }
    } else {
        // For now, if we're appointing a new leader as a result of a
        // failure, just pick the first replica in the children list.
        // Could eventually do something more complex here to try to keep a
        // semi-balance, but it's unclear that this has much utility until
        // we add rebalancing on rejoin as well.
        masterHostId = -1;
    }
    long masterHSId = children.get(0);
    for (Long child : children) {
        if (CoreUtils.getHostIdFromHSId(child) == masterHostId) {
            masterHSId = child;
            break;
        }
    }
    tmLog.info("Appointing HSId " + CoreUtils.hsIdToString(masterHSId) + " as leader for partition " + partitionId);
    try {
        m_iv2appointees.put(partitionId, masterHSId);
    } catch (Exception e) {
        VoltDB.crashLocalVoltDB("Unable to appoint new master for partition " + partitionId, true, e);
    }
    return masterHSId;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) JSONException(org.json_voltpatches.JSONException) ExecutionException(java.util.concurrent.ExecutionException)

Example 30 with JSONObject

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

the class BalancePartitionsRequest method parseRanges.

private List<PartitionPair> parseRanges(JSONObject jsObj) throws JSONException {
    ImmutableList.Builder<PartitionPair> builder = ImmutableList.builder();
    JSONArray pairsArray = jsObj.getJSONArray("partitionPairs");
    for (int i = 0; i < pairsArray.length(); i++) {
        JSONObject pairObj = pairsArray.getJSONObject(i);
        builder.add(new PartitionPair(pairObj.getInt("srcPartition"), pairObj.getInt("destPartition"), pairObj.getInt("rangeStart"), pairObj.getInt("rangeEnd")));
    }
    return builder.build();
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ImmutableList(com.google_voltpatches.common.collect.ImmutableList) JSONArray(org.json_voltpatches.JSONArray)

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