From 0d40bfd55b81dd543e079cd8c67d35e4b379adcc Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Mon, 6 Jan 2025 11:21:16 -0800 Subject: [PATCH] go/store/chunks: Remove unused remote_requests structs and related code. --- go/store/chunks/remote_requests.go | 166 ---------------------- go/store/chunks/remote_requests_test.go | 177 ------------------------ go/utils/copyrightshdrs/main.go | 2 - 3 files changed, 345 deletions(-) delete mode 100644 go/store/chunks/remote_requests.go delete mode 100644 go/store/chunks/remote_requests_test.go diff --git a/go/store/chunks/remote_requests.go b/go/store/chunks/remote_requests.go deleted file mode 100644 index bbaff7ce23e..00000000000 --- a/go/store/chunks/remote_requests.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2019 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// This file incorporates work covered by the following copyright and -// permission notice: -// -// Copyright 2016 Attic Labs, Inc. All rights reserved. -// Licensed under the Apache License, version 2.0: -// http://www.apache.org/licenses/LICENSE-2.0 - -package chunks - -import ( - "sync" - - "github.com/dolthub/dolt/go/store/hash" -) - -type ReadRequest interface { - Hashes() hash.HashSet - Outstanding() OutstandingRequest -} - -func NewGetRequest(r hash.Hash, ch chan<- *Chunk) GetRequest { - return GetRequest{hash.HashSet{r: struct{}{}}, ch} -} - -type GetRequest struct { - hashes hash.HashSet - ch chan<- *Chunk -} - -func NewGetManyRequest(hashes hash.HashSet, wg *sync.WaitGroup, ch chan<- *Chunk) GetManyRequest { - return GetManyRequest{hashes, wg, ch} -} - -type GetManyRequest struct { - hashes hash.HashSet - wg *sync.WaitGroup - ch chan<- *Chunk -} - -func NewAbsentRequest(r hash.Hash, ch chan<- bool) AbsentRequest { - return AbsentRequest{hash.HashSet{r: struct{}{}}, ch} -} - -type AbsentRequest struct { - hashes hash.HashSet - ch chan<- bool -} - -func NewAbsentManyRequest(hashes hash.HashSet, wg *sync.WaitGroup, ch chan<- hash.Hash) AbsentManyRequest { - return AbsentManyRequest{hashes, wg, ch} -} - -type AbsentManyRequest struct { - hashes hash.HashSet - wg *sync.WaitGroup - ch chan<- hash.Hash -} - -func (g GetRequest) Hashes() hash.HashSet { - return g.hashes -} - -func (g GetRequest) Outstanding() OutstandingRequest { - return OutstandingGet(g.ch) -} - -func (g GetManyRequest) Hashes() hash.HashSet { - return g.hashes -} - -func (g GetManyRequest) Outstanding() OutstandingRequest { - return OutstandingGetMany{g.wg, g.ch} -} - -func (h AbsentRequest) Hashes() hash.HashSet { - return h.hashes -} - -func (h AbsentRequest) Outstanding() OutstandingRequest { - return OutstandingAbsent(h.ch) -} - -func (h AbsentManyRequest) Hashes() hash.HashSet { - return h.hashes -} - -func (h AbsentManyRequest) Outstanding() OutstandingRequest { - return OutstandingAbsentMany{h.wg, h.ch} -} - -type OutstandingRequest interface { - Satisfy(h hash.Hash, c *Chunk) - Fail() -} - -type OutstandingGet chan<- *Chunk -type OutstandingGetMany struct { - wg *sync.WaitGroup - ch chan<- *Chunk -} -type OutstandingAbsent chan<- bool -type OutstandingAbsentMany struct { - wg *sync.WaitGroup - ch chan<- hash.Hash -} - -func (r OutstandingGet) Satisfy(h hash.Hash, c *Chunk) { - r <- c -} - -func (r OutstandingGet) Fail() { - r <- &EmptyChunk -} - -func (ogm OutstandingGetMany) Satisfy(h hash.Hash, c *Chunk) { - ogm.ch <- c - ogm.wg.Done() -} - -func (ogm OutstandingGetMany) Fail() { - ogm.wg.Done() -} - -func (oh OutstandingAbsent) Satisfy(h hash.Hash, c *Chunk) { - oh <- false -} - -func (oh OutstandingAbsent) Fail() { - oh <- true -} - -func (ohm OutstandingAbsentMany) Satisfy(h hash.Hash, c *Chunk) { - ohm.ch <- h - ohm.wg.Done() -} - -func (ohm OutstandingAbsentMany) Fail() { - ohm.wg.Done() -} - -// ReadBatch represents a set of queued Get/Has requests, each of which are blocking on a receive channel for a response. -type ReadBatch map[hash.Hash][]OutstandingRequest - -// Close ensures that callers to Get() and Has() are failed correctly if the corresponding chunk wasn't in the response from the server (i.e. it wasn't found). -func (rb *ReadBatch) Close() error { - for _, reqs := range *rb { - for _, req := range reqs { - req.Fail() - } - } - return nil -} diff --git a/go/store/chunks/remote_requests_test.go b/go/store/chunks/remote_requests_test.go deleted file mode 100644 index 221e8a4f4f6..00000000000 --- a/go/store/chunks/remote_requests_test.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2019 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// This file incorporates work covered by the following copyright and -// permission notice: -// -// Copyright 2016 Attic Labs, Inc. All rights reserved. -// Licensed under the Apache License, version 2.0: -// http://www.apache.org/licenses/LICENSE-2.0 - -package chunks - -import ( - "sync" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/dolthub/dolt/go/store/hash" -) - -func TestGetRequestBatch(t *testing.T) { - assert := assert.New(t) - h0 := hash.Parse("00000000000000000000000000000000") - c1 := NewChunk([]byte("abc")) - h1 := c1.Hash() - c2 := NewChunk([]byte("123")) - h2 := c2.Hash() - - tally := func(b bool, trueCnt, falseCnt *int) { - if b { - *trueCnt++ - } else { - *falseCnt++ - } - } - - req0chan := make(chan bool, 1) - req1chan := make(chan *Chunk, 1) - req2chan := make(chan bool, 1) - req3chan := make(chan bool, 1) - req4chan := make(chan *Chunk, 1) - defer func() { close(req0chan); close(req1chan); close(req2chan); close(req3chan); close(req4chan) }() - - batch := ReadBatch{ - h0: []OutstandingRequest{OutstandingAbsent(req0chan), OutstandingGet(req1chan)}, - h1: []OutstandingRequest{OutstandingAbsent(req2chan)}, - h2: []OutstandingRequest{OutstandingAbsent(req3chan), OutstandingGet(req4chan)}, - } - go func() { - for requestedHash, reqs := range batch { - for _, req := range reqs { - if requestedHash == h1 { - req.Satisfy(h1, &c1) - delete(batch, h1) - } else if requestedHash == h2 { - req.Satisfy(h2, &c2) - delete(batch, h2) - } - } - } - batch.Close() - }() - - var r0True, r0False, r2True, r2False, r3True, r3False int - b := <-req0chan - tally(b, &r0True, &r0False) - c := <-req1chan - assert.EqualValues(EmptyChunk.Hash(), c.Hash()) - b = <-req2chan - tally(b, &r2True, &r2False) - b = <-req3chan - tally(b, &r3True, &r3False) - c = <-req4chan - assert.EqualValues(c2.Hash(), c.Hash()) - - assert.Equal(1, r0True) - assert.Equal(0, r0False) - assert.Equal(0, r2True) - assert.Equal(1, r2False) - assert.Equal(0, r3True) - assert.Equal(1, r3False) -} - -func TestGetManyRequestBatch(t *testing.T) { - assert := assert.New(t) - h0 := hash.Parse("00000000000000000000000000000000") - c1 := NewChunk([]byte("abc")) - h1 := c1.Hash() - c2 := NewChunk([]byte("123")) - h2 := c2.Hash() - - chunks := make(chan *Chunk) - hashes := hash.NewHashSet(h0, h1, h2) - wg := &sync.WaitGroup{} - wg.Add(len(hashes)) - go func() { wg.Wait(); close(chunks) }() - - req := NewGetManyRequest(hashes, wg, chunks) - batch := ReadBatch{ - h0: {req.Outstanding()}, - h1: {req.Outstanding()}, - h2: {req.Outstanding()}, - } - go func() { - for reqHash, reqs := range batch { - for _, req := range reqs { - if reqHash == h1 { - req.Satisfy(h1, &c1) - delete(batch, h1) - } else if reqHash == h2 { - req.Satisfy(h2, &c2) - delete(batch, h2) - } - } - } - batch.Close() - }() - - for c := range chunks { - hashes.Remove(c.Hash()) - } - assert.Len(hashes, 1) - assert.True(hashes.Has(h0)) -} - -func TestAbsentManyRequestBatch(t *testing.T) { - assert := assert.New(t) - h0 := hash.Parse("00000000000000000000000000000000") - c1 := NewChunk([]byte("abc")) - h1 := c1.Hash() - c2 := NewChunk([]byte("123")) - h2 := c2.Hash() - - found := make(chan hash.Hash) - hashes := hash.NewHashSet(h0, h1, h2) - wg := &sync.WaitGroup{} - wg.Add(len(hashes)) - go func() { wg.Wait(); close(found) }() - - req := NewAbsentManyRequest(hashes, wg, found) - batch := ReadBatch{} - for h := range req.Hashes() { - batch[h] = []OutstandingRequest{req.Outstanding()} - } - go func() { - for reqHash, reqs := range batch { - for _, req := range reqs { - if reqHash == h1 { - req.Satisfy(h1, &EmptyChunk) - delete(batch, h1) - } else if reqHash == h2 { - req.Satisfy(h2, &EmptyChunk) - delete(batch, h2) - } - } - } - batch.Close() - }() - - for h := range found { - hashes.Remove(h) - } - assert.Len(hashes, 1) - assert.True(hashes.Has(h0)) -} diff --git a/go/utils/copyrightshdrs/main.go b/go/utils/copyrightshdrs/main.go index 623b71749bc..c31b453b336 100644 --- a/go/utils/copyrightshdrs/main.go +++ b/go/utils/copyrightshdrs/main.go @@ -96,8 +96,6 @@ var CopiedNomsFiles []CopiedNomsFile = []CopiedNomsFile{ {Path: "store/chunks/chunk_test.go", NomsPath: "go/chunks/chunk_test.go", HadCopyrightNotice: true}, {Path: "store/chunks/memory_store.go", NomsPath: "go/chunks/memory_store.go", HadCopyrightNotice: true}, {Path: "store/chunks/memory_store_test.go", NomsPath: "go/chunks/memory_store_test.go", HadCopyrightNotice: true}, - {Path: "store/chunks/remote_requests.go", NomsPath: "go/chunks/remote_requests.go", HadCopyrightNotice: true}, - {Path: "store/chunks/remote_requests_test.go", NomsPath: "go/chunks/remote_requests_test.go", HadCopyrightNotice: true}, {Path: "store/chunks/test_utils.go", NomsPath: "go/chunks/test_utils.go", HadCopyrightNotice: true}, {Path: "store/cmd/noms/commit_iterator.go", NomsPath: "cmd/noms/commit_iterator.go", HadCopyrightNotice: true}, {Path: "store/cmd/noms/noms.go", NomsPath: "cmd/noms/noms.go", HadCopyrightNotice: true},