Author Topic: Tablespace Creation exit Routines  (Read 6563 times)

gopikrishna

  • Guest
Tablespace Creation exit Routines
« on: December 19, 2011, 12:23:40 PM »
Please can any one of you provide the samples codes and documentation for TableSpace exits.

Below are the steps we followed and also let us know if we miss anything from our end. We need a sample file and how to use to create  exists.

We have gone throught the below URL which have been provided by IBM     
CMOD support                                                           
http://publib.boulder.ibm.com/infocenter/cmod/v8r5m0/index.jsp?topic=% 
2Fcom.ibm.ondemand.installingmp.doc%2Fars1i071694.htm                   
                                                                       
Steps we are following:-                                               
1. we have gone through the C file "ARSUTBL.c" sample program which     
contains a sample table space creation exit in C and In this file there
is a function called "TBLSPCRT" having some set of parameters.         
TBLSPCRT Function :-                                                   
int TBLSPCRT( ArcCSXitApplGroup *appl_grp,                             
              char tblsp_name,                                         
              char table_name,                                         
              char idx_name,                                           
              char sql,                                                 
              int  action,                                             
              int  created                                             
            )                                                           
2. Modifying the copy "/usr/lpp/ars/exits/arsutbl.c" with "Sample.c"   
3. Passing the application group to "TBLSPCRT" function and planning to
place in the below path "/usr/lpp/ars/exits/Sample.c"                   
                                                                       
All the above steps we are followed but we have some of the queries :- 
1. CMOD passes all the input parameters to the user exit by itself to   
the given function "TBLSPCRT" Or where does the tablespace user exit   
gets the input parameters from?                                         
2. Once we change the our own Sample.C file and copy in the location   
"/usr/lpp/ars/exits/Sample.c" how to comple the code and generate the   
exe file to configure in the ars.cfg file.                             
3. Can we update the "/usr/lpp/ars/config/ars.cfg" to contain           
"ARS_DB_TABLESPACE_USEREXIT=absoulte path name of the exe file         
generated"?                                                             
4. If we update the ars.cfg file what further step we need to follow to
see the TableSpace User exit created on specified Application Group in 
the CMOD server.                                                       
                                                                       
Version Info:-                                                         
CMOD - 8.4.1.3                                                         
DB2 - 9.5.0.7                                                           
AIX - 5.3.0.0                                                           
                                                                       
Thanks                                                                 
Gopi                                                                   

pankaj.puranik

  • Sr. Member
  • ****
  • Posts: 374
    • View Profile
Re: Tablespace Creation exit Routines
« Reply #1 on: December 19, 2011, 11:09:28 PM »
Hi Gopi

For point number 2 below, you need to compile the .c file using some C compiler and place it in the respective directory.

Cheers
Pankaj.

Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: Tablespace Creation exit Routines
« Reply #2 on: December 21, 2011, 07:43:22 AM »
Hello Gopi,

Why do you want to use userexits for Tablespace?

I'm asking, because I have a customer, that use Oracle, and for some unknown reasons for me (except that Oracle DBA are strange people...) they insisted to have the oracle DB outside from CMOD server.

This is something we normally don't do, CMOD and DB should be in the same server for performance and also for maintenance point of view.

Why am I explaning that? CMOD will automatically create for you tablespace, tables, indexes. Remove them if needed.
Everything would be automatically done for you.

By starting to use the user exit for tablespace, you will need to do everything the CMOD does for you automatically, manually...
Instead of helping you, it would be your role to ensure that what you do will work with CMOD.
Of course, if you play too much then CMOD works in a strange way... then you might be out of luck with IBM support, depending on what you have done...

My advice, open a PMR with IBM Support and ask them if what you want to do is ok with the CMOD philosophy, otherwise you might have a problem when the CMOD developpers wants to change something, and then what you did, just break in the new versions...

Starting with CMOD 8.5.0.3, you have an extension of this user exits, that allows you also to catch all the "alter/drop tablespace/tables/indexes" that CMOD might want to do from time to time... Before 8.5.0.3 it was not possible... only the create one were ok.

The documentation in the .h header is quite clear:

