ronantakizawa/codereview-bench huggingface dataset:
Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/dtables/conflicts_tables_root_objects.go (Go)

Code before:

package dtables

import (
	"errors"
	"io"

	"github.com/dolthub/go-mysql-server/sql"

	"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
)

// NewConflictsTableRootObject returns a new conflicts table for root objects.
func NewConflictsTableRootObject(ctx *sql.Context, baseTableName string, rootObject doltdb.ConflictRootObject, root doltdb.RootValue, rs RootSetter) (sql.Table, error) {
	return ConflictsTableRootObject{
		baseTableName: baseTableName,
		sqlSch:        rootObject.Schema(baseTableName),
		root:          root,
		rootObject:    rootObject,
		rs:            rs,
	}, nil
}

// ConflictsTableRootObject is a sql.Table implementation that provides access to the conflicts that exist on a root
// object.
type ConflictsTableRootObject struct {
	baseTableName string
	sqlSch        sql.Schema
	root          doltdb.RootValue
	rootObject    doltdb.ConflictRootObject
	rs            RootSetter
}

var _ sql.Table = ConflictsTableRootObject{}
var _ sql.DeletableTable = ConflictsTableRootObject{}

// Name implements the interface sql.Table.
func (ct ConflictsTableRootObject) Name() string {
	return ct.baseTableName
}

// String implements the interface sql.Table.
func (ct ConflictsTableRootObject) String() string {
	return ct.baseTableName
}

// Schema implements the interface sql.Table.
func (ct ConflictsTableRootObject) Schema() sql.Schema {
	return ct.sqlSch
}


Review comment (suggestion):
"ConflictsTableRootObject" makes it sound like this is a type of "RootObject" to me. You might consider "ConflictRootObjectTable" to make it sound more like this is a type of table for a ConflictRootObject. 

Code after:

package dtables

import (
	"errors"
	"io"

	"github.com/dolthub/go-mysql-server/sql"

	"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
)

// NewConflictRootObjectTable returns a new conflicts table for root objects.
func NewConflictRootObjectTable(ctx *sql.Context, rootObject doltdb.ConflictRootObject, root doltdb.RootValue, rs RootSetter) (sql.Table, error) {
	tableName := rootObject.Name()
	return ConflictRootObjectTable{
		tableName:  tableName,
		sqlSch:     rootObject.Schema(tableName.Name),
		root:       root,
		rootObject: rootObject,
		rs:         rs,
	}, nil
}

// ConflictRootObjectTable is a sql.Table implementation that provides access to the conflicts that exist on a root
// object.
type ConflictRootObjectTable struct {
	tableName  doltdb.TableName
	sqlSch     sql.Schema
	root       doltdb.RootValue
	rootObject doltdb.ConflictRootObject
	rs         RootSetter
}

var _ sql.Table = ConflictRootObjectTable{}
var _ sql.DeletableTable = ConflictRootObjectTable{}

// Name implements the interface sql.Table.
func (ct ConflictRootObjectTable) Name() string {
	return ct.tableName.Name
}

// String implements the interface sql.Table.
func (ct ConflictRootObjectTable) String() string {
	return ct.tableName.Name
}

// Schema implements the interface sql.Table.
func (ct ConflictRootObjectTable) Schema() sql.Schema {
	return ct.sqlSch
}
Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go (Go)

Code before:
		return 0, err
	}

	tbl = strings.ToLower(tbl)

	given, err := CoerceAutoIncrementValue(ctx, insertVal)
	if err != nil {
		return 0, err
	}

	if a.lockMode == LockMode_Interleaved {
		release := a.mm.Lock(tbl)
		defer release()
	}

	curr := loadAutoIncValue(a.sequences, tbl)

	if given == 0 {
		// |given| is 0 or NULL
		a.sequences.Store(tbl, curr+1)
		return curr, nil
	}

	if given >= curr {
		nextVal := given
		if a.canIncrementAutoIncVal(ctx, tbl, given) {
			nextVal++
		}
		a.sequences.Store(tbl, nextVal)
		return given, nil
	}

	// |given| < curr
	return given, nil
}

