Permalink
Browse files

store: replace the CAS concept with revisions.

  • Loading branch information...
1 parent 14c58c5 commit 01d16c64991e10146760ca5b04070c7bfa209980 @bmizerany bmizerany committed with kr Mar 19, 2011
Showing with 11 additions and 6 deletions.
  1. +4 −2 doc/proto.md
  2. +1 −1 src/pkg/store/node.go
  3. +4 −1 src/pkg/store/node_test.go
  4. +2 −2 src/pkg/store/store_test.go
View
@@ -169,7 +169,8 @@ This is indicated by a + sign after the response fields.
* `DEL` *path*, *cas* ⇒ ∅
- Del deletes the file at *path* if its CAS token matches *cas*.
+ Del deletes the file at *path* if *cas* is greater than
+ or equal to the file's CAS token.
* `ELOCK` (not yet implemented)
@@ -223,7 +224,8 @@ This is indicated by a + sign after the response fields.
* `SET` *path*, *cas*, *value* ⇒ *cas*
Sets the contents of the file at *path* to *value*,
- as long as the file's old CAS token matches *cas*.
+ as long as *cas* is greater than or equal to the file's
+ old CAS token.
Returns the new CAS token.
* `SYNCPATH` (not yet implemented)
@@ -152,7 +152,7 @@ func (n node) apply(seqn int64, mut string) (rep node, ev Event) {
if ev.Err == nil {
_, curCas := n.Get(ev.Path)
- if cas != Clobber && cas != curCas {
+ if cas != Clobber && cas < curCas {
ev.Err = ErrCasMismatch
} else if curCas == Dir {
ev.Err = os.EISDIR
@@ -56,8 +56,11 @@ func TestNodeApplyBadInstruction(t *testing.T) {
func TestNodeApplyCasMismatch(t *testing.T) {
k, v, seqn, cas := "x", "a", int64(1), int64(1)
p := "/" + k
- m := MustEncodeSet(p, v, 123)
+
+ // -123 is less that the current rev, which is zero; and not Clobber.
+ m := MustEncodeSet(p, v, -123)
n, e := emptyDir.apply(seqn, m)
+
exp := node{"", Dir, map[string]node{"store": {"", Dir, map[string]node{"error": {ErrCasMismatch.String(), cas, nil}}}}}
assert.Equal(t, exp, n)
assert.Equal(t, Event{seqn, ErrorPath, ErrCasMismatch.String(), cas, m, ErrCasMismatch, n}, e)
@@ -875,7 +875,7 @@ func TestStoreWaitCasMatchReplace(t *testing.T) {
}
func TestStoreWaitCasMismatchMissing(t *testing.T) {
- mut := MustEncodeSet("/a", "foo", 123)
+ mut := MustEncodeSet("/a", "foo", -123)
st := New()
defer close(st.Ops)
@@ -891,7 +891,7 @@ func TestStoreWaitCasMismatchMissing(t *testing.T) {
func TestStoreWaitCasMismatchReplace(t *testing.T) {
mut1 := MustEncodeSet("/a", "foo", Clobber)
- mut2 := MustEncodeSet("/a", "foo", 123)
+ mut2 := MustEncodeSet("/a", "foo", 0)
st := New()
defer close(st.Ops)

0 comments on commit 01d16c6

Please sign in to comment.