Skip to content

Commit

Permalink
[AMORO-3365]The table is always in committing state (#3366)
Browse files Browse the repository at this point in the history
* [AMORO-3365]The table is always in committing state

* Close the committing process on start

* Fix unit tests

Fix unit tests

Fix unit tests

Fix unit tests

---------

Co-authored-by: Congxian Qiu <[email protected]>
  • Loading branch information
7hong and klion26 authored Jan 23, 2025
1 parent c69a236 commit 49989ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.amoro.ServerTableIdentifier;
import org.apache.amoro.api.OptimizingTaskId;
import org.apache.amoro.exception.OptimizingClosedException;
import org.apache.amoro.exception.PersistenceException;
import org.apache.amoro.optimizing.MetricsSummary;
import org.apache.amoro.optimizing.OptimizingType;
import org.apache.amoro.optimizing.RewriteFilesInput;
Expand Down Expand Up @@ -120,9 +121,20 @@ private void initTableRuntime(TableRuntime tableRuntime) {
if (tableRuntime.isOptimizingEnabled()) {
tableRuntime.resetTaskQuotas(
System.currentTimeMillis() - AmoroServiceConstants.QUOTA_LOOK_BACK_TIME);
// Close the committing process to avoid duplicate commit on the table.
if (tableRuntime.getOptimizingStatus() == OptimizingStatus.COMMITTING) {
OptimizingProcess process = tableRuntime.getOptimizingProcess();
if (process != null) {
LOG.warn(
"Close the committing process {} on table {}",
process.getProcessId(),
tableRuntime.getTableIdentifier());
process.close();
}
}
if (!tableRuntime.getOptimizingStatus().isProcessing()) {
scheduler.addTable(tableRuntime);
} else if (tableRuntime.getOptimizingStatus() != OptimizingStatus.COMMITTING) {
} else {
tableQueue.offer(new TableOptimizingProcess(tableRuntime));
}
} else {
Expand Down Expand Up @@ -569,6 +581,10 @@ public void commit() {
try {
if (hasCommitted) {
LOG.warn("{} has already committed, give up", tableRuntime.getTableIdentifier());
try {
persistAndSetCompleted(status == ProcessStatus.SUCCESS);
} catch (Exception ignored) {
}
throw new IllegalStateException("repeat commit, and last error " + failedReason);
}
try {
Expand All @@ -577,10 +593,15 @@ public void commit() {
status = ProcessStatus.SUCCESS;
endTime = System.currentTimeMillis();
persistAndSetCompleted(true);
} catch (Exception e) {
LOG.error("{} Commit optimizing failed ", tableRuntime.getTableIdentifier(), e);
} catch (PersistenceException e) {
LOG.warn(
"{} failed to persist process completed, will retry next commit",
tableRuntime.getTableIdentifier(),
e);
} catch (Throwable t) {
LOG.error("{} Commit optimizing failed ", tableRuntime.getTableIdentifier(), t);
status = ProcessStatus.FAILED;
failedReason = ExceptionUtil.getErrorMessage(e, 4000);
failedReason = ExceptionUtil.getErrorMessage(t, 4000);
endTime = System.currentTimeMillis();
persistAndSetCompleted(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ public void testReloadCompletedTask() {
optimizingService().completeTask(token, buildOptimizingTaskResult(task.getTaskId()));

reload();
assertTaskCompleted(null);
Assertions.assertNull(optimizingService().pollTask(token, THREAD_ID));
// Committing process will be closed when reloading
Assertions.assertNull(
tableService().getRuntime(serverTableIdentifier().getId()).getOptimizingProcess());
Assertions.assertEquals(
OptimizingStatus.IDLE,
tableService().getRuntime(serverTableIdentifier().getId()).getOptimizingStatus());
}

@Test
Expand Down

0 comments on commit 49989ba

Please sign in to comment.