CERN IT Department CH-1211 Genève 23 Switzerland www.cern.ch/i t ES Developing C++ applications using Oracle OCI Lessons learnt from CORAL Andrea Valassi.

Slides:



Advertisements
Similar presentations
January 30, 2014 Copyright Jim Farley Beyond JDBC: Java Object- Relational Mappings Jim Farley e-Commerce Program Manager GE Research and Development
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
QA practitioners viewpoint
CERN IT Department CH-1211 Genève 23 Switzerland t ES CORAL & COOL A critical review from the inside Andrea Valassi (IT-ES) WLCG TEG on Databases,
Introduction to Oracle Call Interface © Martin Cetkovský, 2005
CERN - IT Department CH-1211 Genève 23 Switzerland t CORAL Server A middle tier for accessing relational database servers from CORAL applications.
CERN - IT Department CH-1211 Genève 23 Switzerland t LCG Persistency Framework CORAL, POOL, COOL – Status and Outlook A. Valassi, R. Basset,
CORAL and COOL news for ATLAS (update since March 2012 ATLAS sw workshop)March 2012 Andrea Valassi (IT-SDC) ATLAS Database Meeting 24 th October 2013.
CERN IT Department CH-1211 Genève 23 Switzerland t ES Discussion of COOL - CORAL - POOL priorities for ATLAS Andrea Valassi (IT-ES) For the.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Pragmatic Application Building: Step by Step Jay Sissom Principal Systems Analyst Indiana University
Web Application Architecture: multi-tier (2-tier, 3-tier) & mvc
Andrea Valassi (CERN IT-SDC) DPHEP Full Costs of Curation Workshop CERN, 13 th January 2014 The Objectivity migration (and some more recent experience.
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
CERN - IT Department CH-1211 Genève 23 Switzerland t Monitoring the ATLAS Distributed Data Management System Ricardo Rocha (CERN) on behalf.
CERN IT Department CH-1211 Genève 23 Switzerland t SDC Stabilizing SQL execution plans in COOL using Oracle hints Andrea Valassi (IT-SDC)
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Fundamentals of Database Chapter 7 Database Technologies.
M1G Introduction to Database Development 6. Building Applications.
I Copyright © 2004, Oracle. All rights reserved. Introduction Copyright © 2004, Oracle. All rights reserved.
OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida
CHEP 2006, Mumbai13-Feb-2006 LCG Conditions Database Project COOL Development and Deployment: Status and Plans Andrea Valassi On behalf of the COOL.
Databases E. Leonardi, P. Valente. Conditions DB Conditions=Dynamic parameters non-event time-varying Conditions database (CondDB) General definition:
A. Valassi – QA for CORAL and COOL Forum – 29 h Sep Quality assurance for CORAL and COOL within the LCG software stack for the LHC.
CERN - IT Department CH-1211 Genève 23 Switzerland t DB Development Tools Benthic SQL Developer Application Express WLCG Service Reliability.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
CERN IT Department CH-1211 Genève 23 Switzerland t ES Future plans for CORAL and COOL Andrea Valassi (IT-ES) For the Persistency Framework.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
ALICE, ATLAS, CMS & LHCb joint workshop on
CERN - IT Department CH-1211 Genève 23 Switzerland t CORAL Server A middle tier for accessing relational database servers from CORAL applications.
1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle.
INTRODUCTION TO DBS Database: a collection of data describing the activities of one or more related organizations DBMS: software designed to assist in.
CERN - IT Department CH-1211 Genève 23 Switzerland t COOL Conditions Database for the LHC Experiments Development and Deployment Status Andrea.
EGEE User Forum Data Management session Development of gLite Web Service Based Security Components for the ATLAS Metadata Interface Thomas Doherty GridPP.
CERN - IT Department CH-1211 Genève 23 Switzerland t CORAL COmmon Relational Abstraction Layer Radovan Chytracek, Ioannis Papadopoulos (CERN.
Using MS Excel to validate & load your data into Oracle EBS.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Database authentication in CORAL and COOL Database authentication in CORAL and COOL Giacomo Govi Giacomo Govi CERN IT/PSS CERN IT/PSS On behalf of the.
A. Valassi – Python bindings for C++ in PyCool ROOT Workshop – 16 th Sep Python bindings for C++ via PyRoot User experience from PyCool in COOL.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Basics of JDBC Session 14.
Grid Technology CERN IT Department CH-1211 Geneva 23 Switzerland t DBCF GT Upcoming Features and Roadmap Ricardo Rocha ( on behalf of the.
Andrea Valassi (CERN IT-DB)CHEP 2004 Poster Session (Thursday, 30 September 2004) 1 HARP DATA AND SOFTWARE MIGRATION FROM TO ORACLE Authors: A.Valassi,
Overview of C/C++ DB APIs Dirk Düllmann, IT-ADC Database Workshop for LHC developers 27 January, 2005.
CORAL CORAL a software system for vendor-neutral access to relational databases Ioannis Papadopoulos, Radoval Chytracek, Dirk Düllmann, Giacomo Govi, Yulia.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Status of tests in the LCG 3D database testbed Eva Dafonte Pérez LCG Database Deployment and Persistency Workshop.
CERN - IT Department CH-1211 Genève 23 Switzerland t Persistency Framework CORAL, POOL, COOL status and plans Andrea Valassi (IT-PSS) On.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Evaluation of the C++ binding to the Oracle Database System Dirk Geppert and Krzysztof Nienartowicz, IT/DB CERN IT Fellow Seminar November 20, 2002.
CERN IT Department CH-1211 Genève 23 Switzerland t ES CORAL Server & CORAL Server Proxy: Scalable Access to Relational Databases from CORAL.
CERN IT Department CH-1211 Genève 23 Switzerland t Load testing & benchmarks on Oracle RAC Romain Basset – IT PSS DP.
CERN IT Department CH-1211 Genève 23 Switzerland t DPM status and plans David Smith CERN, IT-DM-SGT Pre-GDB, Grid Storage Services 11 November.
Jean-Philippe Baud, IT-GD, CERN November 2007
DEPTT. OF COMP. SC & APPLICATIONS
Database Replication and Monitoring
ODBC, OCCI and JDBC overview
(on behalf of the POOL team)
Web Technologies IT230 Dr Mohamed Habib.
Andrea Valassi (IT-ES)
POOL persistency framework for LHC
Dirk Düllmann CERN Openlab storage workshop 17th March 2003
Multitier Architecture, MySQL & PHP
Oracle Architecture Overview
Enterprise Java Beans.
Presentation transcript:

CERN IT Department CH-1211 Genève 23 Switzerland t ES Developing C++ applications using Oracle OCI Lessons learnt from CORAL Andrea Valassi Raffaello Trentadue (IT-ES) CERN Oracle tutorial, 8 th June 2012

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 2Oracle tutorials (OCI) – 8 th June 2012 Agenda What is CORAL? Why OCI (instead of OCCI) from C++? A walk-through the OCI features used in CORAL –Will only cover (some of!) the OCI features used in CORAL Focus on ‘tricky’ issues rather than present a proper tutorial – sorry  –Will also point out a few Oracle client bugs affecting CORAL _____________________________________________________ Disclaimer: the present CORAL team does not include the original authors of the OracleAccess plugins –We learnt a lot by ‘reverse engineering’ it during its maintenance… –Some strengths and weaknesses of the original implementation have only become apparent with several years of production use

CERN IT Department CH-1211 Genève 23 Switzerland t Oracle tutorials (OCI) – 8 th June 2012A. Valassi, R. Trentadue – 3 What is CORAL? The Common Relational Abstraction Layer (CORAL) is a C++ framework to access data in relational databases –It is used by three LHC experiments (ATLAS, CMS and LHCb) to store and retrieve conditions data and other types of relational data –With COOL and CORAL it is part of the Persistency Framework common project (joint development of IT and LHC experiments) Its C++ API is a set of SQL-free abstract interfaces that isolate the user code from the implementation technology –CORAL supports several back-ends (Oracle, MySQL, SQLite…) Users write the same code for all back-ends A detailed knowledge of the many SQL flavors is not required The SQL commands specific to each backend are executed by the relevant library, loaded at run-time by a C++ plugin infrastructure Oracle is accessed in CORAL via the OracleAccess library –The CORAL OracleAccess library is implemented using OCI

Oracle tutorials (OCI) – 8 th June 2012A. Valassi, R. Trentadue – 4 CORAL components DB lookup XML COOL C++ API C++ code of LHC experiments (independent of DB choice) POOL C++ API use CORAL directly OracleAccess (CORAL Plugin) OCI C API CORAL C++ API (technology-independent) Oracle DB SQLiteAccess (CORAL Plugin) SQLite C API MySQLAccess (CORAL Plugin) MySQL C API MySQL DB SQLite DB (file) OCI FrontierAccess (CORAL Plugin) Frontier API CoralAccess (CORAL Plugin) coral protocol Frontier Server (web server) CORAL server JDBC http coral Squid (web cache) CORAL proxy (cache) coral http XMLLookupSvc XMLAuthSvc LFCReplicaSvc (CORAL Plugins) Authentication XML (file) LFC server (DB lookup and authentication) No longer used Drop in 2012 ? CORAL is used by ATLAS, CMS and LHCb in most of the client applications that access physics data stored in Oracle CORAL is now the most active of the three Persistency packages: closer to lower-level services used by COOL and POOL ES

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 5Oracle tutorials (OCI) – 8 th June 2012 Why OCI? (the problem with OCCI) Why should we develop C++ applications using OCI? An Oracle C++ library does exist: OCCI –Used extensively for COMPASS and HARP Objectivity migration –OCCI does have a very nice API (much nicer in C++ than OCI…) OCCI is a C++ library built only for some C++ compilers –Problem in the past: OCCI for gcc2.96, we needed or –Now better (several compilers), but still limited to gcc4.3 and ???… It would be different if Oracle released OCCI sources… it does not  OCI is a C library – it can be used with any C++ compiler –OCI is the basic client library, used internally by all Oracle tools e.g. also one of the java drivers for Oracle is based on OCI –CORAL OracleAccess, based on OCI, is used and must be built on Linux for gcc4.3, gcc4.6, gcc4.7, icc11, clang3.0…

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 6Oracle tutorials (OCI) – 8 th June 2012 OCI workflow in CORAL Environment bootstrap: OCIEnvCreate –Several options (e.g. to configure multi-threaded clients, as in CORAL) –Runtime libraries (libociei or libocicus) are loaded here (see strace) Setup – allocate handles (all along): OCIHandleAlloc –Set relations between handles: OCIAttrSet Connect to the DB server: OCIServerAttach (CORAL Connection) –One such physical connection can be used for many user sessions Authenticate user session: OCISessionBegin (CORAL Session) –Via username/password in CORAL X509 proxy certificates would need a middle tier (e.g. CORAL server) Start the transaction: OCITransStart –This is only needed for updates, not for read-only use cases… Prepare the SQL statement: OCIStmtPrepare2 ______________________________________________________________________________________________ Execute the SQL statement: OCIStmtExecute –SQL (SELECT, DDL, DML), PL/SQL (as CALL xxx), control (ALTER SESSION…) –Iterate on cursor: OCIStmtFetch2 ______________________________________________________________________________________________ Release the SQL statement: OCIStmtRelease Commit the transaction: OCITransCommit Close the session: OCISessionEnd Disconnect the server: OCIServerDetach Cleanup – release handles (all along): OCIHandleFree –Unset relations between handles: OCIAttrSet

Oracle tutorials (OCI) – 8 th June 2012A. Valassi, R. Trentadue – 7 OCIHandleAlloc OCIAttrSet OCIHandleAlloc OCI connections/sessions in CORAL 0Initialize OCI ( e.g. load Oracle client libraries) - Create OCIEnv (via OCIEnvCreate) - Create OCIError (via OCIHandleAlloc) 1Set up physical connection to DB server - Create OCIServer (via OCIHandleAlloc) - Establish connection (via OCIServerAttach) 2Set up logical user session on DB server - Create OCISvcCtx (via OCIHandleAlloc) - Link server connection to it (via OCIAttrSet) - Create OCISession (via OCIHandleAlloc) - Link it to service context (via OCIAttrSet) - Set session’s user and password (via 2 x OCIAttrSet) - Begin user session (via OCISessionBegin) - Create OCITrans (via OCIHandleAlloc) - Link it to service context (via OCIAttrSet) - Start transaction (via OCITransStart) OCITrans “transaction handle” or “transaction context handle” One OCITrans per CORAL Session Connection sharing? - One OCIServer (One CORAL Connection) - Many sets of (OCISvcCtx, OCISession, OCITrans) using the same OCIServer (Many CORAL Sessions) OCISvcCtx “service context handle” One OCISvcCtx per CORAL Session OCIServer “server handle” or “server context handle” One OCIServer per CORAL Connection OCISession “session handle” or “session context handle” One OCISession per CORAL Session ES

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 8Oracle tutorials (OCI) – 8 th June 2012 Transactions – comments CORAL presently calls OCITrans also for read-only use cases –This is equivalent to ‘SET TRANSACTION READ ONLY’ –These are serializable read-only transactions A SELECT statement issued at time t1 will always return a result set describing the state of the database at the time t0 (< t1) when the transaction started –Advantages: all data can be cached (e.g. used in COOL) –Disadvantages: several Heavy operation on the redo logs (has been seen to lead to ORA-01555) Querying newly created tables in COOL tests leads to OCI (Oracle bug) Sometimes you do want to read newly added data (e.g. ATLAS HLT) Summary: calling OCITrans is NOT needed in read-only use cases –Not clear to me if originally this was intentional or unintentional in CORAL –We plan to properly support three use cases in CORAL eventually: RW transactions, serializable RO transactions, “non-serializable RO” transactions You may simply skip OCITrans and execute your SQL directly (e.g. ATLAS HLT) See

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 9Oracle tutorials (OCI) – 8 th June 2012 Data handling – comments Bind variables (recommended in CORAL to reduce server load!) –OCIBindByPos, OCIBindByName, OCIBindArrayOfStruct, OCIBindDynamic Data types –Simple data types (C++ numbers/strings) Described in OCI calls by SQLT_INT, SQLT_FLT, SQLT_STR… –Oracle special data types (e.g. DATE) –BLOBs and CLOBs (for C++ strings longer than 4000 characters) OCILobOpen, OCILobClose, OCILobRead, OCILobWriteAppend… –No C++ “object” types in CORAL More generally, no user defined types and no OTT (Object Type Translator) Mapping C++ and SQL/OCI data types? –Custom implementation in CORAL (based on C++ types, e.g. “long”) And a slightly different one in COOL (based on storage precision, e.g. int32, int64) –Personally I am somewhat suspicious of wildly generic auto-translations The C++ program flow and SQL query optimization are two separate areas that both need a lot of care Developing C++ code ‘letting another layer take care of all SQL translations’ brings the risk of poor schema design and poor query performance You are the developer, you are in charge of SQL query performance!

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 10Oracle tutorials (OCI) – 8 th June 2012 Cleanup phase – comments Release OCI handles and break relations in the right order –reverse order to that used for allocating and associating handles Crashes observed in an older CORAL implementation –if a connection is broken and the corresponding handle is released before an associated (e.g. statement) handle is used/released –patched by fixes/workarounds in CORAL since then –strictly speaking some of these are Oracle client bugs the crash (segmentation fault) is deep inside the Oracle client the Oracle client should do its internal bookkeeping to be able to tell if a first OCI handle has gone out of scope when a second OCI handle tries to access it inside the implementation of an Oracle method… I would expect an ORA-24xxx or ORA-031xx error rather than a crash

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 11Oracle tutorials (OCI) – 8 th June 2012 The OCI client library – comments The OCI library is definitely more ‘portable’ than the OCCI library –e.g. no need to respect a specific libstdc++ dependency But also the OCI library (libclntsh.so) does have some limitations –if you run your client software on non-standard O/S (e.g. SLC) –if client applications have multiple dependencies (e.g. LHC experiments) –different issues from those seen when installing the server software on very controlled environments (e.g. strict RedHat Enterprise Linux) Example 1 (Oracle bug – fixed): SELinux –out-of-the-box, the library could not be loaded due to SELinux –patched version (for OCI and OCCI too) is installed for the LHC experiments see /afs/cern.ch/sw/lcg /external/oracle/ p3/doc/README_ p3.txt Examples 2/3 (Oracle bugs – not yet fixed): GSSAPI and Kerberos –the OCI library redefines its own custom versions of some security libraries (GSSAPI and Kerberos), conflicting with the version provided by the O/S –user applications that need Oracle AND another security-aware component (e.g. xrootd) may fail one or the other depending on the loading order… –we were lucky so far and we could find workarounds… for how long? a strategy to fix exists: using ‘versioned symbols’ (recently used by EMI middleware to fix a similar bug in Globus due to GSSAPI)

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 12Oracle tutorials (OCI) – 8 th June g advanced topics – not yet used OCI callbacks for Transparent Application Failover (TAF) –CORAL has its own custom implementation to react to “network glitches” Oracle TAF is mainly about instance crashes – failover to another instance CORAL implementation is mainly about temporary network/database glitches OCI client result cache –Would be an interesting area to test –CORAL caches data via Frontier/Squid and CoralServer/Proxy middle tiers

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 13Oracle tutorials (OCI) – 8 th June 2012 Python access: PyCoral and PyCool PyCool – Python bindings for COOL –Implemented automatically via ROOT (Reflex, PyCintex, PyRoot) ROOT will internally move this from CINT to llvm by the end of 2012 –Easy to maintain, ~nothing to do when a class is added/modified PyCoral – Python bindings for CORAL –Implemented manually (class by class) via low-level C calls –Very painful to maintain, may merge with PyCool eventually Both PyCoral and PyCool allow Oracle access from Python –Ultimately via the OCI implementation in the OracleAccess C++

CERN IT Department CH-1211 Genève 23 Switzerland t A. Valassi, R. Trentadue – 14Oracle tutorials (OCI) – 8 th June 2012 Conclusions To access Oracle from C++: –you could use OCCI (but this may limit your set of compilers) –or you can use OCI –or you can also use CORAL directly References –Oracle Call Interface (OCI) 11g Programmer’s Guide (html, pdf)htmlpdf –CORAL twiki, savannah and CVStwikisavannahCVS All OCI in CORAL can be found in the OracleAccess library in CVSCVS A standalone example of OCI connection sharing is in the COOL CVSCVS