Пример #1
0
static bool
scan_table(NdbInfo& ndbinfo, const NdbInfo::Table* table, int &rows)
{
    NdbInfoScanOperation* scanOp = NULL;
    if (ndbinfo.createScanOperation(table, &scanOp))
    {
        g_err << "No NdbInfoScanOperation" << endl;
        return false;
    }

    if (scanOp->readTuples() != 0)
    {
        g_err << "scanOp->readTuples failed" << endl;
        ndbinfo.releaseScanOperation(scanOp);
        return false;
    }

    int columnId = 0;
    while (scanOp->getValue(columnId))
        columnId++;
    // At least one column
    require(columnId >= 1);
    int ret;
    if((ret = scanOp->execute()) != 0)
    {
        g_err << "scanOp->execute failed, ret: " << ret << endl;
        ndbinfo.releaseScanOperation(scanOp);
        return false;
    }

    while((ret = scanOp->nextResult()) == 1)
        rows++;

    ndbinfo.releaseScanOperation(scanOp);

    if (ret != 0)
    {
        g_err << "scanOp->nextResult failed, ret: " << ret << endl;
        return false;
    }

    return true;
}
Пример #2
0
int runTestNdbInfo(NDBT_Context* ctx, NDBT_Step* step)
{
    NdbInfo ndbinfo(&ctx->m_cluster_connection, "ndbinfo/");
    if (!ndbinfo.init())
    {
        g_err << "ndbinfo.init failed" << endl;
        return NDBT_FAILED;
    }

    const NdbInfo::Table* table;
    if (ndbinfo.openTable("ndbinfo/tables", &table) != 0)
    {
        g_err << "Failed to openTable(tables)" << endl;
        return NDBT_FAILED;
    }

    for (int l = 0; l < ctx->getNumLoops(); l++)
    {

        NdbInfoScanOperation* scanOp = NULL;
        if (ndbinfo.createScanOperation(table, &scanOp))
        {
            g_err << "No NdbInfoScanOperation" << endl;
            return NDBT_FAILED;
        }

        if (scanOp->readTuples() != 0)
        {
            g_err << "scanOp->readTuples failed" << endl;
            return NDBT_FAILED;
        }

        const NdbInfoRecAttr* tableName = scanOp->getValue("table_name");
        const NdbInfoRecAttr* comment = scanOp->getValue("comment");

        if(scanOp->execute() != 0)
        {
            g_err << "scanOp->execute failed" << endl;
            return NDBT_FAILED;
        }

        while(scanOp->nextResult() == 1)
        {
            g_info << "NAME: " << tableName->c_str() << endl;
            g_info << "COMMENT: " << comment->c_str() << endl;
        }
        ndbinfo.releaseScanOperation(scanOp);
    }

    ndbinfo.closeTable(table);
    return NDBT_OK;
}
Пример #3
0
bool NdbInfo::load_ndbinfo_tables(void)
{
  DBUG_ENTER("load_ndbinfo_tables");
  assert(m_tables_table && m_columns_table);

  {
    // Create tables by scanning the TABLES table
    NdbInfoScanOperation* scanOp = NULL;
    if (createScanOperation(m_tables_table, &scanOp) != 0)
      DBUG_RETURN(false);

    if (scanOp->readTuples() != 0)
    {
      releaseScanOperation(scanOp);
      DBUG_RETURN(false);
    }

    const NdbInfoRecAttr *tableIdRes = scanOp->getValue("table_id");
    const NdbInfoRecAttr *tableNameRes = scanOp->getValue("table_name");
    if (!tableIdRes || !tableNameRes)
    {
      releaseScanOperation(scanOp);
      DBUG_RETURN(false);
    }

    if (scanOp->execute() != 0)
    {
      releaseScanOperation(scanOp);
      DBUG_RETURN(false);
    }

    int err;
    while ((err = scanOp->nextResult()) == 1)
    {
      Uint32 tableId = tableIdRes->u_32_value();
      const char * tableName = tableNameRes->c_str();
      DBUG_PRINT("info", ("table: '%s', id: %u",
                 tableName, tableId));
      switch (tableId) {
      case 0:
        assert(strcmp(tableName, "tables") == 0);
        break;
      case 1:
        assert(strcmp(tableName, "columns") == 0);
        break;

      default:
        BaseString hash_key = mysql_table_name(tableName);
        if (!m_tables.insert(hash_key.c_str(),
                             Table(tableName, tableId)))
        {
          DBUG_PRINT("error", ("Failed to insert Table('%s', %u)",
                     tableName, tableId));
          releaseScanOperation(scanOp);
          DBUG_RETURN(false);
        }
      }
    }
    releaseScanOperation(scanOp);

   if (err != 0)
      DBUG_RETURN(false);
  }

  {
    // Fill tables with columns by scanning the COLUMNS table
    NdbInfoScanOperation* scanOp = NULL;
    if (createScanOperation(m_columns_table, &scanOp) != 0)
      DBUG_RETURN(false);

    if (scanOp->readTuples() != 0)
    {
      releaseScanOperation(scanOp);
      DBUG_RETURN(false);
    }

    const NdbInfoRecAttr *tableIdRes = scanOp->getValue("table_id");
    const NdbInfoRecAttr *columnIdRes = scanOp->getValue("column_id");
    const NdbInfoRecAttr *columnNameRes = scanOp->getValue("column_name");
    const NdbInfoRecAttr *columnTypeRes = scanOp->getValue("column_type");
    if (!tableIdRes || !columnIdRes || !columnNameRes || !columnTypeRes)
    {
      releaseScanOperation(scanOp);
      DBUG_RETURN(false);
    }
    if (scanOp->execute() != 0)
    {
      releaseScanOperation(scanOp);
      DBUG_RETURN(false);
    }

    int err;
    while ((err = scanOp->nextResult()) == 1)
    {
      Uint32 tableId = tableIdRes->u_32_value();
      Uint32 columnId = columnIdRes->u_32_value();
      const char * columnName = columnNameRes->c_str();
      Uint32 columnType = columnTypeRes->u_32_value();
      DBUG_PRINT("info",
                 ("tableId: %u, columnId: %u, column: '%s', type: %d",
                 tableId, columnId, columnName, columnType));
      switch (tableId) {
      case 0:
      case 1:
        // Ignore columns for TABLES and COLUMNS tables since
        // those are already known(hardcoded)
        break;

      default:
      {
        Column::Type type;
        switch(columnType)
        {
        case 1:
          type = Column::String;
          break;
        case 2:
          type = Column::Number;
          break;
        case 3:
          type = Column::Number64;
          break;
        default:
        {
          DBUG_PRINT("error", ("Unknown columntype: %d", columnType));
          releaseScanOperation(scanOp);
          DBUG_RETURN(false);
        }
        }

        Column column(columnName, columnId, type);

        // Find the table with given id

        if (!addColumn(tableId, column))
        {
          DBUG_PRINT("error", ("Failed to add column for %d, %d, '%s', %d)",
                     tableId, columnId, columnName, columnType));
          releaseScanOperation(scanOp);
          DBUG_RETURN(false);
        }
        break;
      }
      }
    }
    releaseScanOperation(scanOp);

    if (err != 0)
      DBUG_RETURN(false);
  }
  DBUG_RETURN(true);
}
Пример #4
0
int runTestTable(NDBT_Context* ctx, NDBT_Step* step)
{
    NdbInfo ndbinfo(&ctx->m_cluster_connection, "ndbinfo/");
    if (!ndbinfo.init())
    {
        g_err << "ndbinfo.init failed" << endl;
        return NDBT_FAILED;
    }

    const NdbInfo::Table* table;
    if (ndbinfo.openTable("ndbinfo/test", &table) != 0)
    {
        g_err << "Failed to openTable(test)" << endl;
        return NDBT_FAILED;
    }

    for (int l = 0; l < ctx->getNumLoops(); l++)
    {

        NdbInfoScanOperation* scanOp = NULL;
        if (ndbinfo.createScanOperation(table, &scanOp))
        {
            ndbinfo.closeTable(table);
            g_err << "No NdbInfoScanOperation" << endl;
            return NDBT_FAILED;
        }

        if (scanOp->readTuples() != 0)
        {
            ndbinfo.releaseScanOperation(scanOp);
            ndbinfo.closeTable(table);
            g_err << "scanOp->readTuples failed" << endl;
            return NDBT_FAILED;
        }

        const NdbInfoRecAttr* nodeId= scanOp->getValue("node_id");
        const NdbInfoRecAttr* blockNumber= scanOp->getValue("block_number");
        const NdbInfoRecAttr* blockInstance= scanOp->getValue("block_instance");
        const NdbInfoRecAttr* counter= scanOp->getValue("counter");
        const NdbInfoRecAttr* counter2= scanOp->getValue("counter2");

        if(scanOp->execute() != 0)
        {
            ndbinfo.releaseScanOperation(scanOp);
            ndbinfo.closeTable(table);
            g_err << "scanOp->execute failed" << endl;
            return NDBT_FAILED;
        }

        int ret;
        int rows = 0;
        while((ret = scanOp->nextResult()) == 1)
        {
            rows++;
            (void)nodeId->u_32_value();
            (void)blockNumber->u_32_value();
            (void)blockInstance->u_32_value();
            (void)counter->u_32_value();
            (void)counter2->u_64_value();
        }
        ndbinfo.releaseScanOperation(scanOp);
        if (ret != 0)
        {
            ndbinfo.closeTable(table);
            g_err << "scan failed, ret: " << ret << endl;
            return NDBT_FAILED;
        }
        ndbout << "rows: " << rows << endl;

    }

    ndbinfo.closeTable(table);
    return NDBT_OK;
}
Пример #5
0
int runRatelimit(NDBT_Context* ctx, NDBT_Step* step)
{
    NdbInfo ndbinfo(&ctx->m_cluster_connection, "ndbinfo/");
    if (!ndbinfo.init())
    {
        g_err << "ndbinfo.init failed" << endl;
        return NDBT_FAILED;
    }

    Uint32 tableId = 0;
    while(true) {

        const NdbInfo::Table* table;

        int err = ndbinfo.openTable(tableId, &table);
        if (err == NdbInfo::ERR_NoSuchTable)
        {
            // No more tables -> return
            return NDBT_OK;
        }
        else if (err != 0)
        {
            // Unexpected return code
            g_err << "Failed to openTable(" << tableId << "), err: " << err << endl;
            return NDBT_FAILED;
        }
        ndbout << "table: " << table->getName() << endl;


        struct {
            Uint32 rows;
            Uint32 bytes;
        } limits[] = {
            { 0, 0 },
            { 1, 0 }, { 2, 0 }, { 10, 0 }, { 37, 0 }, { 1000, 0 },
            { 0, 1 }, { 0, 2 }, { 0, 10 }, { 0, 37 }, { 0, 1000 },
            { 1, 1 }, { 2, 2 }, { 10, 10 }, { 37, 37 }, { 1000, 1000 }
        };

        int lastRows = 0;
        for (int l = 0; l < (int)(sizeof(limits)/sizeof(limits[0])); l++)
        {

            Uint32 maxRows = limits[l].rows;
            Uint32 maxBytes = limits[l].bytes;

            NdbInfoScanOperation* scanOp = NULL;
            if (ndbinfo.createScanOperation(table, &scanOp, maxRows, maxBytes))
            {
                g_err << "No NdbInfoScanOperation" << endl;
                return NDBT_FAILED;
            }

            if (scanOp->readTuples() != 0)
            {
                g_err << "scanOp->readTuples failed" << endl;
                return NDBT_FAILED;
            }

            int columnId = 0;
            while (scanOp->getValue(columnId))
                columnId++;
            // At least one column
            require(columnId >= 1);

            if(scanOp->execute() != 0)
            {
                g_err << "scanOp->execute failed" << endl;
                return NDBT_FAILED;
            }

            int row = 0;
            while(scanOp->nextResult() == 1)
                row++;
            ndbinfo.releaseScanOperation(scanOp);

            ndbout_c("[%u,%u] rows: %d", maxRows, maxBytes, row);
            if (lastRows != 0)
            {
                // Check that the number of rows is same as last round on same table
                if (lastRows != row)
                {
                    g_err << "Got different number of rows this round, expected: "
                          << lastRows << ", got: " << row << endl;
                    ndbinfo.closeTable(table);
                    return NDBT_FAILED;
                }
            }
            lastRows = row;
        }
        ndbinfo.closeTable(table);
        tableId++;
    }

    // Should never come here
    require(false);
    return NDBT_FAILED;
}
Пример #6
0
int runScanStop(NDBT_Context* ctx, NDBT_Step* step)
{
    NdbInfo ndbinfo(&ctx->m_cluster_connection, "ndbinfo/");
    if (!ndbinfo.init())
    {
        g_err << "ndbinfo.init failed" << endl;
        return NDBT_FAILED;
    }

    Uint32 tableId = 0;
    while(true) {
        const NdbInfo::Table* table;

        int err = ndbinfo.openTable(tableId, &table);
        if (err == NdbInfo::ERR_NoSuchTable)
        {
            // No more tables -> return
            return NDBT_OK;
        }
        else if (err != 0)
        {
            // Unexpected return code
            g_err << "Failed to openTable(" << tableId << "), err: " << err << endl;
            return NDBT_FAILED;
        }
        ndbout << "table: " << table->getName() << endl;

        for (int l = 0; l < ctx->getNumLoops()*10; l++)
        {
            NdbInfoScanOperation* scanOp = NULL;
            if (ndbinfo.createScanOperation(table, &scanOp))
            {
                g_err << "No NdbInfoScanOperation" << endl;
                return NDBT_FAILED;
            }

            if (scanOp->readTuples() != 0)
            {
                g_err << "scanOp->readTuples failed" << endl;
                return NDBT_FAILED;
            }

            int columnId = 0;
            while (scanOp->getValue(columnId))
                columnId++;
            // At least one column
            require(columnId >= 1);

            if(scanOp->execute() != 0)
            {
                g_err << "scanOp->execute failed" << endl;
                return NDBT_FAILED;
            }

            int stopRow = rand() % 100;
            int row = 0;
            while(scanOp->nextResult() == 1)
            {
                row++;
                if (row == stopRow)
                {
                    ndbout_c("Aborting scan at row %d", stopRow);
                    break;
                }
            }
            ndbinfo.releaseScanOperation(scanOp);
        }
        ndbinfo.closeTable(table);
        tableId++;
    }

    // Should never come here
    require(false);
    return NDBT_FAILED;
}