Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Apr 30, 2024
2 parents 857734d + 2bcab94 commit 95d759e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ ENV JVM_OPTS="-Xmx256m -Xms256m" \
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone

Expose 8090

ENTRYPOINT ["sh", "-c", "java ${JVM_OPTS} org.springframework.boot.loader.launch.JarLauncher ${0} ${@}"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.OptimisticLockingFailureException;
Expand Down Expand Up @@ -328,9 +329,11 @@ public Mono<ContentWrapper> deleteContent(String postName, String snapshotName)
.flatMap(post -> {
var headSnapshotName = post.getSpec().getHeadSnapshot();
if (StringUtils.equals(headSnapshotName, snapshotName)) {
// update head to release
post.getSpec().setHeadSnapshot(post.getSpec().getReleaseSnapshot());
return updatePostWithRetry(post);
return updatePostWithRetry(post, record -> {
// update head to release
record.getSpec().setHeadSnapshot(record.getSpec().getReleaseSnapshot());
return record;
});
}
return Mono.just(post);
})
Expand All @@ -352,14 +355,15 @@ public Mono<ContentWrapper> deleteContent(String postName, String snapshotName)
});
}

private Mono<Post> updatePostWithRetry(Post post) {
return client.update(post)
private Mono<Post> updatePostWithRetry(Post post, UnaryOperator<Post> func) {
return client.update(func.apply(post))
.onErrorResume(OptimisticLockingFailureException.class,
e -> Mono.defer(() -> client.get(Post.class, post.getMetadata().getName())
.flatMap(client::update))
.retryWhen(Retry.backoff(8, Duration.ofMillis(100))
.filter(OptimisticLockingFailureException.class::isInstance)
.map(func)
.flatMap(client::update)
)
.retryWhen(Retry.backoff(8, Duration.ofMillis(100))
.filter(OptimisticLockingFailureException.class::isInstance))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.OptimisticLockingFailureException;
Expand Down Expand Up @@ -206,9 +207,11 @@ public Mono<ContentWrapper> deleteContent(String pageName, String snapshotName)
.flatMap(page -> {
var headSnapshotName = page.getSpec().getHeadSnapshot();
if (StringUtils.equals(headSnapshotName, snapshotName)) {
// update head to release
page.getSpec().setHeadSnapshot(page.getSpec().getReleaseSnapshot());
return updatePostWithRetry(page);
return updatePageWithRetry(page, record -> {
// update head to release
page.getSpec().setHeadSnapshot(page.getSpec().getReleaseSnapshot());
return record;
});
}
return Mono.just(page);
})
Expand All @@ -230,14 +233,15 @@ public Mono<ContentWrapper> deleteContent(String pageName, String snapshotName)
});
}

private Mono<SinglePage> updatePostWithRetry(SinglePage page) {
return client.update(page)
private Mono<SinglePage> updatePageWithRetry(SinglePage page, UnaryOperator<SinglePage> func) {
return client.update(func.apply(page))
.onErrorResume(OptimisticLockingFailureException.class,
e -> Mono.defer(() -> client.get(SinglePage.class, page.getMetadata().getName())
.flatMap(client::update))
.retryWhen(Retry.backoff(8, Duration.ofMillis(100))
.filter(OptimisticLockingFailureException.class::isInstance)
.map(func)
.flatMap(client::update)
)
.retryWhen(Retry.backoff(8, Duration.ofMillis(100))
.filter(OptimisticLockingFailureException.class::isInstance))
);
}

Expand Down

0 comments on commit 95d759e

Please sign in to comment.