IBM Books

Administering Satellites Guide and Reference


Using DB2 APIs

Refer to the Application Building Guide for general information about building DB2 applications. Specifically, refer to the information that applies to building applications for Windows 32-bit operating systems. In addition, you should familiarize yourself with the information that applies to using the DB2 C/C++ APIs. The APIs that are used for synchronizing are provided in C only.

Each DB2 SDK includes sample programs that call DB2 APIs. The sample programs for Windows 32-bit operating systems are in the %DB2PATH%\samples\cli directory. You can build these sample programs for the Microsoft Visual C++ and IBM VisualAge C++ for Windows compilers using the DB2 API build files that are supplied with the DB2 SDK. You can also use the makefiles that are supplied. Both the makefiles and the build files show you the compiler options that you can use. These options are defined for each platform's supported compilers. You may need to modify the options for your environment. Refer to the Application Building Guide for information.

After you build the sample programs, you can use them as templates for creating your own applications.

Satellite APIs

The following sections describe the satellite APIs that you can use to set up and test the satellite environment, and to synchronize a satellite. For the full list of available APIs, refer to the Administrative API Reference.

Setting the Application Version on the Satellite

Before a satellite can synchronize with its DB2 control server, two attributes of the satellite's environment must be configured: the unique satellite ID, and the application version. You do not use an API to set the satellite ID. Instead, you use the db2set command to set the value of the DB2SATELLITEID registry variable, or you use the logon ID of the satellite user as the satellite ID. See Setting the DB2SATELLITEID Registry Variable for information on setting the satellite ID.

You can use the db2SetSyncSession API to set the value of the application version on the satellite:

  SQL_API_RC SQL_API_FN                  /* Set sync session for a satellite    */
    db2SetSyncSession (
     db2Uint32 versionNumber,            /* Database version number             */
     void * pParmStruct,                 /* Input parameters                    */
     struct sqlca * pSqlca);             /* SQLCA                               */
Note:The application version is case sensitive.

The maximum length of an application version is:

  #define SQL_SYNCSESSIONID_SZ 18

When you set the application version for a satellite, use the following structure for the pParmStruct to define the string:

  typedef struct db2SetSyncSessionStruct
  {
     char            *piSyncSessionID;   /* ID for sync session                 */
  } db2SetSyncSessionStruct;

If you supply an empty string for piSyncSessionID, you will reset the satellite's application version to NULL.

When setting the application version, the most common return codes are:

Retrieving the Application Version

You can use the db2GetSyncSession API to query the value of the application version on the satellite:

  SQL_API_RC SQL_API_FN                  /* Get sync session ID for a           */
                                         /* satellite                           */
    db2GetSyncSession (
     db2Uint32 versionNumber,            /* Database version number             */
     void * pParmStruct,                 /* Output parameters                   */
     struct sqlca * pSqlca);             /* SQLCA                               */

When you retrieve the current application version for a satellite, supply the following structure for the pParmStruct to retrieve the value:

  typedef struct db2GetSyncSessionStruct
  {
     char            *poSyncSessionID;   /* ID for sync session                 */
  } db2GetSyncSessionStruct;

You must supply a buffer at least as large as SQL_SYNCSESSIONID_SZ (+1 for the NULL terminator) to receive the application version.

When retrieving the application version, the most common return codes are:

Testing the Satellite Environment

You can test the ability of a satellite to synchronize with its DB2 control server by executing the db2SyncSatelliteTest API on the satellite:

  SQL_API_RC SQL_API_FN                  /* Test Satellite's ability to         */
                                         /* synchronize                         */
    db2SyncSatelliteTest (
     db2Uint32 versionNumber,            /* Database version number             */
     void * pParmStruct,                 /* Input/Output parameters              */
     struct sqlca * pSqlca);             /* SQLCA                               */

Because the satellite ID and application version are retrieved from the satellite environment, no parameter structure (pParmStruct) is required.

This API validates the following required configuration elements, which are necessary for synchronization to occur:

When testing the satellite environment, the most common return codes are:

Synchronizing a Satellite

Figure 6 shows the events that can occur when a satellite is synchronized, including the APIs that can be called from the synchronizing application. Specifically:

  1. The db2SyncSatellite API is invoked, which starts the synchronization session. This API does not return until the session completes.
  2. The db2QuerySatelliteProgress API is invoked, which returns information about the progress of the synchronization session. This API can be invoked more than once to return progress information. Invoke this API on another thread or process.
  3. The db2SyncSatellite API returns when the synchronization session ends. The API can return normally, or the db2SyncSatelliteStop API can be invoked (on another thread or process) during a synchronization session to interrupt the session. When invoked, the db2SyncSatelliteStop API issues a STOP request to the db2SyncSatellite API. The db2SyncSatellite API, however, does not return until it completes executing the current step of the synchronization process.

Figure 6. Synchronization Time Line


sattimel

The sections that follow described the APIs that you can use to cause these events. For additional information about these APIs, and other satellite-related APIs that are not described in this book, refer to the Administrative API Reference.

Initiating a Synchronization Session

