Object-Oriented Databases db4o: Part 2

Similar documents
Using Object Database db4o as Storage Provider in Voldemort

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Developing a Three Tier Web Application Using ASP.NET and Open Source Object-Oriented Database DB4Objects

Raima Database Manager Version 14.0 In-memory Database Engine

Job Reference Guide. SLAMD Distributed Load Generation Engine. Version 1.8.2

Matisse Server Administration Guide

There and Back Again As Quick As a Flash

EXAM PRO:Design & Develop Windows Apps Using MS.NET Frmwk 4. Buy Full Product.

Enterprise JavaBeans 3.1

Object Oriented Database Management System for Decision Support System.

<Insert Picture Here> Oracle SQL Developer 3.0: Overview and New Features

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

Lecture 7: Class design for security

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Comparing Microsoft SQL Server 2005 Replication and DataXtend Remote Edition for Mobile and Distributed Applications

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

How To Write A Store On A Microsoft Database On A Flash (Orchestra) On A Linux Computer (Ortho) On An Ipro (Orroster) On Your Computer Or Your Computer (For Ahem) On The

MarkLogic Server. Database Replication Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

SQL Server Training Course Content

SQL Server Replication Guide

Data sharing in the Big Data era

A Brief Introduction to MySQL

1 File Processing Systems

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package Data Federation Administration Tool Guide

1 Changes in this release

Database Administration

Outline. Failure Types

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

Replication on Virtual Machines

Caché License Management

Easy-Cassandra User Guide

A Fully Standards-Based Approach to Logging High-Throughput Distributed Real-Time Data. Leveraging the DDS and SQL Standards

Comparing SQL and NOSQL databases

Hypertable Architecture Overview

Web Development in Java

Complex Data and Object-Oriented. Databases

SQLITE C/C++ TUTORIAL

Bigdata High Availability (HA) Architecture

Configuring Log Files and Filtering Log Messages for Oracle WebLogic Server c (12.1.3)

MongoDB Developer and Administrator Certification Course Agenda

Introduction to Database Systems. Chapter 1 Introduction. Chapter 1 Introduction

SQL Anywhere 12 New Features Summary

In Memory Accelerator for MongoDB

Tier Architectures. Kathleen Durant CS 3200

A Java-based system support for distributed applications on the Internet

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Efficient database auditing

Web Service Caching Using Command Cache

IBrokers - Interactive Brokers and R

Media Upload and Sharing Website using HBASE

Distributed File Systems

EMC Documentum Content Services for SAP iviews for Related Content

Volume SYSLOG JUNCTION. User s Guide. User s Guide

Oracle Database 11 g Performance Tuning. Recipes. Sam R. Alapati Darl Kuhn Bill Padfield. Apress*

Geodatabase Programming with SQL

Oracle WebLogic Server 11g Administration

Integrating VoltDB with Hadoop

Introduction to Synoptic

LICENSE4J FLOATING LICENSE SERVER USER GUIDE

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

System Monitoring and Diagnostics Guide for Siebel Business Applications. Version 7.8 April 2005

Adaptive Server Enterprise

Configuring the Bundled SESM RADIUS Server

IBM WebSphere Distributed Caching Products

PRO: Optimizing and Maintaining a Database Administration Solution by Using Microsoft SQL Server Practice Test. Version 2.

EMC Backup and Recovery for Microsoft SQL Server 2008 Enabled by EMC Celerra Unified Storage

æ A collection of interrelated and persistent data èusually referred to as the database èdbèè.

Distributed Database Guide Version: 00.01

Database Administration with MySQL

In-Memory Databases MemSQL

Merkle Hash Trees for Distributed Audit Logs

Customer Bank Account Management System Technical Specification Document

StoreGrid Backup Server With MySQL As Backend Database:

MySQL for Beginners Ed 3

Informatica Master Data Management Multi Domain Hub API: Performance and Scalability Diagnostics Checklist

Release Notes LS Retail Data Director August 2011

Best Practices for SAP MaxDB Backup and Recovery using IBM Tivoli Storage Manager

MarkLogic Server. Node.js Application Developer s Guide. MarkLogic 8 February, Copyright 2016 MarkLogic Corporation. All rights reserved.

Choosing a Data Model for Your Database

EMBL-EBI. Database Replication - Distribution

