This is an automated email from the ASF dual-hosted git repository.

jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 88d615dbd Issue #1970: allow clients to prevent HelixProperty from 
cloning the ZNRecord (#2072)
88d615dbd is described below

commit 88d615dbd9aaf09ede161e6a881874059fc63d5f
Author: Richard Startin <[email protected]>
AuthorDate: Fri Apr 29 00:42:52 2022 +0100

    Issue #1970: allow clients to prevent HelixProperty from cloning the 
ZNRecord (#2072)
---
 .../main/java/org/apache/helix/HelixProperty.java  | 39 ++++++++++++++++++----
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/HelixProperty.java 
b/helix-core/src/main/java/org/apache/helix/HelixProperty.java
index 52780ed6f..cac483e79 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixProperty.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixProperty.java
@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
  * A wrapper class for ZNRecord. Used as a base class for IdealState, 
CurrentState, etc.
  */
 public class HelixProperty {
-  private static Logger LOG = LoggerFactory.getLogger(HelixProperty.class);
+  private static final Logger LOG = 
LoggerFactory.getLogger(HelixProperty.class);
 
   public enum HelixPropertyAttribute {
     BUCKET_SIZE, BATCH_MESSAGE_MODE
@@ -156,25 +156,50 @@ public class HelixProperty {
    * @param id
    */
   public HelixProperty(String id) {
-    this(new ZNRecord(id), id);
+    this(new ZNRecord(id), id, false);
   }
 
   /**
    * Initialize the property with an existing ZNRecord
-   * @param record
+   * @param record a deep copy of the record is made, updates to this record 
will not be reflected
+   *               by the HelixProperty
    */
   public HelixProperty(ZNRecord record) {
-    this(record, record.getId());
+    this(record, true);
   }
 
   /**
-   * Initialize the property with an existing ZNRecord with new record id
+   * Initialize the property with an existing ZNRecord
    * @param record
+   * @param deepCopyRecord set to true to make a copy of the ZNRecord, false 
otherwise
+   */
+  public HelixProperty(ZNRecord record, boolean deepCopyRecord) {
+    this(record, record.getId(), deepCopyRecord);
+  }
+
+  /**
+   * Initialize the property with an existing ZNRecord with new record id
+   * @param record a deep copy of the record is made, updates to this record 
will not be reflected by the HelixProperty
    * @param id
    */
   public HelixProperty(ZNRecord record, String id) {
-    _record = (record instanceof SessionAwareZNRecord) ? new 
SessionAwareZNRecord(record, id)
-        : new ZNRecord(record, id);
+    this(record, id, true);
+  }
+
+  /**
+   * Initialize the property with an existing ZNRecord with new record id
+   * @param record
+   * @param id
+   * @param deepCopyRecord whether to deep copy the ZNRecord, set to true if 
subsequent changes to
+   *                       the ZNRecord should not affect this HelixProperty 
and vice versa, or false
+   */
+  public HelixProperty(ZNRecord record, String id, boolean deepCopyRecord) {
+    if (deepCopyRecord) {
+      _record = record instanceof SessionAwareZNRecord ? new 
SessionAwareZNRecord(record, id)
+          : new ZNRecord(record, id);
+    } else {
+      _record = record;
+    }
     _stat = new Stat(_record.getVersion(), _record.getCreationTime(), 
_record.getModifiedTime(),
         _record.getEphemeralOwner());
   }

Reply via email to