Exemple #1
0
 /** Create a native VoltDB execution engine */
 ExecutionEngine initializeEE(String serializedCatalog, final long timestamp) {
   String hostname = CoreUtils.getHostnameOrAddress();
   ExecutionEngine eeTemp = null;
   try {
     if (m_backend == BackendTarget.NATIVE_EE_JNI) {
       eeTemp =
           new ExecutionEngineJNI(
               m_context.cluster.getRelativeIndex(),
               m_siteId,
               m_partitionId,
               CoreUtils.getHostIdFromHSId(m_siteId),
               hostname,
               m_context
                   .cluster
                   .getDeployment()
                   .get("deployment")
                   .getSystemsettings()
                   .get("systemsettings")
                   .getMaxtemptablesize(),
               m_numberOfPartitions);
       eeTemp.loadCatalog(timestamp, serializedCatalog);
     } else {
       // set up the EE over IPC
       eeTemp =
           new ExecutionEngineIPC(
               m_context.cluster.getRelativeIndex(),
               m_siteId,
               m_partitionId,
               CoreUtils.getHostIdFromHSId(m_siteId),
               hostname,
               m_context
                   .cluster
                   .getDeployment()
                   .get("deployment")
                   .getSystemsettings()
                   .get("systemsettings")
                   .getMaxtemptablesize(),
               m_backend,
               VoltDB.instance().getConfig().m_ipcPorts.remove(0),
               m_numberOfPartitions);
       eeTemp.loadCatalog(timestamp, serializedCatalog);
     }
   }
   // just print error info an bail if we run into an error here
   catch (final Exception ex) {
     hostLog.l7dlog(
         Level.FATAL,
         LogKeys.host_ExecutionSite_FailedConstruction.name(),
         new Object[] {m_siteId, m_siteIndex},
         ex);
     VoltDB.crashLocalVoltDB(ex.getMessage(), true, ex);
   }
   return eeTemp;
 }
Exemple #2
0
 public void runDDL(String ddl) {
   try {
     // LOG.info("Executing " + ddl);
     Statement stmt = dbconn.createStatement();
     /*boolean success =*/ stmt.execute(ddl);
     SQLWarning warn = stmt.getWarnings();
     if (warn != null) sqlLog.warn(warn.getMessage());
     // LOG.info("SQL DDL execute result: " + (success ? "true" : "false"));
   } catch (SQLException e) {
     hostLog.l7dlog(Level.ERROR, LogKeys.host_Backend_RunDDLFailed.name(), new Object[] {ddl}, e);
   }
 }
Exemple #3
0
 /**
  * Log and exit if a dependency list fails an invariant.
  *
  * @param dependencyId
  * @param dependencies
  */
 void verifyDependencySanity(final Integer dependencyId, final List<VoltTable> dependencies) {
   if (dependencies == null) {
     hostLog.l7dlog(
         Level.FATAL,
         LogKeys.host_ExecutionSite_DependencyNotFound.name(),
         new Object[] {dependencyId},
         null);
     VoltDB.crashLocalVoltDB("No additional info.", false, null);
     // Prevent warnings.
     return;
   }
   for (final Object dependency : dependencies) {
     if (dependency == null) {
       hostLog.l7dlog(
           Level.FATAL,
           LogKeys.host_ExecutionSite_DependencyContainedNull.name(),
           new Object[] {dependencyId},
           null);
       VoltDB.crashLocalVoltDB("No additional info.", false, null);
       // Prevent warnings.
       return;
     }
     if (log.isTraceEnabled()) {
       log.l7dlog(
           Level.TRACE,
           LogKeys.org_voltdb_ExecutionSite_ImportingDependency.name(),
           new Object[] {dependencyId, dependency.getClass().getName(), dependency.toString()},
           null);
     }
     if (!(dependency instanceof VoltTable)) {
       hostLog.l7dlog(
           Level.FATAL,
           LogKeys.host_ExecutionSite_DependencyNotVoltTable.name(),
           new Object[] {dependencyId},
           null);
       VoltDB.crashLocalVoltDB("No additional info.", false, null);
     }
   }
 }
Exemple #4
0
 private void shutdown() {
   try {
     try {
       Statement stmt = dbconn.createStatement();
       stmt.execute("SHUTDOWN;");
     } catch (Exception e) {
     }
     ;
     dbconn.close();
     dbconn = null;
     System.gc();
   } catch (Exception e) {
     hostLog.l7dlog(Level.ERROR, LogKeys.host_Backend_ErrorOnShutdown.name(), e);
   }
 }
