What do you mean, Backwards Compatibility? Trisha Gee, Java Driver - - PowerPoint PPT Presentation

what do you mean backwards compatibility
SMART_READER_LITE
LIVE PREVIEW

What do you mean, Backwards Compatibility? Trisha Gee, Java Driver - - PowerPoint PPT Presentation

#gotober What do you mean, Backwards Compatibility? Trisha Gee, Java Driver Developer @trisha_gee Friday, 18 October 13 Whats the problem? Friday, 18 October 13 The Domain Friday, 18 October 13 MongoDB is an open-source document


slide-1
SLIDE 1

Trisha Gee, Java Driver Developer

#gotober

What do you mean, Backwards Compatibility?

@trisha_gee

Friday, 18 October 13

slide-2
SLIDE 2

What’s the problem?

Friday, 18 October 13

slide-3
SLIDE 3

The Domain

Friday, 18 October 13

slide-4
SLIDE 4

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-5
SLIDE 5

The Driver

Friday, 18 October 13

slide-6
SLIDE 6

Friday, 18 October 13

slide-7
SLIDE 7

Friday, 18 October 13

slide-8
SLIDE 8

Friday, 18 October 13

slide-9
SLIDE 9

Why is this my problem?

Friday, 18 October 13

slide-10
SLIDE 10

What do we want to do?

Friday, 18 October 13

slide-11
SLIDE 11

Design Goals

  • Intuitive API
  • Consistency
  • Understandable exceptions
  • Cleaner design
  • Test friendly
  • Backwards compatible
  • http://is.gd/java3mongodb

Friday, 18 October 13

slide-12
SLIDE 12

Happy Users

Friday, 18 October 13

slide-13
SLIDE 13

Three Types Of Users

Friday, 18 October 13

slide-14
SLIDE 14
  • 1. Java Developers

Three Types Of Users

Friday, 18 October 13

slide-15
SLIDE 15
  • 1. Java Developers
  • 2. ODMs / other drivers / third parties

Three Types Of Users

Friday, 18 October 13

slide-16
SLIDE 16
  • 1. Java Developers
  • 2. ODMs / other drivers / third parties
  • 3. Contributors

Three Types Of Users

Friday, 18 October 13

slide-17
SLIDE 17

What’s stopping us?

Friday, 18 October 13

slide-18
SLIDE 18

Lots of unknowns

Friday, 18 October 13

slide-19
SLIDE 19

Lots of APIs

Friday, 18 October 13

slide-20
SLIDE 20

Backward Compatibility

Friday, 18 October 13

slide-21
SLIDE 21

What did we do?

Friday, 18 October 13

slide-22
SLIDE 22

Architecture

Friday, 18 October 13

slide-23
SLIDE 23

How Hard Can It Be?

Friday, 18 October 13

slide-24
SLIDE 24

Domain

Friday, 18 October 13

slide-25
SLIDE 25

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-26
SLIDE 26

Bit more complex...

Friday, 18 October 13

slide-27
SLIDE 27

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-28
SLIDE 28

Instead of this...

Friday, 18 October 13

slide-29
SLIDE 29

Model the Domain

Friday, 18 October 13

slide-30
SLIDE 30

Scala Driver

Friday, 18 October 13

slide-31
SLIDE 31

Backwards Compatible!

Friday, 18 October 13

slide-32
SLIDE 32

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-33
SLIDE 33

Multi Server

Friday, 18 October 13

slide-34
SLIDE 34

Replica Set

Friday, 18 October 13

slide-35
SLIDE 35

Replica Set

Friday, 18 October 13

slide-36
SLIDE 36

Friday, 18 October 13

slide-37
SLIDE 37

Replica Set Sharding

Friday, 18 October 13

slide-38
SLIDE 38

Friday, 18 October 13

slide-39
SLIDE 39

Finding Servers the Old Way

Friday, 18 October 13

slide-40
SLIDE 40

Friday, 18 October 13

slide-41
SLIDE 41

