Skip to content
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

[ISSUE #87] Fix listSubjectsByTenant bug & listTenants return to duplicate #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.rocketmq.schema.registry.storage.jdbc;

import com.google.common.collect.Lists;
import org.apache.avro.Schema;
import org.apache.rocketmq.schema.registry.common.QualifiedName;
import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext;
Expand Down Expand Up @@ -138,7 +139,7 @@ public List<String> listSubjectsByTenant(StorageServiceContext context, Qualifie

@Override
public List<String> listTenants(StorageServiceContext storageService, QualifiedName qualifiedName) {
return handler.getTenants(qualifiedName.getCluster());
return Lists.newArrayList(handler.getTenants(qualifiedName.getCluster()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.Closeable;
import java.util.List;
import java.util.Set;

public abstract class IHandler implements Closeable {
/**
Expand Down Expand Up @@ -100,7 +101,7 @@ public abstract class IHandler implements Closeable {
* @param cluster
* @return
*/
public abstract List<String> getTenants(String cluster);
public abstract Set<String> getTenants(String cluster);


protected void changeNotify() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.rocketmq.schema.registry.storage.jdbc.handler;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.hazelcast.config.Config;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.Hazelcast;
Expand All @@ -42,6 +42,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.rocketmq.schema.registry.storage.jdbc.store.JdbcSchemaMapStore.SCHEMAS;
Expand Down Expand Up @@ -214,16 +215,18 @@ public List<String> getSubjects(StorageServiceContext context, String tenant) {
for (Map.Entry<String, SchemaRecordInfo> schemaRecordEntry : subjects.entrySet()) {
String subjectFullName = schemaRecordEntry.getKey();
String[] subjectFromCache = subjectFullName.split(String.valueOf(SchemaConstants.SUBJECT_SEPARATOR));
String tenantFromKey = subjectFromCache[1];
String subjectFromKey = subjectFromCache[2];
// Check permission
allSubjects.add(subjectFromKey);
if (tenant.equals(tenantFromKey)) {
allSubjects.add(subjectFromKey);
}
}
return allSubjects;
}

@Override
public List<String> getTenants(String cluster) {
List<String> tenants = Lists.newArrayList();
public Set<String> getTenants(String cluster) {
Set<String> tenants = Sets.newHashSet();
for (Map.Entry<String, SchemaRecordInfo> schemaRecordEntry : subjects.entrySet()) {
String subjectFullName = schemaRecordEntry.getKey();
String tenant = subjectFullName.split(String.valueOf(SchemaConstants.SUBJECT_SEPARATOR))[1];
Expand Down