Skip to content

Commit

Permalink
Refactor MetadataService to Use ContentTransformer
Browse files Browse the repository at this point in the history
Motivation:
Previously, the Central Dogma server in `MetadataService` would repeatedly attempt to commit until it succeeded. With the introduction of `ContentTransformer` in line#1064, the server can now handle transformations in a single attempt, avoiding unnecessary retries.

Modifications:
- Updated `MetadataService` to utilize `ContentTransformer` for commit operations.

Result:
- Improved efficiency in `MetadataService` by eliminating repeated commit attempts.
  • Loading branch information
minwoox committed Dec 4, 2024
1 parent 2506b7d commit d2e3664
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,33 @@

package com.linecorp.centraldogma.common;

import static java.util.Objects.requireNonNull;

import javax.annotation.Nullable;

/**
* A {@link CentralDogmaException} that is raised when attempted to push a commit without effective changes.
*/
public class RedundantChangeException extends CentralDogmaException {

private static final long serialVersionUID = 8739464985038079688L;

/**
* Creates a new instance.
*/
public RedundantChangeException() {}
@Nullable
private final Revision headRevision;

/**
* Creates a new instance.
*/
public RedundantChangeException(String message) {
super(message);
headRevision = null;
}

/**
* Creates a new instance.
*/
public RedundantChangeException(Throwable cause) {
super(cause);
}

/**
* Creates a new instance.
*/
public RedundantChangeException(String message, Throwable cause) {
super(message, cause);
public RedundantChangeException(Revision headRevision, String message) {
super(message);
this.headRevision = requireNonNull(headRevision, "headRevision");
}

/**
Expand All @@ -57,13 +53,15 @@ public RedundantChangeException(String message, Throwable cause) {
*/
public RedundantChangeException(String message, boolean writableStackTrace) {
super(message, writableStackTrace);
headRevision = null;
}

/**
* Creates a new instance.
* Returns the head revision of the repository when this exception was raised.
*/
protected RedundantChangeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
public Revision headRevision() {
// This is only called from the server-side which always sets the head revision.
assert headRevision != null;
return headRevision;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ RevisionAndEntries commit(@Nullable Revision prevRevision, Revision nextRevision
}

if (!allowEmptyCommit && isEmpty) {
// prevRevision is not null when allowEmptyCommit is false.
assert prevRevision != null;
throw new RedundantChangeException(
prevRevision,
"changes did not change anything in " + gitRepository.parent().name() + '/' +
gitRepository.name() + " at revision " +
(prevRevision != null ? prevRevision.major() : 0) + ": " + changes);
gitRepository.name() + " at revision " + prevRevision.major() + ": " + changes);
}

// flush the current index to repository and get the result tree object id.
Expand Down
Loading

0 comments on commit d2e3664

Please sign in to comment.