Exemple #5
0
  public VoltTable runDML(String dml) {
    dml = dml.trim();
    String indicator = dml.substring(0, 1).toLowerCase();
    if (indicator.equals("s")
        || // "s" is for "select ..."
        indicator.equals("(")) { // "(" is for "(select ... UNION ...)" et. al.
      try {
        Statement stmt = dbconn.createStatement();
        sqlLog.l7dlog(
            Level.DEBUG, LogKeys.sql_Backend_ExecutingDML.name(), new Object[] {dml}, null);
        sqlLog.debug("Executing " + dml);
        ResultSet rs = stmt.executeQuery(dml);
        ResultSetMetaData rsmd = rs.getMetaData();

        // note the index values here carefully
        VoltTable.ColumnInfo[] columns = new VoltTable.ColumnInfo[rsmd.getColumnCount()];
        for (int i = 1; i <= rsmd.getColumnCount(); i++) {
          String colname = rsmd.getColumnLabel(i);
          String type = rsmd.getColumnTypeName(i);
          // LOG.fine("Column type: " + type);
          if (type.equals("VARCHAR"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.STRING);
          else if (type.equals("TINYINT"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.TINYINT);
          else if (type.equals("SMALLINT"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.SMALLINT);
          else if (type.equals("INTEGER"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.INTEGER);
          else if (type.equals("BIGINT"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.BIGINT);
          else if (type.equals("DECIMAL"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.DECIMAL);
          else if (type.equals("FLOAT"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.FLOAT);
          else if (type.equals("TIMESTAMP"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.TIMESTAMP);
          else if (type.equals("VARBINARY"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.VARBINARY);
          else if (type.equals("CHARACTER"))
            columns[i - 1] = new VoltTable.ColumnInfo(colname, VoltType.STRING);
          else
            throw new ExpectedProcedureException(
                "Trying to create a column in Backend with a (currently) unsupported type: "
                    + type);
        }
        VoltTable table = new VoltTable(columns);
        while (rs.next()) {
          Object[] row = new Object[table.getColumnCount()];
          for (int i = 0; i < table.getColumnCount(); i++) {
            // TODO(evanj): JDBC returns 0 instead of null. Put null into the row?
            if (table.getColumnType(i) == VoltType.STRING) row[i] = rs.getString(i + 1);
            else if (table.getColumnType(i) == VoltType.TINYINT) row[i] = rs.getByte(i + 1);
            else if (table.getColumnType(i) == VoltType.SMALLINT) row[i] = rs.getShort(i + 1);
            else if (table.getColumnType(i) == VoltType.INTEGER) row[i] = rs.getInt(i + 1);
            else if (table.getColumnType(i) == VoltType.BIGINT) row[i] = rs.getLong(i + 1);
            else if (table.getColumnType(i) == VoltType.DECIMAL) row[i] = rs.getBigDecimal(i + 1);
            else if (table.getColumnType(i) == VoltType.FLOAT) row[i] = rs.getDouble(i + 1);
            else if (table.getColumnType(i) == VoltType.VARBINARY) row[i] = rs.getBytes(i + 1);
            else if (table.getColumnType(i) == VoltType.TIMESTAMP) {
              Timestamp t = rs.getTimestamp(i + 1);
              if (t == null) {
                row[i] = null;
              } else {
                // convert from millisecond to microsecond granularity
                row[i] = new org.voltdb.types.TimestampType(t.getTime() * 1000);
              }
            } else {
              throw new ExpectedProcedureException(
                  "Trying to read a (currently) unsupported type from a JDBC resultset.");
            }
          }
          table.addRow(row);
        }
        stmt.close();
        rs.close();
        return table;
      } catch (Exception e) {
        if (e instanceof ExpectedProcedureException) {
          throw (ExpectedProcedureException) e;
        }
        sqlLog.l7dlog(Level.TRACE, LogKeys.sql_Backend_DmlError.name(), e);
        throw new ExpectedProcedureException("HSQLDB Backend DML Error ", e);
      }
    } else {
      try {
        Statement stmt = dbconn.createStatement();
        sqlLog.debug("Executing: " + dml);
        long ucount = stmt.executeUpdate(dml);
        sqlLog.debug("  result: " + String.valueOf(ucount));
        VoltTable table = new VoltTable(new VoltTable.ColumnInfo("", VoltType.BIGINT));
        table.addRow(ucount);
        return table;
      } catch (SQLException e) {
        // glorious hack to determine if the error is a constraint failure
        if (e.getMessage().contains("constraint")) {
          sqlLog.l7dlog(Level.TRACE, LogKeys.sql_Backend_ConvertingHSQLExtoCFEx.name(), e);
          final byte messageBytes[] = e.getMessage().getBytes();
          ByteBuffer b = ByteBuffer.allocate(25 + messageBytes.length);
          b.putInt(messageBytes.length);
          b.put(messageBytes);
          b.put(e.getSQLState().getBytes());
          b.putInt(0); // ConstraintFailure.type
          try {
            FastSerializer.writeString("HSQL", b);
          } catch (IOException e1) {
            e1.printStackTrace();
          }
          b.putInt(0); // Table size is 0
          b.rewind();
          throw new ConstraintFailureException(b);
        } else {
          sqlLog.l7dlog(Level.TRACE, LogKeys.sql_Backend_DmlError.name(), e);
          throw new ExpectedProcedureException("HSQLDB Backend DML Error ", e);
        }

      } catch (Exception e) {
        // rethrow an expected exception
        sqlLog.l7dlog(Level.TRACE, LogKeys.sql_Backend_DmlError.name(), e);
        throw new ExpectedProcedureException("HSQLDB Backend DML Error ", e);
      }
    }
  }