Supporting Persistent Objects In Python Jeremy Hylton

Slides:



Advertisements
Similar presentations
PCT303 – Content Publishing in SharePoint Eugene Rosenfeld Black Blade Associates
Advertisements

1 SRI International Bioinformatics The Ocelot Frame Knowledge Representation System Peter D. Karp, Ph.D. Bioinformatics Research Group SRI International.
Persistent Programming with ZODB 10 th International Python Conference Alexandria, Virginia Jeremy Hylton and Barry Warsaw
Persistent Programming with ZODB 10 th International Python Conference Alexandria, Virginia Jeremy Hylton and Barry Warsaw
Persistent Programming with ZODB 10 th International Python Conference Alexandria, Virginia February 4, 2002 Jeremy Hylton and Barry Warsaw
What is Persistence? Automatic management of persistent storage Frees programmer from writing code to dump objects into files Allows programmer to focus.
(Very) Simple Group Calendar Calendar which can display a whole month, or a single day, with events Can create new appointments with rendezvous information.
Writing persistent classes Persistent if reachable from the root Persistency by storing/loading pickles ZODB must know when an object is accessed or changed.
Transaction Intro slide XXX New builtin get_transaction() Returns transaction for current thread ZEO manages transactions across processes, machines Transactions.
Object orientation and persistent objects Dragos Chirila Finsiel Romania Copenhagen, 24 May 2004.
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Lightweight Languages Workshop November 2002 © 2002 IBM Corporation IBM Lightweight Services Implementing persistent server-side JavaScript Christopher.
Database System Concepts and Architecture
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
My first computer: The Apple ][ It wanted to be programmed.
Thread-Level Transactional Memory Decoupling Interface and Implementation UW Computer Architecture Affiliates Conference Kevin Moore October 21, 2004.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
Chapter 15 Transaction Management. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Transaction basics Concurrency.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
11 3 / 12 CHAPTER Databases MIS105 Lec14 Irfan Ahmed Ilyas.
Chapter 10 Classes Continued
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Architecture of Enterprise Systems: Domain Model and Database layer
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
IMS 4212: Distributed Databases 1 Dr. Lawrence West, Management Dept., University of Central Florida Distributed Databases Business needs.
Common Object Request Broker Architecture (CORBA) CS-328.
LINQ Boot Camp ADO.Net Entity Framework Presenter : Date : Mahesh Moily Nov 26, 2009.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
Institute of Computer and Communication Network Engineering OFC/NFOEC, 6-10 March 2011, Los Angeles, CA Lessons Learned From Implementing a Path Computation.
Entity Beans BMP Celsina Bignoli
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Rethinking Game Architecture with Immutability Jacob Dufault Faculty Advisor: Dr. Phil Bernhard, Dept of Computer Science, Florida Institute of Technology.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
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.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
DireXions – Your Tool Box just got Bigger PxPlus Version Control System Using TortoiseSVN Presented by: Jane Raymond.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
CHEP 2003 March 22-28, 2003 POOL Data Storage, Cache and Conversion Mechanism Motivation Data access Generic model Experience & Conclusions D.Düllmann,
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
CS425 / CSE424 / ECE428 — Distributed Systems — Fall 2011 Some material derived from slides by Prashant Shenoy (Umass) & courses.washington.edu/css434/students/Coda.ppt.
OOPSLA 2001 Choosing Transaction Models for Enterprise Applications Jim Tyhurst, Ph.D. Tyhurst Technology Group LLC.
Persistent State Service 1  Concept  Persistence is the ability of an object state to survive termination of the process in which the object executes.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
Object storage and object interoperability
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
E.Bertino, L.Matino Object-Oriented Database Systems 1 Chapter 9. Systems Seoul National University Department of Computer Engineering OOPSLA Lab.
Database Management Systems.  Instructor: Yrd. Doç. Dr. Cengiz Örencik   Course material.
1 Channel Access Concepts – IHEP EPICS Training – K.F – Aug EPICS Channel Access Concepts Kazuro Furukawa, KEK (Bob Dalesio, LANL)
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
G.Govi CERN/IT-DB 1GridPP7 June30 - July 2, 2003 Data Storage with the POOL persistency framework Motivation Strategy Storage model Storage operation Summary.
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED INTERSTAGE BPM ARCHITECTURE BPMS.
Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.
Databases and DBMSs Todd S. Bacastow January 2005.
EE2E1. JAVA Programming Revision Lecture.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
Data, Databases, and DBMSs
The command invocation protocol
On transactions, and Atomic Operations
Introduction to Databases Transparencies
On transactions, and Atomic Operations
Thor: a Fast, Distributed, Persistent Object System
Understanding and Designing with EJB
Channel Access Concepts
Presentation transcript:

Supporting Persistent Objects In Python Jeremy Hylton

(C) 2002 Zope Corp. What is persistence? Data lives longer than programs –Files, pipes, relational databases, etc. –But, discontinuity of representation Orthogonal persistence –Automatic management of program state –Independent of data type or longevity –Allow programmer to focus on application data model

(C) 2002 Zope Corp. Python approach Goals –Minimize changes to existing programs –Work with standard interpreter Zope Object Database (ZODB) –Support Zope application server –Originally targeted for web development Separate database and storage layers

(C) 2002 Zope Corp. Not on todays agenda Benefits of persistence Discussion of related work –Early work PS-algol, Napier88 –Much recent work on Java PJava, ObjectStore PSE

(C) 2002 Zope Corp. ZODB key ideas Persistence by reachability –Any reachable object is saved Transactions to control updates –Safe sharing among clients Implement with Persistent mixin –Provides hook for persistence –Compromise on transparency

(C) 2002 Zope Corp. Persistent base class C extension type that defines –Four _p_ attributes –Custom attribute accessors –Efficient C API Marks serialization boundaries Interacts with database –Load objects on demand –Register modifications with TM

(C) 2002 Zope Corp. Persistence by reachability Any object reachable from ZODB root is persistent

(C) 2002 Zope Corp. A simple example from Persistence import Persistent from Transaction import get_transaction from ZODB.FileStorage import DB class Counter(Persistent): _value = 0 def inc(self): self._value += 1 def main(): fs = DB(data.fs) conn = db.open(); root = conn.root() obj = root[myobj] = Counter() get_transaction().commit() obj.inc() get_transaction().commit()

(C) 2002 Zope Corp. Object serialization Standard pickle library –Serializes arbitrary object graph –Raises TypeError for sockets, files, &c. –Instance vars serialized via dictionary Hooks to define custom state –__getstate__() / __setstate__() –Persistent mixin ignores _v_ attributes

(C) 2002 Zope Corp. Pickling persistent objects Stores objects in separate records –Persistent objs pickled as oid + class –Works with cache to maintain identity Handling non-persistent objects –Copied into record of containing object –Sharing by persistent objs is problematic

(C) 2002 Zope Corp. Object identity / caching Cache maintains oid obj mapping –Guarantees only one copy of object –Unpickler loads all referenced objects Ghost objects –Only Persistent header initialized –No instance state loaded –State loaded on first object access LRU cache of recent objects

(C) 2002 Zope Corp. Attribute access handlers Persistent implements C wrappers –Override tp_getattro, tp_setattro slots –Mediate access to instance variables –Crucial Python feature

(C) 2002 Zope Corp. Example __getattribute__() hook class Example(object): _p_state = False def _p_activate(self): print "activate" self._p_state = True def __getattribute__(self, attr): print "intercept", attr if not attr.startswith("_p_") and not self._p_state: self._p_activate() return super(Example, self).__getattribute__(attr) >>> obj = Example(); obj.value = "test" >>> print obj.value intercept value intercept _p_state intercept _p_activate activate test

(C) 2002 Zope Corp. Transactions Supports multiple threads, processes –Independent database connections –Updates visible at transaction boundaries Optimistic concurrency control –When conflict occurs, abort and retry On error, abort to restore consistency –Reverts to last saved state

(C) 2002 Zope Corp. Concurrency and conflicts Invalidations sent at commit time –Clients process at transaction boundaries Conflicting transactions aborted –Write conflict at commit time –Read conflict on object access Application must retry on conflict –Can use generic wrapper –Can define conflict resolution method

(C) 2002 Zope Corp. Retrying conflicts Example wrapper for retries def transact(f, retries=3): def wrapper(*args, **kwargs): n = retries while n: try: try: return f(*args, **kwargs) finally: get_transaction().commit() except ConflictError: n -= 1 if n == 0: raise except: get_transaction().abort() raise return wrapper

(C) 2002 Zope Corp. Other features Undo support –Storage stores multiple revisions –Transactional undo reverts to earlier state BTrees: efficient persistent containers Storing code in database

(C) 2002 Zope Corp. Limitations Schema evolution –Must code manually in __setstate__() Database management –Manual pack() to remove revisions, do GC Sharing of non-persistent objects Integration with legacy code –Multiple inheritance helps –Factory classes

(C) 2002 Zope Corp. Getting the software –info central for ZODB ZODB 3.1 released Oct –Uses ExtensionClass ZODB4 alpha planned for Dec –Based on Python 2.2 type support –Fewer onions in the varnish