Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VolatileSubtreeIterator missing update buffer if all nodes in new buffer are not qualified #12093

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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 @@ -38,6 +38,8 @@
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicLong;

import static org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.pbtree.memory.MemoryManager.STATUS.ITERATE_NEW_BUFFER;
import static org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.pbtree.memory.MemoryManager.STATUS.ITERATE_UPDATE_BUFFER;
import static org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.pbtree.mnode.container.ICachedMNodeContainer.getBelongedContainer;
import static org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.pbtree.mnode.container.ICachedMNodeContainer.getCachedMNodeContainer;

Expand Down Expand Up @@ -293,13 +295,13 @@ private class VolatileSubtreeIterator implements Iterator<ICachedMNode> {

private final ICachedMNodeContainer container;
private Iterator<ICachedMNode> bufferedNodeIterator;
private byte status;
private STATUS status;
private ICachedMNode nextSubtree = null;

private VolatileSubtreeIterator(ICachedMNodeContainer container) {
this.container = container;
this.bufferedNodeIterator = container.getNewChildFlushingBuffer().values().iterator();
this.status = 0;
this.status = ITERATE_NEW_BUFFER;
}

@Override
Expand All @@ -323,13 +325,16 @@ public ICachedMNode next() {
private void tryGetNext() {
ICachedMNode node;
CacheEntry cacheEntry;
if (!bufferedNodeIterator.hasNext() && status == 0) {
// flushingBuffer of NewChildBuffer has been traversed, and the flushingBuffer of
// UpdateChildBuffer needs to be traversed.
bufferedNodeIterator = container.getUpdatedChildFlushingBuffer().values().iterator();
status = 1;
}
while (bufferedNodeIterator.hasNext()) {
while (bufferedNodeIterator.hasNext() || status == ITERATE_NEW_BUFFER) {
if (!bufferedNodeIterator.hasNext()) {
// flushingBuffer of NewChildBuffer has been traversed, and the flushingBuffer of
// UpdateChildBuffer needs to be traversed.
bufferedNodeIterator = container.getUpdatedChildFlushingBuffer().values().iterator();
status = ITERATE_UPDATE_BUFFER;
if (!bufferedNodeIterator.hasNext()) {
return;
}
}
node = bufferedNodeIterator.next();

// prevent this node being added buffer during the following check and potential flush
Expand All @@ -345,7 +350,7 @@ private void tryGetNext() {
cacheEntry = getCacheEntry(node);

synchronized (cacheEntry) {
if (status == 1
if (status == ITERATE_UPDATE_BUFFER
&& container.getUpdatedChildReceivingBuffer().containsKey(node.getName())) {
if (cacheEntry.hasVolatileDescendant()
&& getCachedMNodeContainer(node).hasChildrenInBuffer()) {
Expand All @@ -356,13 +361,15 @@ && getCachedMNodeContainer(node).hasChildrenInBuffer()) {
// return for flush
nextSubtree = node;
unlockImmediately = false;
return;
} else {
continue;
}
return;
}

cacheEntry.setVolatile(false);
memoryStatistics.removeVolatileNode();
if (status == 1) {
if (status == ITERATE_UPDATE_BUFFER) {
container.moveMNodeFromUpdateChildBufferToCache(node.getName());
} else {
container.moveMNodeFromNewChildBufferToCache(node.getName());
Expand Down Expand Up @@ -625,4 +632,15 @@ public long getBufferNodeNum() {
public long getCacheNodeNum() {
return nodeCache.getCacheNodeNum();
}

enum STATUS {
ITERATE_NEW_BUFFER((byte) 0),
ITERATE_UPDATE_BUFFER((byte) 1);

private final byte status;

STATUS(byte status) {
this.status = status;
}
}
}
Loading