• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Detailed look at consistent NoSQL data storage with ModeShape

Detailed look at consistent NoSQL data storage with ModeShape



ModeShape 3 is an elastic, strongly-consistent hierarchical database that supports queries, full-text search, versioning, events, locking and use of schema-rich or schema-less constraints. It's ...

ModeShape 3 is an elastic, strongly-consistent hierarchical database that supports queries, full-text search, versioning, events, locking and use of schema-rich or schema-less constraints. It's perfect for storing files and hierarchically structured data that will be accessed by navigation or queries. You can choose where (if at all) you want ModeShape to enforce your schema, but your structure and schema can always evolve as your needs change. Sequencers make it easy to extract structure from stored files, and federation can bring into your database information from external systems. It's fast, sits on top of an Infinispan data grid, and open source. This presentation provides an introduction to how ModeShape 3 works, and was given at the Alpes JUG (in Grenoble, France) and the Geneva JUG (in Switzerland).



Total Views
Views on SlideShare
Embed Views



3 Embeds 2,112

http://modeshape.wordpress.com 2082
http://planet.jboss.org 28
http://www.365dailyjournal.com 2



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • @SyedKRasheed It already is: Data Virtualization (http://www.redhat.com/products/jbossenterprisemiddleware/data-virtualization/) includes ModeShape 3.x
    Are you sure you want to
    Your message goes here
  • Is there any plans to offer this as commercial offering?
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Detailed look at consistent NoSQL data storage with ModeShape Detailed look at consistent NoSQL data storage with ModeShape Presentation Transcript

    • Elastic consistentNoSQL data storage withModeShape 3April 2013Randall HauchPrincipal Software Engineer at Red Hat@rhauch@modeshape
    • SQL databases2BLOBorCLOBrecursive JOINsand queriesSQL types(CHAR, VARCHAR, etc.)
    • NoSQL databases3http://www.flickr.com/photos/8431398@N04/2680944871
    • NoSQL databases4DocumentKey/ValueColumn-orientedGraphOthers, including hierarchical...
    • ModeShapeAn open sourceelastic in-memory hierarchical databasewith queries, transactions, events & more5
    • Hierarchical• Organize the data into a tree structure– A lot of data has natural hierarchies– Conceptually similar to a file system– Nodes with properties– References enable graphs (not limited to parent/child)• Navigate or query– Quickly navigate to related (or contained) data– Use queries to find data independently of location6
    • Nodes and names• Node names– consist of a local part and a namespace (like XML names)– need not be unique within a parent node (but it is recommended)• Namespaces– are URIs that are registered and can be assigned a prefix– prefixes are repository-wide, but can be permanently changed oroverridden locally by clients7Each  node  has  a  name.Namespace  prefix:  “”  (empty  string)Local  part:    “equipment”Namespace  prefix:  “jcr”Local  part:    “system”
    • Node paths• Absolute paths– the sequence of names from the root to the node in question– always start with a ‘/’ signifying the root node– may use a 1-based same-name-sibling positional index (which canchange if order of children are changed)8Each  node  is  identified  by  a  path.These  paths  are  equivalent:/facilities/San Fransisco/Eastford Plaza/facilities[1]/San Fransisco[1]/Eastford Plaza[1]
    • Node paths (cont’d)• Relative paths– the sequence of names from one node to another– never start with a ‘/’– similar to file system relative paths9Paths  can  be  relative  and  can  use  “.”  and  “..”From  the  “passenger”  node  to  the  “Eastford Plaza”  node:../../facilities/San Fransisco/Eastford Plaza
    • Node identifier• Used to lookup that node directly– no navigation is required– will never change after a new node is saved*, even if moved(unlike paths)– behaves as a “unique key” within the workspace(shared nodes behave differently)• A node in one workspace can “correspond” to a node ina different workspace– they have the same identifier– one was created by “cloning” the other (in separate workspaces)– state can be transferred with “update” process– corresponding nodes share the same version history– this behavior is critical to understanding when to use separate workspaces10Each  node  has  an  opaque  string  identifier* ModeShape assigns identifier at creation and never changes it
    • Properties• Nodes can have 0+ properties– each property must havea unique name in a node• Properties have values– single-valued: exactly 1non-null value– multi-valued: 0 or morepossibly null values• Values– are immutable– have an implicit type– are accessed by desiredtype with auto-conversion;e.g., value.getString() orvalue.getNode()11The  only  place  to  store  data  on  the  nodesProperty Type Java typeSTRING java.lang.StringNAME java.lang.StringPATH java.lang.StringBOOLEAN java.lang.BooleanLONG java.lang.LongDOUBLE java.lang.DoubleDATE java.util.CalendarBINARY javax.jcr.BinaryREFERENCE javax.jcr.NodeWEAKREFERENCE javax.jcr.NodeDECIMAL java.math.BigDecimalURI java.lang.String
    • BINARY property values• Any size binary content– read/written via streams• Separate storage– content keyed by SHA-1– property value stored with nodecontains SHA-1 and resolvedwhen stream is read– streamed content always buffered• Automatic text extraction– text is used for full-text searching• Choices for binary storage– File, DBMS, MongoDB, data grid– Custom–12Binary  Storage
    • Workspace• Comprised of– a single root node– the “/jcr:system” branch containing the system-wide information– other nodes that have child nodes and properties13Named  segments  of  a  repository
    • Putting the pieces together• Repository contains– named workspaces– namespaces, node types, version storage, etc.• Workspaces have– hierarchy of nodes– access to the shared system area• Nodes have– name (can change)– identifier (doesn’t change)– path (can change)– properties (can change)• Properties have values– single-valued: exactly 1 non-null value– multi-valued: 0 or more possibly null values• Values– are immutable & can be reused– have an implicit type– are accessed by desired type with auto-conversion; e.g., value.getString()14
    • Session• Authenticated and authorized– only sees content authorized by credentials– only changes content authorized by credentials– use the built-in auth service or integrate with your own• Stateful– changes are kept in the session’s transient state until the session is saved– changes can be dropped without saving (e.g., “refreshing the session”)• Lightweight– intended to be created, used, then closed– pooling sessions is more trouble than it’s worth• Self-contained– exposed objects are tied to the session; can’t be shared w/ others15An  authenticated  connection  to  a  repository,  used  to  access  a  single  workspace
    • With or without schema• Choose how much schema is enforced– define patterns for values and structure– use different patterns for different parts of the database– change the patterns over time– use the “best” levels of schema validation– evolve as necessary16STRICTENFORCEMENTNOENFORCEMENT
    • Queries• Find the data independently of the hierarchy• SQL-like language (including full-text search)17SELECT * FROM [car:Car] WHERE [car:model] LIKE ‘%Toyota%’ AND [car:year] >= 2006SELECT [jcr:primaryType],[jcr:created],[jcr:createdBy] FROM [nt:file]WHERE PATH() LIKE $pathSELECT [jcr:primaryType],[jcr:created],[jcr:createdBy] FROM [nt:file]WHERE PATH() IN (SELECT [vdb:originalFile] FROM [vdb:virtualDatabase]WHERE [vdb:version] <= $maxVersionAND CONTAINS([vdb:description],xml OR xml maybe))SELECT file.*,content.* FROM [nt:file] AS fileJOIN [nt:resource] AS content ON ISCHILDNODE(content,file)WHERE file.[jcr:path] LIKE /files/q*.2.vdb
    • Sequencing• Automatically extract structured content– just write BINARY or STRING property values on nodes, then save– sequencers run asynchronously based upon path rules & MIME types– output stored in repository at configurable location• Sequencers– DDL (variety)– text (fixed width, delimited)– Microsoft Office™– Java (source & class)– ZIP (and JAR/WAR/EAR)– XML, XSD, and WSDL– Teiid VDBs– audio (MP3)– images– CND– custom181)  upload2)  notify3)  derive  and  storeSequencers4)  navigate  or  query
    • Federation• Access data in external systems– external data projected as nodeswith properties and node types– supports read and optional writewith same validation rules– transparent to applications• Connector options– File system– Local git– CMIS repository– custom– (more are planned)19External  source  BExternal  source  A
    • Other features• Events– register listeners to be notified of changes in content– optional criteria limits what listeners are interested in• Versioning– checkin/checkout nodes & subtrees– branch, merge, restore• Locking– short-lived locks (longer than transaction scope)• Namespace management– programmatically (un)register namespaces• Node type management– programmatically/declaratively define or update node types• Monitoring– statistics for a variety of metrics20
    • Public APIs21
    • Java API• Standard Java API (JSR-283)– javax.jcr packages– programmatically access,find, update, query content– commonly needed features:events, versioning, etc.– 95% of API• ModeShape extensions– additional node type management methods– additional event types– additional Binary value methods (hash)– additional JCR-QOM language objects– cancel queries– sequencer and text extraction SPIs– monitoring API22
    • Other APIs• JDBC driver– connect to local or remote repository– execute queries– access database metadata– enables existing applications to access content• RESTful API– POST, PUT, GET, DELETE methods– JSON representations of one or multiple nodes– Streams large binary values– Execute queries• WebDAV API– Exposes content as files and directories– Mount repository using file system23
    • ModeShapeAn open sourceelastic in-memory hierarchical databasewith queries, transactions, events & more24
    • Elastic• Add more processes to increase storagecapacity and/or throughput– Transparent to applications!– No master, no slaves– Data is rebalanced as needed– Optionally separate database engine from storageprocesses• Fault tolerant– Processes can fail without loss of data– Cross-data center distribution (in near future)25
    • In-memory• Memory is really fast (and cheap)• Why not keep all data in application memory?– practical limits to memory on particular machines– memory isn’t shared between machines– data stored in memory isn’t durable– no queries, structure, or transactions• ModeShape– distributes multiple copies of data across the combinedmemory of many machines– persist data to disk or DB (if really needed)– transparent to applications26
    • Strongly consistent• ACID– Atomic, Consistent, Isolated, Durable– Already familiar to most developers– Easy to reason about code– Writes don’t block reads (MVCC)– Writes to one node don’t block writes to others• JTA– Participate in user transactions– Works with Java EE27
    • Why not eventually-consistent?• In eventually-consistent databases– changes made by one client will eventually (but notimmediately) be propagated to all processes– other clients won’t see latest data right away, yet can still makeother changes– there may be multiple versions of a particular piece of data• Can be ideal for some scenarios– read-heavy and/or best-effort• Applications that update data may need to– expect inconsistencies (and/or multiple versions)– specify conflict strategies– resolve conflicts (inconsistencies)28
    • Clustering topologies29
    • Single process30......ModeShapeInfinispan cache(local)Persistent Storedata
    • Small cluster31......ModeShapeInfinispan cache(replicated)......ModeShapeInfinispan cache(replicated)......ModeShapeInfinispan cache(replicated)Persistent Storedataeventsdataeventsdatadatadata
    • Moderate single- or multi-site cluster32......ModeShapeInfinispan(distributed)......ModeShapeInfinispan(distributed)dataevents......ModeShapeInfinispan(distributed)dataevents ......ModeShapeInfinispan(distributed)dataevents...
    • Large single- or multi-site cluster33......ModeShape......ModeShapeevents......ModeShapeevents ......ModeShapeevents...Infinispan data griddatadata data data
    • Philosophy• Often useful to start writing the code to create the nodes– use unstructured nodes to start out– create a node hierarchy using the natural data, and not too narrow or wide– determine when to use properties vs children with properties– determine how nodes will be named– set the properties using the desired names• Step back– look at structural patterns and naming conventions– identify patterns, constraints, cardinalities, and limitations in property values– identify sets of properties that form characteristics– identify children and properties that are always there• Create node types and mixin node types– use node types for essential/critical aspects that will likely never change– use mixin types wherever possible– consider how the data will be queried (more on this later)34Start  creating  content,  and  then  design  the  structure
    • Node type• Define required and allowed properties– rules applied based upon: name, type, and multiplicity (wildcards allowed)– rules define: default value(s), attributes (e.g., autocreated, mandatory, protected,versioning semantics, applicable query operators, used to order query results, full-text searchability), value constraints• Define required and allowed child nodes– rules applied based upon: child name and required type (wildcards allowed)– rules define: default type for child node of a given name pattern, and attributes(e.g., autocreated, mandatory, protected, versioning semantics, whether same-name-siblings are allowed)• Node type characteristics– the supertypes (for inheritance)– whether it can be added/removed (“mixed in”) after a node is created– whether it is abstract– whether child nodes are ordered– whether it can be queried– which property or child node should be considered the “primary item” (if any)35Enforce  structural  restrictions  on  nodes  and  properties
    • Node and node types• Every node has a “primary type”– specified when the node is created; defaults to “nt:unstructured”– name of type is stored in the single-valued mandatory “jcr:primaryType” property– implementations may support changing primary type (ModeShape does)• Every node has 0+ “mixin types”– can be added to a node at any time– can be removed from a node (assuming the node is valid without it)– name of mixins are stored in the multi-valued “jcr:mixinTypes” property• A node is valid only when– every property has an applicable property definition rule in the primary type (or itssupertypes) or in any of the mixin types (or their supertypes)– every child node has an applicable child node definition rule in the primary type (orits supertypes) or in any of the mixin types (or their supertypes)– validation is performed when saving a session36How  are  node  types  used?
    • Wrap-up37
    • Best practices (1 of 2)• Build structure first, then node types– most important to get your node structure right– it will change over time anyway, so don’t define the node types too soon• Use mixin node types and mixins– where possible define sets of properties as mixins– use in primary types and dynamically add to nodes• Limit use of same-name-siblings– useful when required, but can be expensive and difficult to use (i.e., paths change)• Prefer hierarchies– moderate numbers of child nodes, use multiple levels if necessary• Store files and folders with ‘nt:file’ and ‘nt:folder’– use it wherever appropriate; not for all binary data, though!• Verify features are enabled– improves portability and safety with configuration changes• Import and export– avoid document view; use system view wherever possible38
    • Best practices (2 of 2)• Prefer JCR-SQL2 and JCR-QOM over other query languages– by far the richest and most useful– do this even when it appears the queries are more complicated• Only Repository is thread-safe; no other APIs are– don’t share sessions– don’t share anything between sessions• Register all listeners in special long-lived sessions– do nothing else with these sessions, however (Session is not threadsafe)– get off the notification thread ASAP, using work queues where necessary– Session is not threadsafe• Create new sessions rather than reusing a pool of sessions– Sessions are intended to be lightweight as possible– Create a session, use it, log out (even web applications and services!)• Avoid deprecated APIs– either perform poorly or are a bad idea; besides, they’ll be removed eventually• Use Session.save() not Node.save()39
    • • Project ! http://modeshape.org• Blog ! http://modeshape.wordpress.com• Twitter ! @modeshape• IRC ! #modeshape (irc.freenode.org)• Code ! http://github.com/modeshape40Want more ModeShape?
    • Questions?41