[fix](export) the label of export should be unique with database scope (#27401)
### How to reproduce 1. create a database db1 and a table tbl1; 2. insert some data and export with label L1; 3. drop the db1 and tbl1, and recreate them with same name. 4. insert some data and export with same label L1; Expect: export success Actual: error: Label L1 have already been used. This PR fix it.
This commit is contained in:
@ -65,7 +65,8 @@ public class ExportMgr {
|
||||
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
|
||||
|
||||
private Map<Long, ExportJob> exportIdToJob = Maps.newHashMap(); // exportJobId to exportJob
|
||||
private Map<String, Long> labelToExportJobId = Maps.newHashMap();
|
||||
// dbid -> <label -> job>
|
||||
private Map<Long, Map<String, Long>> dbTolabelToExportJobId = Maps.newHashMap();
|
||||
|
||||
public ExportMgr() {
|
||||
}
|
||||
@ -95,7 +96,8 @@ public class ExportMgr {
|
||||
job.setId(jobId);
|
||||
writeLock();
|
||||
try {
|
||||
if (labelToExportJobId.containsKey(job.getLabel())) {
|
||||
if (dbTolabelToExportJobId.containsKey(job.getDbId())
|
||||
&& dbTolabelToExportJobId.get(job.getDbId()).containsKey(job.getLabel())) {
|
||||
throw new LabelAlreadyUsedException(job.getLabel());
|
||||
}
|
||||
unprotectAddJob(job);
|
||||
@ -135,7 +137,8 @@ public class ExportMgr {
|
||||
|
||||
public void unprotectAddJob(ExportJob job) {
|
||||
exportIdToJob.put(job.getId(), job);
|
||||
labelToExportJobId.putIfAbsent(job.getLabel(), job.getId());
|
||||
dbTolabelToExportJobId.computeIfAbsent(job.getDbId(),
|
||||
k -> Maps.newHashMap()).put(job.getLabel(), job.getId());
|
||||
}
|
||||
|
||||
private List<ExportJob> getWaitingCancelJobs(CancelExportStmt stmt) throws AnalysisException {
|
||||
@ -393,7 +396,13 @@ public class ExportMgr {
|
||||
&& (job.getState() == ExportJobState.CANCELLED
|
||||
|| job.getState() == ExportJobState.FINISHED)) {
|
||||
iter.remove();
|
||||
labelToExportJobId.remove(job.getLabel(), job.getId());
|
||||
Map<String, Long> labelJobs = dbTolabelToExportJobId.get(job.getDbId());
|
||||
if (labelJobs != null) {
|
||||
labelJobs.remove(job.getLabel());
|
||||
if (labelJobs.isEmpty()) {
|
||||
dbTolabelToExportJobId.remove(job.getDbId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user