SlideShare a Scribd company logo
1 of 36
Download to read offline
<jon@ivt.com.au>



Dealing drugs to Sakila
The problem
Applications are not static.

New versions mean schema changes.

App / schema mismatches are bad.

Schema changes mean pain.


Self-Healing Databases     Jonathan Oxer <jon@ivt.com.au>
Obvious solution



      Update scripts

Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Update scripts



        Run manually

Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Update scripts



Statically defined

Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
A better way?

Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Self-
               Healing
              Databases
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Reasons for change
New tables required.

New columns required.

Alterations to columns.

Alterations to contents of tables.


Self-Healing Databases     Jonathan Oxer <jon@ivt.com.au>
Failure modes
New tables required.
 “Unknown table”
New columns required.
 “ Unknown column”
Alterations to columns.
 ?
Alterations to contents of tables.
 ?

Self-Healing Databases     Jonathan Oxer <jon@ivt.com.au>
Reactive,
                    not
                 proactive
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Smart error trapping
1. Run queries blindly.
2. Detect failure conditions.
3. Fix them.
4. Profit!
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
But...
...if you don't have a db
abstraction layer you're


                         stuffed!
Self-Healing Databases       Jonathan Oxer <jon@ivt.com.au>
Build, Borrow or Steal


      One central
     query executor
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
MySQL errors
MySQL has built-in error reporting: use it!

In PHP:
  $errno = mysql_errno($link);
  $error = mysql_error($link);

Specify the link or you'll get the value
from the last opened connection, not
the last error from your connection.
Self-Healing Databases     Jonathan Oxer <jon@ivt.com.au>
MySQL errors
Check for specific errors, such as:

  1146: Table doesn't exist
  1054: Unknown column
dev.mysql.com/doc/refman/5.0/en/error-handling.html




Self-Healing Databases            Jonathan Oxer <jon@ivt.com.au>
Missing table
● Store reference schemas in app
● Trap “1146” errors

● Examine error to determine table name

● Load reference schema

● Create table

● Rerun original query

● Return result




The user never even notices a glitch :-)
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Missing table
Embed reference schemas into your app.

[modulename]/sql/articles.sql:

CREATE TABLE `articles` (
`Serial` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`Title` VARCHAR( 255 ) NOT NULL ,
`Article` TEXT NOT NULL
) ENGINE = MYISAM ;



Self-Healing Databases        Jonathan Oxer <jon@ivt.com.au>
Missing column
● Record schema changes in “alter” file
● Trap “unknown column” errors

● Load and execute alter file

● Rerun original query

● Return result




No harm, no foul.


Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Missing column
Make execution of “alter” file idempotent.

[modulename]/sql/alter.php:

if (!$dbase->field_exists(“news”, “Modified”))
{
    $s = “ALTER TABLE news ADD `Modified` TIMESTAMP
      NOT NULL”;
    $dbase->query($s);
}


Self-Healing Databases          Jonathan Oxer <jon@ivt.com.au>
Missing trigger

   Missing triggers
   are a problem:
      silent death
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Missing trigger

[modulename]/sql/alter.php:

if (!$dbase->trigger_exists(“UPDATESTOCK”))
{
    $s = “CREATE TRIGGER UPDATESTOCK ...”;
    $dbase->query($s);
}




Self-Healing Databases          Jonathan Oxer <jon@ivt.com.au>
Missing procedure
● Put procedure additions in “alter” file
● Trap “1106”, errors

● Load and execute alter file

● Rerun original query

● Return result




 (Note: trap “1107” and “1108” errors too,
  for handling altered procedures)

Self-Healing Databases     Jonathan Oxer <jon@ivt.com.au>
Missing procedure

[modulename]/sql/alter.php:

if (!$dbase->procedure_exists(“DISCOUNTCALC”))
{
    $s = “CREATE PROCEDURE DISCOUNTCALC ...”;
    $dbase->query($s);
}




Self-Healing Databases         Jonathan Oxer <jon@ivt.com.au>
That's
  not all,
  folks!
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Problem:

 Multiple module
instances require
 data partitioning
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Solution:

     Three-tier
   dynamic table
  naming scheme
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Dynamic table names
1: Module instance
2: Module name
3: Specific table
hotstuff_news_articles
hotstuff_news_comments
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Benefits
Storage of schema with
module: error handler can
deduce path from table.
Upgrade of tables when you
don't know their name.
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Schema templates
Placeholders in reference schemas

