int write(const int64_t idx) {
   int err = OB_SUCCESS;
   UNUSED(idx);
   while(!stop_ && OB_SUCCESS == err)
   {
     err = write_rows();
   }
   return err;
 }
示例#2
0
rc_t open (param_block * pb)
{
    rc_t rc;

    rc = KDirectoryNativeDir (&pb->pwd);
    if (rc)
        LOGERR (klogFatal, rc, "Failed to open file system");
    else
    {
        rc = KDirectoryOpenFileRead (pb->pwd, &pb->file, "%s", pb->file_path);
        if (rc)
            LOGERR (klogFatal, rc, "Failed to open input file");
        else
        {
            rc = KMMapMakeRead (&pb->mmap, pb->file);
            if (rc)
                LOGERR (klogFatal, rc, "unable to map file");
            else
            {
                rc = VDBManagerMakeUpdate (&pb->mgr, pb->pwd);
                if (rc)
                    LOGERR (klogFatal, rc, "Failed to open DB Manager");
                else
                {
                    rc = VDBManagerMakeSchema (pb->mgr, &pb->schema);
                    if (rc)
                        LOGERR (klogFatal, rc, "Failed to create a schema object");
                    else
                    {
                        VSchemaAddIncludePath (pb->schema, "interfaces");

                        rc = VSchemaParseFile (pb->schema, "%s", pb->schema_path);
                        if (rc)
                            LOGERR (klogFatal, rc, "Failed to parse schema");
                        else
                        {
                            rc = VDBManagerCreateTable (pb->mgr, &pb->table, pb->schema,
                                                        TYPESPEC, kcmCreate, "%s", pb->table_path);
                            if (rc)
                                LOGERR (klogFatal, rc, "Failed to create table");
                            else
                            {
                                rc = VTableCreateCursorWrite (pb->table, &pb->cursor, kcmCreate);
                                if (rc)
                                    LOGERR (klogFatal, rc, "Failed to create cursor");
                                else
                                {
                                    rc = VCursorAddColumn (pb->cursor, &pb->idx, "READ");
                                    if (rc)
                                        LOGERR (klogFatal, rc, "Failed to add READ to cursor");
                                    else
                                    {
                                        rc = VCursorOpen (pb->cursor);
                                        if (rc)
                                            LOGERR (klogFatal, rc, "Failed to open cursor");
                                        else
                                        {
                                            rc = write_rows (pb);
                                            if (rc == 0)
                                                VCursorCommit (pb->cursor);
                                        }
                                    }
                                    VCursorRelease (pb->cursor);
                                }
                                VTableRelease (pb->table);
                            }
                        }
                        VSchemaRelease (pb->schema);
                    }
                    VDBManagerRelease (pb->mgr);
                }
                KMMapRelease (pb->mmap);
            }
            KFileRelease (pb->file);
        }
        KDirectoryRelease (pb->pwd);
    }
    return rc;
}
int main(int argc, const char** argv) {
    ndb_init();

    int operationType = 0;
    int tupTest = 0;
    int scanTest = 0;

    Ndb* pNdb = new Ndb("TEST_DB");
    pNdb->init();

    if (argc != 4  ||  sscanf(argv[1],"%d", &operationType) != 1) {
        operationType = 1 ;
    }
    if (argc != 4  ||  sscanf(argv[2],"%d", &tupTest) != 1) {
        tupTest = 1 ;
    }
    if (argc != 4  ||  sscanf(argv[3],"%d", &scanTest) != 1) {
        scanTest = 1 ;
    }

    ndbout << endl
           << "Test the interpreter in TUP using SimpleTable with\n"
           << nRecords << " records" << endl << endl ;

    if (pNdb->waitUntilReady(30) != 0) {
        ndbout << "NDB is not ready" << endl;
        return -1;
    }

    // Init the pk and attr values.
    for (int i = 0; i < NUMBEROFRECORDS; i ++)
        pkValue[i] = attrValue[i] = i ;

    setAttrNames() ;
    setTableNames() ;

    const void * p = NDBT_Table::discoverTableFromDb(pNdb, tableName);
    if (p != 0) {
        create_table(pNdb);
    }

    write_rows(pNdb);

    ndbout << endl << "Starting interpreter in TUP test." << endl << "Operation type: " ;

    switch(operationType) {
    case 1:
        ndbout << "openScanRead" << endl;
        scan_rows(pNdb,  operationType,  tupTest,  scanTest);
        break;
    case 2:
        ndbout << "openScanExclusive" << endl;
        scan_rows(pNdb,  operationType,  tupTest,  scanTest);
        break;
    case 3:
        ndbout << "interpretedUpdateTuple" << endl;
        update_rows(pNdb,  tupTest,  operationType);
        break;
    case 4:
        ndbout << "interpretedDirtyUpdate" << endl;
        update_rows(pNdb,  tupTest,  operationType);
        break;
    case 5:
        ndbout << "interpretedDeleteTuple" << endl;
        delete_rows(pNdb,  tupTest,  operationType);
        break;
    case 6:
        ndbout << "deleteTuple" << endl;
        break;
    case 7:
        ndbout << "insertTuple" << endl;
        break;
    case 8:
        ndbout << "updateTuple" << endl;
        break;
    case 9:
        ndbout << "writeTuple" << endl;
        break;
    case 10:
        ndbout << "readTuple" << endl;
        break;
    case 11:
        ndbout << "readTupleExclusive" << endl;
        break;
    case 12:
        ndbout << "simpleRead" << endl;
        break;
    case 13:
        ndbout << "dirtyRead" << endl;
        break;
    case 14:
        ndbout << "dirtyUpdate" << endl;
        break;
    case 15:
        ndbout << "dirtyWrite" << endl;
        break;
    default:
        break ;

    }

//  read_and_verify_rows(pNdb, false);

//  delete_rows(pNdb, 0, 0) ;
    delete pNdb ;

    if (bTestPassed == 0) {
        ndbout << "OK: test passed" << endl;
        exit(0);
    } else {
        ndbout << "FAIL: test failed" << endl;
        exit(-1);
    }
}