Jackie-Jiang commented on a change in pull request #7255:
URL: https://github.com/apache/pinot/pull/7255#discussion_r688105049



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/metadata/segment/SegmentZKMetadata.java
##########
@@ -36,209 +34,302 @@
 import org.slf4j.LoggerFactory;
 
 
-public abstract class SegmentZKMetadata implements ZKMetadata {
+public class SegmentZKMetadata implements ZKMetadata {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(SegmentZKMetadata.class);
+  private static final String NULL = "null";
 
-  protected static final String NULL = "null";
-
-  private String _segmentName;
-  private SegmentType _segmentType;
-  private long _startTime = -1;
-  private long _endTime = -1;
-  private TimeUnit _timeUnit;
-  private String _indexVersion;
-  private long _totalDocs = -1;
-  private long _crc = -1;
-  private long _creationTime = -1;
-  private SegmentPartitionMetadata _partitionMetadata;
-  private long _segmentUploadStartTime = -1;
-  private String _crypterName;
-  private Map<String, String> _customMap;
+  private final ZNRecord _znRecord;
+  private Map<String, String> _simpleFields;
 
-  @Deprecated
-  private String _rawTableName;
+  // Cache start/end time because they can be used to sort the metadata
+  private long _startTimeMs = -1;
+  private long _endTimeMs = -1;
 
-  public SegmentZKMetadata() {
+  public SegmentZKMetadata(String segmentName) {
+    _znRecord = new ZNRecord(segmentName);
+    _simpleFields = _znRecord.getSimpleFields();
+    // TODO: Remove this field after releasing 0.9.0
+    _simpleFields.put(Segment.SEGMENT_NAME, segmentName);
   }
 
   public SegmentZKMetadata(ZNRecord znRecord) {
-    _segmentName = znRecord.getSimpleField(Segment.SEGMENT_NAME);
-    _segmentType = znRecord.getEnumField(Segment.SEGMENT_TYPE, 
SegmentType.class, SegmentType.OFFLINE);
-    _startTime = znRecord.getLongField(Segment.START_TIME, -1);
-    _endTime = znRecord.getLongField(Segment.END_TIME, -1);
-    String timeUnitString = znRecord.getSimpleField(Segment.TIME_UNIT);
-    if (timeUnitString != null && !timeUnitString.equals(NULL)) {
-      _timeUnit = znRecord.getEnumField(Segment.TIME_UNIT, TimeUnit.class, 
TimeUnit.DAYS);
-    }
-    _indexVersion = znRecord.getSimpleField(Segment.INDEX_VERSION);
-    _totalDocs = znRecord.getLongField(Segment.TOTAL_DOCS, -1);
-    _crc = znRecord.getLongField(Segment.CRC, -1);
-    _creationTime = znRecord.getLongField(Segment.CREATION_TIME, -1);
-    try {
-      String partitionMetadataJson = 
znRecord.getSimpleField(Segment.PARTITION_METADATA);
-      if (partitionMetadataJson != null) {
-        _partitionMetadata = 
SegmentPartitionMetadata.fromJsonString(partitionMetadataJson);
-      }
-    } catch (IOException e) {
-      LOGGER.error(
-          "Exception caught while reading partition info from zk metadata for 
segment '{}', partition info dropped.",
-          _segmentName, e);
-    }
-    _segmentUploadStartTime = 
znRecord.getLongField(Segment.SEGMENT_UPLOAD_START_TIME, -1);
-    _crypterName = znRecord.getSimpleField(Segment.CRYPTER_NAME);
-    _customMap = znRecord.getMapField(Segment.CUSTOM_MAP);
-
-    // For backward-compatibility
-    setTableName(znRecord.getSimpleField(Segment.TABLE_NAME));
+    _znRecord = znRecord;
+    _simpleFields = znRecord.getSimpleFields();
   }
 
   public String getSegmentName() {
-    return _segmentName;
-  }
-
-  public void setSegmentName(String segmentName) {
-    _segmentName = segmentName;
-  }
-
-  public SegmentType getSegmentType() {
-    return _segmentType;
-  }
-
-  public void setSegmentType(SegmentType segmentType) {
-    _segmentType = segmentType;
+    return _znRecord.getId();
   }
 
   public long getStartTimeMs() {
-    if (_startTime > 0 && _timeUnit != null) {
-      return _timeUnit.toMillis(_startTime);
-    } else {
-      return -1;
+    if (_startTimeMs < 0) {

Review comment:
       Added a boolean field to track whether the time is cached




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to