mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-09 21:13:28 +02:00
sqldb: use uint32 for config values
This commit is contained in:
@@ -788,13 +788,13 @@ func BenchmarkFindOptimalSQLQueryConfig(b *testing.B) {
|
|||||||
// Set the various page sizes we want to test.
|
// Set the various page sizes we want to test.
|
||||||
//
|
//
|
||||||
// NOTE: these are the sqlite paging testing values.
|
// NOTE: these are the sqlite paging testing values.
|
||||||
testSizes := []int{20, 50, 100, 150, 500}
|
testSizes := []uint32{20, 50, 100, 150, 500}
|
||||||
|
|
||||||
configOption := "MaxPageSize"
|
configOption := "MaxPageSize"
|
||||||
if testBatching {
|
if testBatching {
|
||||||
configOption = "MaxBatchSize"
|
configOption = "MaxBatchSize"
|
||||||
|
|
||||||
testSizes = []int{
|
testSizes = []uint32{
|
||||||
50, 100, 150, 200, 250, 300, 350,
|
50, 100, 150, 200, 250, 300, 350,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -806,10 +806,10 @@ func BenchmarkFindOptimalSQLQueryConfig(b *testing.B) {
|
|||||||
// Set the various page sizes we want to test.
|
// Set the various page sizes we want to test.
|
||||||
//
|
//
|
||||||
// NOTE: these are the postgres paging values.
|
// NOTE: these are the postgres paging values.
|
||||||
testSizes = []int{5000, 7000, 10000, 12000}
|
testSizes = []uint32{5000, 7000, 10000, 12000}
|
||||||
|
|
||||||
if testBatching {
|
if testBatching {
|
||||||
testSizes = []int{
|
testSizes = []uint32{
|
||||||
1000, 2000, 5000, 7000, 10000,
|
1000, 2000, 5000, 7000, 10000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -828,7 +828,7 @@ func BenchmarkFindOptimalSQLQueryConfig(b *testing.B) {
|
|||||||
if testBatching {
|
if testBatching {
|
||||||
cfg.MaxBatchSize = size
|
cfg.MaxBatchSize = size
|
||||||
} else {
|
} else {
|
||||||
cfg.MaxPageSize = int32(size)
|
cfg.MaxPageSize = size
|
||||||
}
|
}
|
||||||
|
|
||||||
store := connectNativeSQLite(
|
store := connectNativeSQLite(
|
||||||
|
@@ -283,7 +283,7 @@ func migrateNodes(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
batch[id] = node
|
batch[id] = node
|
||||||
|
|
||||||
// Validate batch when full.
|
// Validate batch when full.
|
||||||
if len(batch) >= cfg.MaxBatchSize {
|
if len(batch) >= int(cfg.MaxBatchSize) {
|
||||||
err := validateBatch()
|
err := validateBatch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("batch validation failed: %w",
|
return fmt.Errorf("batch validation failed: %w",
|
||||||
@@ -548,7 +548,7 @@ func migrateChannelsAndPolicies(ctx context.Context, cfg *SQLStoreConfig,
|
|||||||
dbInfo: dbChanInfo,
|
dbInfo: dbChanInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(batch) >= cfg.QueryCfg.MaxBatchSize {
|
if len(batch) >= int(cfg.QueryCfg.MaxBatchSize) {
|
||||||
// Do batch validation.
|
// Do batch validation.
|
||||||
err := validateMigratedChannels(ctx, cfg, sqlDB, batch)
|
err := validateMigratedChannels(ctx, cfg, sqlDB, batch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -902,7 +902,7 @@ func migratePruneLog(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
batch[height] = *hash
|
batch[height] = *hash
|
||||||
|
|
||||||
// Validate batch when full.
|
// Validate batch when full.
|
||||||
if len(batch) >= cfg.MaxBatchSize {
|
if len(batch) >= int(cfg.MaxBatchSize) {
|
||||||
err := validateBatch()
|
err := validateBatch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("batch "+
|
return fmt.Errorf("batch "+
|
||||||
@@ -1070,7 +1070,7 @@ func migrateClosedSCIDIndex(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
batch = append(batch, chanIDB)
|
batch = append(batch, chanIDB)
|
||||||
|
|
||||||
// Validate batch when full.
|
// Validate batch when full.
|
||||||
if len(batch) >= cfg.MaxBatchSize {
|
if len(batch) >= int(cfg.MaxBatchSize) {
|
||||||
err := validateBatch()
|
err := validateBatch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("batch validation failed: %w",
|
return fmt.Errorf("batch validation failed: %w",
|
||||||
@@ -1251,7 +1251,7 @@ func migrateZombieIndex(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate batch when full.
|
// Validate batch when full.
|
||||||
if len(batch) >= cfg.MaxBatchSize {
|
if len(batch) >= int(cfg.MaxBatchSize) {
|
||||||
err := validateBatch()
|
err := validateBatch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("batch validation failed: %w",
|
return fmt.Errorf("batch validation failed: %w",
|
||||||
|
@@ -37,11 +37,11 @@ const (
|
|||||||
type QueryConfig struct {
|
type QueryConfig struct {
|
||||||
// MaxBatchSize is the maximum number of items included in a batch
|
// MaxBatchSize is the maximum number of items included in a batch
|
||||||
// query IN clauses list.
|
// query IN clauses list.
|
||||||
MaxBatchSize int `long:"max-batch-size" description:"The maximum number of items to include in a batch query IN clause. This is used for queries that fetch results based on a list of identifiers."`
|
MaxBatchSize uint32 `long:"max-batch-size" description:"The maximum number of items to include in a batch query IN clause. This is used for queries that fetch results based on a list of identifiers."`
|
||||||
|
|
||||||
// MaxPageSize is the maximum number of items returned in a single page
|
// MaxPageSize is the maximum number of items returned in a single page
|
||||||
// of results. This is used for paginated queries.
|
// of results. This is used for paginated queries.
|
||||||
MaxPageSize int32 `long:"max-page-size" description:"The maximum number of items to return in a single page of results. This is used for paginated queries."`
|
MaxPageSize uint32 `long:"max-page-size" description:"The maximum number of items to return in a single page of results. This is used for paginated queries."`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate checks that the QueryConfig values are valid.
|
// Validate checks that the QueryConfig values are valid.
|
||||||
@@ -121,9 +121,9 @@ func ExecuteBatchQuery[I any, T any, R any](ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process items in pages.
|
// Process items in pages.
|
||||||
for i := 0; i < len(inputItems); i += cfg.MaxBatchSize {
|
for i := 0; i < len(inputItems); i += int(cfg.MaxBatchSize) {
|
||||||
// Calculate the end index for this page.
|
// Calculate the end index for this page.
|
||||||
end := i + cfg.MaxBatchSize
|
end := i + int(cfg.MaxBatchSize)
|
||||||
if end > len(inputItems) {
|
if end > len(inputItems) {
|
||||||
end = len(inputItems)
|
end = len(inputItems)
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ func ExecutePaginatedQuery[C any, T any](ctx context.Context, cfg *QueryConfig,
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
// Fetch the next page.
|
// Fetch the next page.
|
||||||
items, err := queryFunc(ctx, cursor, cfg.MaxPageSize)
|
items, err := queryFunc(ctx, cursor, int32(cfg.MaxPageSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch page with "+
|
return fmt.Errorf("failed to fetch page with "+
|
||||||
"cursor %v: %w", cursor, err)
|
"cursor %v: %w", cursor, err)
|
||||||
@@ -265,7 +265,7 @@ func ExecuteCollectAndBatchWithSharedDataQuery[C any, T any, I any, D any](
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
// Step 1: Fetch the next page of items.
|
// Step 1: Fetch the next page of items.
|
||||||
items, err := pageQueryFunc(ctx, cursor, cfg.MaxPageSize)
|
items, err := pageQueryFunc(ctx, cursor, int32(cfg.MaxPageSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch page with "+
|
return fmt.Errorf("failed to fetch page with "+
|
||||||
"cursor %v: %w", cursor, err)
|
"cursor %v: %w", cursor, err)
|
||||||
|
@@ -341,7 +341,7 @@ func TestExecutePaginatedQuery(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
pageSize int32
|
pageSize uint32
|
||||||
allItems []testItem
|
allItems []testItem
|
||||||
initialCursor int64
|
initialCursor int64
|
||||||
queryError error
|
queryError error
|
||||||
@@ -592,7 +592,7 @@ func TestExecuteCollectAndBatchWithSharedDataQuery(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
maxPageSize int32
|
maxPageSize uint32
|
||||||
allRows []channelRow
|
allRows []channelRow
|
||||||
initialCursor int64
|
initialCursor int64
|
||||||
pageQueryError error
|
pageQueryError error
|
||||||
|
Reference in New Issue
Block a user