Skip to content

Commit

Permalink
[FIX] KV delete not working correctly accross mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Oct 28, 2022
1 parent ffbe2f9 commit 9d7afb4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,11 @@ func (kv *kvs) Delete(key string, opts ...DeleteOpt) error {
if kv.useJSPfx {
b.WriteString(kv.js.opts.pre)
}
b.WriteString(kv.pre)
if kv.putPre != _EMPTY_ {
b.WriteString(kv.putPre)
} else {
b.WriteString(kv.pre)
}
b.WriteString(key)

// DEL op marker. For watch functionality.
Expand Down
31 changes: 29 additions & 2 deletions test/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@ func TestKeyValueMirrorCrossDomains(t *testing.T) {
expectOk(t, err)
_, err = kv.PutString("age", "22")
expectOk(t, err)
_, err = kv.PutString("v", "v")
expectOk(t, err)
err = kv.Delete("v")
expectOk(t, err)

lnc, ljs := jsClient(t, ln)
defer lnc.Close()
Expand Down Expand Up @@ -933,7 +937,7 @@ func TestKeyValueMirrorCrossDomains(t *testing.T) {
checkFor(t, 2*time.Second, 15*time.Millisecond, func() error {
si, err := ljs.StreamInfo("KV_MIRROR")
expectOk(t, err)
if si.State.Msgs == 2 {
if si.State.Msgs == 3 {
return nil
}
return fmt.Errorf("Did not get synched messages: %d", si.State.Msgs)
Expand All @@ -946,7 +950,19 @@ func TestKeyValueMirrorCrossDomains(t *testing.T) {
_, err = mkv.PutString("name", "rip")
expectOk(t, err)

e, err := mkv.Get("name")
_, err = mkv.PutString("v", "vv")
expectOk(t, err)
e, err := mkv.Get("v")
expectOk(t, err)
if e.Operation() != nats.KeyValuePut {
t.Fatalf("Got wrong value: %q vs %q", e.Operation(), nats.KeyValuePut)
}
err = mkv.Delete("v")
expectOk(t, err)
_, err = mkv.Get("v")
expectErr(t, err, nats.ErrKeyNotFound)

e, err = mkv.Get("name")
expectOk(t, err)
if string(e.Value()) != "rip" {
t.Fatalf("Got wrong value: %q vs %q", e.Value(), "rip")
Expand All @@ -967,6 +983,17 @@ func TestKeyValueMirrorCrossDomains(t *testing.T) {
if string(e.Value()) != "ivan" {
t.Fatalf("Got wrong value: %q vs %q", e.Value(), "ivan")
}
_, err = rkv.PutString("v", "vv")
expectOk(t, err)
e, err = mkv.Get("v")
expectOk(t, err)
if e.Operation() != nats.KeyValuePut {
t.Fatalf("Got wrong value: %q vs %q", e.Operation(), nats.KeyValuePut)
}
err = rkv.Delete("v")
expectOk(t, err)
_, err = rkv.Get("v")
expectErr(t, err, nats.ErrKeyNotFound)

// Shutdown cluster and test get still work.
shutdownJSServerAndRemoveStorage(t, s)
Expand Down

0 comments on commit 9d7afb4

Please sign in to comment.