Skip to content
Permalink
Browse files
Issue #1970: allow clients to prevent HelixProperty from cloning the …
…ZNRecord (#2072)
  • Loading branch information
richardstartin committed Apr 28, 2022
1 parent 77389ac commit 88d615dbd9aaf09ede161e6a881874059fc63d5f
Showing 1 changed file with 32 additions and 7 deletions.
@@ -39,7 +39,7 @@
* 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 String toString() {
* @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());
}

0 comments on commit 88d615d

Please sign in to comment.