Browse Source

Merge pull request #7601 from heyitsanthony/fix-proxy-compact

grpcproxy/cache: only check compaction revision for historical revisions
Anthony Romano 8 years ago
parent
commit
9381b103bb
2 changed files with 11 additions and 2 deletions
  1. 10 1
      integration/v3_grpc_test.go
  2. 1 1
      proxy/grpcproxy/cache/store.go

+ 10 - 1
integration/v3_grpc_test.go

@@ -123,16 +123,25 @@ func TestV3CompactCurrentRev(t *testing.T) {
 			t.Fatalf("couldn't put key (%v)", err)
 		}
 	}
+	// get key to add to proxy cache, if any
+	if _, err := kvc.Range(context.TODO(), &pb.RangeRequest{Key: []byte("foo")}); err != nil {
+		t.Fatal(err)
+	}
 	// compact on current revision
 	_, err := kvc.Compact(context.Background(), &pb.CompactionRequest{Revision: 4})
 	if err != nil {
 		t.Fatalf("couldn't compact kv space (%v)", err)
 	}
-	// key still exists?
+	// key still exists when linearized?
 	_, err = kvc.Range(context.Background(), &pb.RangeRequest{Key: []byte("foo")})
 	if err != nil {
 		t.Fatalf("couldn't get key after compaction (%v)", err)
 	}
+	// key still exists when serialized?
+	_, err = kvc.Range(context.Background(), &pb.RangeRequest{Key: []byte("foo"), Serializable: true})
+	if err != nil {
+		t.Fatalf("couldn't get serialized key after compaction (%v)", err)
+	}
 }
 
 func TestV3TxnTooManyOps(t *testing.T) {

+ 1 - 1
proxy/grpcproxy/cache/store.go

@@ -111,7 +111,7 @@ func (c *cache) Get(req *pb.RangeRequest) (*pb.RangeResponse, error) {
 	c.mu.Lock()
 	defer c.mu.Unlock()
 
-	if req.Revision < c.compactedRev {
+	if req.Revision > 0 && req.Revision < c.compactedRev {
 		c.lru.Remove(key)
 		return nil, ErrCompacted
 	}