Search in sources :

Example 16 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class SwapTablesCore method executePlanFragment.

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
    VoltTable dummy = new VoltTable(STATUS_SCHEMA);
    dummy.addRow(STATUS_OK);
    if (fragmentId == SysProcFragmentId.PF_swapTables) {
        // issue the callback once on each node
        if (context.isLowestSiteId()) {
            VoltDB.instance().swapTables((String) params.getParam(0), (String) params.getParam(1));
        }
        return new TableDependencyPair(DEP_swapTables, dummy);
    } else if (fragmentId == SysProcFragmentId.PF_swapTablesAggregate) {
        return new TableDependencyPair(DEP_swapTablesAggregate, VoltTableUtil.unionTables(dependencies.get(DEP_swapTables)));
    }
    assert false;
    return null;
}
Also used : TableDependencyPair(org.voltdb.DependencyPair.TableDependencyPair) VoltTable(org.voltdb.VoltTable)

Example 17 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class SystemInformation method populateOverviewTable.

/**
     * Accumulate per-host information and return as a table.
     * This function does the real work. Everything else is
     * boilerplate sysproc stuff.
     */
public static VoltTable populateOverviewTable() {
    VoltTable vt = constructOverviewTable();
    int hostId = VoltDB.instance().getHostMessenger().getHostId();
    // try to get the external interface first, if none was set, use local addresses
    InetAddress addr = null;
    String clientInterface = null;
    int clientPort = VoltDB.DEFAULT_PORT;
    String adminInterface = null;
    int adminPort = VoltDB.DEFAULT_ADMIN_PORT;
    String httpInterface = null;
    int httpPort = VoltDB.DEFAULT_HTTP_PORT;
    String internalInterface = null;
    int internalPort = Constants.DEFAULT_INTERNAL_PORT;
    String zkInterface = null;
    int zkPort = Constants.DEFAULT_ZK_PORT;
    String drInterface = null;
    int drPort = VoltDB.DEFAULT_DR_PORT;
    String publicInterface = null;
    try {
        String localMetadata = VoltDB.instance().getLocalMetadata();
        JSONObject jsObj = new JSONObject(localMetadata);
        JSONArray interfaces = jsObj.getJSONArray("interfaces");
        String iface = interfaces.getString(0);
        addr = InetAddress.getByName(iface);
        clientPort = jsObj.getInt("clientPort");
        clientInterface = jsObj.getString("clientInterface");
        adminPort = jsObj.getInt("adminPort");
        adminInterface = jsObj.getString("adminInterface");
        httpPort = jsObj.getInt("httpPort");
        httpInterface = jsObj.getString("httpInterface");
        internalPort = jsObj.getInt("internalPort");
        internalInterface = jsObj.getString("internalInterface");
        zkPort = jsObj.getInt("zkPort");
        zkInterface = jsObj.getString("zkInterface");
        drPort = jsObj.getInt("drPort");
        drInterface = jsObj.getString("drInterface");
        publicInterface = jsObj.getString("publicInterface");
    } catch (JSONException e) {
        hostLog.info("Failed to get local metadata, falling back to first resolvable IP address.");
    } catch (UnknownHostException e) {
        hostLog.info("Failed to determine hostname, falling back to first resolvable IP address.");
    }
    // host name and IP address.
    if (addr == null) {
        addr = org.voltcore.utils.CoreUtils.getLocalAddress();
    }
    vt.addRow(hostId, "IPADDRESS", addr.getHostAddress());
    vt.addRow(hostId, "HOSTNAME", CoreUtils.getHostnameOrAddress());
    vt.addRow(hostId, "CLIENTINTERFACE", clientInterface);
    vt.addRow(hostId, "CLIENTPORT", Integer.toString(clientPort));
    vt.addRow(hostId, "ADMININTERFACE", adminInterface);
    vt.addRow(hostId, "ADMINPORT", Integer.toString(adminPort));
    vt.addRow(hostId, "HTTPINTERFACE", httpInterface);
    vt.addRow(hostId, "HTTPPORT", Integer.toString(httpPort));
    vt.addRow(hostId, "INTERNALINTERFACE", internalInterface);
    vt.addRow(hostId, "INTERNALPORT", Integer.toString(internalPort));
    vt.addRow(hostId, "ZKINTERFACE", zkInterface);
    vt.addRow(hostId, "ZKPORT", Integer.toString(zkPort));
    vt.addRow(hostId, "DRINTERFACE", drInterface);
    vt.addRow(hostId, "DRPORT", Integer.toString(drPort));
    vt.addRow(hostId, "PUBLICINTERFACE", publicInterface);
    // build string
    vt.addRow(hostId, "BUILDSTRING", VoltDB.instance().getBuildString());
    // version
    vt.addRow(hostId, "VERSION", VoltDB.instance().getVersionString());
    // catalog path
    String path = VoltDB.instance().getConfig().m_pathToCatalog;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "CATALOG", path);
    // deployment path
    path = VoltDB.instance().getConfig().m_pathToDeployment;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "DEPLOYMENT", path);
    String cluster_state = VoltDB.instance().getMode().toString();
    vt.addRow(hostId, "CLUSTERSTATE", cluster_state);
    // INITIALIZED, used by VEM to determine the spinny icon state.
    org.voltdb.OperationMode mode = VoltDB.instance().getMode();
    String areInitialized = Boolean.toString(!VoltDB.instance().rejoining() && (mode == org.voltdb.OperationMode.RUNNING || mode == org.voltdb.OperationMode.PAUSED));
    vt.addRow(hostId, "INITIALIZED", areInitialized);
    String replication_role = VoltDB.instance().getReplicationRole().toString();
    vt.addRow(hostId, "REPLICATIONROLE", replication_role);
    vt.addRow(hostId, "LASTCATALOGUPDATETXNID", Long.toString(VoltDB.instance().getCatalogContext().m_transactionId));
    vt.addRow(hostId, "CATALOGCRC", Long.toString(VoltDB.instance().getCatalogContext().getCatalogCRC()));
    vt.addRow(hostId, "IV2ENABLED", "true");
    long startTimeMs = VoltDB.instance().getHostMessenger().getInstanceId().getTimestamp();
    vt.addRow(hostId, "STARTTIME", Long.toString(startTimeMs));
    vt.addRow(hostId, "UPTIME", MiscUtils.formatUptime(VoltDB.instance().getClusterUptime()));
    SocketHubAppender hubAppender = (SocketHubAppender) Logger.getRootLogger().getAppender("hub");
    int port = 0;
    if (hubAppender != null)
        port = hubAppender.getPort();
    vt.addRow(hostId, "LOG4JPORT", Integer.toString(port));
    //Add license information
    if (MiscUtils.isPro()) {
        vt.addRow(hostId, "LICENSE", VoltDB.instance().getLicenseInformation());
    }
    populatePartitionGroups(hostId, vt);
    // root path
    vt.addRow(hostId, "VOLTDBROOT", VoltDB.instance().getVoltDBRootPath());
    vt.addRow(hostId, "FULLCLUSTERSIZE", Integer.toString(VoltDB.instance().getCatalogContext().getClusterSettings().hostcount()));
    vt.addRow(hostId, "CLUSTERID", Integer.toString(VoltDB.instance().getCatalogContext().getCluster().getDrclusterid()));
    return vt;
}
Also used : UnknownHostException(java.net.UnknownHostException) SocketHubAppender(org.apache.log4j.net.SocketHubAppender) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) VoltTable(org.voltdb.VoltTable) JSONObject(org.json_voltpatches.JSONObject) InetAddress(java.net.InetAddress) File(java.io.File)

