Skip to content

Commit

Permalink
EEA: Rely solely on entity instances table (#4301)
Browse files Browse the repository at this point in the history
This reverts commit 74b9fdf.

Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX authored Aug 28, 2024
1 parent 805b55a commit b598620
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 67 deletions.
29 changes: 29 additions & 0 deletions database/migrations/000101_eea_rm_indexes.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Copyright 2023 Stacklok, 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.

BEGIN;

CREATE UNIQUE INDEX IF NOT EXISTS entity_execution_lock_idx ON entity_execution_lock(
entity,
repository_id,
COALESCE(artifact_id, '00000000-0000-0000-0000-000000000000'::UUID),
COALESCE(pull_request_id, '00000000-0000-0000-0000-000000000000'::UUID));

CREATE UNIQUE INDEX IF NOT EXISTS flush_cache_idx ON flush_cache(
entity,
repository_id,
COALESCE(artifact_id, '00000000-0000-0000-0000-000000000000'::UUID),
COALESCE(pull_request_id, '00000000-0000-0000-0000-000000000000'::UUID));

COMMIT;
20 changes: 20 additions & 0 deletions database/migrations/000101_eea_rm_indexes.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Copyright 2023 Stacklok, 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.

BEGIN;

DROP INDEX IF EXISTS entity_execution_lock_idx;
DROP INDEX IF EXISTS flush_cache_idx;

COMMIT;
12 changes: 0 additions & 12 deletions database/query/entity_execution_lock.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ INSERT INTO entity_execution_lock(
entity,
locked_by,
last_lock_time,
repository_id,
artifact_id,
pull_request_id,
project_id,
entity_instance_id
) VALUES(
sqlc.arg(entity)::entities,
gen_random_uuid(),
NOW(),
sqlc.narg(repository_id)::UUID,
sqlc.narg(artifact_id)::UUID,
sqlc.narg(pull_request_id)::UUID,
sqlc.arg(project_id)::UUID,
sqlc.arg(entity_instance_id)::UUID
) ON CONFLICT(entity_instance_id)
Expand All @@ -45,16 +39,10 @@ WHERE entity_instance_id = $1 AND locked_by = sqlc.arg(locked_by)::UUID;
-- name: EnqueueFlush :one
INSERT INTO flush_cache(
entity,
repository_id,
artifact_id,
pull_request_id,
project_id,
entity_instance_id
) VALUES(
sqlc.arg(entity)::entities,
sqlc.narg(repository_id)::UUID,
sqlc.narg(artifact_id)::UUID,
sqlc.narg(pull_request_id)::UUID,
sqlc.arg(project_id)::UUID,
sqlc.arg(entity_instance_id)::UUID
) ON CONFLICT(entity_instance_id)
Expand Down
50 changes: 11 additions & 39 deletions internal/db/entity_execution_lock.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions internal/db/entity_execution_lock.sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)

Expand All @@ -51,9 +50,6 @@ func TestQueries_LockIfThresholdNotExceeded(t *testing.T) {
defer wg.Done()
_, err := testQueries.LockIfThresholdNotExceeded(context.Background(), LockIfThresholdNotExceededParams{
Entity: EntitiesRepository,
RepositoryID: uuid.NullUUID{UUID: repo.ID, Valid: true},
ArtifactID: uuid.NullUUID{},
PullRequestID: uuid.NullUUID{},
Interval: fmt.Sprintf("%d", threshold),
ProjectID: project.ID,
EntityInstanceID: repo.ID,
Expand All @@ -66,9 +62,6 @@ func TestQueries_LockIfThresholdNotExceeded(t *testing.T) {

_, err := testQueries.EnqueueFlush(context.Background(), EnqueueFlushParams{
Entity: EntitiesRepository,
RepositoryID: uuid.NullUUID{UUID: repo.ID, Valid: true},
ArtifactID: uuid.NullUUID{},
PullRequestID: uuid.NullUUID{},
ProjectID: project.ID,
EntityInstanceID: repo.ID,
})
Expand All @@ -93,9 +86,6 @@ func TestQueries_LockIfThresholdNotExceeded(t *testing.T) {

_, err := testQueries.LockIfThresholdNotExceeded(context.Background(), LockIfThresholdNotExceededParams{
Entity: EntitiesRepository,
RepositoryID: uuid.NullUUID{UUID: repo.ID, Valid: true},
ArtifactID: uuid.NullUUID{},
PullRequestID: uuid.NullUUID{},
Interval: fmt.Sprintf("%d", threshold),
EntityInstanceID: repo.ID,
})
Expand Down
6 changes: 0 additions & 6 deletions internal/eea/eea.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ func (e *EEA) aggregate(msg *message.Message) (*message.Message, error) {

res, err := e.querier.LockIfThresholdNotExceeded(ctx, db.LockIfThresholdNotExceededParams{
Entity: entities.EntityTypeToDB(inf.Type),
RepositoryID: repoID,
ArtifactID: artifactID,
PullRequestID: pullRequestID,
EntityInstanceID: entityID,
ProjectID: projectID,
Interval: fmt.Sprintf("%d", e.cfg.LockInterval),
Expand All @@ -163,9 +160,6 @@ func (e *EEA) aggregate(msg *message.Message) (*message.Message, error) {

_, err := e.querier.EnqueueFlush(ctx, db.EnqueueFlushParams{
Entity: entities.EntityTypeToDB(inf.Type),
RepositoryID: repoID,
ArtifactID: artifactID,
PullRequestID: pullRequestID,
EntityInstanceID: entityID,
ProjectID: projectID,
})
Expand Down

0 comments on commit b598620

Please sign in to comment.