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(connect): failed to connect to a standby cluster and view table structure #2648

Merged
merged 1 commit into from
Jun 5, 2024
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 @@ -17,6 +17,7 @@
package com.oceanbase.odc.metadb.connection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -103,4 +104,20 @@ public void find_findByConnectionId_findSucceed() {
Assert.assertEquals(actual, expect);
}

@Test
public void find_findByConnectionIdIn_findSucceed() {
List<ConnectionAttributeEntity> entities = new ArrayList<>();
entities.add(TestRandom.nextObject(ConnectionAttributeEntity.class));
entities.add(TestRandom.nextObject(ConnectionAttributeEntity.class));
Long connectionId = 100L;
entities.forEach(e -> e.setConnectionId(connectionId));
entities = this.repository.saveAll(entities);

List<ConnectionAttributeEntity> results = this.repository
.findByConnectionIdIn(Collections.singletonList(connectionId));
Set<ConnectionAttributeEntity> actual = new HashSet<>(results);
Set<ConnectionAttributeEntity> expect = new HashSet<>(entities);
Assert.assertEquals(actual, expect);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.oceanbase.odc.metadb.connection;

import java.util.Collection;
import java.util.List;
import java.util.Set;

Expand All @@ -40,6 +41,8 @@ public interface ConnectionAttributeRepository extends JpaRepository<ConnectionA

List<ConnectionAttributeEntity> findByConnectionId(Long connectionId);

List<ConnectionAttributeEntity> findByConnectionIdIn(Collection<Long> ids);

@Transactional
@Modifying
@Query(value = "delete from connect_connection_attribute where connection_id=?1", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ public Map<Long, CheckState> getStatus(@NonNull Set<Long> ids) {
.where(ConnectionSpecs.organizationIdEqual(currentOrganizationId()))
.and(ConnectionSpecs.idIn(connIds));
Map<Long, ConnectionConfig> connMap =
entitiesToModels(repository.findAll(spec), currentOrganizationId(), false, false).stream()
.collect(Collectors.toMap(ConnectionConfig::getId, c -> c));

entitiesToModels(repository.findAll(spec), currentOrganizationId(), false, false)
.stream().collect(Collectors.toMap(ConnectionConfig::getId, c -> c));
fullFillAttributes(connMap.values());
if (authenticationFacade.currentOrganization().getType() == OrganizationType.INDIVIDUAL) {
return getIndividualSpaceStatus(ids, connMap);
} else {
Expand Down Expand Up @@ -565,8 +565,7 @@ public PageAndStats<ConnectionConfig> list(@Valid QueryConnectionParams params,
}

@PreAuthenticate(actions = "update", resourceType = "ODC_CONNECTION", indexOfIdParam = 0)
public ConnectionConfig update(@NotNull Long id, @NotNull @Valid ConnectionConfig connection)
throws InterruptedException {
public ConnectionConfig update(@NotNull Long id, @NotNull @Valid ConnectionConfig connection) {
ConnectionConfig config = txTemplate.execute(status -> {
try {
environmentAdapter.adaptConfig(connection);
Expand Down Expand Up @@ -775,6 +774,7 @@ private Page<ConnectionConfig> innerList(@NotNull QueryConnectionParams params,
: PageRequest.of(pageable.getPageNumber(), pageable.getPageSize());
Page<ConnectionEntity> entities = this.repository.findAll(spec, page);
List<ConnectionConfig> models = entitiesToModels(entities.getContent(), currentOrganizationId(), true, true);
fullFillAttributes(models);
return new PageImpl<>(models, page, entities.getTotalElements());
}

Expand Down Expand Up @@ -986,4 +986,11 @@ private Date getEarliestObjectSyncTime(@NotNull Long connectionId) {
return syncTimes.stream().min(Date::compareTo).orElse(null);
}

private void fullFillAttributes(Collection<ConnectionConfig> models) {
Map<Long, List<ConnectionAttributeEntity>> id2Attrs = this.attributeRepository
.findByConnectionIdIn(models.stream().map(ConnectionConfig::getId).collect(Collectors.toSet()))
.stream().collect(Collectors.groupingBy(ConnectionAttributeEntity::getConnectionId));
models.forEach(c -> c.setAttributes(attrEntitiesToMap(id2Attrs.getOrDefault(c.getId(), new ArrayList<>()))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public ConnectionTestResult test(@NonNull ConnectionConfig config) {
}
if (result.getErrorCode() == ErrorCodes.ObWeakReadConsistencyRequired
&& type.getDialectType().isOceanbase()) {
return ConnectionTestResult.fail(ErrorCodes.ObWeakReadConsistencyRequired, null);
return ConnectionTestResult.fail(
ErrorCodes.ObWeakReadConsistencyRequired, new String[] {});
}
if (result.getErrorCode() == ErrorCodes.ConnectionInitScriptFailed) {
return ConnectionTestResult.initScriptFailed(result.getArgs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public static TestConnectionReq fromConnection(ConnectionConfig connection,
req.setSid(connection.getSid());
req.setServiceName(connection.getServiceName());
req.setUserRole(connection.getUserRole());
req.setSessionInitScript(connection.getSessionInitScript());
req.setJdbcUrlParameters(connection.getJdbcUrlParameters());
return req;
}

Expand Down