func (a *AutoIncrementTracker) CoerceAutoIncrementValue(ctx *sql.Context, val interface{}) (uint64, error) {
	err := a.waitForInit()
	if err != nil {
		return 0, err
	}
	return CoerceAutoIncrementValue(ctx, val)
}

// CoerceAutoIncrementValue converts |val| into an AUTO_INCREMENT sequence value
func CoerceAutoIncrementValue(ctx *sql.Context, val interface{}) (uint64, error) {
	switch typ := val.(type) {
	case float32:
		val = math.Round(float64(typ))
	case float64:
		val = math.Round(typ)

Review comment (suggestion):
just have this be `incrementAutoIncVal` that returns the nextVal and an ok boolean indicating if nextVal is valid.

Code after:
		return 0, err
	}

	tbl = strings.ToLower(tbl)

	given, err := CoerceAutoIncrementValue(ctx, insertVal)
	if err != nil {
		return 0, err
	}

	if a.lockMode == LockMode_Interleaved {
		release := a.mm.Lock(tbl)
		defer release()
	}

	curr := loadAutoIncValue(a.sequences, tbl)

	if given == 0 {
		// |given| is 0 or NULL
		a.sequences.Store(tbl, curr+1)
		return curr, nil
	}

	if given >= curr {
		nextVal := given
		if a.incrementAutoIncVal(ctx, tbl, given) {
			nextVal++
		}
		a.sequences.Store(tbl, nextVal)
		return given, nil
	}

	// |given| < curr
	return given, nil
}

func (a *AutoIncrementTracker) CoerceAutoIncrementValue(ctx *sql.Context, val interface{}) (uint64, error) {
	err := a.waitForInit()
	if err != nil {
		return 0, err
	}
	return CoerceAutoIncrementValue(ctx, val)
}

// CoerceAutoIncrementValue converts |val| into an AUTO_INCREMENT sequence value
func CoerceAutoIncrementValue(ctx *sql.Context, val interface{}) (uint64, error) {
	switch typ := val.(type) {
	case float32:
		val = math.Round(float64(typ))
	case float64:
		val = math.Round(typ)
Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/sqlutil/sql_row.go (Go)

Code before:
}

// SqlColToStr is a utility function for converting a sql column of type interface{} to a string.
// NULL values are treated as empty strings. Handle nil separately if you require other behavior.
func SqlColToStr(ctx *sql.Context, sqlType sql.Type, col interface{}) (string, error) {
	if col != nil {
		switch typedCol := col.(type) {
		case bool:
			if typedCol {
				return "true", nil
			} else {
				return "false", nil
			}
		case sql.SpatialColumnType:
			res, err := sqlType.SQL(ctx, nil, col)
			hexRes := fmt.Sprintf("0x%X", res.Raw())
			if err != nil {
				return "", err
			}
			return hexRes, nil
		default:
			if sqlType != nil {
				if stringType, ok := sqlType.(sql.StringType); ok {
					if stringType.Type() == sqltypes.VarBinary || stringType.Type() == sqltypes.Binary {
						if binaryBytes, ok := typedCol.([]byte); ok {
							// Match MySQL's --binary-as-hex behavior
							if isInteractiveMode() {
								return "0x" + strings.ToUpper(hex.EncodeToString(binaryBytes)), nil
							}
						}
					}
				}
			}

			res, err := sqlType.SQL(ctx, nil, col)
			if err != nil {
				return "", err
			}
			return res.ToString(), nil
		}
	}

	return "", nil
}


Review comment (suggestion):
We should probably implement the client command line option and support `--skip-binary-as-hex` in the future.

MySQL Docs:
https://dev.mysql.com/doc/refman/8.4/en/mysql-command-options.html#option_mysql_binary-as-hex


Code after:
		if hexVal, ok := col.(BinaryAsHexDisplayValue); ok {
			return string(hexVal), nil
		}

		switch typedCol := col.(type) {
		case bool:
			if typedCol {
				return "true", nil
			} else {
				return "false", nil
			}
		case sql.SpatialColumnType:
			res, err := sqlType.SQL(ctx, nil, col)
			hexRes := fmt.Sprintf("0x%X", res.Raw())
			if err != nil {
				return "", err
			}
			return hexRes, nil
		default:
			res, err := sqlType.SQL(ctx, nil, col)
			if err != nil {
				return "", err
			}
			return res.ToString(), nil
		}
	}

	return "", nil
}

