Skip to content

Commit

Permalink
Linter, review feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
  • Loading branch information
pstibrany committed Jun 8, 2023
1 parent 24328ed commit 27a4fe4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
15 changes: 7 additions & 8 deletions pkg/ingester/client/buffering_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@ import (

func setupGrpc(t testing.TB) (*mockServer, *grpc.ClientConn) {
server := grpc.NewServer()
l, err := net.Listen("tcp", "127.0.0.1:")
require.NoError(t, err)

ingServ := &mockServer{}

RegisterIngesterServer(server, ingServ)

go func() {
_ = server.Serve(l)
}()

l, err := net.Listen("tcp", "127.0.0.1:")
require.NoError(t, err)
t.Cleanup(func() {
_ = l.Close()
})

// Start gRPC server.
go func() {
_ = server.Serve(l)
}()

c, err := grpc.Dial(l.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)

t.Cleanup(func() {
_ = c.Close()
})
Expand Down
22 changes: 11 additions & 11 deletions pkg/util/pool/fast_releasing_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const (

// Release decreases reference counter for given slab ID. (Slab ids equal to or less than 0 are ignored).
// If reference counter is 0, slab may be returned to the delegate pool.
func (b *FastReleasingSlabPool[T]) Release(slabId int) {
if slabId <= 0 {
func (b *FastReleasingSlabPool[T]) Release(slabID int) {
if slabID <= 0 {
return
}

Expand All @@ -51,11 +51,11 @@ func (b *FastReleasingSlabPool[T]) Release(slabId int) {
b.mtx.Lock()
defer b.mtx.Unlock()

if slabId >= len(b.slabs) {
panic(fmt.Sprintf("invalid slab id: %d", slabId))
if slabID >= len(b.slabs) {
panic(fmt.Sprintf("invalid slab id: %d", slabID))
}

ts := b.slabs[slabId]
ts := b.slabs[slabID]
if ts == nil {
panic("nil slab")
}
Expand All @@ -66,7 +66,7 @@ func (b *FastReleasingSlabPool[T]) Release(slabId int) {

ts.references--
if ts.references == 0 {
b.slabs[slabId] = nil
b.slabs[slabID] = nil
slabToRelease = ts.slab
}
}
Expand All @@ -86,20 +86,20 @@ func (b *FastReleasingSlabPool[T]) Get(size int) ([]T, int) {
b.mtx.Lock()
defer b.mtx.Unlock()

slabId := 0
slabID := 0
ts := (*trackedSlab[T])(nil)

// Look at last few slabs, since we assume that these slabs have the most free space.
for sid := len(b.slabs) - 1; sid >= len(b.slabs)-freeSlabChecks && sid >= 0; sid-- {
s := b.slabs[sid]
if s != nil && len(s.slab)-s.nextFreeIndex >= size {
slabId = sid
slabID = sid
ts = s
break
}
}

if slabId == 0 {
if slabID == 0 {
var slab []T

if fromDelegate := b.delegate.Get(); fromDelegate != nil {
Expand All @@ -111,13 +111,13 @@ func (b *FastReleasingSlabPool[T]) Get(size int) ([]T, int) {
ts = &trackedSlab[T]{
slab: slab,
}
slabId = len(b.slabs)
slabID = len(b.slabs)
b.slabs = append(b.slabs, ts)
}

out := ts.slab[ts.nextFreeIndex : ts.nextFreeIndex+size : ts.nextFreeIndex+size]
ts.nextFreeIndex += size
ts.references++

return out, slabId
return out, slabID
}

0 comments on commit 27a4fe4

Please sign in to comment.