criteria overview - university of waterlooa78khan/cs446/additional... · 2011. 7. 27. · • an...

39

Upload: others

Post on 23-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user
Page 2: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

file synchronizer

data synchronizer

distributed file system

versioncontrol

Page 3: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Criteria Overview

Page 4: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Fitness for Purpose

• safety is job #1

• don’t lose or corrupt data

• even in the presence of hardware failures

• performance

• low bandwidth connections

• cross-platform

Page 5: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Fitness for FutureModifiability

• Not expecting much change.

• Problem is well-defined and formally specified.

• Perhaps support for new file systems.

• Non-hierarchical FS?

Reusability

• Not designed for reusability.

• Can call the binary.

• Build a data synchronizer?

Page 6: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Cost of Production

• An academic project

• Supporting thousands of users

• Willing to spend time on interesting things

• Written in OCaml

• strongly-typed functional language

• close to formalism

Page 7: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Cost of Operation

• Not a primary design consideration

• In practice requires a server

• DropBox’s competitive advantages:

• DropBox provides the server

• DropBox has a simpler UI

Page 8: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Main AlternativesTrace-Based

• work from a log of edits

• used by:

• distributed DBs

• middleware

• git

State-Based

• work from the current state of the data

• used by:

• unison

• dropbox

• subversion

Page 9: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Safety

Page 10: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Invariant #1

At every moment, each path in each replica has either

1. its original contents (i.e., no change at all has been made to this path), or

2. its correct final contents (i.e., the value that the user expected to be propagated from the other replica).

Page 11: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Invariant #2

At every moment, the information stored on disk about Unison's private state can be either

1. unchanged, or

2. updated to reflect those paths that have been successfully synchronized.

Page 12: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

How to atomically replace a file?

Page 13: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

How to atomically replace a file?

• Most file systems do not have an atomic replace operation.

1. Create a tmp file with the new contents

2. Delete the old file

3. Rename the tmp file to the proper name

Page 14: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

CaveatThe above is almost true there are occasionally brief periods where it is not (and, because of shortcoming of the Posix filesystem API, cannot be). In particular, when it is copying a file onto a directory or vice versa, it must first move the original contents out of the way. If Unison gets interrupted during one of these periods, some manual cleanup may be required. In this case, a file called DANGER.README will be left in our home directory. Next run Unison will warn us about it.

Page 15: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Update Detection Alternatives

Page 16: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Trivial Detection

• Always say every file has been modified

• Requires comparing the state of every file

• Expensive if files are large and link is slow

Page 17: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Exact Detection

• Keep a local copy of the data at the time of last synchronization (Subversion does this)

• Doubles the disk space

• May also be computationally expensive

Page 18: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Modtime Check

• Works in theory but not in practice

• In *nix, renaming a file does not change its modtime

• changes the modtime of the parent dir

• directory modtime may be changed for other reasons

• renaming a file near the root will make the whole tree look dirty

Page 19: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

INode + Modtime

• Dirty =

• inode changed or

• modtime > last synchronization time

• INodes contain file metadata: size, permissions, owner, group, etc.

• but not file names

• Ok for Posix systems, but not for Windows

Page 20: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Online Detection

• Listen to file system events

• What DropBox does

• Easier to implement at the user level on Windows than on *nix

• Some wrappers for Unison try to do this

Page 21: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Reconciliation

Page 22: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

What does the user expect?

Page 23: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Synchronization (a simple example)

A synchronizer should propagate changes...

DIR

f’ g’

ba

DIR

f’ g

ba

DIR

f g’

ba

DIR

f’ g’

ba

snc / 6

Easy

Cas

e: N

on-c

onfli

ctin

g ch

ange

s

Page 24: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Easy

Cas

e: C

onfli

ctin

g ch

ange

s

... as long as they do not conflict:

DIR

f’ g’’

ba

DIR

f’ g’

ba

DIR

f g’’

ba

DIR

f’ g’

ba

snc / 7

Page 25: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

A more interesting example

If a file gets renamed on one side and modified on the other, what shouldthe synchronizer do?

DIR

f g

ba

DIR

f g’

bac

g

snc / 8

rename modify

???

Page 26: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Three reasonable possibilities:

1. Copy old version with new name ( ); report a conflict for old name( )

DIR

f

a

DIR

f g’

bac

g

c

g

2. Modify the file in the first replica and move it in the second

DIR

f

a

DIR

f

ac

g’

c

g’

3. Do nothing (report a conflict)

snc / 9

Page 27: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Another unclear case

Suppose a file is created on one side and its parent directory is deletedon the other side...

DIR

d

DIR

DIR

f

d

ba

g’

DIR

f

a

What should happen?

snc / 10

Page 28: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Another unclear case

Suppose a file is created on one side and its parent directory is deletedon the other side...

DIR

d

DIR

DIR

f

d

ba

g’

DIR

f

a

What should happen?

snc / 10

1. Nothing; a conflict should be reported

2. The siblings ( ) should be deleted from the second replica, leavingjust the file ( ) and its parent directory ( )

3. The siblings and parent directory should all be deleted from thesecond replica; the file should be moved to a special “orphanage” andthe user alerted

snc / 11

Page 29: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

A, B are filesystemsp is the path to be synchronizedreturns “new” file systems with synchronized contents

Page 30: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Specification

Page 31: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Conflicts

Key question: What is a conflict?

Our answer: A conflict occurs when the two replicas do not agree (atsome path), and both have been changed.

Formally, we say there is a conflict at path if

“ and are different at ”

and “ has been changed at (or below) ”

and “ has been changed at (or below) ”

snc / 17-b

Page 32: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Core Specification

Each run of a file synchronizer takes filesystems , , and as inputsand yields new filesystems and as outputs. A run is said to beacceptable if, for all paths :

(1) if , then

if , then

(“don’t overwrite user changes”)

(2) if , then

if , then

(“only change replicas by (completely) propagating user changes”)

(3) if there is a conflict at , then and

(“don’t change (at or below) conflicting paths”)

A synchronizer implementation is correct if all its runs are acceptable.

snc / 18

Page 33: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Architecture

Page 34: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Client FS Server FS

rpc over ssh

ServerClient

System Architecture

replicaarchive

replicaarchive

su

er I

U

updatedetector detector

update

reconciler

transportagent

snc / 29

Page 35: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

PerformanceThe RSync Algorithm

Page 36: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Extensions

Page 37: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Synchronizing Multiple replicas

We’ve treated just the two-replica case in this specification (and in ourimplementation).

Pairwise synchronization can be used to keep 3-5 replicas in sync. Justsynchronize successive pairs in a star or ring topology.

For synchronizing more replicas, both specification and implementationcan be extended straightforwardly... iff we require that all replicasparticipate in every synchronization.

For synchronizing many replicas, we need to deal with the fact that onlya subset may participate in any given sync. Problems become significantlytrickier. (Need something like version vectors.)

snc / 23

Page 38: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user

Data Synchronization

• Should fit in the formalism

• As long as the data is hierarchical

• Just extend the notion of path to records

Page 39: Criteria Overview - University of Waterlooa78khan/cs446/additional... · 2011. 7. 27. · • An academic project ... 2. its correct final contents (i.e., the value that the user