Skip to content

Commit

Permalink
add additional logs to check whether persistenceImplementation in tra…
Browse files Browse the repository at this point in the history
…nsactionManager in HistoryService and transactionManager in HibernateHistoryFlowEventRepository
  • Loading branch information
IvanChupin committed Sep 6, 2024
1 parent af634e6 commit 708b189
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public void store(PortEventData data) {
public List<FlowEvent> listFlowEvents(String flowId, Instant timeFrom, Instant timeTo, int maxCount) {
log.info("F_C_CH HistoryService.listFlowEvents start");
List<FlowEvent> result = new ArrayList<>();
log.info("CHUPIN HistoryService listFlowEvents, persistenceImplementation for transactionManager:{}",
transactionManager.getImplementation());
transactionManager.doInTransaction(() -> flowEventRepository
.findByFlowIdAndTimeFrame(flowId, timeFrom, timeTo, maxCount)
.forEach(entry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.openkilda.persistence.spi.PersistenceImplementationFactory;
import org.openkilda.persistence.tx.TransactionManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -39,6 +42,7 @@
* The implementation must be serializable, see {@link Serializable}.
*/
public class PersistenceManager implements Serializable {
private static final Logger log = LoggerFactory.getLogger(PersistenceManager.class);
private final PersistenceConfig persistenceConfig;

private final PersistenceLayout layout;
Expand Down Expand Up @@ -73,8 +77,12 @@ public TransactionManager getTransactionManager() {
return newTransactionManager(implementation);
}

/**
* Some method.
*/
public TransactionManager getTransactionManager(PersistenceImplementationType implementationType) {
PersistenceImplementation implementation = getImplementation(implementationType);
log.info("CHUPIN PersistenceManager getTransactionManager, persistenceImplementation: {}", implementation);
return newTransactionManager(implementation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.openkilda.persistence.repositories.history.HaFlowEventRepository;
import org.openkilda.persistence.repositories.history.PortEventRepository;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RepositoryFactoryProxy implements RepositoryFactory {
private final PersistenceManager manager;

Expand Down Expand Up @@ -224,8 +227,11 @@ public HaFlowPathRepository createHaFlowPathRepository() {
}

private RepositoryFactory resolve(Class<?> repositoryClass) {
log.info("CHUPIN RepositoryFactoryProxy resolve {}. PersistenceManager should be the same:{}",
repositoryClass, manager);
PersistenceArea area = RepositoryAreaBinding.INSTANCE.lookup(repositoryClass);
PersistenceImplementation implementation = manager.getImplementation(area);
log.info("CHUPIN RepositoryFactoryProxy resolve persistenceImplementation: {}", implementation);
return implementation.getRepositoryFactory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openkilda.persistence.exceptions.PersistenceException;
import org.openkilda.persistence.exceptions.RecoverablePersistenceException;

import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
Expand All @@ -37,7 +38,8 @@
*/
@Slf4j
public class TransactionManager implements Serializable {
private final PersistenceImplementation implementation;
@Getter
protected final PersistenceImplementation implementation;

private final int transactionRetriesLimit;
private final int transactionRetriesMaxDelay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected Session getSession() {

protected TransactionManager getTransactionManager() {
PersistenceManager manager = PersistenceContextManager.INSTANCE.getPersistenceManager();
log.info("CHUPIN HibernateGenericRepository getTransactionManager, persistenceManager is {}", manager);
return manager.getTransactionManager(implementation.getType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent_;
import org.openkilda.persistence.hibernate.utils.UniqueKeyUtil;
import org.openkilda.persistence.repositories.history.FlowEventRepository;
import org.openkilda.persistence.tx.TransactionManager;

import lombok.extern.slf4j.Slf4j;

import java.time.Instant;
import java.util.ArrayList;
Expand All @@ -43,6 +46,7 @@
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

@Slf4j
public class HibernateHistoryFlowEventRepository
extends HibernateGenericRepository<FlowEvent, FlowEventData, HibernateFlowEvent>
implements FlowEventRepository {
Expand All @@ -60,10 +64,18 @@ public Optional<FlowEvent> findByTaskId(String taskId) {
return getTransactionManager().doInTransaction(() -> findEntityByTaskId(taskId).map(FlowEvent::new));
}

/**
* Some method.
*/
@Override
public List<FlowEvent> findByFlowIdAndTimeFrame(
String flowId, Instant timeFrom, Instant timeTo, int maxCount) {
List<FlowEvent> results = getTransactionManager().doInTransaction(
TransactionManager transactionManager = getTransactionManager();

log.info("CHUPIN HibernateHistoryFlowEventRepository findByFlowIdAndTimeFrame," +
"transactionManager.getImplementation():{}. and this.implementation: {}",
transactionManager.getImplementation(), this.implementation);
List<FlowEvent> results = transactionManager.doInTransaction(
() -> fetch(flowId, timeFrom, timeTo, maxCount).stream()
.map(FlowEvent::new)
.collect(Collectors.toList()));
Expand Down

0 comments on commit 708b189

Please sign in to comment.