Search in sources :

Example 16 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class TestInvocationAcceptancePolicy method testUserPermissionReadOnly.

@Test
public void testUserPermissionReadOnly() {
    Procedure proc = new Procedure();
    proc.setDefaultproc(true);
    proc.setReadonly(true);
    AuthSystem.AuthUser user = createUser(false, false, false, proc, true, false, false);
    StoredProcedureInvocation invocation = new StoredProcedureInvocation();
    invocation.setProcName("X.select");
    invocation.setParams("test");
    InvocationPermissionPolicy policy = new InvocationDefaultProcPermissionPolicy();
    assertEquals(policy.shouldAccept(user, invocation, proc), PolicyResult.ALLOW);
    // A user that doesn't have crud permission
    Procedure procw = new Procedure();
    procw.setDefaultproc(true);
    procw.setReadonly(false);
    user = createUser(false, false, false, null, false, false, false);
    assertEquals(policy.shouldAccept(user, invocation, proc), PolicyResult.DENY);
}
Also used : Procedure(org.voltdb.catalog.Procedure) Test(org.junit.Test)

Example 17 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class MockVoltDB method addProcedureForTest.

public Procedure addProcedureForTest(String name) {
    Procedure retval = getCluster().getDatabases().get(m_databaseName).getProcedures().add(name);
    retval.setClassname(name);
    retval.setHasjava(true);
    retval.setSystemproc(false);
    retval.setDefaultproc(false);
    return retval;
}
Also used : Procedure(org.voltdb.catalog.Procedure)

Example 18 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class ClientInterface method initiateSnapshotDaemonWork.

@Override
public void initiateSnapshotDaemonWork(final String procedureName, long clientData, final Object[] params) {
    final Config sysProc = SystemProcedureCatalog.listing.get(procedureName);
    if (sysProc == null) {
        throw new RuntimeException("SnapshotDaemon attempted to invoke " + procedureName + " which is not a known procedure");
    }
    Procedure catProc = sysProc.asCatalogProcedure();
    StoredProcedureInvocation spi = new StoredProcedureInvocation();
    spi.setProcName(procedureName);
    spi.params = new FutureTask<ParameterSet>(new Callable<ParameterSet>() {

        @Override
        public ParameterSet call() {
            ParameterSet paramSet = ParameterSet.fromArrayWithCopy(params);
            return paramSet;
        }
    });
    spi.clientHandle = clientData;
    // Ugh, need to consolidate this with handleRead() somehow but not feeling it at the moment
    if (procedureName.equals("@SnapshotScan")) {
        InvocationDispatcher.dispatchStatistics(OpsSelector.SNAPSHOTSCAN, spi, m_snapshotDaemonAdapter);
        return;
    } else if (procedureName.equals("@SnapshotDelete")) {
        InvocationDispatcher.dispatchStatistics(OpsSelector.SNAPSHOTDELETE, spi, m_snapshotDaemonAdapter);
        return;
    }
    // initiate the transaction
    createTransaction(m_snapshotDaemonAdapter.connectionId(), spi, catProc.getReadonly(), catProc.getSinglepartition(), catProc.getEverysite(), 0, 0, System.nanoTime());
}
Also used : Config(org.voltdb.SystemProcedureCatalog.Config) Procedure(org.voltdb.catalog.Procedure) Callable(java.util.concurrent.Callable)

Example 19 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class ExplainProc method run.

