SlideShare une entreprise Scribd logo
1  sur  32
APACHE SLING&FRIENDSTECHMEETUP
BERLIN, 28-30SEPTEMBER 2015
ConflicthandlingwithOak
Michael Dürig, Adobe Research
Agenda
adaptTo()2015 2
 Why?
 What?
 How?
 Conclusion
https://www.flickr.com/photos/35168673@N03/3792471453/
All you need toknow about JCR
adaptTo()2015 3
 Hierarchical database
 Oak implementsJCR
 Pluginsfor customisation
adaptTo()2015 4
Why?
Collaboration causesconflicts
adaptTo()2015 5
 Collaborative applications
 Internetscale applications
 Scalability
 Weak consistency
adaptTo()2015 6
What?
Whatis a conflict?
adaptTo()2015 7
 Conflictsemantics
 Back-end
 Application
 Incompatible, concurrent updates
Resource inJCR
adaptTo()2015 8
 Identifiedby path
 No conflicts between
 Nodes and properties
 Items with different names
Incompatibleupdates
adaptTo()2015 9
Change Add Remove
Remove NA
Add NA
Change
Saving changes
adaptTo()2015 10
 Rebase
 Handleconflicts
 Built-in
 Custom
 Persist or fail
 Run commit hooks HEAD
adaptTo()2015 11
How?
Conflicthandling strategies
adaptTo()2015 12
Lock Retry Resolve Avoid
Pessimistic Optimistic Proactive Anticipatory
Consensus Bruteforce Resolving Contentionfree
Wasteful Wasteful Economical Economical
Serial Parallel
Transparent Nottransparent Transparent Nottransparent
Constrained Constrained
Atomiccounter
adaptTo()2015 13
 Use cases
 Rating
 Booking
 Buildingblocks
 Up/down votes
 Average
Naïve implementation
adaptTo()2015 14
void increment(long delta) {
while (true) {
Property counter = node.getProperty("count");
long count = counter.getLong();
counter.setValue(count + delta);
try {
counter.getSession().save();
break;
} catch (RepositoryException ignore) { }
}
}
Avoiding conflicts
adaptTo()2015 15
 Datastructure
 Avoid application conflicts
 Leverage back-end
Share nothing
adaptTo()2015 16
 Counterper process
 Sumof counters
 Accumulatevia commithook