[modulename]/sql/articles.sql:

CREATE TABLE <articles> (
`Serial` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`Title` VARCHAR( 255 ) NOT NULL ,
`Article` TEXT NOT NULL
) ENGINE = MYISAM ;



Self-Healing Databases        Jonathan Oxer <jon@ivt.com.au>
“Alter” templates
Make table names in “alter” file dynamic
[modulename]/sql/alter.php:
$articles = $instance.'_news_articles';
if (!$dbase->field_exists($articles, “Modified”))
{
     $s = “ALTER TABLE $articles ADD `Modified` TIMESTAMP
      NOT NULL”;
     $dbase->query($s);
}




Self-Healing Databases              Jonathan Oxer <jon@ivt.com.au>
Benefits
Stop caring about:

● App / schema mismatches
● Knowing what tables are called

● Telling users to run upgrade scripts




Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Caveat:
this messes with

      triggers
           and

               procedures
Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Is This A Fairy Tale?




Self-Healing Databases     Jonathan Oxer <jon@ivt.com.au>
Is this a fairy tale?
Technique in production use in the
SiteBuilder web application framework
and modules for more than 7 years:
● 1.2 million lines of PHP
● 149 modules

● 11,779 SQL statements

● 1,247 embedded table schemas



Self-Healing Databases   Jonathan Oxer <jon@ivt.com.au>
Is this a fairy tale?
Deployments include:

Siemens national intranet with over 5,000
dynamically managed tables
Shaver Shop e-commerce system with tens
of thousands of transactions / year
Gift Store Online with over 800k users
Brisbane Airport security credential system
with 10k users / 30k cards
Self-Healing Databases      Jonathan Oxer <jon@ivt.com.au>
Self-healing databases


Thankyou :-)
  These slides: jon.oxer.com.au/talks
   We're hiring: www.ivt.com.au/jobs
Flames: Jonathan Oxer (jon@ivt.com.au)

More Related Content

More from Jonathan Oxer

Self-Healing Databases
Self-Healing DatabasesSelf-Healing Databases
Self-Healing DatabasesJonathan Oxer
 
How To Build A Website And Stay Sane
How To Build A Website And Stay SaneHow To Build A Website And Stay Sane
How To Build A Website And Stay SaneJonathan Oxer
 
Managing Source Code With Subversion
Managing Source Code With SubversionManaging Source Code With Subversion
Managing Source Code With SubversionJonathan Oxer
 
PHP Performance Profiling
PHP Performance ProfilingPHP Performance Profiling
PHP Performance ProfilingJonathan Oxer
 
Compiling kernels the Debian way
Compiling kernels the Debian wayCompiling kernels the Debian way
Compiling kernels the Debian wayJonathan Oxer
 

More from Jonathan Oxer (8)

Introduction to DNS
Introduction to DNSIntroduction to DNS
Introduction to DNS
 
Self-Healing Databases
Self-Healing DatabasesSelf-Healing Databases
Self-Healing Databases
 
How To Build A Website And Stay Sane
How To Build A Website And Stay SaneHow To Build A Website And Stay Sane
How To Build A Website And Stay Sane
 
Managing Source Code With Subversion
Managing Source Code With SubversionManaging Source Code With Subversion
Managing Source Code With Subversion
 
Large Scale PHP
Large Scale PHPLarge Scale PHP
Large Scale PHP
 
PHP On Steroids
PHP On SteroidsPHP On Steroids
PHP On Steroids
 
PHP Performance Profiling
PHP Performance ProfilingPHP Performance Profiling
PHP Performance Profiling
 
