You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Cpaulyz (via GitHub)" <gi...@apache.org> on 2023/01/31 12:53:50 UTC

[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8864: [IOTDB-5413] ReadWriteLock for CachedMTreeStore

Cpaulyz commented on code in PR #8864:
URL: https://github.com/apache/iotdb/pull/8864#discussion_r1091882843


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/CachedMTreeReadWriteLock.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.metadata.mtree.store;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * CachedMTreeReadWriteLock is a special read-write lock.
+ *
+ * <p>There are two modes of reading locks. The first mode uses NON_STAMP for identification, and
+ * the acquirement and release of the read lock is thread-bound, supporting reentry within the same
+ * thread. In the other mode, the read operation may be performed collaboratively by multiple
+ * threads, so the acquirement and release of the read lock is not thread-bound, but stamp-bound.
+ * Read lock can be locked by one thread but unlocked by another thread. It supports reentry by
+ * stamp.
+ *
+ * <p>Write lock is thread-bound, so it must be acquired and released by the same thread.
+ *
+ * <ul>
+ *   <li>!!!WARNING!!!
+ *   <li>As the lock holder is not recorded, the caller must assure that lock() and unlock() match,
+ *       i.e., if you only call lock() once then do not call unlock() more than once and vice versa.
+ *   <li>In particular, if the current thread has already requested a WriteLock, it can continue to
+ *       reenter to acquire a WriteLock or a ReadLock. However, if a ReadLock has already been
+ *       acquired (including by the current thread), the WriteLock acquiring will be blocked, which
+ *       may cause deadlocks. Therefore, if a write operation needs to be performed, a WriteLock
+ *       must be applied first.
+ *   <li>Writer preferred is used to avoid starving the write lock request, which means once a write
+ *       lock request is waiting, it will block the newly arriving read lock request expect for the
+ *       re-entrant read lock request.
+ * </ul>
+ */
+public class CachedMTreeReadWriteLock {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org