Example 18 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class UpdateSettings method executePlanFragment.

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
    if (fragmentId == SysProcFragmentId.PF_updateSettingsBarrier) {
        DependencyPair success = new DependencyPair.TableDependencyPair(DEP_updateSettingsBarrier, new VoltTable(new ColumnInfo[] { new ColumnInfo("UNUSED", VoltType.BIGINT) }));
        if (log.isInfoEnabled()) {
            log.info("Site " + CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()) + " reached settings update barrier.");
        }
        return success;
    } else if (fragmentId == SysProcFragmentId.PF_updateSettingsBarrierAggregate) {
        Object[] paramarr = params.toArray();
        byte[] settingsBytes = (byte[]) paramarr[0];
        int version = ((Integer) paramarr[1]).intValue();
        ZooKeeper zk = getHostMessenger().getZK();
        Stat stat = null;
        try {
            stat = zk.setData(VoltZK.cluster_settings, settingsBytes, version);
        } catch (KeeperException | InterruptedException e) {
            String msg = "Failed to update cluster settings";
            log.error(msg, e);
            throw new SettingsException(msg, e);
        }
        log.info("Saved new cluster settings state");
        return new DependencyPair.TableDependencyPair(DEP_updateSettingsBarrierAggregate, getVersionResponse(stat.getVersion()));
    } else if (fragmentId == SysProcFragmentId.PF_updateSettings) {
        Object[] paramarr = params.toArray();
        byte[] settingsBytes = (byte[]) paramarr[0];
        int version = ((Integer) paramarr[1]).intValue();
        ClusterSettings settings = ClusterSettings.create(settingsBytes);
        Pair<CatalogContext, CatalogSpecificPlanner> ctgdef = getVoltDB().settingsUpdate(settings, version);
        context.updateSettings(ctgdef.getFirst(), ctgdef.getSecond());
        VoltTable result = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
        result.addRow(VoltSystemProcedure.STATUS_OK);
        return new DependencyPair.TableDependencyPair(DEP_updateSettings, result);
    } else if (fragmentId == SysProcFragmentId.PF_updateSettingsAggregate) {
        VoltTable result = VoltTableUtil.unionTables(dependencies.get(DEP_updateSettings));
        return new DependencyPair.TableDependencyPair(DEP_updateSettingsAggregate, result);
    } else {
        VoltDB.crashLocalVoltDB("Received unrecognized plan fragment id " + fragmentId + " in UpdateSettings", false, null);
    }
    throw new RuntimeException("Should not reach this code");
}
Also used : ClusterSettings(org.voltdb.settings.ClusterSettings) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) VoltTable(org.voltdb.VoltTable) SettingsException(org.voltdb.settings.SettingsException) CatalogSpecificPlanner(org.voltdb.CatalogSpecificPlanner) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) CatalogContext(org.voltdb.CatalogContext) DependencyPair(org.voltdb.DependencyPair)

