Search in sources :

Example 21 with Procedure

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

the class TestInvocationAcceptancePolicy method testAdHocReadUserPermission.

@Test
public void testAdHocReadUserPermission() {
    AuthSystem.AuthUser user = createUser(false, false, false, null, true, true, true);
    StoredProcedureInvocation invocation = new StoredProcedureInvocation();
    invocation.setProcName("@AdHoc_RO_MP");
    invocation.setParams("select * from T;");
    Procedure proc = SystemProcedureCatalog.listing.get("@AdHoc_RO_MP").asCatalogProcedure();
    InvocationPermissionPolicy policy = new InvocationSqlPermissionPolicy();
    assertEquals(policy.shouldAccept(user, invocation, proc), PolicyResult.ALLOW);
    // A user that doesn't have adhoc permission
    user = createUser(false, false, false, null, true, false, false);
    assertEquals(policy.shouldAccept(user, invocation, proc), PolicyResult.DENY);
}
Also used : Procedure(org.voltdb.catalog.Procedure) Test(org.junit.Test)

Example 22 with Procedure

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

the class TestFragmentProgressUpdate method setUp.

@Override
protected void setUp() throws Exception {
    final int CLUSTER_ID = 2;
    final long NODE_ID = 1;
    super.setUp();
    VoltDB.instance().readBuildInfo("Test");
    m_warehousedata = new VoltTable(new VoltTable.ColumnInfo("W_ID", VoltType.SMALLINT), new VoltTable.ColumnInfo("W_NAME", VoltType.STRING), new VoltTable.ColumnInfo("W_STREET_1", VoltType.STRING), new VoltTable.ColumnInfo("W_STREET_2", VoltType.STRING), new VoltTable.ColumnInfo("W_CITY", VoltType.STRING), new VoltTable.ColumnInfo("W_STATE", VoltType.STRING), new VoltTable.ColumnInfo("W_ZIP", VoltType.STRING), new VoltTable.ColumnInfo("W_TAX", VoltType.FLOAT), new VoltTable.ColumnInfo("W_YTD", VoltType.FLOAT));
    m_itemData = new VoltTable(new VoltTable.ColumnInfo("I_ID", VoltType.INTEGER), new VoltTable.ColumnInfo("I_IM_ID", VoltType.INTEGER), new VoltTable.ColumnInfo("I_NAME", VoltType.STRING), new VoltTable.ColumnInfo("I_PRICE", VoltType.FLOAT), new VoltTable.ColumnInfo("I_DATA", VoltType.STRING));
    TPCCProjectBuilder builder = new TPCCProjectBuilder();
    m_catalog = builder.createTPCCSchemaCatalog();
    Cluster cluster = m_catalog.getClusters().get("cluster");
    WAREHOUSE_TABLEID = m_catalog.getClusters().get("cluster").getDatabases().get("database").getTables().get("WAREHOUSE").getRelativeIndex();
    ITEM_TABLEID = m_catalog.getClusters().get("cluster").getDatabases().get("database").getTables().get("ITEM").getRelativeIndex();
    CatalogMap<Procedure> procedures = cluster.getDatabases().get("database").getProcedures();
    m_testProc = procedures.getIgnoreCase("FragmentUpdateTestProcedure");
    m_ee = new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, LegacyHashinator.getConfigureBytes(1), 0, 0), false);
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) Cluster(org.voltdb.catalog.Cluster) Procedure(org.voltdb.catalog.Procedure) VoltTable(org.voltdb.VoltTable) TPCCProjectBuilder(org.voltdb.benchmark.tpcc.TPCCProjectBuilder)

Example 23 with Procedure

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

the class ClientInterface method callExecuteTaskAsync.