// DatabaseTypeNameToSqlType converts a MySQL wire protocol database type name
// to a go-mysql-server sql.Type. This uses the same type mapping logic as the existing
// Dolt type system for consistency.
// TODO: Add support for BLOB types (TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB) and BIT type
// as confirmed by testing MySQL 8.4+ binary-as-hex behavior
func DatabaseTypeNameToSqlType(databaseTypeName string) sql.Type {
	typeName := strings.ToLower(databaseTypeName)
	switch typeName {
	case "binary":
		return gmstypes.MustCreateBinary(sqltypes.Binary, 255)
	case "varbinary":
		return gmstypes.MustCreateBinary(sqltypes.VarBinary, 255)
	default:
		// Default to LongText for all other types (as was done before)
		return gmstypes.LongText
	}
}
Repository: dolthub/dolt
File: go/libraries/doltcore/doltdb/root_val.go (Go)

Code before:
	tbl, ok, err := root.GetTable(ctx, TableName{Name: resolvedName, Schema: tName.Schema})
	if err != nil {
		return nil, "", false, err
	}
	return tbl, resolvedName, ok, nil
}

// GetTableByColTag looks for the table containing the given column tag.
func GetTableByColTag(ctx context.Context, root RootValue, tag uint64) (tbl *Table, name TableName, found bool, err error) {
	err = root.IterTables(ctx, func(tn TableName, t *Table, s schema.Schema) (bool, error) {
		_, found = s.GetAllCols().GetByTag(tag)
		if found {
			name, tbl = tn, t
		}

		return found, nil
	})

	if err != nil {
		return nil, TableName{}, false, err
	}

	return tbl, name, found, nil
}

// GetTableNames retrieves the lists of all tables for a RootValue
func (root *rootValue) GetAllTableNames(ctx context.Context, _ bool) ([]TableName, error) {
	names, err := root.GetTableNames(ctx, DefaultSchemaName, false)
	if err != nil {
		return nil, err
	}
	tblNames := make([]TableName, len(names))
	for i, name := range names {
		tblNames[i] = TableName{
			Name:   name,
			Schema: DefaultSchemaName,
		}
	}
	return tblNames, nil
}

// GetTableNames retrieves the lists of all tables for a RootValue
func (root *rootValue) GetTableNames(ctx context.Context, schemaName string, _ bool) ([]string, error) {
	tableMap, err := root.getTableMap(ctx, schemaName)
	if err != nil {
		return nil, err
	}

	tablesHash := xxhash.New()

	var names []string

Review comment (suggestion):
```suggestion
// GetAllTableNames retrieves the lists of all tables for a RootValue
```

Code after:
	tbl, ok, err := root.GetTable(ctx, TableName{Name: resolvedName, Schema: tName.Schema})
	if err != nil {
		return nil, "", false, err
	}
	return tbl, resolvedName, ok, nil
}

// GetTableByColTag looks for the table containing the given column tag.
func GetTableByColTag(ctx context.Context, root RootValue, tag uint64) (tbl *Table, name TableName, found bool, err error) {
	err = root.IterTables(ctx, func(tn TableName, t *Table, s schema.Schema) (bool, error) {
		_, found = s.GetAllCols().GetByTag(tag)
		if found {
			name, tbl = tn, t
		}

		return found, nil
	})

	if err != nil {
		return nil, TableName{}, false, err
	}

	return tbl, name, found, nil
}

