Skip to content

Fix DB integer out of range error - #8390

Merged
xtremerui merged 3 commits into
masterfrom
issue/8364-int-to-bigint
Jun 8, 2022
Merged

xtremerui merged 3 commits into
masterfrom
issue/8364-int-to-bigint

Conversation

@xtremerui

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

closes #8364
closes #6354

  • convert build id related columns to type bigint in DB

  • build tracking lock id will be computed from build_id%max_int

  • for build events, select on build id only when it is beyond max_int so it wont query old build id (integer type) with a beyond max_int value and fail the query

  • done

  • todo

Release Note

  • Fix DB out of range error due to build numbers exceed the integer limit

 * convert build id related columns to type bigint in DB
 * advisoring lock will be computed from build_id%max_int
 * for build events, select on build id only when it is beyond max_int
  so it wont query old build id (integer type) with a beyond max_int
  value and fail the query

Signed-off-by: Rui Yang <[email protected]>
@xtremerui
xtremerui requested a review from a team May 31, 2022 19:55
@xtremerui xtremerui added the bug label May 31, 2022
Comment thread atc/db/lock/lock.go Resolved
Comment thread atc/db/build_event_source.go Resolved
Comment thread atc/db/lock/lock.go Outdated

func NewBuildTrackingLockID(buildID int) LockID {
return LockID{LockTypeBuildTracking, buildID}
return LockID{LockTypeBuildTracking, buildID % MaxInt}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I suggested in #8364 (comment), I still think the change should be in LockID.toDBArgs(). This is not just a problem with build id, I would consider volume id, container id to be larger than build id. As the restriction comes from PG, the fix should be as close as possible to db related code.

If you change LockID.toDBArgs(), please add some tests accordingly.

@xtremerui xtremerui Jun 1, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For hush-house (being up for 4 years), we have the maximum ids as following

1081477231 build id
214934158  container id
410257222  volumn id

Could you list the ids in runway for comparation? Ideally I want to keep the impact as minimum as possible, until we see the same problem reported for container/volumn ID.

I can see a trend that the increasing of build ID will be way faster than container/volume ids since in 7.0 all checks run as build. But for other IDs I think their grow should be the same as before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On our prod cluster (6.7.8):

10422031       build id
308650846   container id
707639294   volume id

In theory, a build needs to run a least one container and one volume, thus container id and volume id should be consumed faster than build id.

In your cluster, I think check builds (before in-memory check build) wasted a lot of build ids, many checks didn't actually run anything. After in-memory check build is in place, only a check build that really runs should consume a build id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if runway is in 6.7.8, it doesn't have in-memory check build either. How come its maximum build id is like that? How long has been the cluster up and running?

@evanchaoli evanchaoli Jun 2, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our prod cluster has been running for ~3 years. To roughly calculate, say 1000 working days, 10422031 / 1000 = 10422 builds per day, that's a reasonable number. As most of builds are triggered by code check-in.

Remember that, 6.x uses checks table, so that checks doesn't consume any build id.

From the other perspective, majority workloads on our cluster are coming from checks, that's reason why I spent so much efforts on optimizing checks.

@xtremerui xtremerui Jun 2, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want to add this overhead dividen operation to not needed lock ids so to me LockID.toDBArgs() is the least place I want to solve the problem. Plus the way you suggested will also calculate the lock_type % maxint32 which seems unnecessary.

I agree that volume id and container id should be considered though. However it seems there is no lock ID that depends on container ID.

@evanchaoli evanchaoli Jun 2, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing to the following DB operation pg_try_advisory_lock, cost of % operator can be ignored.

With your current implementation, there are still potential problems:

  • When container_id related lock is added, or other lock types that need build id or volume id are added, future developers have to remember % MaxInt32, which is error-prone.
  • Job id, resource configure id may eventually reach to MaxInt32 though possibility is low.

The following implementation will not % lock type:

func (l LockID) toDBArgs() []interface{} {
	result := []interface{}{l[0]}
	if len(l) > 1 {
             result = append(result, l[1] % math.MaxInt32)
        }

	return result
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • When container_id related lock is added, or other lock types that need build id or volume id are added, future developers have to remember % MaxInt32, which is error-prone.

I have added a block of comment for furture reference of developing lock type. Plus I can hardly imagine there will be a change of existing lock type or adding a new one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I am not convinced. I still think the change should be in toDBArgs(). But anyway I don't want to block you.

Rui Yang added 2 commits June 2, 2022 01:46
@evanchaoli

Copy link
Copy Markdown
Contributor

@xtremerui It seems I have no permission to approve this PR, thus just putting a comment here: LGTM, Approved.

@xtremerui

Copy link
Copy Markdown
Contributor Author

Thank you for reviewing @evanchaoli !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concourse cannot handle more than 2147483647 checks/builds pq: nextval: reached maximum value of sequence "resource_config_versions_id_seq"

2 participants