Friday, 18 October 13

slide-42
SLIDE 42

Friday, 18 October 13

slide-43
SLIDE 43

Friday, 18 October 13

slide-44
SLIDE 44

Friday, 18 October 13

slide-45
SLIDE 45

Friday, 18 October 13

slide-46
SLIDE 46

Friday, 18 October 13

slide-47
SLIDE 47

Friday, 18 October 13

slide-48
SLIDE 48

Friday, 18 October 13

slide-49
SLIDE 49

Friday, 18 October 13

slide-50
SLIDE 50

But now...

Friday, 18 October 13

slide-51
SLIDE 51

Friday, 18 October 13

slide-52
SLIDE 52

Friday, 18 October 13

slide-53
SLIDE 53

Friday, 18 October 13

slide-54
SLIDE 54

Friday, 18 October 13

slide-55
SLIDE 55

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-56
SLIDE 56

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-57
SLIDE 57

The New API

Friday, 18 October 13

slide-58
SLIDE 58

Caveats

  • It won’t look like this
  • Haven’t decided consistent names yet
  • Need something that suits all drivers

Friday, 18 October 13

slide-59
SLIDE 59

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-60
SLIDE 60

patron = { _id: "joe", name: "Joe Bookreader", address: { street: "123 Fake St", city: "Faketon", state: "MA", zip: 12345 } books: [ 27464, 747854, ...] }

Friday, 18 October 13

slide-61
SLIDE 61

Building a Document

List books = new BasicDBList(); books.add(27464, 747854); new BasicDBObject("_id", "joe") .append("name", "Joe Bookreader") .append("address", new BasicDBObject("street", "123 Fake St") .append("city", "Faketon") .append("state", "MA") .append("zip", 12345)) .append("books", books); collection.insert(books);

Friday, 18 October 13

slide-62
SLIDE 62

Getting it back

DBCollection collection = database.getCollection("coll"); ArrayList<Patron> resultsToReturn = new ArrayList<Patron>(); DBObject query = new BasicDBObject("name", theNameToFind); DBCursor results = collection.find(query); for (DBObject dbObject : results) { Patron patron = new Patron((String) dbObject.get("name"), new Address((String)dbObject.get("street"), (String)dbObject.get("city"), (String)dbObject.get("state"), (Integer)dbObject.get("zip")), (BasicDBList)dbObject.get("books")); resultsToReturn.add(patron); } return resultsToReturn;

Friday, 18 October 13

slide-63
SLIDE 63

Casting is fun

DBCollection collection = database.getCollection("coll"); ArrayList<Patron> resultsToReturn = new ArrayList<Patron>(); DBObject query = new BasicDBObject("name", theNameToFind); DBCursor results = collection.find(query); for (DBObject dbObject : results) { Patron patron = new Patron((String) dbObject.get("name"), new Address((String)dbObject.get("street"), (String)dbObject.get("city"), (String)dbObject.get("state"), (Integer)dbObject.get("zip")), (BasicDBList)dbObject.get("books")); resultsToReturn.add(patron); } return resultsToReturn;

Friday, 18 October 13

slide-64
SLIDE 64

New API

MongoCollection<Patron> collection = database.getCollection("coll", new PatronCodec()); Document query = new Document("name", theNameToFind); return collection.find(query).into(new ArrayList<Patron>());

Friday, 18 October 13

slide-65
SLIDE 65

Separation of concerns

MongoCollection<Patron> collection = database.getCollection("coll", new PatronCodec()); Document query = new Document("name", theNameToFind); return collection.find(query).into(new ArrayList<Patron>());

Friday, 18 October 13

slide-66
SLIDE 66

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-67
SLIDE 67

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-68
SLIDE 68

Find

Friday, 18 October 13

slide-69
SLIDE 69

Find

collection.find(query).skip(1000).limit(100);

Friday, 18 October 13

slide-70
SLIDE 70

Find

collection.find(query).skip(1000).limit(100); collection.find(query).skip(1000).limit(100);

