Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/catalog-karapace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jacoco.coverage.ratio>0.85</jacoco.coverage.ratio>
<jacoco.coverage.ratio>0.83</jacoco.coverage.ratio>
<jacoco.missed.count>0</jacoco.missed.count>
</properties>

Expand Down
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));

Copy link
Copy Markdown
Contributor

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 0 to AtomicInteger constructor.


public String schema;
public AtomicInteger event;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is called event.
Isn't this just tracking the number of retries, which is normally 0 when everything is working normally?


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are both unmodifiable, then they should be marked final too.

public CachedSchema(
String schema,
AtomicInteger event)
{
this.schema = schema;
this.event = event;
}
Comment on lines +27 to +40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have a convenience constructor with just schema defauting to new AtomicInteger().

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should some or all of these be final?


public CachedSchemaId(
long timestamp,
int id)
int id,
AtomicInteger event,
long retry)
{
this.timestamp = timestamp;
this.id = id;
this.event = event;
this.retry = retry;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is saying retryAfter, right?

}

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<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package io.aklivity.zilla.runtime.catalog.karapace.internal;

import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import io.aklivity.zilla.runtime.engine.Configuration;
import io.aklivity.zilla.runtime.engine.EngineContext;
Expand All @@ -25,9 +27,12 @@ public class KarapaceCatalog implements Catalog
{
public static final String NAME = "karapace";

private final ConcurrentMap<Long, KarapaceCache> cache;

public KarapaceCatalog(
Configuration config)
{
this.cache = new ConcurrentHashMap<>();
}

@Override
Expand All @@ -40,7 +45,7 @@ public String name()
public CatalogContext supply(
EngineContext context)
{
return new KarapaceCatalogContext(context);
return new KarapaceCatalogContext(context, cache);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package io.aklivity.zilla.runtime.catalog.karapace.internal;

import java.util.concurrent.ConcurrentMap;

import io.aklivity.zilla.runtime.catalog.karapace.internal.config.KarapaceOptionsConfig;
import io.aklivity.zilla.runtime.engine.EngineContext;
import io.aklivity.zilla.runtime.engine.catalog.CatalogContext;
Expand All @@ -23,17 +25,21 @@
public class KarapaceCatalogContext implements CatalogContext
{
private final EngineContext context;
private final ConcurrentMap<Long, KarapaceCache> cachesById;

public KarapaceCatalogContext(
EngineContext context)
EngineContext context,
ConcurrentMap<Long, KarapaceCache> cachesById)
{
this.context = context;
this.cachesById = cachesById;
}

@Override
public CatalogHandler attach(
CatalogConfig catalog)
{
return new KarapaceCatalogHandler(KarapaceOptionsConfig.class.cast(catalog.options), context, catalog.id);
KarapaceCache cache = cachesById.computeIfAbsent(catalog.id, id -> new KarapaceCache());
return new KarapaceCatalogHandler(KarapaceOptionsConfig.class.cast(catalog.options), context, catalog.id, cache);
}
}
Loading