Files
substrate/cmd/ateapi/internal/controlapi/pagination.go
T
Jet Chiang f1e5d8e4e3 Harden PostgreSQL concurrency, integrity, and error handling (#1023)
Part of #731 and follow up to #640. This PR makes improvements to the
Postgres store by addressing review comments on #940 and optimizing
Postgres updates as suggested in #988.

- Replaces Postgres row-locking updates for actors, templates, and
snapshot tags with bounded optimistic concurrency control using
UID/version CAS checks.
- Strengthens relational integrity with missing FKs and indexes, and
replace snapshot-tag creation pre-check with FK
- Removes unnecessary UID uniqueness constraints
- Standardize pagination and validation across stores, map malformed
tokens and invalid sizes to appropriate gRPC errors
- Improves actor resume race handling when workers disappear or
concurrent assignments exhaust their retry budget
- Improves reliability with startup retries, expired-lease cleanup,
worker-watch reconnection after malformed msg
- Expand Postgres, Redis, Contract, and Control API tests to cover new
constraints, error semantics, concurrency

---------

Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
2026-08-24 12:56:01 -04:00

45 lines
1.3 KiB
Go

// Copyright 2026 Google LLC
//
// 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 controlapi
import (
"errors"
"github.com/agent-substrate/substrate/cmd/ateapi/internal/store"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const maxPageSize = 1000
// effectivePageSize applies the server-chosen default for an unset page_size
// and silently coerces oversized values.
func effectivePageSize(requested int32) int32 {
if requested == 0 || requested > maxPageSize {
return maxPageSize
}
return requested
}
func mapListError(err error) error {
if errors.Is(err, store.ErrInvalidPageToken) {
return status.Error(codes.InvalidArgument, "invalid page_token")
}
if errors.Is(err, store.ErrInvalidPageSize) {
return status.Error(codes.InvalidArgument, "invalid page_size")
}
return err
}