Browse Source

VC: handle error on too big commit; prevent UndeclaredThrowableException

pull/9897/head
ViacheslavKlimov 2 years ago
parent
commit
b16ee4e9b3
  1. 18
      application/src/main/java/org/thingsboard/server/service/sync/vc/DefaultEntitiesVersionControlService.java
  2. 10
      common/version-control/src/main/java/org/thingsboard/server/service/sync/vc/DefaultClusterVersionControlService.java

18
application/src/main/java/org/thingsboard/server/service/sync/vc/DefaultEntitiesVersionControlService.java

@ -287,7 +287,15 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
private <R> VersionLoadResult doInTemplate(EntitiesImportCtx ctx, VersionLoadRequest request, Function<EntitiesImportCtx, VersionLoadResult> function) {
try {
VersionLoadResult result = transactionTemplate.execute(status -> function.apply(ctx));
VersionLoadResult result = transactionTemplate.execute(status -> {
try {
return function.apply(ctx);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e); // to prevent UndeclaredThrowableException
}
});
for (ThrowingRunnable throwingRunnable : ctx.getEventCallbacks()) {
throwingRunnable.run();
}
@ -355,9 +363,9 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
sw.stop();
for (var task : sw.getTaskInfo()) {
log.info("[{}] Executed: {} in {}ms", ctx.getTenantId(), task.getTaskName(), task.getTimeMillis());
log.debug("[{}] Executed: {} in {}ms", ctx.getTenantId(), task.getTaskName(), task.getTimeMillis());
}
log.info("[{}] Total time: {}ms", ctx.getTenantId(), sw.getTotalTimeMillis());
log.debug("[{}] Total time: {}ms", ctx.getTenantId(), sw.getTotalTimeMillis());
return VersionLoadResult.success(new ArrayList<>(ctx.getResults().values()));
}
@ -380,8 +388,8 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
do {
try {
entityDataList = gitServiceQueue.getEntities(ctx.getTenantId(), ctx.getVersionId(), entityType, offset, limit).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw e.getCause();
}
log.debug("[{}] Loading {} entities pack ({})", ctx.getTenantId(), entityType, entityDataList.size());
for (EntityExportData entityData : entityDataList) {

10
common/version-control/src/main/java/org/thingsboard/server/service/sync/vc/DefaultClusterVersionControlService.java

@ -24,6 +24,7 @@ import com.google.common.util.concurrent.MoreExecutors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.eclipse.jgit.errors.LargeObjectException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
@ -261,7 +262,7 @@ public class DefaultClusterVersionControlService extends TbApplicationEventListe
}
}
} catch (Exception e) {
reply(ctx, Optional.of(e));
reply(ctx, Optional.of(handleError(e)));
} finally {
lock.unlock();
}
@ -496,6 +497,13 @@ public class DefaultClusterVersionControlService extends TbApplicationEventListe
}
}
private Exception handleError(Exception e) {
if (e instanceof LargeObjectException) {
return new RuntimeException("Version is too big");
}
return e;
}
private void reply(VersionControlRequestCtx ctx, VersionCreationResult result) {
var responseBuilder = CommitResponseMsg.newBuilder().setAdded(result.getAdded())
.setModified(result.getModified())

Loading…
Cancel
Save