Control the VP environment

The routine manager executes your C UDR in a virtual-processor (VP) environment.

The VP environment consists of a VP and VP class, as follows:
  • The current VP

    When a C UDR executes, it runs on a particular virtual processor called the current VP, which has an ID number from 1 to MAXVPS. A current VP is an active VP; that is, it is currently performing some task. The task that the active VP performs depends on the VP class to which it belongs. For example, a CPU VP can execute SQL statements and well-behaved UDRs. A user-defined VP executes those UDRs that are assigned to it (with the CLASS routine modifier of the CREATE FUNCTION or CREATE PROCEDURE statement).

  • The VP class to which the current VP belongs

    The UDR specifies its VP class with the CLASS routine modifier when it is registered. If the CREATE FUNCTION or CREATE PROCEDURE statement omits the CLASS modifier, the UDR executes in the current active VP class.

The following traits of C UDRs are common reasons for needing to control the VP environment:
  • The code uses advanced operating-system calls.

    For more information, see Avoid restricted system calls.

  • The code performs some other task that is ill-behaved.

    For more information, see Preserving availability of the CPU VP and Write threadsafe code.

  • The code is written in C++.

    All C++ code has the potential to not follow the memory management rules for well-behaved code. The most serious violation of these rules is the use of static virtual function pointers in C++ classes.

Important: The ability of the database server to support some C++ features must not be taken as an open invitation to freely use C++ in your UDR code. Many C++ features implicitly violate the Safe-Coding Requirements for a well-behaved routine (see Safe-code requirements for a well-behaved UDR ). Problems can arise if some C++ features are used in a UDR.
If the source code is not available to change the UDR so that it is well-behaved, the only solution is to isolate the code execution from the CPU VP class. Possible execution scenarios include executing:
  • In a user-defined VP class
  • Locked to one VP or VP class
  • As a separate process
The DataBlade® API provides the following functions to enable UDRs and DataBlade modules to examine their VP environment and to control portions thereof.
VP-environment information DataBlade API function
Obtain information about the current VP environment from within a UDR mi_vpinfo_classid(), mi_vpinfo_isnoyield(), mi_vpinfo_vpid() mi_class_id(), mi_class_maxvps(), mi_class_name(), mi_class_numvp()
Lock the UDR to a VP environment mi_module_lock(), mi_udr_lock()
Change the VP environment in which a UDR executes mi_call_on_vp(), mi_process_exec()
Important: These advanced functions can adversely affect your UDR if you use them incorrectly. Use them only when no regular DataBlade API functions can perform the tasks you need done.