Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.fluss.config.Configuration;
import org.apache.fluss.exception.FlussRuntimeException;
import org.apache.fluss.exception.LogStorageException;
import org.apache.fluss.exception.PartitionNotExistException;
import org.apache.fluss.exception.SchemaNotExistException;
import org.apache.fluss.metadata.LogFormat;
import org.apache.fluss.metadata.PhysicalTablePath;
Expand Down Expand Up @@ -338,6 +339,15 @@ private LogTablet loadLog(
PhysicalTablePath physicalTablePath = pathAndBucket.f0;
TablePath tablePath = physicalTablePath.getTablePath();
TableInfo tableInfo = getTableInfo(zkClient, tablePath);

// to check the partition existence
Long partitionId = tableBucket.getPartitionId();
if (partitionId != null) {
if (!zkClient.getPartitionIdAndNames(tablePath).keySet().contains(partitionId)) {
throw new PartitionNotExistException("Partition not exist");
}
}

LogTablet logTablet =
LogTablet.create(
physicalTablePath,
Expand Down Expand Up @@ -487,9 +497,10 @@ public void run() {
loadLog(tabletDir, cleanShutdown, recoveryPoints, conf, clock);
} catch (Exception e) {
LOG.error("Fail to loadLog from {}", tabletDir, e);
if (e instanceof SchemaNotExistException) {
if (e instanceof SchemaNotExistException
|| e instanceof PartitionNotExistException) {
LOG.error(
"schema not exist, table for {} has already been dropped, the residual data will be removed.",
"table bucket for {} has already been dropped, the residual data will be removed.",
tabletDir,
e);
FileUtils.deleteDirectoryQuietly(tabletDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.fluss.server.zk.NOPErrorHandler;
import org.apache.fluss.server.zk.ZooKeeperClient;
import org.apache.fluss.server.zk.ZooKeeperExtension;
import org.apache.fluss.server.zk.data.BucketAssignment;
import org.apache.fluss.server.zk.data.PartitionAssignment;
import org.apache.fluss.server.zk.data.TableRegistration;
import org.apache.fluss.testutils.common.AllCallbackWrapper;
import org.apache.fluss.utils.clock.SystemClock;
Expand All @@ -47,6 +49,7 @@

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -300,6 +303,49 @@ void testDeleteLog(String partitionName) throws Exception {
assertThat(logManager.getLog(log1.getTableBucket()).isPresent()).isTrue();
}

/**
* When a partitioned bucket's on-disk data remains but the partition was removed from metadata,
* startup should skip normal recovery and delete the residual log directory.
*/
@Test
void testLogRecoverySkipWhenPartitionDropped() throws Exception {
String partitionName = "2024";
long partitionId = 11L;
PartitionAssignment partitionAssignment =
new PartitionAssignment(
DATA1_TABLE_ID, Collections.singletonMap(1, BucketAssignment.of(1, 2)));
zkClient.registerPartitionAssignmentAndMetadata(
partitionId,
partitionName,
partitionAssignment,
DEFAULT_REMOTE_DATA_DIR,
tablePath1,
DATA1_TABLE_ID);

initTableBuckets(partitionName);
LogTablet log1 = getOrCreateLog(tablePath1, partitionName, tableBucket1);
File logDir = log1.getLogDir();
assertThat(logDir).exists();

logManager.shutdown();
logManager = null;

zkClient.deletePartition(tablePath1, partitionName);

LogManager newLogManager =
LogManager.create(
conf,
zkClient,
new FlussScheduler(1),
SystemClock.getInstance(),
TestingMetricGroups.TABLET_SERVER_METRICS);
newLogManager.startup();
logManager = newLogManager;

assertThat(logDir).doesNotExist();
assertThat(logManager.getLog(tableBucket1).isPresent()).isFalse();
}

private LogTablet getOrCreateLog(
TablePath tablePath, String partitionName, TableBucket tableBucket) throws Exception {
return logManager.getOrCreateLog(
Expand Down