// GetAllTableNames retrieves all table names for a RootValue. Dolt only has a single schema (the default empty schema),
// and does not have root objects, so both of those are ignored here specifically.
func (root *rootValue) GetAllTableNames(ctx context.Context, _ bool) ([]TableName, error) {
	names, err := root.GetTableNames(ctx, DefaultSchemaName, false)
	if err != nil {
		return nil, err
	}
	tblNames := make([]TableName, len(names))
	for i, name := range names {
		tblNames[i] = TableName{
			Name:   name,
			Schema: DefaultSchemaName,
		}
	}
	return tblNames, nil
}

// GetTableNames retrieves the lists of all tables for a RootValue
func (root *rootValue) GetTableNames(ctx context.Context, schemaName string, _ bool) ([]string, error) {
	tableMap, err := root.getTableMap(ctx, schemaName)
	if err != nil {
		return nil, err
	}

	tablesHash := xxhash.New()
Repository: dolthub/dolt
File: go/performance/dolt_log_bench/dolt_log_test.go (Go)

Code before:
// Copyright 2022 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.

package dolt_log_bench

import (
	"context"
	"fmt"
	"io"
	"testing"

	"github.com/dolthub/go-mysql-server/sql"
	"github.com/stretchr/testify/require"

	"github.com/dolthub/dolt/go/cmd/dolt/commands"

Review comment (suggestion):
```suggestion
// Copyright 2025 Dolthub, Inc.
```

Code after:
// Copyright 2025 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.

package dolt_log_bench

import (
	"context"
	"fmt"
	"io"
	"testing"

	"github.com/dolthub/go-mysql-server/sql"
	"github.com/stretchr/testify/require"

	"github.com/dolthub/dolt/go/cmd/dolt/commands"
Repository: dolthub/dolt
File: go/libraries/doltcore/doltdb/system_table.go (Go)

Code before:

# Start in background
dolt sql-server --port=3307 &
` + "```" + `

### Connecting to SQL Server
` + "```bash" + `
# Connect with dolt sql command
dolt sql

# Connect with mysql client
mysql -h 127.0.0.1 -P 3306 -u root

# Connect with specific database
mysql -h 127.0.0.1 -P 3306 -u root -D <database-name>
` + "```" + `

## Dolt Testing with dolt_test System Table

### Unit Testing with dolt_test

The dolt_test system table provides a powerful way to create and run unit tests for your database. This is the preferred method for testing data integrity, business rules, and schema validation.

#### Creating Tests

Tests are created by inserting rows into the dolt_tests system table:

` + "```sql" + `
-- Create a simple test
INSERT INTO dolt_tests VALUES (
    'test_user_count', 
    'validation', 
    'SELECT COUNT(*) as user_count FROM users;', 
    'row_count',
    '>',
    '0'
);

-- Create a test with expected result
INSERT INTO dolt_tests VALUES (
    'test_valid_emails', 
    'validation', 
    'SELECT COUNT(*) FROM users WHERE email NOT LIKE "%@%";', 
    'row_count',
    '==',
    '0'
);

-- Create a schema validation test
INSERT INTO dolt_tests VALUES (
    'test_users_schema', 

Review comment (suggestion):
```suggestion
Tests are created by inserting rows into the `dolt_tests` system table:
```

Code after:

# Start in background
dolt sql-server --port=3307 &
` + "```" + `

### Connecting to SQL Server
` + "```bash" + `
# Connect with dolt sql command
dolt sql

# Connect with mysql client
mysql -h 127.0.0.1 -P 3306 -u root

# Connect with specific database
mysql -h 127.0.0.1 -P 3306 -u root -D <database-name>
` + "```" + `

## Dolt Testing with dolt_test System Table

### Unit Testing with dolt_test

The dolt_test system table provides a powerful way to create and run unit tests for your database. This is the preferred method for testing data integrity, business rules, and schema validation.

#### Creating Tests

Tests are created by inserting rows into the ` + "`dolt_tests`" + ` system table:

` + "```sql" + `
-- Create a simple test
INSERT INTO ` + "`dolt_tests`" + ` VALUES (
    'test_user_count', 
    'validation', 
    'SELECT COUNT(*) as user_count FROM users;', 
    'row_count',
    '>',
    '0'
);

-- Create a test with expected result
INSERT INTO ` + "`dolt_tests`" + ` VALUES (
    'test_valid_emails', 
    'validation', 
    'SELECT COUNT(*) FROM users WHERE email NOT LIKE "%@%";', 
    'row_count',
    '==',
    '0'
);

-- Create a schema validation test
INSERT INTO ` + "`dolt_tests`" + ` VALUES (
    'test_users_schema',
Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/commit_hooks.go (Go)

Code before:

		if async {
			return &m.asyncHook, nil
		}
		return &m.syncHook, nil
	}()

	if err != nil {
		logrus.Warnf("replication hook failed: %v", err)
		return nil, err
	}

	if hook == nil {
		// replication disabled
		return nil, nil
	}

	logrus.Debugf("replication hook invoked. pushing to '%s' (asyn=%t)", remoteName, async)
	return hook.Execute(ctx, ds, db)
}

func (m *DynamicPushOnWriteHook) ExecuteForWorkingSets() bool {
	return false
}

var _ doltdb.CommitHook = (*DynamicPushOnWriteHook)(nil)


Review comment (suggestion):
(minor) most of our code puts these checks right after the struct definition. Nice to see upfront what interfaces a type implements. 

Code after:
			m.async = false
			m.asyncHook.destDb = nil
			m.syncHook.destDb = nil
			return nil, nil
		}

		m.remote = remoteName

		destDb, err := getDestinationDb(ctx, m.dEnv, m.remote)
		if err != nil {
			return nil, err
		}

		m.syncHook.destDb = destDb
		m.asyncHook.destDb = destDb

		if async {
			return &m.asyncHook, nil
		}
		return &m.syncHook, nil
	}()

	if err != nil {
		logrus.Warnf("replication hook failed: %v", err)
		return nil, err
	}

	if hook == nil {
		// replication disabled
		return nil, nil
	}

	logrus.Debugf("replication hook invoked. pushing to '%s' (asyn=%t)", remoteName, async)
	return hook.Execute(ctx, ds, db)
}