Example 19 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class LoadSinglepartitionTable method run.

/**
     * These parameters, with the exception of ctx, map to user provided values.
     *
     * @param ctx Internal API provided to all system procedures.
     * @param partitionParam Partitioning parameter used to match invocation to partition.
     * @param tableName Name of persistent, parititoned table receiving data.
     * @param table A VoltTable with schema matching the target table containing data to load.
     *              It's assumed that each row in this table partitions to the same partition
     *              as the other rows, and to the same partition as the partition parameter.
     * @param upsertMode True if using upsert instead of insert. If using insert, this proc
     *              will fail if there are any uniqueness constraints violated.
     * @return The number of rows modified. This will be inserts in insert mode, but in upsert
     *              mode, this will be the sum of inserts and updates.
     * @throws VoltAbortException on any failure, but the most common failures are non-matching
     *              partitioning or unique constraint violations.
     */
public long run(SystemProcedureExecutionContext ctx, byte[] partitionParam, String tableName, byte upsertMode, VoltTable table) throws VoltAbortException {
    // if tableName is replicated, fail.
    // otherwise, create a VoltTable for each partition and
    // split up the incoming table .. then send those partial
    // tables to the appropriate sites.
    // Get the metadata object for the table in question from the global metadata/config
    // store, the Catalog.
    Table catTable = ctx.getDatabase().getTables().getIgnoreCase(tableName);
    if (catTable == null) {
        throw new VoltAbortException("Table not present in catalog.");
    }
    // if tableName is replicated, fail.
    if (catTable.getIsreplicated()) {
        throw new VoltAbortException(String.format("LoadSinglepartitionTable incompatible with replicated table %s.", tableName));
    }
    // convert from 8bit signed integer (byte) to boolean
    boolean isUpsert = (upsertMode != 0);
    // upsert requires a primary key on the table to work
    if (isUpsert) {
        boolean hasPkey = false;
        for (Constraint c : catTable.getConstraints()) {
            if (c.getType() == ConstraintType.PRIMARY_KEY.getValue()) {
                hasPkey = true;
                break;
            }
        }
        if (!hasPkey) {
            throw new VoltAbortException(String.format("The --update argument cannot be used for LoadingSinglePartionTable because the table %s does not have a primary key. " + "Either remove the --update argument or add a primary key to the table.", tableName));
        }
    }
    // action should be either "insert" or "upsert"
    final String action = (isUpsert ? "upsert" : "insert");
    // fix any case problems
    tableName = catTable.getTypeName();
    // check that the schema of the input matches
    int columnCount = table.getColumnCount();
    //////////////////////////////////////////////////////////////////////
    // Find the insert/upsert statement for this table
    // This is actually the big trick this procedure does.
    // It borrows the insert plan from the auto-generated insert procedure
    // named "TABLENAME.insert" or "TABLENAME.upsert".
    // We don't like it when users do this stuff, but it is safe in this
    // case.
    //
    // Related code to read is org.voltdb.DefaultProcedureManager, which
    // manages all of the default (CRUD) procedures created lazily for
    // each table in the database, including the plans used here.
    //
    String crudProcName = String.format("%s.%s", tableName, action);
    Procedure p = ctx.ensureDefaultProcLoaded(crudProcName);
    if (p == null) {
        throw new VoltAbortException(String.format("Unable to locate auto-generated CRUD %s statement for table %s", action, tableName));
    }
    // statements of all single-statement procs are named "sql"
    Statement catStmt = p.getStatements().get(VoltDB.ANON_STMT_NAME);
    if (catStmt == null) {
        throw new VoltAbortException(String.format("Unable to find SQL statement for found table %s: BAD", tableName));
    }
    // Create a SQLStmt instance on the fly
    // This unusual to do, as they are typically required to be final instance variables.
    // This only works because the SQL text and plan is identical from the borrowed procedure.
    SQLStmt stmt = new SQLStmt(catStmt.getSqltext());
    m_runner.initSQLStmt(stmt, catStmt);
    long queued = 0;
    long executed = 0;
    // make sure at the start of the table
    table.resetRowPosition();
    // iterate over the rows queueing a sql statement for each row to insert
    for (int i = 0; table.advanceRow(); ++i) {
        Object[] params = new Object[columnCount];
        // get the parameters from the volt table
        for (int col = 0; col < columnCount; ++col) {
            params[col] = table.get(col, table.getColumnType(col));
        }
        // queue an insert and count it
        voltQueueSQL(stmt, params);
        ++queued;
        // 100 is an arbitrary number
        if ((i % 100) == 0) {
            executed += executeSQL();
        }
    }
    // execute any leftover batched statements
    if (queued > executed) {
        executed += executeSQL();
    }
    return executed;
}
Also used : SQLStmt(org.voltdb.SQLStmt) Table(org.voltdb.catalog.Table) VoltTable(org.voltdb.VoltTable) Constraint(org.voltdb.catalog.Constraint) Statement(org.voltdb.catalog.Statement) VoltSystemProcedure(org.voltdb.VoltSystemProcedure) Procedure(org.voltdb.catalog.Procedure) Constraint(org.voltdb.catalog.Constraint)

