From 95a01ff9eb543329cc8087583ef825710918f490 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Mon, 21 Mar 2022 17:35:32 +0800 Subject: [PATCH 1/2] cache: fix assert node.next=empty Change-Id: Idd337f2bebff2b03a5eefdfb9b189b9e012a7ae2 --- .../hugegraph/backend/cache/RamCache.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java index 4fcdddf4ac..be2b44b089 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java @@ -405,13 +405,13 @@ public LinkNode enqueue(LinkNode node) { } /* - * Link the node to the rear before to the last if we - * have not locked the node itself, because dumpKeys() + * Link the node to the `rear` before to the `last` if we + * have not locked the `node` itself, because dumpKeys() * may get the new node with next=null. * TODO: it also depends on memory barrier. */ - // Build the link between `node` and the rear + // Build the link between `node` and the `rear` node.next = this.rear; assert this.rear.prev == last : this.rear.prev; this.rear.prev = node; @@ -445,12 +445,12 @@ public LinkNode dequeue() { continue; } - // Break the link between the head and `first` + // Break the link between the `head` and `first` assert first.next != null; this.head.next = first.next; first.next.prev = this.head; - // Clear the links of the first node + // Clear the links of the `first` node first.prev = this.empty; first.next = this.empty; @@ -469,13 +469,12 @@ public LinkNode remove(LinkNode node) { assert node != this.head && node != this.rear; while (true) { - LinkNode prev = node.prev; - if (prev == this.empty) { - assert node.next == this.empty; - // Ignore the node if it has been removed + if (node.prev == this.empty || node.next == this.empty) { + // Ignore the `node` if it has been removed return null; } + LinkNode prev = node.prev; List locks = this.lock(prev, node); try { if (prev != node.prev) { @@ -487,9 +486,10 @@ public LinkNode remove(LinkNode node) { continue; } assert node.next != null : node; + assert node.next != this.empty : node.next; assert node.next != node.prev : node.next; - // Build the link between node.prev and node.next + // Break `node` & Build the link between node.prev~node.next node.prev.next = node.next; node.next.prev = node.prev; From 0f7cef0cf7a4fa40d3ad68ad908181a06205b077 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Mon, 21 Mar 2022 18:04:23 +0800 Subject: [PATCH 2/2] fix prev may change after empty judgment Change-Id: I6814e588c67018b13fcefbc373f02912dbf08c6a --- .../java/com/baidu/hugegraph/backend/cache/RamCache.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java index be2b44b089..0bfda706db 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java @@ -395,6 +395,7 @@ public LinkNode enqueue(LinkNode node) { while (true) { LinkNode last = this.rear.prev; + assert last != this.empty : last; // TODO: should we lock the new `node`? List locks = this.lock(last, this.rear); @@ -446,7 +447,7 @@ public LinkNode dequeue() { } // Break the link between the `head` and `first` - assert first.next != null; + assert first.next != null && first.next != this.empty; this.head.next = first.next; first.next.prev = this.head; @@ -469,12 +470,12 @@ public LinkNode remove(LinkNode node) { assert node != this.head && node != this.rear; while (true) { - if (node.prev == this.empty || node.next == this.empty) { + LinkNode prev = node.prev; + if (prev == this.empty || node.next == this.empty) { // Ignore the `node` if it has been removed return null; } - LinkNode prev = node.prev; List locks = this.lock(prev, node); try { if (prev != node.prev) {