-
Notifications
You must be signed in to change notification settings - Fork 70
unify caching across workers to maximize cache hits #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
d6dffb6
d778b9e
6844810
04ee960
da28dd7
4602867
e6d7cf5
d92bc16
0027f5f
3485813
dc244a6
0ce3f55
62c8220
4fba34f
0fd0060
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright 2021-2023 Aklivity Inc | ||
| * | ||
| * Licensed under the Aklivity Community License (the "License"); you may not use | ||
| * this file except in compliance with the License. You may obtain a copy of the | ||
| * License at | ||
| * | ||
| * https://www.aklivity.io/aklivity-community-license/ | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| */ | ||
| package io.aklivity.zilla.runtime.catalog.karapace.internal; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| public class CachedSchema | ||
| { | ||
| public static final String SCHEMA_PLACEHOLDER = "schema"; | ||
| public static final CachedSchema IN_PROGRESS = new CachedSchema(SCHEMA_PLACEHOLDER, new AtomicInteger(0)); | ||
|
|
||
| public String schema; | ||
| public AtomicInteger event; | ||
|
Contributor
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. Not sure why this is called |
||
|
|
||
|
Contributor
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. If these are both unmodifiable, then they should be marked |
||
| public CachedSchema( | ||
| String schema, | ||
| AtomicInteger event) | ||
| { | ||
| this.schema = schema; | ||
| this.event = event; | ||
| } | ||
|
Comment on lines
+27
to
+40
Contributor
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. Does it make sense to have a convenience constructor with just |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,16 +14,39 @@ | |
| */ | ||
| package io.aklivity.zilla.runtime.catalog.karapace.internal; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| public class CachedSchemaId | ||
| { | ||
| public static final int PLACEHOLDER_SCHEMA_ID = -1; | ||
| public static final CachedSchemaId IN_PROGRESS = new CachedSchemaId(Long.MAX_VALUE, PLACEHOLDER_SCHEMA_ID, | ||
| new AtomicInteger(0), Long.MAX_VALUE); | ||
|
|
||
| public long timestamp; | ||
| public int id; | ||
| public AtomicInteger event; | ||
| public long retry; | ||
|
Contributor
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. Should some or all of these be |
||
|
|
||
| public CachedSchemaId( | ||
| long timestamp, | ||
| int id) | ||
| int id, | ||
| AtomicInteger event, | ||
| long retry) | ||
| { | ||
| this.timestamp = timestamp; | ||
| this.id = id; | ||
| this.event = event; | ||
| this.retry = retry; | ||
|
Contributor
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 think this is saying |
||
| } | ||
|
|
||
| public boolean expired( | ||
| long maxAgeMillis) | ||
| { | ||
| return System.currentTimeMillis() - this.timestamp > maxAgeMillis; | ||
| } | ||
|
|
||
| public boolean retry() | ||
| { | ||
| return System.currentTimeMillis() - this.timestamp > this.retry; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright 2021-2023 Aklivity Inc | ||
| * | ||
| * Licensed under the Aklivity Community License (the "License"); you may not use | ||
| * this file except in compliance with the License. You may obtain a copy of the | ||
| * License at | ||
| * | ||
| * https://www.aklivity.io/aklivity-community-license/ | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| */ | ||
| package io.aklivity.zilla.runtime.catalog.karapace.internal; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ConcurrentMap; | ||
|
|
||
| public class KarapaceCache | ||
| { | ||
| public final ConcurrentMap<Integer, CompletableFuture<CachedSchema>> schemas; | ||
| public final ConcurrentMap<Integer, CompletableFuture<CachedSchemaId>> schemaIds; | ||
|
|
||
| public KarapaceCache() | ||
| { | ||
| this.schemas = new ConcurrentHashMap<>(); | ||
| this.schemaIds = new ConcurrentHashMap<>(); | ||
| } | ||
| } |
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.
No need to explicitly pass
0toAtomicIntegerconstructor.