c-core/24_core/core24Example_main.c
/*
 * Raima Database Manager
 *
 * Copyright (c) 2019 Raima Inc.,  All rights reserved.
 *
 * Use of this software, whether in source code format, or in executable,
 * binary object code form, is governed by the Raima LICENSE which
 * is fully described in the LICENSE.TXT file, included within this
 * distribution of files.
 */
 
#include <stdio.h>
#include "example_fcns.h"
#include "rdm.h"
#include "rdmstartupapi.h"
 
/* Generated \c struct and \c typedef definitions to be used with the RDM APIs
 */
#include "core24_structs.h"
 
/* Generated catalog definition to be used with the RDM rdm_dbSetCatalog() API
 */
#include "core24_cat.h"
 
const char *const description =
    "Performance Test (inmemory): comparing transaction sizes";
const RDM_CMDLINE_OPT opts[] = {{NULL, NULL, NULL, NULL}};
 
#define NUM_RECORDS 50000
 
RDM_RETCODE delete_records (
    RDM_DB hDB) 
{
    RDM_RETCODE rc;
 
    rc = rdm_dbStartUpdate (hDB, RDM_LOCK_ALL, 0, NULL, 0, NULL);
    print_error (rc);
    if (rc == sOKAY)
    {
        /* empty the table */
        rc = rdm_dbDeleteAllRowsFromTable (hDB, TABLE_SIMPLE);
        print_error (rc);
        rdm_dbEnd (hDB);
    }
    return rc;
}
 
RDM_RETCODE add_records (
    unsigned int trans_size, 
    RDM_DB hDB)              
{
    RDM_RETCODE rc = sOKAY;
    SIMPLE simple_rec = {0};
    perfTimer_t timer;
    unsigned int count = 0;
    unsigned int ii;
 
    printf (
        "Add %d records with %-5d per transaction:\t", NUM_RECORDS, trans_size);
 
    timeMeasureBegin (&timer);
 
    /* Loop to add 50,000 new simple record */
    for (ii = 0, count = 0; ii < NUM_RECORDS && rc == sOKAY; ii++)
    {
        if (count == 0)
        {
            /* Start an update transaction and lock the table */
            rc = rdm_dbStartUpdate (hDB, RDM_LOCK_ALL, 0, NULL, 0, NULL);
            print_error (rc);
        }
 
        if (rc == sOKAY)
        {
            /* Set values for the new record */
            simple_rec.int_col = 1;
 
            /* Add the record to the database */
            rc = rdm_dbInsertRow (
                hDB, TABLE_SIMPLE, &simple_rec, sizeof (simple_rec), NULL);
            print_error (rc);
        }
 
        if (rc == sOKAY)
        {
            /* Is it time to commit the transaction? */
            if (++count == trans_size)
            {
                rc = rdm_dbEnd (hDB);
                print_error (rc);
                count = 0;
            }
        }
    }
    timeMeasureEnd (&timer);
 
    printf ("%u milliseconds\n", timeMeasureDiff (&timer));
 
    return rc;
}
 
int main_core24 (int argc, const char *const *argv)
{
    RDM_DB hDB;
    RDM_TFS hTFS;
    RDM_RETCODE rc;
    unsigned int trans_size[] = {50000, 10000, 5000, 1000, 500, 100};
 
    rc = rdm_cmdlineInit (&cmd, argc, argv, description, opts);
    if (rc != sCMD_USAGE)
        print_error (rc);
 
    if (rc == sOKAY)
    {
        /* Initialize the TFS, task, and open/initialize the database */
        rc = exampleOpenEmptyDatabaseInMemory (
            &hTFS, &hDB, "core24", core24_cat);
        if (rc == sOKAY)
        {
            int ii;
            for (ii = 0; rc == sOKAY && ii < RLEN (trans_size); ii++)
            {
                /* delete all records before testing insert */
                rc = delete_records (hDB);
 
                if (rc == sOKAY)
                {
                    /* Add records to the database */
                    rc = add_records (trans_size[ii], hDB);
                }
            }
            exampleCleanup (hTFS, hDB);
        }
    }
    return (int) rc;
}
Header for the native RDM Runtime API.
RDM_RETCODE rdm_dbEnd(RDM_DB db)
End a transactional operation.
@ sCMD_USAGE
Definition: rdmretcodetypes.h:71
The buffer used by the command line parser to hold state information.
Definition: rdmcmdlinetypes.h:85
@ sOKAY
Definition: rdmretcodetypes.h:95
Generic usage function option record.
Definition: rdmcmdlinetypes.h:32
#define RDM_STARTUP_EXAMPLE(name)
Definition: rdmstartuptypes.h:73
RDM_RETCODE rdm_dbInsertRow(RDM_DB db, RDM_TABLE_ID tableId, const void *colValues, size_t bytesIn, RDM_CURSOR *pCursor)
Insert a new row into a table at the specified rowId.
struct RDM_TFS_S * RDM_TFS
RDM TFS Handle.
Definition: rdmtfstypes.h:21
RDM_RETCODE rdm_cmdlineInit(RDM_CMDLINE *cmd, int32_t argc, const char *const argv[], const char *description, const RDM_CMDLINE_OPT *opts)
Initialize an RDM_CMDLINE buffer and validate the command line.
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:303
#define RDM_LOCK_ALL
Definition: rdmtypes.h:170
RDM_RETCODE rdm_dbStartUpdate(RDM_DB db, const RDM_TABLE_ID *writeTableIds, uint32_t numWriteTableIds, const RDM_TABLE_ID *readTableIds, uint32_t numReadTableIds, RDM_TRANS *pTrans)
Get write locks.
RDM_RETCODE rdm_dbDeleteAllRowsFromTable(RDM_DB db, RDM_TABLE_ID tableId)
Remove all rows from a table.
Internal RDM Startup API used by startup macros.
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:43