-
Notifications
You must be signed in to change notification settings - Fork 618
feat(batchUpdate): enhance batch update functionality #1483
Changes from 11 commits
f3afc76
3e1a88e
192605e
200c7e9
e4cd816
eb74cf5
6ab5f7e
99f549e
f88f5db
7a6bf50
894299a
537587b
fb29c9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { | ||
|
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. With this flip, I think the entire batch fails now vs. only a chunk of it - intentional?
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. Guess that's partly the point of this PR - just wondering if that's a good thing?
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. Can ignore this mostly just curious philosophically which is better :) |
||
| 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 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.