Code: [Select]
/**********************************************************************/
/* TBLSPCRT - Tablespace Create Exit                                  */
/*                                                                    */
/*  To activate the tablespace creation exit, set the following       */
/*  variable in the appropriate OnDemand instance ars.cfg file:       */
/*                                                                    */
/*    ARS_DB_TABLESPACE_USEREXIT=<absolute_dll_path_name>             */
/*                                                                    */
/* INPUT: appl_grp                                                    */
/*        tblsp_name                                                  */
/*        table_name                                                  */
/*        idx_name                                                    */
/*        sql (allocated with 16384 bytes)                            */
/*        action                                                      */
/*        instance                                                    */
/*                                                                    */
/* OUTPUT:                                                            */
/*                                                                    */
/*        1) OnDemand will invoke the exit with action == 1           */
/*           so that the exit can create the tablespace (tblsp_name)  */
/*           using (sql)                                              */
/*            *created  -> 0 exit did not create the tablespace,      */
/*                           OnDemand needs to create the tablespace  */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit created the tablespace              */
/*                                                                    */
/*        2) OnDemand will then invoke the exit with action == 2      */
/*           so that the exit can create the table (table_name)       */
/*           inside of the tablespace (tblsp_name) using (sql)        */
/*            *created  -> 0 exit did not create the table,           */
/*                           OnDemand needs to create the table       */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit created the table                   */
/*                                                                    */
/*        3) OnDemand will then invoke the exit with action == 3      */
/*           so that the exit can create the table indexes (idx_name) */
/*           inside of the tablespace (tblsp_name) for table          */
/*           (table_name) using (sql).  This will be invoked based    */
/*           inside of the tablespace (tblsp_name) for table          */
/*           (table_name) using (sql).  This will be invoked based    */
/*           on the number of indexes to create for the appl_grp      */
/*            *created  -> 0 exit did not create the index,           */
/*                           OnDemand needs to create the index       */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit created the index                   */
/*                                                                    */
/*        4) OnDemand will then invoke the exit with action == 4      */
/*           so that the exit can perform any additional work         */
/*            *created  -> Is not used                                */
/*            sql       -> If sql is not an empty string, OnDemand    */
/*                         will issue (sql) to the database           */
/*                                                                    */
/*        If ARS_DB_TABLESPACE_USEREXIT_EXTRA=1 is defined in         */
/*        ars.cfg, then the following actions will also be invoked    */
/*        when OnDemand needs to do further actions:                  */
/*                                                                    */
/*        5) OnDemand will invoke the exit with action == 5           */
/*           so that the exit can drop the tablespace (tblsp_name)    */
/*           using (sql)                                              */
/*            *created  -> 0 exit did not drop the tablespace,        */
/*                           OnDemand needs to drop the tablespace    */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit dropped the tablespace              */
/*                                                                    */
/*        6) OnDemand will invoke the exit with action == 6           */
/*           so that the exit can drop the table (table_name)         */
/*           using (sql) when OnDemand needs to drop a table          */
/*            *created  -> 0 exit did not drop the table,             */
/*                           OnDemand needs to drop the table         */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit dropped the table                   */
/*                                                                    */
/*        7) OnDemand will invoke the exit with action == 7           */
/*           so that the exit can drop the index (idx_name)           */
/*           using (sql)                                              */
/*            *created  -> 0 exit did not drop the index,             */
/*                           OnDemand needs to drop the index         */
/*                           using (sql), which can be left unchanged */
/*                           OnDemand needs to drop the index         */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit dropped the index                   */
/*                                                                    */
/*        8) OnDemand will invoke the exit with action == 8           */
/*           so that the exit can alter the table (table_name)        */
/*           using (sql)                                              */
/*            *created  -> 0 exit did not alter the table,            */
/*                           OnDemand needs to alter the table        */
/*                           using (sql), which can be left unchanged */
/*                           or modified by the exit                  */
/*            *created  -> 1 exit altered the table                   */
/*                                                                    */
/* RETURN_CODE:                                                       */
/*        0         -> Successful                                     */
/*        Otherwise -> Failed                                         */
/*                                                                    */
/**********************************************************************/
ArcI32
ARSCSXIT_EXPORT
ARSCSXIT_API
TBLSPCRT( ArcCSXitApplGroup *appl_grp,
          char *tblsp_name,
          char *table_name,
          char *idx_name,
          char *sql,
          ArcI32 action,
          ArcI32 *created,
          char *instance
        );

You won't find anything else, than what you have in this exits directory... unfortunately.
With my customer we did just that, experiment. Until they were confident that it worked as they expected.