To initiate the synchronization session, use the db2SyncSatellite API:

  SQL_API_RC SQL_API_FN                  /* Synchronize Satellite               */
    db2SyncSatellite (
     db2Uint32 versionNumber,            /* Database version number             */
     void * pParmStruct,                 /* Input/Output parameters              */
     struct sqlca * pSqlca);             /* SQLCA                               */

You must invoke the db2SyncSatellite API from the context of the satellite's instance (the same as a synchronization test). This API does not return until the synchronization session ends, successfully or otherwise.

Only one synchronization session can be active on the satellite at a time. If this API is invoked and a synchronization session is currently active on the satellite, the following SQLCODE is issued:

  SQL3950N A synchronization session is active. 
  At most one synchronization session can be active.

When this API ends successfully, the following SQLCODE is issued:

  SQL3910I Synchronization session completed successfully.

Querying the Progress of a Synchronization Session

Use the db2QuerySatelliteProgress API to return information about the progress of an active synchronization session:

  SQL_API_RC SQL_API_FN                  /* Query Satellite Progress            */
    db2QuerySatelliteProgress (
     db2Uint32 versionNumber,            /* Database version number             */
     void * pParmStruct,                 /* Output parameters                    */
     struct sqlca * pSqlca);             /* SQLCA                               */

If the db2QuerySatelliteProgress API successfully returns the progress information, the following SQLCODE is issued:

  SQL3918I Synchronization progress information was obtained successfully.

If a synchronization session is not active when the API is invoked, the following SQLCODE is issued:

  SQL3936W No progress information is available.

You must supply the following output parameters for the pParmStruct parameter structure:

  typedef struct db2QuerySatelliteProgressStruct
  {
     db2int32        oStep;              /* current step of synchronization     */
     db2int32        oSubstep;           /* substep of the current step         */
     db2int32        oNumSubsteps;       /* total number of substeps            */
     db2int32        oScriptStep;        /* step of current script substep      */
     db2int32        oNumScriptSteps;    /* total number of script steps        */
     char            *poDescription;     /* description of step                 */
     char            *poError;           /* error text, if available            */
     char            *poProgressLog;     /* contents of progress log            */
  } db2QuerySatelliteProgressStruct;

Where:

oStep
Output. The current phase of the synchronization session (defined in db2ApiDf.h). For example, sync initiated or downloading batch steps.

oSubstep
Output. If the synchronization step (oStep) can be broken down into substeps, this will be the current substep. Typically, the substep is the execution of a batch step.

oNumSubsteps
Output. If there exists a substep (oSubstep) for the current step of the synchronization session, this will be the total number of substeps (or batch steps) that comprise the synchronization session. Typically, oNumSubsteps is the total number of batch steps.

oScriptStep
Output. If the current substep is the execution of a batch step, this parameter reports on the progress of the script execution, if available. For example, if DB2 data replication is invoked as a batch step, the replication will report its own process.

oNumScriptSteps
Output. If a script step is reported, this parameter contains the total number of steps that comprise the script's execution.

poDescription
Output. A description of the state of the current phase of the satellite's synchronization session.

poError
Output. If the synchronization session is in error, a description of the error is passed by this parameter.

poProgressLog
Output. The entire log of the satellite's synchronization session is returned by this parameter.

Stopping a Synchronization Session

You can use the db2SyncSatelliteStop API to interrupt an active synchronization session:

  SQL_API_RC SQL_API_FN                  /* Stop Satellite's Synchronization    */
                                         /* Session                             */
    db2SyncSatelliteStop (
     db2Uint32 versionNumber,            /* Database version number             */
     void * pParmStruct,                 /* Input/Output parameters              */
     struct sqlca * pSqlca);             /* SQLCA                               */

The db2SyncSatelliteStop API issues an asynchronous STOP request to the synchronization session. That is, the API returns immediately after it issues the STOP request, and not after the synchronization session stops. If a synchronization session is active and the STOP request is issued successfully, the following SQLCODE is issued:

  SQL3912I STOP completed successfully.

If no synchronization session is active when the API is invoked, the following SQLCODE is issued:

  SQL3913I STOP issued, but no synchronization session is currently active.

The db2SyncSatellite API only returns as a result of the interrupt when it has reached an appropriately safe point in the session. That is, a STOP request is not necessarily executed as soon as it is received. Instead, the db2SyncSatellite API finishes executing the current step in the synchronization process before exiting. For example, if the db2SyncSatelliteStop API is issued while the db2SyncSatellite API is executing a script, the db2SyncSatellite API completes executing the script before stopping. As another example, if the db2SyncSatellite API is interrupted before the satellite can upload the results of the synchronization session to the DB2 control server, the API issues the following SQLCODE:

  SQL3917I A STOP request was received before the results were uploaded to the 
  satellite control server. 
  The results will be uploaded during the next synchronization session.

The next time db2SyncSatellite is invoked, the synchronization session resumes where it stopped.

Because the db2SyncSatellite API does not return until the synchronization session completes, and the db2SyncSatelliteStop is asynchronous, you must execute these two APIs on different threads or processes.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ Top of Page ]