No no-argument constructor. No default constructor found

Visual Basic. murach's TRAINING & REFERENCE

Microsoft SQL Server performance tuning for Microsoft Dynamics NAV

PERFORMANCE EVALUATION OF JAVA OBJECT-RELATIONAL MAPPING TOOLS HASEEB YOUSAF. (Under the Direction of John A. Miller)

DBA Tutorial Kai Voigt Senior MySQL Instructor Sun Microsystems Santa Clara, April 12, 2010

Using LDAP Authentication in a PowerCenter Domain

Using DOTS as Apache Derby System Test

MBP_MSTR: Modbus Plus Master 12

McAfee Web Gateway 7.4.1

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

HDFS Users Guide. Table of contents

Auditing manual. Archive Manager. Publication Date: November, 2015

Transcription:

Object-Oriented Databases db4o: Part 2 Configuration and Tuning Distribution and Replication Callbacks and Translators 1

Summary: db4o Part 1 Managing databases with an object container Retrieving objects query by example native queries SODA queries Updating and deleting simple and complex objects configuration of update, delete and activation depth inconsistencies between in-memory and stored objects transparent activation and persistence Transactions commit and rollback concurrent transactions, collision detection and avoidance 2

Configuration and Tuning Configuration interface configuration obtained through Db4oEmbedded.newConfiguration() Db4oClientServer.newClientConfiguration() Db4oClientServer.newServerConfiguration() configuration set when object container, client or server opened configuring an existing object container or object server access settings with ExtObjectContainer.configure() or ExtObjectServer.configure(), respectively External tools performance tuning database diagnostics Indexes optimise query evaluation 3

External Tools Defragment removes unused fields, classes and management information compacts database file and provides faster access initiated from command line or from within application Statistics computes and outputs statistics about how queries behave and perform. how many objects are stored, deleted and activated. the IO-operations of db4o. the network operations of db4o. executed from command line or programmatically Logger logs all objects in a database file logs all objects of a given class run from command line 4

