-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Transform maxclauses fix (#477) (#482) * transform maxClauses fix Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * added bucket log to track processed buckets Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * various renames/changes Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * fixed detekt issues Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * added comments to test Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * removed debug logging Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * empty commit to trigger checks Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * reduced pageSize to 1 in few ITs to avoid flaky tests; fixed bug where pagesProcessed was calculated incorrectly Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> * reverted pagesProcessed change; fixed few ITs Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com> (cherry picked from commit 7475cfd) Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com> (cherry picked from commit b39bd64) * Update kotlin 1.6.10 to fix kotlin-stdlib-1.4.0 vulnerability Signed-off-by: Angie Zhang <langelzh@amazon.com> * Update kotlin 1.4.32 to fix kotlin-stdlib-1.4.0 vulnerability Signed-off-by: Angie Zhang <langelzh@amazon.com> Signed-off-by: Angie Zhang <langelzh@amazon.com> Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8b39773
commit 73161b5
Showing
6 changed files
with
216 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/org/opensearch/indexmanagement/transform/TransformProcessedBucketLog.kt
This file contains 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,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.transform | ||
|
||
import java.math.BigInteger | ||
import java.security.MessageDigest | ||
|
||
class TransformProcessedBucketLog { | ||
|
||
companion object { | ||
const val MAX_SIZE = 100_000_000 | ||
const val HEX_RADIX = 16 | ||
} | ||
|
||
private var processedBuckets: MutableSet<String> = HashSet() | ||
|
||
fun addBuckets(buckets: List<Map<String, Any>>) { | ||
buckets.forEach { | ||
addBucket(it) | ||
} | ||
} | ||
|
||
fun addBucket(bucket: Map<String, Any>) { | ||
if (processedBuckets.size >= MAX_SIZE) return | ||
processedBuckets.add(computeBucketHash(bucket)) | ||
} | ||
|
||
fun isProcessed(bucket: Map<String, Any>): Boolean { | ||
return processedBuckets.contains(computeBucketHash(bucket)) | ||
} | ||
|
||
fun isNotProcessed(bucket: Map<String, Any>) = !isProcessed(bucket) | ||
|
||
fun computeBucketHash(bucket: Map<String, Any>): String { | ||
val md5Crypt = MessageDigest.getInstance("MD5") | ||
bucket.entries.sortedBy { it.key }.also { | ||
it.forEach { entry -> | ||
md5Crypt.update( | ||
if (entry.value == null) "null".toByteArray() | ||
else entry.value.toString().toByteArray() | ||
) | ||
} | ||
} | ||
return BigInteger(1, md5Crypt.digest()).toString(HEX_RADIX) | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.