I would just suggest that you test it in a developpement server, and test it very very very carefully, because each customer has it's own requirements.

Unfortunately I cannot reproduce the code they use.
But I can show you a template of what they do basically:

Code: [Select]
#define _ARSUSTBL_C

/*********************************************************************/
/*                                                                   */
/* MODULE NAME: ARSUSTBL.C                                            */
/*                                                                   */
/*                                                                   */
/* SYNOPSIS:  OnDemand TableSpace Creation Exit                      */
/*                                                                   */
/*                                                                   */
/* DESCRIPTION:  This module contains the Table Space creation       */
/*               function.                                           */
/*                                                                   */
/* COPYRIGHT:                                                        */
/*  5724-J33 (C) COPYRIGHT IBM CORPORATION 2007.                     */
/*  All Rights Reserved                                              */
/*  Licensed Materials - Property of IBM                             */
/*                                                                   */
/*  US Government Users Restricted Rights - Use, duplication or      */
/*  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.*/
/*                                                                   */
/* NOTE: This program sample is provided on an as-is basis.          */
/*       The licensee of the OnDemand product is free to copy,       */
/*       revise modify, and make derivative works of this program    */
/*       sample as they see fit.                                     */
/*                                                                   */
/*********************************************************************/

#include <arscsxit.h>

ArcI32
ARSCSXIT_EXPORT
ARSCSXIT_API
TBLSPCRT( ArcCSXitApplGroup *appl_grp,
          ArcChar *tblsp_name,
          ArcChar *table_name,
          ArcChar *idx_name,
          ArcChar *sql,
          ArcI32 action,
          ArcI32 *created,
          ArcChar *instance
        )
{
   ArcI32 rc;

  if (action == 1) { /* Creation TBLSpace */
    rc=do_something_tbsp;
    *created=1;  /* CMOD will aknowledge the change but do nothing */
  }

  if (action == 2) { /* Creation Table */
    rc=do_something_table;
    *created=1;  /* CMOD will aknowledge the change but do nothing */
  }

  ...

  if (action == 6) { /* Drop Table */
     sql=change_sql_for_fun(sql);
     *created=0;  /* Let CMOD do it himself with our corrected sql */
  }

  if (action == 7) { /* Drop Indexes */
    rc=drop_something_indexes;
    *created=1;  /* CMOD will aknowledge the change but do nothing */
  }

  if (action == 8) { /* Alter Table */
    rc=alter_something_table;
    *created=1;  /* CMOD will aknowledge the change but do nothing */
  }

   return( rc );
}


Basically there is no more than that...
Now your turn, to test, test, test, test, test, test, test, test, test, test... and maybe again test.

Sincerely yours,
Alessandro
« Last Edit: December 21, 2011, 08:00:58 AM by AlessandroPerucchi »
Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML

Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: Tablespace Creation exit Routines
« Reply #3 on: December 21, 2011, 07:57:13 AM »
All the above steps we are followed but we have some of the queries :- 
1. CMOD passes all the input parameters to the user exit by itself to   
the given function "TBLSPCRT" Or where does the tablespace user exit   
gets the input parameters from?

CMOD passes all the input parameters to the user exit.

Quote
2. Once we change the our own Sample.C file and copy in the location   
"/usr/lpp/ars/exits/Sample.c" how to comple the code and generate the   
exe file to configure in the ars.cfg file.

you have a Makefile in the /usr/lpp/ars/exits directory.

just launch the "make" command.

Of course it means that in your AIX box, you have "make" installed and also a C compiler.

Quote
3. Can we update the "/usr/lpp/ars/config/ars.cfg" to contain           
"ARS_DB_TABLESPACE_USEREXIT=absoulte path name of the exe file         
generated"?

yes

Quote
4. If we update the ars.cfg file what further step we need to follow to
see the TableSpace User exit created on specified Application Group in 
the CMOD server.                                                       

You will need to stop/restart CMOD.

Quote
CMOD - 8.4.1.3                                                         
DB2 - 9.5.0.7                                                           
AIX - 5.3.0.0                                                           

Just for Info, AIX 5.3 will be end of support is 30/4/2012 and CMOD 8.4.1.X the 30/9/2012.

Sincerely yours,
Alessandro
Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML

gopikrishna

  • Guest
Re: Tablespace Creation exit Routines
« Reply #4 on: December 28, 2011, 10:43:28 AM »
Hi,

