Fixes #3501 - Having more than one instance behind a load balancer w/o stickiness breaks API pagination (#3510)

This commit is contained in:
Suresh Srinivas 2022-03-18 09:21:33 -07:00 committed by GitHub
parent 29e42051ec
commit d31431024e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 9 deletions

View File

@ -73,7 +73,6 @@ import org.openmetadata.catalog.util.RestUtil.DeleteResponse;
import org.openmetadata.catalog.util.RestUtil.PatchResponse;
import org.openmetadata.catalog.util.RestUtil.PutResponse;
import org.openmetadata.catalog.util.ResultList;
import org.openmetadata.common.utils.CipherText;
import org.openmetadata.common.utils.CommonUtil;
/**
@ -282,7 +281,7 @@ public abstract class EntityRepository<T> {
throws GeneralSecurityException, IOException, ParseException {
// forward scrolling, if after == null then first page is being asked
List<String> jsons =
dao.listAfter(fqnPrefix, limitParam + 1, after == null ? "" : CipherText.instance().decrypt(after), include);
dao.listAfter(fqnPrefix, limitParam + 1, after == null ? "" : RestUtil.decodeCursor(after), include);
List<T> entities = new ArrayList<>();
for (String json : jsons) {
@ -306,7 +305,7 @@ public abstract class EntityRepository<T> {
UriInfo uriInfo, Fields fields, String fqnPrefix, int limitParam, String before, Include include)
throws IOException, GeneralSecurityException, ParseException {
// Reverse scrolling - Get one extra result used for computing before cursor
List<String> jsons = dao.listBefore(fqnPrefix, limitParam + 1, CipherText.instance().decrypt(before), include);
List<String> jsons = dao.listBefore(fqnPrefix, limitParam + 1, RestUtil.decodeCursor(before), include);
List<T> entities = new ArrayList<>();
for (String json : jsons) {

View File

@ -37,8 +37,8 @@ import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.EntityUtil.Fields;
import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.RestUtil;
import org.openmetadata.catalog.util.ResultList;
import org.openmetadata.common.utils.CipherText;
public class LocationRepository extends EntityRepository<Location> {
// Location fields that can be patched in a PATCH request
@ -93,7 +93,7 @@ public class LocationRepository extends EntityRepository<Location> {
fqn,
service,
limitParam + 1,
CipherText.instance().decrypt(before));
RestUtil.decodeCursor(before));
List<Location> entities = new ArrayList<>();
for (String json : jsons) {
@ -129,7 +129,7 @@ public class LocationRepository extends EntityRepository<Location> {
fqn,
service,
limitParam + 1,
after == null ? "" : CipherText.instance().decrypt(after));
after == null ? "" : RestUtil.decodeCursor(after));
List<Location> entities = new ArrayList<>();
for (String json : jsons) {

View File

@ -16,10 +16,12 @@ package org.openmetadata.catalog.util;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.lang.reflect.Field;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
@ -133,6 +135,14 @@ public final class RestUtil {
}
}
public static String encodeCursor(String cursor) {
return cursor == null ? null : Base64.getUrlEncoder().encodeToString(cursor.getBytes(StandardCharsets.UTF_8));
}
public static String decodeCursor(String cursor) {
return cursor == null ? null : new String(Base64.getUrlDecoder().decode(cursor));
}
public static class PutResponse<T> {
private T entity;
private ChangeEvent changeEvent;

View File

@ -21,7 +21,6 @@ import java.security.GeneralSecurityException;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.openmetadata.catalog.type.Paging;
import org.openmetadata.common.utils.CipherText;
/**
* Class used for generating JSON response for APIs returning list of objects in the following format: { "data" : [ {
@ -84,8 +83,8 @@ public class ResultList<T> {
this.data = data;
paging =
new Paging()
.withBefore(CipherText.instance().encrypt(beforeCursor))
.withAfter(CipherText.instance().encrypt(afterCursor))
.withBefore(RestUtil.encodeCursor(beforeCursor))
.withAfter(RestUtil.encodeCursor(afterCursor))
.withTotal(total);
}