Class PGSegment

java.lang.Object
org.yamcs.parameterarchive.PGSegment

public class PGSegment extends Object
Parameter Group segment - keeps references to Time and Value segments for a given parameter group and segment.

This class is used during the parameter archive buildup.

In Yamcs 5.10 the RocksDB merge operator has been introduced. The operator is responsible for merging multiple segments into an interval.

Merging the time, engineering/raw values, and status segments is straightforward - they are just appended one after the other.

Merging the gap segments is tricky: the gaps store the indices of the elements that are missing for one particular parameter. When we merge segments into intervals, the indices change so we have to renumber all of them. For this purpose the segmentIdxInsideInterval is used - it represents where in the interval this segment starts.

In general we do not want to create records for parameters that do not appear at all in the interval (that's why this class does not cater for all parameters that might be in a ParameterGroupIdDb.ParameterGroup). However if a parameter appears in one of the segments of the interval, it has to be propagated throughout the interval - that is we have to create gaps for those segments in the interval where it does not appear.

There are two situations to handle:

  1. A segment seg1 contains a parameter p but the subsequent segment seg2 does not contain it. In this case we have to add a full gap segment for seg2.
  2. A segment seg1 does not contain a parameter p but the subsequent segment seg2 contains it. In this case we have to add a full gap segment for seg1. Since when seg1 was created we did not know that the parameter p will be part of the interval and seg1 may already be written in the archive when the subsequent segment is encountered, we need to write the gap segment later.
  • Constructor Details

    • PGSegment

      public PGSegment(int parameterGroupId, long interval)
    • PGSegment

      public PGSegment(int parameterGroupId, long interval, int capacity)
    • PGSegment

      public PGSegment(int parameterGroupId, SortedTimeSegment timeSegment, List<ParameterValueSegment> pvSegments)
  • Method Details

    • addRecord

      public void addRecord(long instant, org.yamcs.parameterarchive.BasicParameterList sortedPvList)
    • addRecord

      public void addRecord(long instant, IntArray pids, List<BasicParameterValue> values)
      Add a new record

      instant goes into the timeSegment the values goes each into a value segment

    • consolidate

      public void consolidate()
    • getParameterValue

      public ParameterValueSegment getParameterValue(int pid)
    • getParametersValues

      public MultiParameterValueSegment getParametersValues(ParameterId[] pids)
    • continueSegment

      public void continueSegment(PGSegment prevSegment)
      populate the currentFullGaps and previousFullGaps based on the previous segment parameters and gaps

      sets also the segmentIdxInsideInterval

    • getInterval

      public long getInterval()
    • getSegmentStart

      public long getSegmentStart()
    • getSegmentEnd

      public long getSegmentEnd()
      Returns:
      timestamp of the last parameter in this segment
    • getTimeSegment

      public SortedTimeSegment getTimeSegment()
    • getParameterGroupId

      public int getParameterGroupId()
    • size

      public int size()
      returns the number of rows in the segment group
    • numParameters

      public int numParameters()
      returns the number of parameter segments inside this segment group
    • getParameterId

      public int getParameterId(int idx)
    • isFirstInInterval

      public boolean isFirstInInterval()
    • getSegmentIdxInsideInterval

      public int getSegmentIdxInsideInterval()
      In case the interval is composed of multiple segments, this returns the idx of the segment inside interval.

      For the first segment this will be 0, for the following segments it is the sum of the number of elements of the previous segments.

      The number is used when merging the segments together in the interval to know where the gaps are in the combined interval.

    • isFrozen

      public boolean isFrozen()
    • freeze

      public void freeze()
      after this is called, no more data can be inserted in the segment

      It is used as a safety check when initialising the next segment in the interval

    • wasPreviousGap

      public boolean wasPreviousGap(int pid)
      returns true if this segment contains the first value of this parameter for this interval
    • makeWritable

      public void makeWritable()
      In rare circumstances, a segment read from the archive has to be modified.

      This method updates the object such that it can be modified

    • toString

      public String toString()
      Overrides:
      toString in class Object