/**
     * Asynchronous version, call @ExecuteTask to generate a MP transaction.
     *
     * @param cb  maximum timeout in milliseconds
     * @param params  actual parameter(s) for sub task to run
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
public void callExecuteTaskAsync(SimpleClientResponseAdapter.Callback cb, byte[] params) throws IOException {
    final String procedureName = "@ExecuteTask";
    Config procedureConfig = SystemProcedureCatalog.listing.get(procedureName);
    Procedure proc = procedureConfig.asCatalogProcedure();
    StoredProcedureInvocation spi = new StoredProcedureInvocation();
    spi.setProcName(procedureName);
    spi.setParams(params);
    spi.setClientHandle(m_executeTaskAdpater.registerCallback(cb));
    if (spi.getSerializedParams() == null) {
        spi = MiscUtils.roundTripForCL(spi);
    }
    synchronized (m_executeTaskAdpater) {
        createTransaction(m_executeTaskAdpater.connectionId(), spi, proc.getReadonly(), proc.getSinglepartition(), proc.getEverysite(), 0, /* Can provide anything for multi-part */
        spi.getSerializedSize(), System.nanoTime());
    }
}
Also used : Config(org.voltdb.SystemProcedureCatalog.Config) Procedure(org.voltdb.catalog.Procedure)

Example 24 with Procedure

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

the class DefaultProcedureManager method addShimProcedure.

private void addShimProcedure(String name, Table table, Constraint pkey, boolean tableCols, int partitionParamIndex, Column partitionColumn, boolean readOnly) {
    Procedure proc = m_fakeDb.getProcedures().add(name);
    proc.setClassname(name);
    proc.setDefaultproc(true);
    proc.setHasjava(false);
    proc.setHasseqscans(false);
    proc.setSinglepartition(partitionParamIndex >= 0);
    proc.setPartitioncolumn(partitionColumn);
    proc.setPartitionparameter(partitionParamIndex);
    proc.setReadonly(readOnly);
    proc.setEverysite(false);
    proc.setSystemproc(false);
    proc.setPartitiontable(table);
    if (partitionParamIndex >= 0) {
        proc.setAttachment(new ProcedurePartitionInfo(VoltType.get((byte) partitionColumn.getType()), partitionParamIndex));
    }
    int paramCount = 0;
    if (tableCols) {
        for (Column col : table.getColumns()) {
            // name each parameter "param1", "param2", etc...
            ProcParameter procParam = proc.getParameters().add("param" + String.valueOf(paramCount));
            procParam.setIndex(col.getIndex());
            procParam.setIsarray(false);
            procParam.setType(col.getType());
            paramCount++;
        }
    }
    if (pkey != null) {
        CatalogMap<ColumnRef> pkeycols = pkey.getIndex().getColumns();
        int paramCount2 = paramCount;
        for (ColumnRef cref : pkeycols) {
            // name each parameter "param1", "param2", etc...
            ProcParameter procParam = proc.getParameters().add("param" + String.valueOf(paramCount2));
            procParam.setIndex(cref.getIndex() + paramCount);
            procParam.setIsarray(false);
            procParam.setType(cref.getColumn().getType());
            paramCount2++;
        }
    }
    m_defaultProcMap.put(name.toLowerCase(), proc);
}
Also used : ProcedurePartitionInfo(org.voltdb.CatalogContext.ProcedurePartitionInfo) Column(org.voltdb.catalog.Column) Procedure(org.voltdb.catalog.Procedure) ColumnRef(org.voltdb.catalog.ColumnRef) ProcParameter(org.voltdb.catalog.ProcParameter) Constraint(org.voltdb.catalog.Constraint)

Example 25 with Procedure

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

the class InvocationDispatcher method dispatch.