Usage
adaptTo()2015 17
void increment(long delta) {
session.getNode("/counter")
.setProperty("oak:increment", delta);
session.save();
}
long get() {
session.getNode("/counter")
.getProperty("oak:counter").getLong();
}
Accumulate
adaptTo()2015 18
public class AtomicCountEditor extends DefaultEditor {
@Override
public void propertyAdded(PropertyState after) {
...
}
@Override
public void leave(NodeState before, NodeState after) {
...
}
}
Accumulate
adaptTo()2015 19
public class AtomicCountEditor extends DefaultEditor {
private final NodeBuilder builder;
private long total;
public AtomicCountEditor(NodeBuilder builder) {
this.builder = builder;
total = builder.getProperty("oak:counter").getValue(LONG);
}
...
}
Accumulate
adaptTo()2015 20
public void propertyAdded(PropertyState after) {
if ("oak:increment".equals(after.getName()) {
total += after.getValue(LONG);
builder.removeProperty("oak:increment");
}
}
public void leave(NodeState before, NodeState after) {
builder.setProperty("oak:counter", total);
}
Demo
adaptTo()2015 21
https://www.flickr.com/photos/ruiwen/3260095534/
From here...
adaptTo()2015 22
 Bidding
 Maximum instead of addition
 Shopping
 Set union insteadof addition
 Signal
 Logical or insteadof addition
Resolvingconflicts
adaptTo()2015 23
 Conflicthandler
 Close to source
 Noretry
Multi-valueregister
adaptTo()2015 24
 Store conflictingvalues
 Materialiseconflict
 Delegate resolution
 Additional round trip
Usage
adaptTo()2015 25
session1.getNode("/mv").setProperty("value", 1);
session2.getNode("/mv").setProperty("value", 2);
session1.save();
session2.save();
session3.getProperty("/mv/value"); // Multi valued [1, 2]
Conflicthandler
adaptTo()2015 26
public interface PartialConflictHandler {
Resolution addExistingProperty(...);
Resolution changeDeletedProperty(...);
Resolution changeChangedProperty(...);
Resolution deleteDeletedProperty(...);
Resolution deleteChangedProperty(...);
Resolution addExistingNode(...);
Resolution changeDeletedNode(...);
Resolution deleteChangedNode(...);
Resolution deleteDeletedNode(...);
}
enum Resolution {
OURS,
THEIRS,
MERGED
}
Conflicthandler
adaptTo()2015 27
@Override
public Resolution addExistingProperty(
NodeBuilder parent,
PropertyState ours,
PropertyState theirs) {
parent.setProperty(
ours.getName(),
union(getValues(ours), getValues(theirs)), LONGS);
return Resolution.MERGED;
}
@Override
public Resolution changeChangedProperty(
NodeBuilder parent,
PropertyState ours,
PropertyState theirs) {
parent.setProperty(
ours.getName(),
union(getValues(ours), getValues(theirs)), LONGS);
return Resolution.MERGED;
}
Conflicthandler
adaptTo()2015 28
@Override
public Resolution changeDeletedProperty(...) {
return Resolution.OURS;
}
@Override
public Resolution deleteChangedProperty(...) {
return Resolution.THEIRS;
}
@Override
public Resolution deleteDeletedProperty(...) {
return Resolution.MERGED;
}
Demo
adaptTo()2015 29
https://www.flickr.com/photos/ruiwen/3260095534/
adaptTo()2015 30
Conclusion
Conclusion
adaptTo()2015 31
 Avoid conflicts
 Private copy
 Accumulate
 Resolve conflicts
 Custom handler
 Prevent retry
Thank you
adaptTo()2015 32
 https://github.com/mduerig/oak-crdt

Contenu connexe

Similaire à Avoiding and dealing with conflicting updates in Oak

Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)Alina Vilk
 
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slidesC# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slidesSami Mut
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code lessAnton Novikau
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonAEM HUB
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling RewriterJustin Edelson
 
MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library Magda Miu
 
Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2Max Pronko
 
Testable Android Apps using data binding and MVVM
Testable Android Apps using data binding and MVVMTestable Android Apps using data binding and MVVM
Testable Android Apps using data binding and MVVMFabio Collini
 
Gradle plugin, take control of the build
Gradle plugin, take control of the buildGradle plugin, take control of the build
Gradle plugin, take control of the buildEyal Lezmy
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Schalk Cronjé
 
C++ Interface Versioning
C++ Interface VersioningC++ Interface Versioning
C++ Interface VersioningSkills Matter
 
SOLID & IoC Principles
SOLID & IoC PrinciplesSOLID & IoC Principles
SOLID & IoC PrinciplesPavlo Hodysh
 
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...DicodingEvent
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorialAnh Quân
 
Google analytics
Google analyticsGoogle analytics
Google analyticsSean Tsai
 

Similaire à Avoiding and dealing with conflicting updates in Oak (20)

Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
 
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slidesC# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code less
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin Edelson
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library
 
Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2
 
Testable Android Apps using data binding and MVVM
Testable Android Apps using data binding and MVVMTestable Android Apps using data binding and MVVM
Testable Android Apps using data binding and MVVM
 
Gradle plugin, take control of the build
Gradle plugin, take control of the buildGradle plugin, take control of the build
Gradle plugin, take control of the build
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Devoxx 2012 (v2)
Devoxx 2012 (v2)Devoxx 2012 (v2)
Devoxx 2012 (v2)
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016
 
C++ Interface Versioning
C++ Interface VersioningC++ Interface Versioning
C++ Interface Versioning
 
SOLID & IoC Principles
SOLID & IoC PrinciplesSOLID & IoC Principles
SOLID & IoC Principles
 
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
 
Google GIN
Google GINGoogle GIN
Google GIN
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
Google analytics
Google analyticsGoogle analytics
Google analytics
 
Sprint 54
Sprint 54Sprint 54
Sprint 54
 

Dernier

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 

Dernier (20)

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 

Avoiding and dealing with conflicting updates in Oak