Example 20 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class Shutdown method executePlanFragment.

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
    if (fragmentId == SysProcFragmentId.PF_shutdownSync) {
        VoltDB.instance().getHostMessenger().prepareForShutdown();
        if (!m_failsafeArmed.getAndSet(true)) {
            m_failsafe.start();
            VoltLogger voltLogger = new VoltLogger("HOST");
            String msg = "VoltDB shutdown operation requested and in progress. Cluster will terminate shortly.";
            CoreUtils.PrintGoodLookingLog(voltLogger, msg, Level.WARN);
        }
        VoltTable rslt = new VoltTable(new ColumnInfo[] { new ColumnInfo("HA", VoltType.STRING) });
        return new DependencyPair.TableDependencyPair(DEP_shutdownSync, rslt);
    } else if (fragmentId == SysProcFragmentId.PF_shutdownSyncDone) {
        VoltTable rslt = new VoltTable(new ColumnInfo[] { new ColumnInfo("HA", VoltType.STRING) });
        return new DependencyPair.TableDependencyPair(DEP_shutdownSyncDone, rslt);
    } else if (fragmentId == SysProcFragmentId.PF_shutdownCommand) {
        Thread shutdownThread = new Thread() {

            @Override
            public void run() {
                boolean die = false;
                try {
                    die = VoltDB.instance().shutdown(this);
                } catch (InterruptedException e) {
                    new VoltLogger("HOST").error("Exception while attempting to shutdown VoltDB from shutdown sysproc", e);
                }
                if (die) {
                    VoltLogger voltLogger = new VoltLogger("HOST");
                    String msg = "VoltDB shutting down as requested by @Shutdown command.";
                    CoreUtils.PrintGoodLookingLog(voltLogger, msg, Level.WARN);
                    System.exit(0);
                } else {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                    }
                }
            }
        };
        shutdownThread.start();
    }
    return null;
}
Also used : VoltLogger(org.voltcore.logging.VoltLogger) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) VoltTable(org.voltdb.VoltTable) DependencyPair(org.voltdb.DependencyPair)

Aggregations

VoltTable (org.voltdb.VoltTable)887 Client (org.voltdb.client.Client)497 ClientResponse (org.voltdb.client.ClientResponse)193 ProcCallException (org.voltdb.client.ProcCallException)144 IOException (java.io.IOException)100 VoltTableRow (org.voltdb.VoltTableRow)57 NoConnectionsException (org.voltdb.client.NoConnectionsException)52 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)42 TimestampType (org.voltdb.types.TimestampType)37 BigDecimal (java.math.BigDecimal)30 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)26 File (java.io.File)25 HashMap (java.util.HashMap)21 ClientResponseImpl (org.voltdb.ClientResponseImpl)20 Timestamp (java.sql.Timestamp)15 Date (java.util.Date)15 VoltDB (org.voltdb.VoltDB)15 DependencyPair (org.voltdb.DependencyPair)14 Configuration (org.voltdb.VoltDB.Configuration)14