I am trying to drop a table using create exits.
1. I have written below sample code to drop a table. I have placed the execute file into /usr/lpp/ars/exits/arsutbl.

#include <arscsxit.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

ArcI32
ARSCSXIT_EXPORT
ARSCSXIT_API
TBLSPCRT( ArcCSXitApplGroup *appl_grp,
          ArcChar *tblsp_name,
          ArcChar *table_name,
          ArcChar *idx_name,
          ArcChar *sql,
          ArcI32 action,
          ArcI32 *created,
          ArcChar *instance
        )
{
   ArcI32 rc;
 if (action == 6) {
     rc=0;
     sql="drop table root.YLA1";
     *created=1;
  }

   return( rc );
}

2. I have updated the ARS.AFG file ARS_DB_TABLESPACE_USEREXIT=/usr/lpp/ars/exits/arsutbl to activate the execute file (arsutbl)

Could you please suggest what next I need to follow to drop the table and tell me know the above program is valid or not.

Justin Derrick

  • IBM Content Manager OnDemand Consultant
  • Administrator
  • Hero Member
  • *****
  • Posts: 2231
  • CMOD Guru for hire...
    • View Profile
    • Tenacious Consulting
Re: Tablespace Creation exit Routines
« Reply #5 on: December 28, 2011, 03:37:06 PM »
Hi Gopi.

Maybe the code you pasted in was just an example -- but why are you trying to re-write the table deletion code?  The sample you provided doesn't appear to do anything other than delete the same table over and over again (regardless of which table was requested to be deleted).

CMOD does an excellent job of managing tables all by itself -- I'm having a hard time trying to imagine a situation where you'd want to modify the table deletion step.

Can you fill us in on what goal you're working towards?

-JD.
IBM CMOD Professional Services: http://TenaciousConsulting.com
Call:  +1-866-533-7742  or  eMail:  jd@justinderrick.com
IBM CMOD Wiki:  https://CMOD.wiki/
FREE IBM CMOD Education & Webinars:  https://CMOD.Training/

Interests: #AIX #Linux #Multiplatforms #DB2 #TSM #SP #Performance #Security #Audits #Customizing #Availability #HA #DR

gopikrishna

  • Guest
Re: Tablespace Creation exit Routines
« Reply #6 on: December 29, 2011, 11:58:44 AM »
Hi,

Question :- CMOD passes all the input parameters to the user exit by itself to   
the given function "TBLSPCRT" Or where does the tablespace user exit   
gets the input parameters from?

Response from other forum Member (AlessandroPerucchi/JD) :- CMOD passes all the input parameters to the user exit.

TableSpace create exit function will have set of parameters
TBLSPCRT( ArcCSXitApplGroup *appl_grp,
          ArcChar *tblsp_name,
          ArcChar *table_name,
          ArcChar *idx_name,
          ArcChar *sql,
          ArcI32 action,
          ArcI32 *created,
          ArcChar *instance)

As mentioned "CMOD passes all the input parameters to the user exit." how to capture/get the above input parameters(TBLSPCRT function) values in c program to know the default input parameters passed by CMOD itself.

Note:- Here we are trying to mark table as volatile, so we are trying in different ways to call the function.
1. We tried to alter the table as volatile.
2. we tried to drop the table.

Thanks
Gopi

Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: Tablespace Creation exit Routines
« Reply #7 on: January 03, 2012, 04:08:22 AM »
Hello,

Just to inform you that the "drop" table is only active starting with CMOD 8.5.0.3 and not below.
Since you are with CMOD 8.4.1.3 it won't work.

In addition to that, you will need to add another user exit parameter

ARS_DB_TABLESPACE_USEREXIT_EXTRA=1 is defined in ars.cfg

to have access to action 5 to 8.

Sincerely yours,
Alessandro
Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML

Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: Tablespace Creation exit Routines
« Reply #8 on: January 03, 2012, 04:14:07 AM »
   ArcI32 rc;
 if (action == 6) {
     rc=0;
     sql="drop table root.YLA1";
     *created=1;
  }

   return( rc );
}

According to the documentation if *created=1 -> it means YOU have dropped the table.
And by doing what you do in your example, then you tell CMOD that you did it, but in fact you didn't.
It means that in the database, the table is always there...
You need to write *created=0.
Be careful with the \0 at the end of the string in sql, otherwise CMOD might have some problems.

Sincerely yours,
Alessandro
Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML