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

fix: lookup DB if leader address is not yet cached #659

Merged
merged 1 commit into from
Nov 17, 2023
Merged
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 @@ -729,7 +729,18 @@ public TopicManager topicManager() {
public Optional<BrokerNode> getNode(int nodeId) {
BrokerNode node = nodes.get(nodeId);
if (null == node) {
return Optional.empty();
try (SqlSession session = openSession()) {
NodeMapper mapper = session.getMapper(NodeMapper.class);
Node rawNode = mapper.get(nodeId, null, null, null);
if (null != rawNode) {
addBrokerNode(rawNode);
}
}

node = nodes.get(nodeId);
if (null == node) {
return Optional.empty();
}
}
return Optional.of(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.concurrent.TimeUnit;
import org.apache.ibatis.session.SqlSession;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
Expand Down Expand Up @@ -1279,4 +1280,27 @@ public void testOnQueueClose_Remote() throws IOException {
assertThrows(CompletionException.class, () -> spy.onQueueClosed(2, 1).join());
}
}

@Test
public void testGetNode() throws IOException {
try (MetadataStore metadataStore = new DefaultMetadataStore(client, getSessionFactory(), config)) {
metadataStore.start();
awaitElectedAsLeader(metadataStore);
Optional<BrokerNode> brokerNode = metadataStore.getNode(config.nodeId());
Assertions.assertTrue(brokerNode.isPresent());
Assertions.assertTrue(metadataStore.leaderAddress().isPresent());

try (SqlSession session = metadataStore.openSession()) {
NodeMapper mapper = session.getMapper(NodeMapper.class);
Node node = new Node();
node.setName("n1");
node.setAddress("localhost:2345");
node.setInstanceId("i-2345");
node.setVolumeId("v-2345");
mapper.create(node);
session.commit();
Assertions.assertTrue(metadataStore.getNode(node.getId()).isPresent());
}
}
}
}