public CompletableFuture<ClientResponse> run(String procedureNames) {
    // Go to the catalog and fetch all the "explain plan" strings of the queries in the procedure.
    CatalogContext context = VoltDB.instance().getCatalogContext();
    /*
         * TODO: We don't actually support multiple proc names in an ExplainProc call,
         * so I THINK that the string is always a single procname symbol and all this
         * splitting and iterating is a no-op.
         */
    List<String> procNames = SQLLexer.splitStatements(procedureNames);
    int size = procNames.size();
    VoltTable[] vt = new VoltTable[size];
    for (int i = 0; i < size; i++) {
        String procName = procNames.get(i);
        // look in the catalog
        Procedure proc = context.procedures.get(procName);
        if (proc == null) {
            // check default procs and send them off to be explained using the regular
            // adhoc explain process
            proc = context.m_defaultProcs.checkForDefaultProcedure(procName);
            if (proc != null) {
                String sql = DefaultProcedureManager.sqlForDefaultProc(proc);
                List<String> sqlStatements = new ArrayList<>(1);
                sqlStatements.add(sql);
                return runNonDDLAdHoc(context, sqlStatements, true, null, ExplainMode.EXPLAIN_DEFAULT_PROC, false, new Object[0]);
            }
            return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, "Procedure " + procName + " not in catalog");
        }
        vt[i] = new VoltTable(new VoltTable.ColumnInfo("SQL_STATEMENT", VoltType.STRING), new VoltTable.ColumnInfo("EXECUTION_PLAN", VoltType.STRING));
        for (Statement stmt : proc.getStatements()) {
            vt[i].addRow(stmt.getSqltext(), Encoder.hexDecodeToString(stmt.getExplainplan()));
        }
    }
    ClientResponseImpl response = new ClientResponseImpl(ClientResponseImpl.SUCCESS, ClientResponse.UNINITIALIZED_APP_STATUS_CODE, null, vt, null);
    CompletableFuture<ClientResponse> fut = new CompletableFuture<>();
    fut.complete(response);
    return fut;
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Statement(org.voltdb.catalog.Statement) ArrayList(java.util.ArrayList) VoltTable(org.voltdb.VoltTable) CompletableFuture(java.util.concurrent.CompletableFuture) Procedure(org.voltdb.catalog.Procedure) ClientResponseImpl(org.voltdb.ClientResponseImpl) CatalogContext(org.voltdb.CatalogContext)

Example 20 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class LoadMultipartitionTable method run.

/**
     * These parameters, with the exception of ctx, map to user provided values.
     *
     * @param ctx
     *            Internal. Not a user-supplied parameter.
     * @param tableName
     *            Name of persistent table receiving data.
     * @param table
     *            A VoltTable with schema matching tableName containing data to
     *            load.
     * @param upsertMode
     *            True if using upsert instead of insert
     * @return {@link org.voltdb.VoltSystemProcedure#STATUS_SCHEMA}
     * @throws VoltAbortException
     */
public long run(SystemProcedureExecutionContext ctx, String tableName, byte upsertMode, VoltTable table) throws VoltAbortException {
    // if tableName is replicated, just send table everywhere.
    // otherwise, create a VoltTable for each partition and
    // split up the incoming table .. then send those partial
    // tables to the appropriate sites.
    Table catTable = ctx.getDatabase().getTables().getIgnoreCase(tableName);
    if (catTable == null) {
        throw new VoltAbortException("Table not present in catalog.");
    }
    boolean isUpsert = (upsertMode != 0);
    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 LoadMultipartitionTable 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 statement for this table
    String crudProcName = String.format("%s.%s", tableName.toUpperCase(), action);
    Procedure proc = ctx.ensureDefaultProcLoaded(crudProcName);
    if (proc == null) {
        throw new VoltAbortException(String.format("Unable to locate auto-generated CRUD %s statement for table %s", action, tableName));
    }
    // ensure MP fragment tasks load the plan for the table loading procedure
    m_runner.setProcNameToLoadForFragmentTasks(crudProcName);
    Statement catStmt = proc.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 (unusual to do)
    SQLStmt stmt = new SQLStmt(catStmt.getSqltext());
    m_runner.initSQLStmt(stmt, catStmt);
    if (catTable.getIsreplicated()) {
        long queued = 0;
        long executed = 0;
        // make sure at the start of the table
        table.resetRowPosition();
        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;
    } else {
        throw new VoltAbortException("LoadMultipartitionTable no longer supports loading partitioned tables" + " use CRUD procs instead");
    }
}
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)

Aggregations

Procedure (org.voltdb.catalog.Procedure)42 Statement (org.voltdb.catalog.Statement)12 Database (org.voltdb.catalog.Database)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Table (org.voltdb.catalog.Table)6 VoltTable (org.voltdb.VoltTable)5 Catalog (org.voltdb.catalog.Catalog)5 Constraint (org.voltdb.catalog.Constraint)5 ProcParameter (org.voltdb.catalog.ProcParameter)5 Config (org.voltdb.SystemProcedureCatalog.Config)4 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)3 JSONException (org.json_voltpatches.JSONException)3 ProcInfoData (org.voltdb.ProcInfoData)3 SQLStmt (org.voltdb.SQLStmt)3 GroupRef (org.voltdb.catalog.GroupRef)3 PlanFragment (org.voltdb.catalog.PlanFragment)3 File (java.io.File)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2