func (m *DynamicPushOnWriteHook) ExecuteForWorkingSets() bool {
	return false
}
Repository: dolthub/dolt
File: go/store/nbs/quota.go (Go)

Code before:
	ReleaseQuotaBytes(sz int)
	Usage() uint64
}

type UnlimitedQuotaProvider struct {
	mu   sync.Mutex
	used uint64
}

func NewUnlimitedMemQuotaProvider() *UnlimitedQuotaProvider {
	return &UnlimitedQuotaProvider{}
}

func (q *UnlimitedQuotaProvider) AcquireQuotaBytes(ctx context.Context, sz int) ([]byte, error) {
	buf := make([]byte, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz)
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint32s(ctx context.Context, sz int) ([]uint32, error) {
	buf := make([]uint32, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * 4
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint64s(ctx context.Context, sz int) ([]uint64, error) {
	buf := make([]uint64, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * 8
	return buf, nil
}

func (q *UnlimitedQuotaProvider) ReleaseQuotaBytes(sz int) {
	if sz < 0 {
		panic("tried to release negative bytes")
	}
	q.mu.Lock()
	defer q.mu.Unlock()
	if uint64(sz) > q.used {
		panic("tried to release too much quota")
	}
	q.used -= uint64(sz)
}

func (q *UnlimitedQuotaProvider) Usage() uint64 {
	q.mu.Lock()

Review comment (suggestion):
```suggestion
	q.used += uint64(sz) * uint32Size
```

Code after:
	ReleaseQuotaBytes(sz int)
	Usage() uint64
}

type UnlimitedQuotaProvider struct {
	mu   sync.Mutex
	used uint64
}

func NewUnlimitedMemQuotaProvider() *UnlimitedQuotaProvider {
	return &UnlimitedQuotaProvider{}
}

func (q *UnlimitedQuotaProvider) AcquireQuotaBytes(ctx context.Context, sz int) ([]byte, error) {
	buf := make([]byte, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz)
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint32s(ctx context.Context, sz int) ([]uint32, error) {
	buf := make([]uint32, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * uint32Size
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint64s(ctx context.Context, sz int) ([]uint64, error) {
	buf := make([]uint64, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * uint64Size
	return buf, nil
}

func (q *UnlimitedQuotaProvider) ReleaseQuotaBytes(sz int) {
	if sz < 0 {
		panic("tried to release negative bytes")
	}
	q.mu.Lock()
	defer q.mu.Unlock()
	if uint64(sz) > q.used {
		panic("tried to release too much quota")
	}
	q.used -= uint64(sz)
}

func (q *UnlimitedQuotaProvider) Usage() uint64 {
	q.mu.Lock()
Repository: dolthub/dolt
File: go/store/nbs/quota.go (Go)

Code before:

func NewUnlimitedMemQuotaProvider() *UnlimitedQuotaProvider {
	return &UnlimitedQuotaProvider{}
}

func (q *UnlimitedQuotaProvider) AcquireQuotaBytes(ctx context.Context, sz int) ([]byte, error) {
	buf := make([]byte, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz)
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint32s(ctx context.Context, sz int) ([]uint32, error) {
	buf := make([]uint32, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * 4
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint64s(ctx context.Context, sz int) ([]uint64, error) {
	buf := make([]uint64, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * 8
	return buf, nil
}

func (q *UnlimitedQuotaProvider) ReleaseQuotaBytes(sz int) {
	if sz < 0 {
		panic("tried to release negative bytes")
	}
	q.mu.Lock()
	defer q.mu.Unlock()
	if uint64(sz) > q.used {
		panic("tried to release too much quota")
	}
	q.used -= uint64(sz)
}

func (q *UnlimitedQuotaProvider) Usage() uint64 {
	q.mu.Lock()
	defer q.mu.Unlock()
	return q.used
}


Review comment (suggestion):
```suggestion
	q.used += uint64(sz) * uint64Size
```

Code after:

func NewUnlimitedMemQuotaProvider() *UnlimitedQuotaProvider {
	return &UnlimitedQuotaProvider{}
}

func (q *UnlimitedQuotaProvider) AcquireQuotaBytes(ctx context.Context, sz int) ([]byte, error) {
	buf := make([]byte, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz)
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint32s(ctx context.Context, sz int) ([]uint32, error) {
	buf := make([]uint32, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * uint32Size
	return buf, nil
}

func (q *UnlimitedQuotaProvider) AcquireQuotaUint64s(ctx context.Context, sz int) ([]uint64, error) {
	buf := make([]uint64, sz)
	q.mu.Lock()
	defer q.mu.Unlock()
	q.used += uint64(sz) * uint64Size
	return buf, nil
}

func (q *UnlimitedQuotaProvider) ReleaseQuotaBytes(sz int) {
	if sz < 0 {
		panic("tried to release negative bytes")
	}
	q.mu.Lock()
	defer q.mu.Unlock()
	if uint64(sz) > q.used {
		panic("tried to release too much quota")
	}
	q.used -= uint64(sz)
}

func (q *UnlimitedQuotaProvider) Usage() uint64 {
	q.mu.Lock()
	defer q.mu.Unlock()
	return q.used
}