Skip to content

Commit

Permalink
restore: reduce allocations when restoring to longer tenant keys
Browse files Browse the repository at this point in the history
Release note: none.
Epic: none.
  • Loading branch information
dt committed Mar 8, 2024
1 parent a4f061d commit 2bef9e2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/ccl/backupccl/key_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type KeyRewriter struct {
prefixes prefixRewriter
tenants prefixRewriter
descs map[descpb.ID]catalog.TableDescriptor
alloc []byte
}

// MakeKeyRewriterFromRekeys makes a KeyRewriter from Rekey protos.
Expand Down Expand Up @@ -273,7 +274,19 @@ func (kr *KeyRewriter) RewriteKey(
copy(keyTenantPrefix, newTenantPrefix)
rekeyed = append(keyTenantPrefix, rekeyed...)
} else {
rekeyed = append(newTenantPrefix, rekeyed...)
l := len(newTenantPrefix) + len(rekeyed)
if len(kr.alloc) < l {
if l > 1<<20 {
kr.alloc = make([]byte, l*16)
} else {
kr.alloc = make([]byte, l*256)
}
}
tmp := kr.alloc[:l:l]
kr.alloc = kr.alloc[l:]
copy(tmp, newTenantPrefix)
copy(tmp[len(newTenantPrefix):], rekeyed)
rekeyed = tmp
}

return rekeyed, ok, err
Expand Down

0 comments on commit 2bef9e2

Please sign in to comment.