mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-23 17:30:35 +00:00
Fix transactions , remove unnecessary autoCommit flag check (#13234)
* Fix transactions intermittent test failures * Fix transactions intermittent test failures * fix serachIndex list from ui side * invalid file name * Revert "Fix transactions intermittent test failures" This reverts commit 44c4c8c42824beb3e7420e51af0c5f2c6f4de90d. * Fix commit issue and unnecessary closure in NotificationHandler * Remove HTTPGetEventlistner, wrap get handle in try * Fix code style --------- Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com> Co-authored-by: mohitdeuex <mohit.y@deuexsolutions.com>
This commit is contained in:
parent
68fcd551fe
commit
03dfd9e6b2
@ -1,22 +0,0 @@
|
||||
package org.openmetadata.service.jdbi3.unitofwork;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.glassfish.jersey.server.monitoring.RequestEvent;
|
||||
import org.glassfish.jersey.server.monitoring.RequestEventListener;
|
||||
|
||||
@Slf4j
|
||||
class HttpGetRequestJdbiUnitOfWorkEventListener implements RequestEventListener {
|
||||
|
||||
HttpGetRequestJdbiUnitOfWorkEventListener() {}
|
||||
|
||||
@Override
|
||||
public void onEvent(RequestEvent event) {
|
||||
RequestEvent.Type type = event.getType();
|
||||
LOG.debug("Handling GET Request Event {} {}", type, Thread.currentThread().getId());
|
||||
if (type == RequestEvent.Type.RESOURCE_METHOD_START) {
|
||||
JdbiTransactionManager.getInstance().begin(true);
|
||||
} else if (type == RequestEvent.Type.FINISHED) {
|
||||
JdbiTransactionManager.getInstance().terminateHandle();
|
||||
}
|
||||
}
|
||||
}
|
@ -34,8 +34,8 @@ public class JdbiTransactionManager {
|
||||
public void begin(boolean autoCommit) {
|
||||
try {
|
||||
Handle handle = handleManager.get();
|
||||
if (autoCommit) {
|
||||
handle.getConnection().setAutoCommit(autoCommit);
|
||||
if (!autoCommit) {
|
||||
handle.getConnection().setAutoCommit(false);
|
||||
handle.getConfig(Handles.class).setForceEndTransactions(false);
|
||||
handle.begin();
|
||||
IN_TRANSACTION_HANDLES.add(handle.hashCode());
|
||||
@ -52,13 +52,8 @@ public class JdbiTransactionManager {
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
if (handleManager.handleExists()) {
|
||||
Handle handle = handleManager.get();
|
||||
if (handle == null) {
|
||||
LOG.debug(
|
||||
"Handle was found to be null during commit for Thread Id [{}]. It might have already been closed",
|
||||
Thread.currentThread().getId());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
handle.getConnection().commit();
|
||||
LOG.debug(
|
||||
@ -71,6 +66,7 @@ public class JdbiTransactionManager {
|
||||
rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
if (handleManager.handleExists()) {
|
||||
|
@ -2,7 +2,6 @@ package org.openmetadata.service.jdbi3.unitofwork;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.glassfish.jersey.server.monitoring.ApplicationEvent;
|
||||
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
|
||||
@ -29,9 +28,6 @@ public class JdbiUnitOfWorkApplicationEventListener implements ApplicationEventL
|
||||
if (excludedPaths.stream().anyMatch(path::contains)) {
|
||||
return null;
|
||||
}
|
||||
if (event.getContainerRequest().getMethod().equals(HttpMethod.GET)) {
|
||||
return new HttpGetRequestJdbiUnitOfWorkEventListener();
|
||||
}
|
||||
return new NonHttpGetRequestJdbiUnitOfWorkEventListener();
|
||||
}
|
||||
}
|
||||
|
@ -58,10 +58,11 @@ public class ManagedHandleInvocationHandler<T> implements InvocationHandler {
|
||||
} else {
|
||||
// This is non-transactional request
|
||||
Handle handle = JdbiUnitOfWorkProvider.getInstance().getHandleManager().getJdbi().open();
|
||||
try (handle) {
|
||||
handle.getConnection().setAutoCommit(true);
|
||||
dao = handle.attach(underlying);
|
||||
result = invokeMethod(method, dao, args);
|
||||
handle.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ import org.openmetadata.schema.type.Relationship;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.jdbi3.CollectionDAO;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.jdbi3.unitofwork.JdbiUnitOfWorkProvider;
|
||||
import org.openmetadata.service.resources.feeds.MessageParser;
|
||||
import org.openmetadata.service.socket.WebSocketManager;
|
||||
|
||||
@ -63,8 +62,6 @@ public class NotificationHandler {
|
||||
handleNotifications(responseContext, collectionDAO);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("[NotificationHandler] Failed to use mapper in converting to Json", ex);
|
||||
} finally {
|
||||
JdbiUnitOfWorkProvider.getInstance().getHandleManager().clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user