Skip to content

Commit a04aaa1

Browse files
authored
s/dedup/dedupe (#777)
1 parent 81d14a9 commit a04aaa1

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

antispam.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
lru "github.com/hashicorp/golang-lru/v2"
2323
)
2424

25-
// newInMemoryDedupe wraps an Add function to prevent duplicate entries being written to the underlying
25+
// newInMemoryDedup wraps an Add function to prevent duplicate entries being written to the underlying
2626
// storage by keeping an in-memory cache of recently seen entries.
2727
// Where an existing entry has already been `Add`ed, the previous `IndexFuture` will be returned.
2828
// When no entry is found in the cache, the delegate method will be called to store the entry, and
@@ -31,39 +31,39 @@ import (
3131
// Internally this uses a cache with a max size configured by the size parameter.
3232
// If the entry being `Add`ed is not found in the cache, then it calls the delegate.
3333
//
34-
// This object can be used in isolation, or in conjunction with a persistent dedupe implementation.
35-
// When using this with a persistent dedupe, the persistent layer should be the delegate of this
36-
// InMemoryDedupe. This allows recent duplicates to be deduplicated in memory, reducing the need to
34+
// This object can be used in isolation, or in conjunction with a persistent dedup implementation.
35+
// When using this with a persistent dedup, the persistent layer should be the delegate of this
36+
// InMemoryDedup. This allows recent duplicates to be deduplicated in memory, reducing the need to
3737
// make calls to a persistent storage.
38-
func newInMemoryDedupe(size uint) func(AddFn) AddFn {
38+
func newInMemoryDedup(size uint) func(AddFn) AddFn {
3939
return func(af AddFn) AddFn {
4040
c, err := lru.New[string, func() IndexFuture](int(size))
4141
if err != nil {
4242
panic(fmt.Errorf("lru.New(%d): %v", size, err))
4343
}
44-
dedupe := &inMemoryDedupe{
44+
dedup := &inMemoryDedup{
4545
delegate: af,
4646
cache: c,
4747
}
48-
return dedupe.add
48+
return dedup.add
4949
}
5050
}
5151

52-
type inMemoryDedupe struct {
52+
type inMemoryDedup struct {
5353
delegate func(ctx context.Context, e *Entry) IndexFuture
5454
cache *lru.Cache[string, func() IndexFuture]
5555
}
5656

5757
// Add adds the entry to the underlying delegate only if e hasn't been recently seen. In either case,
5858
// an IndexFuture will be returned that the client can use to get the sequence number of this entry.
59-
func (d *inMemoryDedupe) add(ctx context.Context, e *Entry) IndexFuture {
59+
func (d *inMemoryDedup) add(ctx context.Context, e *Entry) IndexFuture {
6060
ctx, span := tracer.Start(ctx, "tessera.Appender.inmemoryDedup.Add")
6161
defer span.End()
6262

6363
id := string(e.Identity())
6464

6565
f := sync.OnceValue(func() IndexFuture {
66-
// However many calls with the same entry come in and are deduped, we should only call delegate
66+
// However many calls with the same entry come in and are deduplicated, we should only call delegate
6767
// once for each unique entry:
6868
df := d.delegate(ctx, e)
6969

antispam_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"testing"
2424
)
2525

26-
func TestDedupe(t *testing.T) {
26+
func TestDedup(t *testing.T) {
2727
ctx := context.Background()
2828
testCases := []struct {
2929
desc string
@@ -59,18 +59,18 @@ func TestDedupe(t *testing.T) {
5959
return Index{Index: thisIdx}, nil
6060
}
6161
}
62-
dedupeAdd := newInMemoryDedupe(256)(delegate)
62+
dedupAdd := newInMemoryDedup(256)(delegate)
6363

6464
// Add foo, bar, baz to prime the cache to make things interesting
6565
for _, s := range []string{"foo", "bar", "baz"} {
66-
if _, err := dedupeAdd(ctx, NewEntry([]byte(s)))(); err != nil {
67-
t.Fatalf("dedupeAdd(%q): %v", s, err)
66+
if _, err := dedupAdd(ctx, NewEntry([]byte(s)))(); err != nil {
67+
t.Fatalf("dedupAdd(%q): %v", s, err)
6868
}
6969
}
7070

71-
i, err := dedupeAdd(ctx, NewEntry([]byte(tC.newValue)))()
71+
i, err := dedupAdd(ctx, NewEntry([]byte(tC.newValue)))()
7272
if err != nil {
73-
t.Fatalf("dedupeAdd(%q): %v", tC.newValue, err)
73+
t.Fatalf("dedupAdd(%q): %v", tC.newValue, err)
7474
}
7575
if i.Index != tC.wantIdx {
7676
t.Errorf("got Index != want Index (%d != %d)", i.Index, tC.wantIdx)
@@ -83,7 +83,7 @@ func TestDedupe(t *testing.T) {
8383
}
8484
}
8585

86-
func TestDedupeDoesNotCacheError(t *testing.T) {
86+
func TestDedupDoesNotCacheError(t *testing.T) {
8787
idx := uint64(0)
8888
rErr := true
8989

@@ -106,24 +106,24 @@ func TestDedupeDoesNotCacheError(t *testing.T) {
106106
return Index{Index: thisIdx}, err
107107
}
108108
}
109-
dedupeAdd := newInMemoryDedupe(256)(delegate)
109+
dedupAdd := newInMemoryDedup(256)(delegate)
110110

111111
k := "foo"
112112
for i := range 10 {
113-
idx, err := dedupeAdd(t.Context(), NewEntry([]byte(k)))()
113+
idx, err := dedupAdd(t.Context(), NewEntry([]byte(k)))()
114114

115115
// We expect an error from the delegate the first time.
116116
if i == 0 && err == nil {
117-
t.Errorf("dedupeAdd(%q)@%d: was successful, want error", k, i)
117+
t.Errorf("dedupAdd(%q)@%d: was successful, want error", k, i)
118118
continue
119119
}
120120
// But the 2nd call should work.
121121
if i > 0 && err != nil {
122-
t.Errorf("dedupeAdd(%q)@%d: got %v, want no error", k, i, err)
122+
t.Errorf("dedupAdd(%q)@%d: got %v, want no error", k, i, err)
123123
continue
124124
}
125125

126-
// After which, all subsequent adds should dedupe to that successful add.
126+
// After which, all subsequent adds should dedup to that successful add.
127127
if i > 1 && !idx.IsDup {
128128
t.Errorf("got IsDup=false, want isDup=true")
129129
continue
@@ -134,7 +134,7 @@ func TestDedupeDoesNotCacheError(t *testing.T) {
134134
}
135135
}
136136

137-
func BenchmarkDedupe(b *testing.B) {
137+
func BenchmarkDedup(b *testing.B) {
138138
ctx := context.Background()
139139
// Outer loop is for benchmark calibration, inside here is each individual run of the benchmark
140140
for b.Loop() {
@@ -146,13 +146,13 @@ func BenchmarkDedupe(b *testing.B) {
146146
return Index{Index: thisIdx}, nil
147147
}
148148
}
149-
dedupeAdd := newInMemoryDedupe(256)(delegate)
149+
dedupAdd := newInMemoryDedup(256)(delegate)
150150
wg := &sync.WaitGroup{}
151151
// Loop to create a bunch of leaves in parallel to test lock contention
152152
for leafIndex := range 1024 {
153153
wg.Add(1)
154154
go func(index int) {
155-
_, err := dedupeAdd(ctx, NewEntry(fmt.Appendf(nil, "leaf with value %d", index%sha256.Size)))()
155+
_, err := dedupAdd(ctx, NewEntry(fmt.Appendf(nil, "leaf with value %d", index%sha256.Size)))()
156156
if err != nil {
157157
b.Error(err)
158158
}

append_lifecycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func (o AppendOptions) valid() error {
580580
//
581581
// For more details on how the antispam mechanism works, including tuning guidance, see docs/design/antispam.md.
582582
func (o *AppendOptions) WithAntispam(inMemEntries uint, as Antispam) *AppendOptions {
583-
o.addDecorators = append(o.addDecorators, newInMemoryDedupe(inMemEntries))
583+
o.addDecorators = append(o.addDecorators, newInMemoryDedup(inMemEntries))
584584
if as != nil {
585585
o.addDecorators = append(o.addDecorators, as.Decorator())
586586
o.followers = append(o.followers, as.Follower(o.bundleIDHasher))

0 commit comments

Comments
 (0)