This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 618
feat(batchUpdate): enhance batch update functionality #1483
Merged
mergify
merged 13 commits into
spinnaker:master
from
kirangodishala:batchUpdate-clean-commits
Aug 17, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f3afc76
refactor(web/test): configure the ObjectMapper in PipelineControllerTck
dbyron-sf 3e1a88e
feat(web/new config): add PipelineControllerConfig to hold the config…
kirangodishala 192605e
feat(sql): make the bulk save operation atomic
kirangodishala 200c7e9
refactor(web): refactor validatePipeline() so that it can be reused f…
kirangodishala e4cd816
feat(batchUpdate): update /pipelines/batchUpdate POST handler method …
kirangodishala eb74cf5
feat(web): add a write permission check and validation to PipelineCon…
kirangodishala 6ab5f7e
feat(web): make batchUpdate return a map response with succeeded and …
kirangodishala 99f549e
feat(web): add staleCheck to batchUpdate so that if a submitted pipel…
kirangodishala f88f5db
feat(web): fine tune permissions on batchUpdate
kirangodishala 7a6bf50
refactor(web): simplify code for setting trigger ids in PipelineContr…
dbyron-sf 894299a
test(batchUpdate): add test cases for testing batchUpdate changes
kirangodishala 537587b
fix(web): minor fixes/improvements
kirangodishala fb29c9d
Merge branch 'master' into batchUpdate-clean-commits
jasonmcintosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,63 +258,58 @@ class SqlStorageService( | |
| } | ||
|
|
||
| override fun <T : Timestamped> storeObjects(objectType: ObjectType, allItems: Collection<T>) { | ||
| // using a lower `chunkSize` to avoid exceeding default packet size limits. | ||
| allItems.chunked(100).forEach { items -> | ||
| try { | ||
| withPool(poolName) { | ||
| jooq.transactional(sqlRetryProperties.transactions) { ctx -> | ||
| withPool(poolName) { | ||
| jooq.transactional(sqlRetryProperties.transactions) { ctx -> | ||
| // using a lower `chunkSize` to avoid exceeding default packet size limits. | ||
| allItems.chunked(100).forEach { items -> | ||
| try { | ||
| ctx.batch( | ||
| items.map { item -> | ||
| val insertPairs = definitionsByType[objectType]!!.getInsertPairs( | ||
| objectMapper, item.id.toLowerCase(), item | ||
| ) | ||
| val updatePairs = definitionsByType[objectType]!!.getUpdatePairs(insertPairs) | ||
|
|
||
| ctx.insertInto( | ||
| table(definitionsByType[objectType]!!.tableName), | ||
| *insertPairs.keys.map { field(it) }.toTypedArray() | ||
| ) | ||
| .values(insertPairs.values) | ||
| .onConflict(field("id", String::class.java)) | ||
| .doUpdate() | ||
| .set(updatePairs.mapKeys { field(it.key) }) | ||
| } | ||
| ).execute() | ||
| } catch (e: SQLDialectNotSupportedException) { | ||
| for (item in items) { | ||
| storeSingleObject(objectType, item.id.toLowerCase(), item) | ||
| } | ||
| } | ||
|
|
||
| if (definitionsByType[objectType]!!.supportsHistory) { | ||
| try { | ||
| ctx.batch( | ||
| items.map { item -> | ||
| val insertPairs = definitionsByType[objectType]!!.getInsertPairs( | ||
| objectMapper, item.id.toLowerCase(), item | ||
| val historyPairs = definitionsByType[objectType]!!.getHistoryPairs( | ||
| objectMapper, clock, item.id.toLowerCase(), item | ||
| ) | ||
| val updatePairs = definitionsByType[objectType]!!.getUpdatePairs(insertPairs) | ||
|
|
||
| ctx.insertInto( | ||
| table(definitionsByType[objectType]!!.tableName), | ||
| *insertPairs.keys.map { field(it) }.toTypedArray() | ||
| ) | ||
| .values(insertPairs.values) | ||
| .onConflict(field("id", String::class.java)) | ||
| .doUpdate() | ||
| .set(updatePairs.mapKeys { field(it.key) }) | ||
| ctx | ||
| .insertInto( | ||
| table(definitionsByType[objectType]!!.historyTableName), | ||
| *historyPairs.keys.map { field(it) }.toTypedArray() | ||
| ) | ||
| .values(historyPairs.values) | ||
| .onDuplicateKeyIgnore() | ||
| } | ||
| ).execute() | ||
| } catch (e: SQLDialectNotSupportedException) { | ||
| for (item in items) { | ||
| storeSingleObject(objectType, item.id.toLowerCase(), item) | ||
| } | ||
| } | ||
|
|
||
| if (definitionsByType[objectType]!!.supportsHistory) { | ||
| try { | ||
| ctx.batch( | ||
| items.map { item -> | ||
| val historyPairs = definitionsByType[objectType]!!.getHistoryPairs( | ||
| objectMapper, clock, item.id.toLowerCase(), item | ||
| ) | ||
|
|
||
| ctx | ||
| .insertInto( | ||
| table(definitionsByType[objectType]!!.historyTableName), | ||
| *historyPairs.keys.map { field(it) }.toTypedArray() | ||
| ) | ||
| .values(historyPairs.values) | ||
| .onDuplicateKeyIgnore() | ||
| } | ||
| ).execute() | ||
| } catch (e: SQLDialectNotSupportedException) { | ||
| for (item in items) { | ||
| storeSingleObjectHistory(objectType, item.id.toLowerCase(), item) | ||
| } | ||
| storeSingleObjectHistory(objectType, item.id.toLowerCase(), item) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt this happens much - but any reason to lose this try/catch here?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking TransientDaoException case where DB is failing or similar...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SHORT answer it'd be nice if these were caught & re-raised as Spinnaker exception objects |
||
| log.error("Unable to store objects (objectType: {}, objectKeys: {})", objectType, items.map { it.id }) | ||
| throw e | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../main/java/com/netflix/spinnaker/front50/config/controllers/PipelineControllerConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright 2024 Salesforce, 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 com.netflix.spinnaker.front50.config.controllers; | ||
|
|
||
| import lombok.Data; | ||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| @Data | ||
| @ConfigurationProperties(prefix = "controller.pipeline") | ||
| public class PipelineControllerConfig { | ||
|
|
||
| /** Holds the configurations to be used for save/update controller mappings */ | ||
| private SavePipelineConfiguration save = new SavePipelineConfiguration(); | ||
|
|
||
| @Data | ||
| public static class SavePipelineConfiguration { | ||
| /** This controls whether cache should be refreshes while checking for duplicate pipelines */ | ||
| boolean refreshCacheOnDuplicatesCheck = true; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this flip, I think the entire batch fails now vs. only a chunk of it - intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess that's partly the point of this PR - just wondering if that's a good thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can ignore this mostly just curious philosophically which is better :)