Notes de l'éditeur

  1. Apache Jackrabbit Oak offers better horizontal scalability and concurrency than its predecessor, Apache Jackrabbit 2. The downside of which is increased chances of conflicts between concurrent updates. In this session I demonstrate how to deal with such conflicts by taking advantage of Oak's underlying consistency model. I will show how to build functionality like counting, voting, rating, negotiating, bidding, etc. common to collaborative applications. Such functionality traditionally requires some form of global consensus (e.g. locking, atomic commit protocols, ...). I will show how with Oak it is often possible to avoid conflicts all together by choosing the right content model. For cases where this is not possible I will discuss the mechanisms that Oak provides to deal with conflicts while they occur and after the fact.
  2. Why should I care about conflicts? Why can’t this be taken care of by the backend? What is a conflict? Specific to the application domain and also to back-end. Definition for Oak. How can we handle conflicts? What does Oak offer? Examples.
  3. All you need to know about JCR and Oak (for this session): Oak is an implementation of the JCR (Java content repository) standard A JCR is a hierarchical database. Its content tree is made up of nodes and properties. Properties are the leaves of the tree and carry values. Oak heavily relies on commit hook plugins for providing its functionality. A commit hook can pass, edit or fail a commit. Custom commit hooks can provide further functionality.
  4. Conflicts appear in the context of collaboration. While this is evident for some applications like collaboratively editing the same spread sheet, it isn’t for others. For example updating the like counts on forum posts is a not so evident form of collaboration. The necessity to rely on a weaker consistency model for such large scale applications force us to cope with conflicts where we traditionally would have relied on the backend. Weaker consistency: giving up on ACID, aka NoSQL, trade consistency for throughput
  5. A conflict is caused by multiple parties updating the same shared resource concurrently in incompatible ways. The exact meaning of incompatible is domain specific. However, there is usually a common least dominator specific to the back-end. When building an application it is important to know the conflict semantics of the back-end and the conflict semantics of the application domain. This allows the application to be built in a way to avoid conflicts where possible and to choose the cheapest method for resolving them otherwise.
  6. Updates on nodes never conflict with updates on properties. Also updates on items with different names never conflict. All conflict are either between nodes of the same name or between properties of the same name.
  7. Updates of items of the same name and type conflict when (marked with a red cross) changing an item that has been concurrently removed adding an item that has been concurrently added with a different value changing an item that has been concurrently changed to a different value Such updates do not conflict when (marked with a green check) removing an item that has been concurrently removed adding an item that has been concurrently added with the same value changing an item that has been concurrently changed to the same value The other combination are not applicable as they cannot occur: an item cannot be concurrently removed or changed before it has been added. Oak’s ConflictHandler interface has one method for each of these conflicts. Implementations are responsible to resolve these conflict according to the applications need.
  8. When saving changes Oak rebases them on top of the latest trunk resolving conflicts along the way. On success the rebased changes are persisted. Otherwise saving fails with an exception. Rebasing is done by calculating the difference between the current state of the sessions against its base state and applying them on top of the latest trunk. This is the point where actual conflicts are detected and resolved according to the mechanism shown on the previous slide. Additionally this the point where Oak allows injection of custom conflict handlers.
  9. Strategies for handling conflicts in order of decreasing cost: Lock Well known, pessimistic approach effectively serialising access to the back-end thus leaving most CPU cores idle. Requires upfront global consensus, which can be expensive to acquire. Transparent to the application. Retry Optimistic brute force approach relying on conflicts being rare. Conflicts are detected after the fact and commits are retried by the application, which wastes CPU cycles. Not transparent to the application due to the retry logic necessary. Constrained by the conflict semantics of the back-end being a subset of those of the application. Otherwise some conflicts will not be detected. Resolve Proactive approach relying on conflicts being rare. Conflicts are detected after the fact and resolved as part of the commit process through custom commit hooks. Transparent to the application. Constrained by the conflict semantics of the back-end being a subset of those of the application. Otherwise some conflicts will not be detected. Avoid Leverage conflict semantics of the application to avoid conflicts. Fully parallel, no point of contention. Not transparent to the application as it needs a conflict aware data model
  10. Atomic counters are useful to implement e.g. rating functionality for blog comments. More complex behaviour (e.g. averages) can be implemented by combining multiple counters. A naïve counter implementation on Oak is prone to data races though as in some cases no conflict is detected on back-end.
  11. This naïve implementation of a counter retries to update its value until it succeeds. Apart from the brute force approach, the implementation has a data race: two concurrent increments by the same value will result in the counter only being updated once.
  12. Leverage conflict semantics of the back-end to resolve application specific conflicts. This requires applications to choose their data model accordingly.
  13. A better approach uses a private counter per involved process, avoiding conflicts altogether. The sum of all private counters is the total sum of the counter. In Oak we can take this further and use a custom commit hook that will take care of accumulating the individual counters into one global value. Also as Oak implements has strong session isolation we don’t need to worry about name clashes of the involved counters. Accumulation allows for easy indexing/sorting/querying of counters values, which would otherwise not be possible.
  14. The retry logic becomes unnecessary when each process has its own counter: instead of counting itself we set the desired increment and let the accumulation logic in the commit hook deal with updating the counter.
  15. To accumulate the individual counter values into on consistent counter value we need to install a custom commit hook into Oak. A commit hook is called once changes are committed and can arbitrarily modify what is being committed. In our case we need to detect additions of properties named oak:increment and add their values to the value of the oak:counter property. Subsequently we can discard the oak:increment property as it is not needed anymore and doesn’t need to be persisted. We implement the commit hook by extending from DefaultEditor. We need to override the propertyAdded method, which is called whenever the commit contains a newly added property and the leave method, which is called once this commit hook is done.
  16. On initialisation we retrieve the current counter value from the oak:counter property. In addition the constructor receives a NodeBuilder instance to record out changes to the commit.
  17. The propertyAdded method updates the total value by adding this counters value and subsequently discarding the transient oak:increment property. When done the oak:counter value will be assigned back to the respective property in the leave method.
  18. The concept is easily adapted to other uses cases. For bidding in an auction we would replace addition with maximum in the accumulation step. This ensures eventually awarding the highest bidder. An e-commerce application would use set union instead of addition to add items to a trolley. For signalling a certain condition with a shared boolean flag, we would use logical or instead of addition. Most generally this concept applies whenever the elements under consideration together with the accumulation function form a semilattice. Put simply: for any two elements we know how to accumulate them.
  19. Resolve conflicts as they occur instead of retrying a failed commit. Requires injection of a custom conflict handler. Oak supports this through implementations of the ConflictHandler and related interfaces.
  20. A multi-value register is much like a register for a single value unless that in the case of a conflict it will store all conflicting values. Multi-value registers provide a simple way for applications to detect a conflict and resolve it after the fact. Such a conflict resolution scheme adds additional round trips in the presence of conflicts though.
  21. Updating the same property from two different sessions concurrently with incompatibly values should not fail (as it usually does). Rather should it create the property as a multi-valued storing both conflicting values. Later updates can overwrite that value again.
  22. Custom conflict handlers can be injected into Oak to resolve conflicts from concurrent updates. A conflict handler needs to implement a method for every type of conflict that can occur. The arguments to those methods provide access to all values of the conflicting parties. It has to come up with a resolution by either choosing one of the values (OURS or THEIRS) or by implementing some custom merge algorithm (MERGED). In addition a partial conflict handler can also choose not to cope with a conflict and result null instead. This means another partial conflict handler further up the chain can take care of the conflict. Oak composes all partial conflict handlers into a (total) conflict handler. This is done by chaining the partial conflict handlers together and adding a default handler at the end of the chain, which will just cause a commit to fail if it detects an unresolved conflict.
  23. The implementations of addExistingProperty and changeChangedProperty read the values of both parties, merge them into one multi-valued property and use that value to resolve the conflict.
  24. The remaining cases can simply resolve to OURS, THEIRS and MERGED, respectively.
  25. Using carefully crafted data structures it is often possible to avoid conflicts altogether. The general pattern here is to provide a private copy to every process involved and accumulate the values later on. Oak supports accumulation through custom commit hooks. This way of avoiding conflict is loosely based on “Convergent and Commutative Replicated Data Types” [1]. The reason for the relative simplicity of our implementations is Oak’s rather strong consistency model (Oak is sequentially consistency, which is only slightly weaker than linearizable). The general approach discussed in [1] is based on a much weaker “eventual consistent” storage model. Alternatively Oak also provides hooks to resolve conflicts as they occur. This allows conflicts to be handled as close as possible to their source preventing the need to retry failed commits. [1] http://hal.upmc.fr/file/index/docid/555588/filename/techreport.pdf