Skip to content

Commit

Permalink
fix concurrent modification
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaojialin committed Jan 9, 2020
1 parent 4c2c6a3 commit 381afdc
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -19,6 +19,7 @@
package org.apache.iotdb.db.query.control;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -67,17 +68,18 @@ public void addUsedFilesForQuery(long queryId, QueryDataSource dataSource) {
}

private void addUsedFilesForQuery(long queryId, List<TsFileResource> resources) {
for (TsFileResource tsFileResource : resources) {
// the file may change from open to closed within the few statements, so the initial status
// should be recorded to ensure consistency
Iterator<TsFileResource> iterator = resources.iterator();
while (iterator.hasNext()) {
TsFileResource tsFileResource = iterator.next();
boolean isClosed = tsFileResource.isClosed();
addFilePathToMap(queryId, tsFileResource, isClosed);

// this file may be deleted just before we lock it
if (tsFileResource.isDeleted()) {
Map<Long, Set<TsFileResource>> pathMap = !isClosed ? unsealedFilePathsMap : sealedFilePathsMap;
pathMap.get(queryId).remove(tsFileResource);
FileReaderManager.getInstance().decreaseFileReaderReference(tsFileResource, isClosed);
resources.remove(tsFileResource);
iterator.remove();
}
}
}
Expand Down

0 comments on commit 381afdc

Please sign in to comment.