Indexes Trade-off between increased query performance and decreased storage, update and delete performance Support for B-Tree indexes on single object fields enabled or disabled using configuration interface index created or removed automatically when object container or object server is opened Set by configuration or annotation Examples public Class Person { // create an index CommonConfiguration.objectClass(...).objectField(...).indexed(true); // remove an index CommonConfiguration.objectClass(...).objectField(...).indexed(false); @Indexed private String name; 5

Tuning for Speed Heuristics to improve performance of db4o weak references, BTree node size, freespace manager, locking, flushing, callbacks, caches, Object loading use appropriate activation depth use multiple object or session containers disable weak references if not required (no updates performed) Database tests disable detection of schema changes disable instantiation tests of persistent classes at start-up Query evaluation set field indexes on most used objects to improve searches optimise native queries 6

Distribution and Replication Embedded mode database accessed by clients in the same virtual machine direct file access: one user and one thread at a time client session: one user and multiple threads Client/Server mode clients in multiple virtual machines access database on server server listens for and accepts connections clients connect to server to perform database tasks Replication multiple servers manage redundant copies of a database changes are replicated from master to client servers replicated databases need to be kept consistent 7

Embedded Mode: Direct File Access Virtual Machine EmbeddedObjectContainer Database File Application and database in the same virtual machine Database file opened, locked and accessed directly Db4oEmbedded.openFile(configuration, name) database operations performed on embedded object container Single user and single thread 8

Embedded Mode: Client Session Virtual Machine ObjectContainer Client Sessions ObjectContainer EmbeddedObjectContainer Database File ObjectContainer Application and database in same virtual machine Database file accessed through client session EmbeddedObjectContainer.openSession() database operation performed on session object container Single user and multiple threads 9

Client/Server Modes: Networking Mode ObjectContainer Database Operations Virtual Machine ObjectContainer ObjectServer Database File ObjectContainer Client opens TCP/IP connection to server Db4oClientServer.openServer(filename, port) Db4oClientServer.openClient(host, port, user, pass) Client sends query, insert, update and delete instructions to server and receives data from the server 10

Client/Server Modes: Out-of-Band Signalling Client Machine Server Machine MessageSender MessageRecipient sendmessage processmessage ObjectContainer Database Operations and Commands ObjectServer Database File Basic client/server mode cannot transmit commands operations are limited to methods of ObjectContainer Out-of-band signalling MessageSender.send(object) MessageRecipient.processMessage(context, message) 11

Replication Database managed by redundant servers data changes on masters or publishers changes replicated to clients of subscribers Several forms of replication supported snapshot replication transactional replication merge replication Replication in db4o has to be coded into application and cannot be configured on an administrative level replication only occurs on demand, i.e. not automatically client/master semantics introduced by developer db4o provides one interface to support all forms of replication 12

Replication Modes: Snapshot Replication Client Client Master Client Client Snapshots of the master database replicated to client state-based periodical schedule Support in db4o special SODA query to detect all new and updated objects 13

Replication Modes: Transactional Replication Client Client Master Client Client Changes are synchronised after transaction operation based changes are replicated immediately Support in db4o single object replication with ReplicationSession 14

Replication Modes: Merge Replication Client Client Master Client Client Changes from client are merged to central server Other clients are updated to reflect changes Can be done either transactionally or on a periodic basis Typically occurs if subscribers are occasionally offline 15

db4o Replication System Introduced in db4o version 5.1 Replication solution separated from db4o core bridges divide between db4o and relational databases uni- or bidirectional replication replication of relational databases based on Hibernate Transfers data between replication providers Supported replication providers db4o to db4o db4o to Hibernate, Hibernate to db4o Hibernate to Hibernate 16

db4o Replication System Requires three steps generating unique IDs and version numbers creating a ReplicationSession object replicating objects Replication mode is dependent on implementation Replication is bidirectional by default replication can be configured to be unidirectional using method ReplicationSession.setDirection(from, to) on ReplicationSession.replicate(object) newer version of object will be transferred to the database with older version Replication has object granularity also traverses new or changed members in object graph 17

db4o Replication System // configuration EmbeddedConfiguration config = Db4oEmbedded.newConfiguration(); config.file().generateuuids(configscope.globally); config.file().generatecommittimestamps(true); ObjectContainer db1 = Db4oEmbedded.openFile(config, "test1.db"); ObjectContainer db2 = Db4oEmbedded.openFile(config, "test2.db"); // replication session ReplicationSession replication = Replication.begin(db1, db2, new ReplicationEventListener() { public onreplicate(replicationevent e) { if (e.isconflict()) { e.overridewith(e.stateinprovidera()); ); // set unidirectional replication.setdirection(db1, db2); 18

db4o Replication System // update database and replicate (transactional replication) Author stanzetta = new Author("Christoph Zimmerli"); db1.store(stanzetta); replication.replicate(stanzetta); replication.commit(); // replicate changed publications (snapshot replication) ReplicationProvider provider1 = replication.providera(); ObjectSet<Publication> result = provider1.objectschangedsincelastreplication(publication.class); for (Publication publication: result) { replication.replicate(publication); replication.commit(); // close the replication session replication.close(); 19

Callbacks Set of methods called in response to events (triggers) db4o events activate and deactivate new, update and delete Methods called before and after event methods starting with can called before event methods starting with on called after event Methods defined by interface ObjectCallbacks interface does not have to be implemented explicitly by persistent class to use its functionality any number of methods can be implemented by persistent class 20

Callbacks package com.db4o.ext; public interface ObjectCallbacks { public boolean objectcanactivate(objectcontainer c); public boolean objectcandeactivate(objectcontainer c); public boolean objectcandelete(objectcontainer c); public boolean objectcannew(objectcontainer c); public boolean objectcanupdate(objectcontainer c); public void objectonactivate(objectcontainer c); public void objectondeactivate(objectcontainer c); public void objectondelete(objectcontainer c); public void objectonnew(objectcontainer c); public void objectonupdate(objectcontainer c); 21

Use Cases for Callbacks Recording or preventing updates methods canupdate() and onupdate() Setting default values after refactoring get values before update using method cannew() Checking object integrity before storing objects check field values using methods cannew() and canupdate() Setting transient fields Restoring connected state when objects activated display graphical elements or restore network connections Creating special indexes detect if a field is queried often and create index automatically 22

Controlling Object Instantiation No convention imposed for persistent classes by db4o Objects are instantiated using one of three techniques using a constructor bypassing the constructor using a translator For certain classes it is important which of these methods is used to retrieve objects if available, bypassing the constructor is default setting behaviour can be configured globally or per class 23

Using Constructors db4o can use a constructor to instantiate objects if no default public constructor is present, all available constructors are tested to create instances of a class null or default values passed to all constructor arguments first successfully tested constructor is used throughout session if instance of a class cannot be created, the object is not stored Settings adjusted through configuration interface // global setting (default: depends on environment) CommonConfiguration#callConstructors(true) // per class setting (default: depends on environment) CommonConfiguration#objectClass(...).callConstructors(true) // exceptions for debugging (default: true) CommonConfiguration#exceptionsOnNotStorable(true) 24

Using Constructors public class Person { Date birthdate; transient Calendar today; public Person() { // get today's date and store it in a transient field this.today = Calendar.getInstance(); public void setbirthdate(date birthdate) { this.birthdate = birthdate; public int getage() { Calendar birth = Calendar.getInstance(); birth.settime(this.birthdate); // NullPointerException in the next line if constructor not called! int years = this.today.get(calendar.year) birth.get(calendar.year); int diff = birth.add(calendar.year, age); return (today.before(birth))? age-- : age; March 18, 2015 Alexandre de Spindler Department of Computer Science despindler@inf.ethz.ch 25

Bypassing Constructors Constructors that cannot handle null or default values must be bypassed db4o uses platform-specific mechanisms to bypass constructors Not all environments support this feature Sun Java Virtual Machine (only JRE 1.4 and above) Microsoft.NET Framework (except Compact Framework) Default setting if supported by current environment Breaks classes that rely on constructors being executed 26

Bypassing Constructors public class Person { Calendar birthdate; int age; public Person(Calendar birthdate) { this.birthdate = birthdate; // calculate age Calendar today = Calendar.getInstance(); // NullPointerException in next line if called with null value! int years = today.get(calendar.year) this.birthdate.get(calendar.year); int diff = birth.add(calendar.year, age); this.age = (today.before(birth))? age-- : age;... 27

Translators Some classes cannot be cleanly reinstantiated by db4o using either method constructor needed to populate transient members constructor fails if called with null or default values Translators control loading and storing of such objects Interface ObjectTranslator public Object onstore(objectcontainer c, Object appobject); public void onactivate( ObjectContainer c, Object appobject, Object storedobject); public Class storedclass(); Interface ObjectConstructor extends ObjectTranslator public Object oninstantiate( ObjectContainer c, Object storedobject); 28

Translators public class Person { String name; Calendar birthdate; transient int age; public Person(String name, Calendar birthdate) { this.name = name; this.birthdate = birthdate; Calendar today = Calendar.getInstance(); int years = today.get(calendar.year) this.birthdate.get(calendar.year); int diff = birth.add(calendar.year, age); this.age = (today.before(birth))? age-- : age; public String getname() {... public Calendar getbirthdate() {... public int getage() {...... 29

Translators public class PersonTranslator implements ObjectConstructor { // map Person object to storage representation public Object onstore(objectcontainer c, Object appobject) { Person person = (Person) appobject; return new Object[] { person.getname(), person.getbirthdate() ; // reconstruct Person object from storage representation public Object oninstantiate(objectcontainer c, Object storedobject) { Object[] raw = (Object[]) storedobject; return new Person((String) raw[0], (Calendar) raw[1]); public void onactivate(objectcontainer c, Object appobject, Object storedobject) { // return metadata about storage representation public Class storedclass() { return Object[].class; CommonConfiguration#objectClass(Person.class).translate( new PersonTranslator()) 30

Type Handlers Instead of Translators, at a lower level. A type handler is registered for a class it should handle. EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration(); configuration.common().registertypehandler( new SingleClassTypeHandlerPredicate( Person.class), new PersonHandler()); As opposed to translators, type handlers write to and read from byte arrays. For example, the PersonHandler class must implement the write method declared by the TypeHandler4 interface. public void write(writecontext writecontext, Object o) { Person person = (Person) o; final byte[] bytes = ; writecontext.writeint(bytes.length); writecontext.writebytes(bytes); 31

Literature db4o Tutorial Course web page db4o Reference Documentation Course web page db4o API Reference Course web page Jim Paterson, Stefan Edlich, Henrik Hörning, and Reidar Hörning: The Definitive Guide to db4o, APress 2006 32