mco_db_extend_t

Extend database memory within a transaction.

Prototype

        MCO_RET mco_db_extend_t(/*IN*/ mco_trans_h t,
                       /*IN*/ void *mem,
                       /*IN*/ uint4 size);

Arguments

t
The current transaction handle.
mem
The starting address of a block of memory.
size
The size, in bytes, of the block of memory.

Description

This function extends the amount of memory used by the database. Note that whereas mco db extend () must be called outside any transaction, mco_db_extend_t() must be called with a READ_WRITE transaction. Typically it is used when a database write operation fails due to low memory.

Return Codes

MCO_S_OK
The database memory was extended successfully.
MCO_E_NOINSTANCE
The specified database is not opened.
MCO_ERR_TRN
A database transaction error occurred. (e.g., the database is already opened by some other thread that has an open transaction.)
MCO_E_ILLEGAL_PARAM
The device size is too small. The minimum size is runtime configuration- and hardware architecture-dependent. On an x64 platform and configured for 100 connections (default) the minimum size is a little over 1K (1104 bytes).

Example

        const char *dbname = "SimpleDb";

        int main(int argc, char* argv[])
        {
            mco_db_h db;
            MCO_RET rc;
            char *mem = malloc(DBSIZE);
            ...

            if ((rc = mco_runtime_start()) != MCO_S_OK)
                exit(-1);

            rc = mco_db_open(dbname, simpledb_get_dictionary(), mem, DBSIZE, (uint2)PAGESIZE);
            ...
            rc = mco_db_connect(dbname, &db);
            ...

            /* If low memory situation detected (see "Auxiliary APIs: Statistics") */
            mco_db_free_pages(db, &freepages);
            mco_db_total_pages(db, &totalpages);
            if (freepages < totalpages / 10)
            {
                // yes. Extend the database
                char *mem2 = malloc(SECOND_SEGSZ);
                if (mem2)
                {
                    rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
                    rc = mco_db_extend_t(t, mem2, SECOND_SEGSZ);

                    if (MCO_S_OK != rc)
                        mco_trans_rollback();
                    else
                        mco_trans_commit();
                    ...
                }
            }
        }

Files

Header file:
mco.h
Source file:
mcodb.c
Library:
libmcolib.a