Friday, 18 October 13

slide-71
SLIDE 71

Find

collection.find(query).skip(1000).limit(100); collection.find(query).skip(1000).limit(100); collection.find(query, fields);

Friday, 18 October 13

slide-72
SLIDE 72

Which One?

Friday, 18 October 13

slide-73
SLIDE 73

Find

Friday, 18 October 13

slide-74
SLIDE 74

Find

collection.find(query).skip(1000).limit(100); collection.find(query).skip(1000).limit(100); collection.find(query, fields);

Friday, 18 October 13

slide-75
SLIDE 75

Find

collection.find(query).skip(1000).limit(100); collection.find(query).skip(1000).limit(100); collection.find(query, fields); collection.find(query).project(fields);

Friday, 18 October 13

slide-76
SLIDE 76

Fewer Decisions

Friday, 18 October 13

slide-77
SLIDE 77

“Ctrl + space” friendly

Friday, 18 October 13

slide-78
SLIDE 78

Remove

Friday, 18 October 13

slide-79
SLIDE 79

Remove

collection.remove(query);

Friday, 18 October 13

slide-80
SLIDE 80

Remove

collection.remove(query); collection.find(query).remove();

Friday, 18 October 13

slide-81
SLIDE 81

Update

Friday, 18 October 13

slide-82
SLIDE 82

Update

collection.update(query, newValues)

Friday, 18 October 13

slide-83
SLIDE 83

Update

collection.update(query, newValues) collection.find(query).updateOne(newValues);

Friday, 18 October 13

slide-84
SLIDE 84

Overloaded Methods

Friday, 18 October 13

slide-85
SLIDE 85

Update

Friday, 18 October 13

slide-86
SLIDE 86

Update

collection.update(query, newValues); collection.find(query).updateOne(newValues); collection.update(query, newValues, false, false, JOURNALED);

Friday, 18 October 13

slide-87
SLIDE 87

Update

collection.update(query, newValues); collection.find(query).updateOne(newValues); collection.update(query, newValues, false, false, JOURNALED); collection.find(query) .withWriteConcern(JOURNALED) .updateOne(newValues);

Friday, 18 October 13

slide-88
SLIDE 88

Update

Friday, 18 October 13

slide-89
SLIDE 89

Update

collection.update(query, newValues); collection.find(query).updateOne(newValues); collection.update(query, newValues, false, false, JOURNALED); collection.find(query) .withWriteConcern(JOURNALED) .updateOne(newValues); collection.update(query, newValues, true, false, JOURNALED);

Friday, 18 October 13

slide-90
SLIDE 90

Update

collection.update(query, newValues); collection.find(query).updateOne(newValues); collection.update(query, newValues, false, false, JOURNALED); collection.find(query) .withWriteConcern(JOURNALED) .updateOne(newValues); collection.update(query, newValues, true, false, JOURNALED); collection.find(query) .withWriteConcern(JOURNALED) .upsert() .updateOne(newValues);

Friday, 18 October 13

slide-91
SLIDE 91

Update

Friday, 18 October 13

slide-92
SLIDE 92

Update

collection.update(query, newValues); collection.find(query).updateOne(newValues); collection.update(query, newValues, false, false, JOURNALED); collection.find(query) .withWriteConcern(JOURNALED) .updateOne(newValues); collection.update(query, newValues, true, true, JOURNALED); collection.find(query) .withWriteConcern(JOURNALED) .upsert() .update(newValues);

Friday, 18 October 13

slide-93
SLIDE 93

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-94
SLIDE 94

MongoDB is an open-source document database, featuring:

  • Document-Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto-Sharding
  • Querying
  • Fast In-Place Updates
  • Map/Reduce
  • GridFS

Friday, 18 October 13

slide-95
SLIDE 95

Atomic Operations

Friday, 18 October 13

slide-96
SLIDE 96

Find and Modify

Friday, 18 October 13

slide-97
SLIDE 97