Compiling kernels the Debian way
Compiling kernels the Debian wayCompiling kernels the Debian way
Compiling kernels the Debian way
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Self-healing databases: managing schema updates in the field

  • 2. The problem Applications are not static. New versions mean schema changes. App / schema mismatches are bad. Schema changes mean pain. Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 3. Obvious solution Update scripts Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 4. Update scripts Run manually Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 5. Update scripts Statically defined Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 6. A better way? Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 7. Self- Healing Databases Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 8. Reasons for change New tables required. New columns required. Alterations to columns. Alterations to contents of tables. Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 9. Failure modes New tables required. “Unknown table” New columns required. “ Unknown column” Alterations to columns. ? Alterations to contents of tables. ? Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 10. Reactive, not proactive Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 11. Smart error trapping 1. Run queries blindly. 2. Detect failure conditions. 3. Fix them. 4. Profit! Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 12. But... ...if you don't have a db abstraction layer you're stuffed! Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 13. Build, Borrow or Steal One central query executor Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 14. MySQL errors MySQL has built-in error reporting: use it! In PHP: $errno = mysql_errno($link); $error = mysql_error($link); Specify the link or you'll get the value from the last opened connection, not the last error from your connection. Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 15. MySQL errors Check for specific errors, such as: 1146: Table doesn't exist 1054: Unknown column dev.mysql.com/doc/refman/5.0/en/error-handling.html Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 16. Missing table ● Store reference schemas in app ● Trap “1146” errors ● Examine error to determine table name ● Load reference schema ● Create table ● Rerun original query ● Return result The user never even notices a glitch :-) Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 17. Missing table Embed reference schemas into your app. [modulename]/sql/articles.sql: CREATE TABLE `articles` ( `Serial` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `Title` VARCHAR( 255 ) NOT NULL , `Article` TEXT NOT NULL ) ENGINE = MYISAM ; Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 18. Missing column ● Record schema changes in “alter” file ● Trap “unknown column” errors ● Load and execute alter file ● Rerun original query ● Return result No harm, no foul. Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 19. Missing column Make execution of “alter” file idempotent. [modulename]/sql/alter.php: if (!$dbase->field_exists(“news”, “Modified”)) { $s = “ALTER TABLE news ADD `Modified` TIMESTAMP NOT NULL”; $dbase->query($s); } Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 20. Missing trigger Missing triggers are a problem: silent death Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 21. Missing trigger [modulename]/sql/alter.php: if (!$dbase->trigger_exists(“UPDATESTOCK”)) { $s = “CREATE TRIGGER UPDATESTOCK ...”; $dbase->query($s); } Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 22. Missing procedure ● Put procedure additions in “alter” file ● Trap “1106”, errors ● Load and execute alter file ● Rerun original query ● Return result (Note: trap “1107” and “1108” errors too, for handling altered procedures) Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 23. Missing procedure [modulename]/sql/alter.php: if (!$dbase->procedure_exists(“DISCOUNTCALC”)) { $s = “CREATE PROCEDURE DISCOUNTCALC ...”; $dbase->query($s); } Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 24. That's not all, folks! Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 25. Problem: Multiple module instances require data partitioning Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 26. Solution: Three-tier dynamic table naming scheme Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 27. Dynamic table names 1: Module instance 2: Module name 3: Specific table hotstuff_news_articles hotstuff_news_comments Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 28. Benefits Storage of schema with module: error handler can deduce path from table. Upgrade of tables when you don't know their name. Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 29. Schema templates Placeholders in reference schemas [modulename]/sql/articles.sql: CREATE TABLE <articles> ( `Serial` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `Title` VARCHAR( 255 ) NOT NULL , `Article` TEXT NOT NULL ) ENGINE = MYISAM ; Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 30. “Alter” templates Make table names in “alter” file dynamic [modulename]/sql/alter.php: $articles = $instance.'_news_articles'; if (!$dbase->field_exists($articles, “Modified”)) { $s = “ALTER TABLE $articles ADD `Modified` TIMESTAMP NOT NULL”; $dbase->query($s); } Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 31. Benefits Stop caring about: ● App / schema mismatches ● Knowing what tables are called ● Telling users to run upgrade scripts Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 32. Caveat: this messes with triggers and procedures Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 33. Is This A Fairy Tale? Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 34. Is this a fairy tale? Technique in production use in the SiteBuilder web application framework and modules for more than 7 years: ● 1.2 million lines of PHP ● 149 modules ● 11,779 SQL statements ● 1,247 embedded table schemas Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 35. Is this a fairy tale? Deployments include: Siemens national intranet with over 5,000 dynamically managed tables Shaver Shop e-commerce system with tens of thousands of transactions / year Gift Store Online with over 800k users Brisbane Airport security credential system with 10k users / 30k cards Self-Healing Databases Jonathan Oxer <jon@ivt.com.au>
  • 36. Self-healing databases Thankyou :-) These slides: jon.oxer.com.au/talks We're hiring: www.ivt.com.au/jobs Flames: Jonathan Oxer (jon@ivt.com.au)