Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8A4C8200AC5 for ; Sun, 5 Jun 2016 11:51:04 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 88F2E160A5C; Sun, 5 Jun 2016 09:51:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D283B160A54 for ; Sun, 5 Jun 2016 11:51:03 +0200 (CEST) Received: (qmail 40023 invoked by uid 500); 5 Jun 2016 09:51:02 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 39748 invoked by uid 99); 5 Jun 2016 09:51:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jun 2016 09:51:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6DE47DFE5F; Sun, 5 Jun 2016 09:51:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mikemccand@apache.org To: commits@lucene.apache.org Date: Sun, 05 Jun 2016 09:51:07 -0000 Message-Id: <709db5c01d3f4ef1bcf2a34e4f80c070@git.apache.org> In-Reply-To: <154c3212ad46480b9e5b8d83371955b4@git.apache.org> References: <154c3212ad46480b9e5b8d83371955b4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/19] lucene-solr:master: sequence numbers: removed synchronized in DocumentsWriterDeleteQueue.add archived-at: Sun, 05 Jun 2016 09:51:04 -0000 sequence numbers: removed synchronized in DocumentsWriterDeleteQueue.add Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8b0b0c93 Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8b0b0c93 Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8b0b0c93 Branch: refs/heads/master Commit: 8b0b0c934063c773b124cdcd560d7824de9ae5af Parents: 39de689 Author: Mike McCandless Authored: Thu May 26 05:39:12 2016 -0400 Committer: Mike McCandless Committed: Thu May 26 05:39:12 2016 -0400 ---------------------------------------------------------------------- .../index/DocumentsWriterDeleteQueue.java | 29 +++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8b0b0c93/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java ---------------------------------------------------------------------- diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java index abb735d..f14c783 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java @@ -150,10 +150,31 @@ final class DocumentsWriterDeleteQueue implements Accountable { return seqNo; } - synchronized long add(Node newNode) { - tail.next = newNode; - tail = newNode; - return seqNo.getAndIncrement(); + long add(Node newNode) { + /* + * this non-blocking / 'wait-free' linked list add was inspired by Apache + * Harmony's ConcurrentLinkedQueue Implementation. + */ + while (true) { + final Node currentTail = tail; + final Node tailNext = currentTail.next; + if (tail == currentTail && tailNext == null) { + /* + * we are in quiescent state and can try to insert the newNode to the + * current tail if we fail to insert we just retry the operation since + * somebody else has already added its newNode + */ + if (currentTail.casNext(null, newNode)) { + /* + * now that we are done we need to advance the tail + */ + long mySeqNo = seqNo.getAndIncrement(); + boolean result = tailUpdater.compareAndSet(this, currentTail, newNode); + assert result; + return mySeqNo; + } + } + } } boolean anyChanges() {