Find and Modify

collection.findAndModify(query, newValues);

Friday, 18 October 13

slide-98
SLIDE 98

Find and Modify

collection.findAndModify(query, newValues); collection.find(query) .getOneAndUpdate(newValues);

Friday, 18 October 13

slide-99
SLIDE 99

They hate me!

Friday, 18 October 13

slide-100
SLIDE 100

Find and Modify

Friday, 18 October 13

slide-101
SLIDE 101

Find and Modify

collection.findAndModify(query, update); collection.find(query) .getOneAndUpdate(update); collection.findAndModify(query, fields, criteria, false, newValues, false, false);

Friday, 18 October 13

slide-102
SLIDE 102

Find and Modify

collection.findAndModify(query, update); collection.find(query) .getOneAndUpdate(update); collection.findAndModify(query, fields, criteria, false, newValues, false, false); collection.find(query) .project(fields) .sort(criteria) .getOneAndUpdate(newValues);

Friday, 18 October 13

slide-103
SLIDE 103

Find and Modify

collection.findAndModify(query, update); collection.find(query) .getOneAndUpdate(update); collection.findAndModify(query, fields, criteria, false, newValues, true, false); collection.find(query) .project(fields) .sort(criteria) .updateOneAndGet(newValues);

Friday, 18 October 13

slide-104
SLIDE 104

Consistency

Friday, 18 October 13

slide-105
SLIDE 105

Consistency at last

collection.find(query).count(); collection.find(query).remove(); collection.find(query).update(newValues); collection.find(query).updateOneAndGet(newValues); collection.find(query).getOneAndUpdate(newValues); collection.find(query).sort(sortCriteria).skip(9).limit(10).get(); collection.find(query).sort(sortCriteria).skip(9).limit(10).getOne(); collection.find(query).sort(ascending("name")).getOne();

Friday, 18 October 13

slide-106
SLIDE 106

How do we know we did it?

Friday, 18 October 13

slide-107
SLIDE 107

Tests Pass...

Friday, 18 October 13

slide-108
SLIDE 108

...and more tests pass...

Friday, 18 October 13

slide-109
SLIDE 109

...even more tests pass...

Friday, 18 October 13

slide-110
SLIDE 110

It’s being used in anger

Friday, 18 October 13

slide-111
SLIDE 111

Conclusion

Friday, 18 October 13

slide-112
SLIDE 112

Conclusion

Friday, 18 October 13

slide-113
SLIDE 113

Conclusion

  • Model your domain

Friday, 18 October 13

slide-114
SLIDE 114

Conclusion

  • Model your domain
  • Know your users

Friday, 18 October 13

slide-115
SLIDE 115

Conclusion

  • Model your domain
  • Know your users
  • API design is hard

Friday, 18 October 13

slide-116
SLIDE 116

http://is.gd/java3mongodb

#gotober

Questions

@trisha_gee

Friday, 18 October 13

slide-117
SLIDE 117

What about async?

MongoFuture<Document> future = collection.find(query).sort(criteria).skip(9).limit(10).asyncOne(); MongoFuture<Long> count = collection.find(query).asyncCount(); MongoFuture<WriteResult> replaceResult = collection.find(query).asyncReplace(replacement);

Friday, 18 October 13

slide-118
SLIDE 118

Understandable Exceptions

  • Client Exceptions
  • Server Exceptions
  • No more parsing error Strings

Friday, 18 October 13

slide-119
SLIDE 119

Documentation

  • Self documenting code
  • JavaDoc
  • Unit, Functional and Acceptance Tests
  • Blogs
  • Tutorials

Friday, 18 October 13

slide-120
SLIDE 120

My Questions

Friday, 18 October 13

slide-121
SLIDE 121
  • 1. Are you using the

Java driver?

Friday, 18 October 13

slide-122
SLIDE 122

2. What do you like about it?

Friday, 18 October 13

slide-123
SLIDE 123
  • 3. What are your pain

points?

Friday, 18 October 13