public final ClientResponseImpl dispatch(StoredProcedureInvocation task, InvocationClientHandler handler, Connection ccxn, AuthUser user, OverrideCheck bypass, boolean ntPriority) {
    final long nowNanos = System.nanoTime();
    // Deserialize the client's request and map to a catalog stored procedure
    final CatalogContext catalogContext = m_catalogContext.get();
    final String procName = task.getProcName();
    // Thread name has to be materialized here
    final String threadName = Thread.currentThread().getName();
    final StoredProcedureInvocation finalTask = task;
    final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.CI);
    if (traceLog != null) {
        traceLog.add(() -> VoltTrace.meta("process_name", "name", CoreUtils.getHostnameOrAddress())).add(() -> VoltTrace.meta("thread_name", "name", threadName)).add(() -> VoltTrace.meta("thread_sort_index", "sort_index", Integer.toString(1))).add(() -> VoltTrace.beginAsync("recvtxn", finalTask.getClientHandle(), "name", procName, "clientHandle", Long.toString(finalTask.getClientHandle())));
    }
    Procedure catProc = getProcedureFromName(task.getProcName(), catalogContext);
    if (catProc == null) {
        String errorMessage = "Procedure " + procName + " was not found";
        RateLimitedLogger.tryLogForMessage(EstTime.currentTimeMillis(), 60, TimeUnit.SECONDS, authLog, Level.WARN, errorMessage + ". This message is rate limited to once every 60 seconds.");
        return unexpectedFailureResponse(errorMessage, task.clientHandle);
    }
    ClientResponseImpl error = null;
    // Check for pause mode restrictions before proceeding any further
    if ((error = allowPauseModeExecution(handler, catProc, task)) != null) {
        if (bypass == null || !bypass.skipAdmimCheck) {
            return error;
        }
    }
    //Check permissions
    if ((error = m_permissionValidator.shouldAccept(procName, user, task, catProc)) != null) {
        if (bypass == null || !bypass.skipPermissionCheck) {
            return error;
        }
    }
    //Check param deserialization policy for sysprocs
    if ((error = m_invocationValidator.shouldAccept(procName, user, task, catProc)) != null) {
        if (bypass == null || !bypass.skipInvocationCheck) {
            return error;
        }
    }
    //Check individual query timeout value settings with privilege
    int batchTimeout = task.getBatchTimeout();
    if (BatchTimeoutOverrideType.isUserSetTimeout(batchTimeout)) {
        if (!user.hasPermission(Permission.ADMIN)) {
            int systemTimeout = catalogContext.cluster.getDeployment().get("deployment").getSystemsettings().get("systemsettings").getQuerytimeout();
            if (systemTimeout != ExecutionEngine.NO_BATCH_TIMEOUT_VALUE && (batchTimeout > systemTimeout || batchTimeout == ExecutionEngine.NO_BATCH_TIMEOUT_VALUE)) {
                String errorMessage = "The attempted individual query timeout value " + batchTimeout + " milliseconds override was ignored because the connection lacks ADMIN privileges.";
                RateLimitedLogger.tryLogForMessage(EstTime.currentTimeMillis(), 60, TimeUnit.SECONDS, log, Level.INFO, errorMessage + " This message is rate limited to once every 60 seconds.");
                task.setBatchTimeout(systemTimeout);
            }
        }
    }
    // only 100% when we're talking Java
    if ((catProc.getTransactional() == false) && catProc.getHasjava()) {
        return dispatchNTProcedure(handler, task, user, ccxn, nowNanos, ntPriority);
    }
    // check for allPartition invocation and provide a nice error if it's misused
    if (task.getAllPartition()) {
        // must be single partition and must be partitioned on parameter 0
        if (!catProc.getSinglepartition() || (catProc.getPartitionparameter() != 0) || catProc.getSystemproc()) {
            return new ClientResponseImpl(ClientResponseImpl.GRACEFUL_FAILURE, new VoltTable[0], "Invalid procedure for all-partition execution. " + "Targeted procedure must be partitioned, must be partitioned on the first parameter, " + "and must not be a system procedure.", task.clientHandle);
        }
    }
    if (catProc.getSystemproc()) {
        // nb: ping is not a real procedure, so this is checked before other "sysprocs"
        if ("@Ping".equals(procName)) {
            return new ClientResponseImpl(ClientResponseImpl.SUCCESS, new VoltTable[0], "", task.clientHandle);
        } else if ("@GetPartitionKeys".equals(procName)) {
            return dispatchGetPartitionKeys(task);
        } else if ("@Subscribe".equals(procName)) {
            return dispatchSubscribe(handler, task);
        } else if ("@Statistics".equals(procName)) {
            return dispatchStatistics(OpsSelector.STATISTICS, task, ccxn);
        } else if ("@SystemCatalog".equals(procName)) {
            return dispatchStatistics(OpsSelector.SYSTEMCATALOG, task, ccxn);
        } else if ("@SystemInformation".equals(procName)) {
            return dispatchStatistics(OpsSelector.SYSTEMINFORMATION, task, ccxn);
        } else if ("@Trace".equals(procName)) {
            return dispatchStatistics(OpsSelector.TRACE, task, ccxn);
        } else if ("@StopNode".equals(procName)) {
            return dispatchStopNode(task);
        } else if ("@LoadSinglepartitionTable".equals(procName)) {
            // FUTURE: When we get rid of the legacy hashinator, this should go away
            return dispatchLoadSinglepartitionTable(catProc, task, handler, ccxn);
        } else if ("@ExecuteTask".equals(procName)) {
            // ExecuteTask is an internal procedure, not for public use.
            return unexpectedFailureResponse("@ExecuteTask is a reserved procedure only for VoltDB internal use", task.clientHandle);
        } else if ("@UpdateLogging".equals(procName)) {
            task = appendAuditParams(task, ccxn, user);
        }
        if (!MiscUtils.isPro()) {
            SystemProcedureCatalog.Config sysProcConfig = SystemProcedureCatalog.listing.get(procName);
            if ((sysProcConfig != null) && (sysProcConfig.commercial)) {
                return new ClientResponseImpl(ClientResponseImpl.GRACEFUL_FAILURE, new VoltTable[0], procName + " is available in the Enterprise Edition of VoltDB only.", task.clientHandle);
            }
        } else if ("@SnapshotSave".equals(procName)) {
            m_snapshotDaemon.requestUserSnapshot(task, ccxn);
            return null;
        } else if ("@SnapshotStatus".equals(procName)) {
            // SnapshotStatus is really through @Statistics now, but preserve the
            // legacy calling mechanism
            Object[] params = new Object[] { "SNAPSHOTSTATUS" };
            task.setParams(params);
            return dispatchStatistics(OpsSelector.STATISTICS, task, ccxn);
        } else if ("@SnapshotScan".equals(procName)) {
            return dispatchStatistics(OpsSelector.SNAPSHOTSCAN, task, ccxn);
        } else if ("@SnapshotDelete".equals(procName)) {
            return dispatchStatistics(OpsSelector.SNAPSHOTDELETE, task, ccxn);
        } else if ("@SnapshotRestore".equals(procName)) {
            ClientResponseImpl retval = SnapshotUtil.transformRestoreParamsToJSON(task);
            if (retval != null) {
                return retval;
            }
            if (m_isInitialRestore.compareAndSet(true, false) && isSchemaEmpty()) {
                m_NTProcedureService.isRestoring = true;
                return useSnapshotCatalogToRestoreSnapshotSchema(task, handler, ccxn, user, bypass);
            }
        } else if ("@Shutdown".equals(procName)) {
            if (task.getParams().size() == 1) {
                return takeShutdownSaveSnapshot(task, handler, ccxn, user, bypass);
            }
        }
        // admin port, otherwise return a failure
        if (("@Pause".equals(procName) || "@Resume".equals(procName) || "@PrepareShutdown".equals(procName)) && !handler.isAdmin()) {
            return unexpectedFailureResponse(procName + " is not available to this client", task.clientHandle);
        }
        // the client is connected to.
        if ("@PrepareShutdown".equals(procName)) {
            String msg = "Admin: " + ccxn.getHostnameAndIPAndPort() + " issued a PrepareShutdown.";
            CoreUtils.PrintGoodLookingLog(hostLog, msg, Level.WARN);
        }
    }
    // If you're going to copy and paste something, CnP the pattern
    // up above.  -rtb.
    int partition = -1;
    try {
        partition = getPartitionForProcedure(catProc, task);
    } catch (Exception e) {
        // unable to hash to a site, return an error
        return getMispartitionedErrorResponse(task, catProc, e);
    }
    boolean success = createTransaction(handler.connectionId(), task, catProc.getReadonly(), catProc.getSinglepartition(), catProc.getEverysite(), partition, task.getSerializedSize(), nowNanos);
    if (!success) {
        // Return an error.
        return new ClientResponseImpl(ClientResponseImpl.SERVER_UNAVAILABLE, new VoltTable[0], "VoltDB failed to create the transaction internally.  It is possible this " + "was caused by a node failure or intentional shutdown. If the cluster recovers, " + "it should be safe to resend the work, as the work was never started.", task.clientHandle);
    }
    return null;
}
Also used : VoltTrace(org.voltdb.utils.VoltTrace) Config(org.voltdb.SystemProcedureCatalog.Config) JSONException(org.json_voltpatches.JSONException) NodeExistsException(org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Procedure(org.voltdb.catalog.Procedure) JSONObject(org.json_voltpatches.JSONObject)

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